Skip to content

发放企业红包

红包金额大于200或者小于1元时,请求参数scene_id必传,参数说明见下文。根据监管要求,新申请商户号使用现金红包需要满足两个条件:1、入驻时间超过90天 2、连续正常交易30天。移动应用的appid无法使用红包接口。

请求参数类型描述
securitytrue声明加载商户API证书
xmlobject声明请求的XML数据结构
nonce_strstring随机字符串
mch_billnostring商户订单号
mch_idstring商户号
wxappidstring公众账号appid
agentidinteger发送红包的应用id
sender_namestring发送者名称
sender_header_media_idstring发送者头像
re_openidstring用户openid
total_amountinteger付款金额
wishingstring红包祝福语
act_namestring活动名称
remarkstring备注
scene_idstring场景id
PRODUCT_1 | PRODUCT_2 | PRODUCT_3 | PRODUCT_4 | PRODUCT_5 | PRODUCT_6 | PRODUCT_7 | PRODUCT_8 枚举值之一
workwx_signstring活动信息
php
$workwxSign = \strtoupper(
  \WeChatPay\Crypto\Hash::md5(
    \WeChatPay\Formatter::queryStringLike(
        \WeChatPay\Formatter::ksort([
          'act_name'     => '猜灯谜抢红包活动',
          'mch_billno'   => '10000098201411111234567890',
          'mch_id'       => '10000098',
          'nonce_str'    => '5K8264ILTKCH16CQ2502SI8ZNMTM67VS',
          're_openid'    => 'oxTWIuGaIt6gTKsQRLau2M0yL16E',
          'total_amount' => '1000',
          'wxappid'      => 'wx8888888888888888',
        ])
    ),
    $agentSecret, //应用的secret字符串
    '1' //应用agentid字符串
  )
);
$instance->v2->mmpaymkttransfers->sendworkwxredpack->postAsync([
  'security' => true,
  'xml' => [
    'nonce_str'              => '5K8264ILTKCH16CQ2502SI8ZNMTM67VS',
    'mch_billno'             => '10000098201411111234567890',
    'mch_id'                 => '10000098',
    'wxappid'                => 'wx8888888888888888',
    'agentid'                => '1',
    'sender_name'            => 'XX活动',
    'sender_header_media_id' => '1G6nrLmr5EC3MMb_-zK1dDdzmd0p7cNliYu9V5w7o8K0',
    're_openid'              => 'oxTWIuGaIt6gTKsQRLau2M0yL16E',
    'total_amount'           => '1000',
    'wishing'                => '感谢您参加猜灯谜活动,祝您元宵节快乐!',
    'act_name'               => '猜灯谜抢红包活动',
    'remark'                 => '猜越多得越多,快来抢!',
    'scene_id'               => 'PRODUCT_8',
    'workwx_sign'            => $workwxSign,
  ],
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(\WeChatPay\Transformer::toArray((string) $response->getBody()));
})
->wait();
php
$workwxSign = \strtoupper(
  \WeChatPay\Crypto\Hash::md5(
    \WeChatPay\Formatter::queryStringLike(
        \WeChatPay\Formatter::ksort([
          'act_name'     => '猜灯谜抢红包活动',
          'mch_billno'   => '10000098201411111234567890',
          'mch_id'       => '10000098',
          'nonce_str'    => '5K8264ILTKCH16CQ2502SI8ZNMTM67VS',
          're_openid'    => 'oxTWIuGaIt6gTKsQRLau2M0yL16E',
          'total_amount' => '1000',
          'wxappid'      => 'wx8888888888888888',
        ])
    ),
    $agentSecret, //应用的secret字符串
    '1' //应用agentid字符串
  )
);
$instance->chain('v2/mmpaymkttransfers/sendworkwxredpack')->postAsync([
  'security' => true,
  'xml' => [
    'nonce_str'              => '5K8264ILTKCH16CQ2502SI8ZNMTM67VS',
    'mch_billno'             => '10000098201411111234567890',
    'mch_id'                 => '10000098',
    'wxappid'                => 'wx8888888888888888',
    'agentid'                => '1',
    'sender_name'            => 'XX活动',
    'sender_header_media_id' => '1G6nrLmr5EC3MMb_-zK1dDdzmd0p7cNliYu9V5w7o8K0',
    're_openid'              => 'oxTWIuGaIt6gTKsQRLau2M0yL16E',
    'total_amount'           => '1000',
    'wishing'                => '感谢您参加猜灯谜活动,祝您元宵节快乐!',
    'act_name'               => '猜灯谜抢红包活动',
    'remark'                 => '猜越多得越多,快来抢!',
    'scene_id'               => 'PRODUCT_8',
    'workwx_sign'            => $workwxSign,
  ],
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(\WeChatPay\Transformer::toArray((string) $response->getBody()));
})
->wait();
php
$workwxSign = \strtoupper(
  \WeChatPay\Crypto\Hash::md5(
    \WeChatPay\Formatter::queryStringLike(
        \WeChatPay\Formatter::ksort([
          'act_name'     => '猜灯谜抢红包活动',
          'mch_billno'   => '10000098201411111234567890',
          'mch_id'       => '10000098',
          'nonce_str'    => '5K8264ILTKCH16CQ2502SI8ZNMTM67VS',
          're_openid'    => 'oxTWIuGaIt6gTKsQRLau2M0yL16E',
          'total_amount' => '1000',
          'wxappid'      => 'wx8888888888888888',
        ])
    ),
    $agentSecret, //应用的secret字符串
    '1' //应用agentid字符串
  )
);
$instance['v2/mmpaymkttransfers/sendworkwxredpack']->postAsync([
  'security' => true,
  'xml' => [
    'nonce_str'              => '5K8264ILTKCH16CQ2502SI8ZNMTM67VS',
    'mch_billno'             => '10000098201411111234567890',
    'mch_id'                 => '10000098',
    'wxappid'                => 'wx8888888888888888',
    'agentid'                => '1',
    'sender_name'            => 'XX活动',
    'sender_header_media_id' => '1G6nrLmr5EC3MMb_-zK1dDdzmd0p7cNliYu9V5w7o8K0',
    're_openid'              => 'oxTWIuGaIt6gTKsQRLau2M0yL16E',
    'total_amount'           => '1000',
    'wishing'                => '感谢您参加猜灯谜活动,祝您元宵节快乐!',
    'act_name'               => '猜灯谜抢红包活动',
    'remark'                 => '猜越多得越多,快来抢!',
    'scene_id'               => 'PRODUCT_8',
    'workwx_sign'            => $workwxSign,
  ],
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(\WeChatPay\Transformer::toArray((string) $response->getBody()));
})
->wait();
php
$workwxSign = \strtoupper(
  \WeChatPay\Crypto\Hash::md5(
    \WeChatPay\Formatter::queryStringLike(
        \WeChatPay\Formatter::ksort([
          'act_name'     => '猜灯谜抢红包活动',
          'mch_billno'   => '10000098201411111234567890',
          'mch_id'       => '10000098',
          'nonce_str'    => '5K8264ILTKCH16CQ2502SI8ZNMTM67VS',
          're_openid'    => 'oxTWIuGaIt6gTKsQRLau2M0yL16E',
          'total_amount' => '1000',
          'wxappid'      => 'wx8888888888888888',
        ])
    ),
    $agentSecret, //应用的secret字符串
    '1' //应用agentid字符串
  )
);
$response = $instance->v2->mmpaymkttransfers->sendworkwxredpack->post([
  'security' => true,
  'xml' => [
    'nonce_str'              => '5K8264ILTKCH16CQ2502SI8ZNMTM67VS',
    'mch_billno'             => '10000098201411111234567890',
    'mch_id'                 => '10000098',
    'wxappid'                => 'wx8888888888888888',
    'agentid'                => '1',
    'sender_name'            => 'XX活动',
    'sender_header_media_id' => '1G6nrLmr5EC3MMb_-zK1dDdzmd0p7cNliYu9V5w7o8K0',
    're_openid'              => 'oxTWIuGaIt6gTKsQRLau2M0yL16E',
    'total_amount'           => '1000',
    'wishing'                => '感谢您参加猜灯谜活动,祝您元宵节快乐!',
    'act_name'               => '猜灯谜抢红包活动',
    'remark'                 => '猜越多得越多,快来抢!',
    'scene_id'               => 'PRODUCT_8',
    'workwx_sign'            => $workwxSign,
  ],
]);
print_r(\WeChatPay\Transformer::toArray((string) $response->getBody()));
php
$workwxSign = \strtoupper(
  \WeChatPay\Crypto\Hash::md5(
    \WeChatPay\Formatter::queryStringLike(
        \WeChatPay\Formatter::ksort([
          'act_name'     => '猜灯谜抢红包活动',
          'mch_billno'   => '10000098201411111234567890',
          'mch_id'       => '10000098',
          'nonce_str'    => '5K8264ILTKCH16CQ2502SI8ZNMTM67VS',
          're_openid'    => 'oxTWIuGaIt6gTKsQRLau2M0yL16E',
          'total_amount' => '1000',
          'wxappid'      => 'wx8888888888888888',
        ])
    ),
    $agentSecret, //应用的secret字符串
    '1' //应用agentid字符串
  )
);
$response = $instance->chain('v2/mmpaymkttransfers/sendworkwxredpack')->post([
  'security' => true,
  'xml' => [
    'nonce_str'              => '5K8264ILTKCH16CQ2502SI8ZNMTM67VS',
    'mch_billno'             => '10000098201411111234567890',
    'mch_id'                 => '10000098',
    'wxappid'                => 'wx8888888888888888',
    'agentid'                => '1',
    'sender_name'            => 'XX活动',
    'sender_header_media_id' => '1G6nrLmr5EC3MMb_-zK1dDdzmd0p7cNliYu9V5w7o8K0',
    're_openid'              => 'oxTWIuGaIt6gTKsQRLau2M0yL16E',
    'total_amount'           => '1000',
    'wishing'                => '感谢您参加猜灯谜活动,祝您元宵节快乐!',
    'act_name'               => '猜灯谜抢红包活动',
    'remark'                 => '猜越多得越多,快来抢!',
    'scene_id'               => 'PRODUCT_8',
    'workwx_sign'            => $workwxSign,
  ],
]);
print_r(\WeChatPay\Transformer::toArray((string) $response->getBody()));
php
$workwxSign = \strtoupper(
  \WeChatPay\Crypto\Hash::md5(
    \WeChatPay\Formatter::queryStringLike(
        \WeChatPay\Formatter::ksort([
          'act_name'     => '猜灯谜抢红包活动',
          'mch_billno'   => '10000098201411111234567890',
          'mch_id'       => '10000098',
          'nonce_str'    => '5K8264ILTKCH16CQ2502SI8ZNMTM67VS',
          're_openid'    => 'oxTWIuGaIt6gTKsQRLau2M0yL16E',
          'total_amount' => '1000',
          'wxappid'      => 'wx8888888888888888',
        ])
    ),
    $agentSecret, //应用的secret字符串
    '1' //应用agentid字符串
  )
);
$response = $instance['v2/mmpaymkttransfers/sendworkwxredpack']->post([
  'security' => true,
  'xml' => [
    'nonce_str'              => '5K8264ILTKCH16CQ2502SI8ZNMTM67VS',
    'mch_billno'             => '10000098201411111234567890',
    'mch_id'                 => '10000098',
    'wxappid'                => 'wx8888888888888888',
    'agentid'                => '1',
    'sender_name'            => 'XX活动',
    'sender_header_media_id' => '1G6nrLmr5EC3MMb_-zK1dDdzmd0p7cNliYu9V5w7o8K0',
    're_openid'              => 'oxTWIuGaIt6gTKsQRLau2M0yL16E',
    'total_amount'           => '1000',
    'wishing'                => '感谢您参加猜灯谜活动,祝您元宵节快乐!',
    'act_name'               => '猜灯谜抢红包活动',
    'remark'                 => '猜越多得越多,快来抢!',
    'scene_id'               => 'PRODUCT_8',
    'workwx_sign'            => $workwxSign,
  ],
]);
print_r(\WeChatPay\Transformer::toArray((string) $response->getBody()));
返回字典类型描述
return_codestring返回状态码
SUCCESS | FAIL 枚举值之一
return_msgstring返回信息
signstring微信支付签名
result_codestring业务结果
SUCCESS | FAIL 枚举值之一
err_codestring错误代码
err_code_desstring错误代码描述
mch_billnostring商户订单号
mch_idstring商户号
wxappidstring公众账号appid
re_openidstring用户openid
total_amountinteger付款金额
send_listidstring微信单号
sender_namestring发送者名称
sender_header_media_idstring发送者头像

参阅 官方文档

Published on the GitHub by TheNorthMemory