Skip to content

沙箱付款码支付

该系统分为两种用例类型:支付成功用例与支付异常用例。请严格按照用例的顺序、金额执行用例,确保用例的检查点完全符合预期。 支付成功用例根据测试用例金额的不同返回不同的响应报文,支付异常用例的识别将通过 Http Header 中添加异常头 Wechatpay-Negative-Test: {用例名} 识别。

请求参数类型描述
xmlarray声明请求的XML数据结构
appidstring公众账号ID
mch_idstring商户号
bodystring商品描述
out_trade_nostring商户订单号
sign_typestring签名类型
MD5 | HMAC-SHA256枚举值之一
默认值 MD5
attachstring附加数据
total_feeinteger订单金额
fee_typestring货币类型
auth_codestring授权码
headersarray请求头
Wechatpay-Negative-Teststring声明所请求的用例名称
php
$instance->v2->xdc->apiv2sandbox->pay->micropay->postAsync([
  'xml' => [
    'version' => '1.0',
    'profit_sharing' => 'N',
    'deposit' => 'Y',
    'appid' => 'wx8888888888888888',
    'sub_appid' => 'wx8888888888888888',
    'mch_id' => '1900000109',
    'sub_mch_id' => '1900000100',
    'device_info' => '013467007045764',
    'sign_type' => 'HMAC-SHA256',
    'body' => 'image形象店-深圳腾大- QQ公仔',
    'attach' => '说明',
    'out_trade_no' => '1217752501201407033233368018',
    'total_fee' => '888',
    'fee_type' => 'CNY',
    'spbill_create_ip' => '8.8.8.8',
    'goods_tag' => '1234',
    'limit_pay' => 'no_credit',
    'time_start' => '20091225091010',
    'time_expire' => '20091227091010',
    'receipt' => 'Y',
    'auth_code' => '120061098828009406',
  ],
  'headers' => [
    'Wechatpay-Negative-Test' => 'MICROPAY_USERPAYING',
  ],
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(\WeChatPay\Transformer::toArray((string)$response->getBody()));
})
->wait();
php
$instance->chain('v2/xdc/apiv2sandbox/pay/micropay')->postAsync([
  'xml' => [
    'version' => '1.0',
    'profit_sharing' => 'N',
    'deposit' => 'Y',
    'appid' => 'wx8888888888888888',
    'sub_appid' => 'wx8888888888888888',
    'mch_id' => '1900000109',
    'sub_mch_id' => '1900000100',
    'device_info' => '013467007045764',
    'sign_type' => 'HMAC-SHA256',
    'body' => 'image形象店-深圳腾大- QQ公仔',
    'attach' => '说明',
    'out_trade_no' => '1217752501201407033233368018',
    'total_fee' => '888',
    'fee_type' => 'CNY',
    'spbill_create_ip' => '8.8.8.8',
    'goods_tag' => '1234',
    'limit_pay' => 'no_credit',
    'time_start' => '20091225091010',
    'time_expire' => '20091227091010',
    'receipt' => 'Y',
    'auth_code' => '120061098828009406',
  ],
  'headers' => [
    'Wechatpay-Negative-Test' => 'MICROPAY_USERPAYING',
  ],
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(\WeChatPay\Transformer::toArray((string)$response->getBody()));
})
->wait();
php
$instance['v2/xdc/apiv2sandbox/pay/micropay']->postAsync([
  'xml' => [
    'version' => '1.0',
    'profit_sharing' => 'N',
    'deposit' => 'Y',
    'appid' => 'wx8888888888888888',
    'sub_appid' => 'wx8888888888888888',
    'mch_id' => '1900000109',
    'sub_mch_id' => '1900000100',
    'device_info' => '013467007045764',
    'sign_type' => 'HMAC-SHA256',
    'body' => 'image形象店-深圳腾大- QQ公仔',
    'attach' => '说明',
    'out_trade_no' => '1217752501201407033233368018',
    'total_fee' => '888',
    'fee_type' => 'CNY',
    'spbill_create_ip' => '8.8.8.8',
    'goods_tag' => '1234',
    'limit_pay' => 'no_credit',
    'time_start' => '20091225091010',
    'time_expire' => '20091227091010',
    'receipt' => 'Y',
    'auth_code' => '120061098828009406',
  ],
  'headers' => [
    'Wechatpay-Negative-Test' => 'MICROPAY_USERPAYING',
  ],
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(\WeChatPay\Transformer::toArray((string)$response->getBody()));
})
->wait();
php
$response = $instance->v2->xdc->apiv2sandbox->pay->micropay->post([
  'xml' => [
    'version' => '1.0',
    'profit_sharing' => 'N',
    'deposit' => 'Y',
    'appid' => 'wx8888888888888888',
    'sub_appid' => 'wx8888888888888888',
    'mch_id' => '1900000109',
    'sub_mch_id' => '1900000100',
    'device_info' => '013467007045764',
    'sign_type' => 'HMAC-SHA256',
    'body' => 'image形象店-深圳腾大- QQ公仔',
    'attach' => '说明',
    'out_trade_no' => '1217752501201407033233368018',
    'total_fee' => '888',
    'fee_type' => 'CNY',
    'spbill_create_ip' => '8.8.8.8',
    'goods_tag' => '1234',
    'limit_pay' => 'no_credit',
    'time_start' => '20091225091010',
    'time_expire' => '20091227091010',
    'receipt' => 'Y',
    'auth_code' => '120061098828009406',
  ],
  'headers' => [
    'Wechatpay-Negative-Test' => 'MICROPAY_USERPAYING',
  ],
]);
print_r(\WeChatPay\Transformer::toArray((string)$response->getBody()));
php
$response = $instance->chain('v2/xdc/apiv2sandbox/pay/micropay')->post([
  'xml' => [
    'version' => '1.0',
    'profit_sharing' => 'N',
    'deposit' => 'Y',
    'appid' => 'wx8888888888888888',
    'sub_appid' => 'wx8888888888888888',
    'mch_id' => '1900000109',
    'sub_mch_id' => '1900000100',
    'device_info' => '013467007045764',
    'sign_type' => 'HMAC-SHA256',
    'body' => 'image形象店-深圳腾大- QQ公仔',
    'attach' => '说明',
    'out_trade_no' => '1217752501201407033233368018',
    'total_fee' => '888',
    'fee_type' => 'CNY',
    'spbill_create_ip' => '8.8.8.8',
    'goods_tag' => '1234',
    'limit_pay' => 'no_credit',
    'time_start' => '20091225091010',
    'time_expire' => '20091227091010',
    'receipt' => 'Y',
    'auth_code' => '120061098828009406',
  ],
  'headers' => [
    'Wechatpay-Negative-Test' => 'MICROPAY_USERPAYING',
  ],
]);
print_r(\WeChatPay\Transformer::toArray((string)$response->getBody()));
php
$response = $instance['v2/xdc/apiv2sandbox/pay/micropay']->post([
  'xml' => [
    'version' => '1.0',
    'profit_sharing' => 'N',
    'deposit' => 'Y',
    'appid' => 'wx8888888888888888',
    'sub_appid' => 'wx8888888888888888',
    'mch_id' => '1900000109',
    'sub_mch_id' => '1900000100',
    'device_info' => '013467007045764',
    'sign_type' => 'HMAC-SHA256',
    'body' => 'image形象店-深圳腾大- QQ公仔',
    'attach' => '说明',
    'out_trade_no' => '1217752501201407033233368018',
    'total_fee' => '888',
    'fee_type' => 'CNY',
    'spbill_create_ip' => '8.8.8.8',
    'goods_tag' => '1234',
    'limit_pay' => 'no_credit',
    'time_start' => '20091225091010',
    'time_expire' => '20091227091010',
    'receipt' => 'Y',
    'auth_code' => '120061098828009406',
  ],
  'headers' => [
    'Wechatpay-Negative-Test' => 'MICROPAY_USERPAYING',
  ],
]);
print_r(\WeChatPay\Transformer::toArray((string)$response->getBody()));
返回字典类型描述
return_codestring返回状态码 SUCCESS | FAIL
return_msgstring返回信息
result_codestring业务结果 SUCCESS | FAIL
err_codestring错误代码
err_code_desstring错误代码描述
trade_typestring交易类型 MICROPAY
trade_statestring交易状态
out_trade_nostring商户订单号
transaction_idstring微信支付订单号
total_feestring标价金额
cash_feestring现金支付金额
coupon_feestring代金券金额

重要提示

  1. $instance 构造实例化时,需要显式初始化 secret 字段,此为沙箱环境密钥,即前序获取沙箱环境密钥获取到的 sandbox_signkey
  2. 请求参数的appid为任意值,官方沙箱环境未做要求,也无需有绑定关系
  3. 此接口请求时,官方会按照支付成功用例所需参数进行校验,即:
    1. 【付款码-正常】订单金额0.01元,用户支付成功
    2. 【付款码-正常】订单金额0.02元(含0.01元代金券),用户支付成功
    3. 【付款码-正常】订单金额0.03元(含0.01元代金券和0.02元免充值现金券),用户支付成功
  4. 此接口第二参数 headers 字段为可选字段,按需显式传递 Wechatpay-Negative-Test 对应的用例名称;
  5. 此接口有QPS限制(官方未公布),高频请求会被官方重定向到腾讯公益404页面;

参阅 官方文档

Published on the GitHub by TheNorthMemory