沙箱付款码支付
该系统分为两种用例类型:支付成功用例与支付异常用例。请严格按照用例的顺序、金额执行用例,确保用例的检查点完全符合预期。 支付成功用例根据测试用例金额的不同返回不同的响应报文,支付异常用例的识别将通过 Http Header 中添加异常头 Wechatpay-Negative-Test: {用例名}
识别。
请求参数 | 类型 | 描述 |
---|---|---|
headers | object | 声明请求的头参数 |
Wechatpay-Negative-Test | string | 异常用例名称MICROPAY_USERPAYING | MICROPAY_TIMEOUT | MICROPAY_PAYERROR | MICROPAY_PAY_QUERY_TIMEOUT 枚举值之一 |
xml | object | 声明请求的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 | 授权码 |
php
$instance->v2->xdc->apiv2sandbox->pay->micropay->postAsync([
'headers' => [
'Wechatpay-Negative-Test' => 'MICROPAY_USERPAYING',
],
'xml' => [
'appid' => 'wx8888888888888888',
'mch_id' => '1900000109',
'sign_type' => 'HMAC-SHA256',
'body' => 'image形象店-深圳腾大- QQ公仔',
'attach' => '说明',
'out_trade_no' => '1217752501201407033233368018',
'total_fee' => '888',
'fee_type' => 'CNY',
'auth_code' => '120061098828009406',
],
])
->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([
'headers' => [
'Wechatpay-Negative-Test' => 'MICROPAY_USERPAYING',
],
'xml' => [
'appid' => 'wx8888888888888888',
'mch_id' => '1900000109',
'sign_type' => 'HMAC-SHA256',
'body' => 'image形象店-深圳腾大- QQ公仔',
'attach' => '说明',
'out_trade_no' => '1217752501201407033233368018',
'total_fee' => '888',
'fee_type' => 'CNY',
'auth_code' => '120061098828009406',
],
])
->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([
'headers' => [
'Wechatpay-Negative-Test' => 'MICROPAY_USERPAYING',
],
'xml' => [
'appid' => 'wx8888888888888888',
'mch_id' => '1900000109',
'sign_type' => 'HMAC-SHA256',
'body' => 'image形象店-深圳腾大- QQ公仔',
'attach' => '说明',
'out_trade_no' => '1217752501201407033233368018',
'total_fee' => '888',
'fee_type' => 'CNY',
'auth_code' => '120061098828009406',
],
])
->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([
'headers' => [
'Wechatpay-Negative-Test' => 'MICROPAY_USERPAYING',
],
'xml' => [
'appid' => 'wx8888888888888888',
'mch_id' => '1900000109',
'sign_type' => 'HMAC-SHA256',
'body' => 'image形象店-深圳腾大- QQ公仔',
'attach' => '说明',
'out_trade_no' => '1217752501201407033233368018',
'total_fee' => '888',
'fee_type' => 'CNY',
'auth_code' => '120061098828009406',
],
]);
print_r(\WeChatPay\Transformer::toArray((string)$response->getBody()));
php
$response = $instance->chain('v2/xdc/apiv2sandbox/pay/micropay')->post([
'headers' => [
'Wechatpay-Negative-Test' => 'MICROPAY_USERPAYING',
],
'xml' => [
'appid' => 'wx8888888888888888',
'mch_id' => '1900000109',
'sign_type' => 'HMAC-SHA256',
'body' => 'image形象店-深圳腾大- QQ公仔',
'attach' => '说明',
'out_trade_no' => '1217752501201407033233368018',
'total_fee' => '888',
'fee_type' => 'CNY',
'auth_code' => '120061098828009406',
],
]);
print_r(\WeChatPay\Transformer::toArray((string)$response->getBody()));
php
$response = $instance['v2/xdc/apiv2sandbox/pay/micropay']->post([
'headers' => [
'Wechatpay-Negative-Test' => 'MICROPAY_USERPAYING',
],
'xml' => [
'appid' => 'wx8888888888888888',
'mch_id' => '1900000109',
'sign_type' => 'HMAC-SHA256',
'body' => 'image形象店-深圳腾大- QQ公仔',
'attach' => '说明',
'out_trade_no' => '1217752501201407033233368018',
'total_fee' => '888',
'fee_type' => 'CNY',
'auth_code' => '120061098828009406',
],
]);
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 | 交易状态SUCCESS | REFUND | NOTPAY | CLOSED | REVOKED | USERPAYING | PAYERROR | ACCEPT 枚举值之一 |
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页面;
参阅 官方文档