PHP SDK(utf-8) JAVA SDK(utf-8) ASP.NET SDK(utf-8) ASP SDK
https://api.xunhupay.com/payment/do.html
使用curl的post方式传参数,并直接获取json返回值,引导客户跳转到支付链接。
支持GET301跳转请求(需额外参数:redirect=Y),无需使用CURL工具提前请求数据。请求示例:浏览器访问https://api.xunhupay.com/payment/do.html?appid=xxx&price=xxx&....&redirect=Y&hash=xxxx
# | 参数名 | 含义 | 类型 | 说明 |
---|---|---|---|---|
1 | version | API 版本号 | string(24) | 必填。目前为1.1 |
2 | appid | APP ID | string(32) | 必填。支付渠道ID |
3 | trade_order_id | 商户订单号 | string(32) | 必填。请确保在当前网站内是唯一订单号 |
4 | total_fee | 订单金额(元) | decimal(18,2) | 必填。单位为人民币,精确到分 |
5 | title | 订单标题 | string(128) | 必填。商户订单标题 |
6 | time | 当前时间戳 | int(11) | 必填。PHP示例:time() |
7 | notify_url | 通知回调网址 | string(128) | 必填。用户支付成功后,我们服务器会主动发送一个post消息到这个网址(注意:当前接口内,SESSION内容无效) |
8 | return_url | 跳转网址 | string(128) | 可选。用户支付成功后,我们会让用户浏览器自动跳转到这个网址 |
9 | callback_url | 商品网址 | string(128) | 可选。用户取消支付后,我们可能引导用户跳转到这个网址上重新进行支付 |
10 | plugins | 备注 | string(128) | 可选。备注字段,可以传入一些备注数据,回调时原样返回 |
11 | nonce_str | 随机值 | string(32) | 必填。作用:1.避免服务器页面缓存,2.防止安全密钥被猜测出来 |
12 | hash | 签名 | string(32) | 必填。 |
13 | redirect=Y | get请求 | string(32) | GET请求必填 |
# | 参数名 | 含义 | 类型 | 说明 |
---|---|---|---|---|
1 | oderid | 订单id | int | 订单id |
2 | url_qrcode | 二维码地址 | string(156) | 可将该参数生成二维码展示出来进行扫码支付 |
3 | url | 请求url | string(155) | |
4 | errcode | 错误码 | int | |
5 | errmsg | 错误信息 | string(8) | 错误信息具体值 |
6 | hash | 签名 | string(32) | 数据签名,参考下面签名算法 |
第一步,设所有发送或者接收到的数据为集合M,将集合M内非空参数值的参数按照参数名ASCII码从小到大排序(字典序),使用URL键值对的格式(即key1=value1&key2=value2…)拼接成字符串stringA。
特别注意以下重要规则:
第二步,在stringA最后拼接上APPSECRET
得到stringSignTemp字符串,并对stringSignTemp进行MD5运算,得到hash值。
function generate_xh_hash(array $datas,$hashkey){ ksort($datas); reset($datas); $arg = ''; foreach ($datas as $key=>$val){ if($key=='hash'||is_null($val)||$val===''){continue;} if($arg){$arg.='&';} $arg.="$key=$val"; } return md5($arg.$hashkey); }
{ "openid":"2019081202", "url":"https:\/\/api.xunhupay.com\/alipay\/pay\/index.html?id=20351731&nonce_str=3642452019&time=1522390464&appid=20146122002&hash=ef07fb856239c6066a8c84c21835e047", "errcode":0, "errmsg":"success!", "hash":"3a91e22ee359c914b0788c6007377638" }
{ "openid":"2019081202", "appid":"1237839372", "prepay_id":"nxhhjkaoasixuwjewnekwpoapxajjasasas", "jsapi":"{"a":1,"b":2}", "errcode":0, "errmsg":"success!", "hash":"3a91e22ee359c914b0788c6007377638" }
{ "errcode":500, "errmsg":"invalid sign!", "hash":"3a91e22ee359c914b0788c6007377638" }
用户付款成功后,我们会向您在发起付款接口传入的notify_url网址发送通知。您的服务器只要返回内容:success
,就表示回调已收到。如果返回内容不是success
,我们会再尝试回调1次。
# | 参数名 | 含义 | 类型 | 说明 |
---|---|---|---|---|
1 | trade_order_id | 商户订单号 | string(32) | 支付时请求的商户订单号 |
2 | total_fee | 订单支付金额 | decimal(18,2) | 订单支付金额 |
3 | transaction_id | 交易号 | string(32) | 支付平台内部订单号 |
4 | open_order_id | 虎皮椒内部订单号 | string(32) | 虎皮椒内部订单号 |
5 | order_title | 订单标题 | string(32) | 订单标题 |
6 | status | 订单状态 | string(2) | 目前固定值为:OD |
7 | plugins | 插件ID | string(32) | 当传入此参数时才会有返回 |
8 | appid | 支付渠道ID | string(32) | |
9 | time | 时间戳 | string(16) | |
10 | nonce_str | 随即字符串 | string(16) | |
11 | hash | 签名 | string(32) | 请参考支付时签名算法 |
用户付款成功后,我们会在先通过notify_url
接口,通知您服务器付款成功,然后引导用户跳转到return_url
网址。