沙箱付款码支付
该系统分为两种用例类型:支付成功用例与支付异常用例。请严格按照用例的顺序、金额执行用例,确保用例的检查点完全符合预期。 支付成功用例根据测试用例金额的不同返回不同的响应报文,支付异常用例的识别将通过 Http Header 中添加异常头 Wechatpay-Negative-Test: {用例名}
识别。
请求参数 | 类型 | 描述 |
---|---|---|
xml | array | 声明请求的XML 数据结构 |
appid | string | 公众账号ID |
mch_id | string | 商户号 |
body | string | 商品描述 |
out_trade_no | string | 商户订单号 |
sign_type | string | 签名类型MD5 | HMAC-SHA256 枚举值之一默认值 MD5 |
attach | string | 附加数据 |
total_fee | integer | 订单金额 |
fee_type | string | 货币类型 |
auth_code | string | 授权码 |
headers | array | 请求头 |
Wechatpay-Negative-Test | string | 声明所请求的用例名称 |
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_code | string | 返回状态码 SUCCESS | FAIL |
return_msg | string | 返回信息 |
result_code | string | 业务结果 SUCCESS | FAIL |
err_code | string | 错误代码 |
err_code_des | string | 错误代码描述 |
trade_type | string | 交易类型 MICROPAY |
trade_state | string | 交易状态 |
out_trade_no | string | 商户订单号 |
transaction_id | string | 微信支付订单号 |
total_fee | string | 标价金额 |
cash_fee | string | 现金支付金额 |
coupon_fee | string | 代金券金额 |
重要提示
- $instance 构造实例化时,需要显式初始化 secret 字段,此为沙箱环境密钥,即前序获取沙箱环境密钥获取到的 sandbox_signkey;
- 请求参数的appid为任意值,官方沙箱环境未做要求,也无需有绑定关系;
- 此接口请求时,官方会按照支付成功用例所需参数进行校验,即:
- 【付款码-正常】订单金额0.01元,用户支付成功
- 【付款码-正常】订单金额0.02元(含0.01元代金券),用户支付成功
- 【付款码-正常】订单金额0.03元(含0.01元代金券和0.02元免充值现金券),用户支付成功
- 此接口第二参数 headers 字段为可选字段,按需显式传递 Wechatpay-Negative-Test 对应的用例名称;
- 此接口有QPS限制(官方未公布),高频请求会被官方重定向到腾讯公益404页面;
参阅 官方文档