加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

php实现银联商务H5支付的示例代码

(2023-02-02 19:05:11)
分类: PHP-GO

转:https://www.zhangshengrong.com/p/O3aAk6p5X4/


银联商务H5支付接口文档:文档地址

一:H5支付的接口地址:

1:支付宝支付

测试地址:http://58.247.0.18:29015/v1/netpay/trade/h5-pay

正式地址:https://api-mop.chinaums.com/v1/netpay/trade/h5-pay

2:银联支付

测试地址:http://58.247.0.18:29015/v1/netpay/uac/order

正式地址:https://api-mop.chinaums.com/v1/netpay/uac/order

二:接口需要的基本参数

接口使用的是get传参,直接将接口参数放到接口地址后,此接口是由浏览器直接跳转到接口

(1)authorization

认证方式,直接填入:OPEN-FORM-PARAM

(2)appId

银联商务用户H5支付产品的AppID

(3)timestamp

时间戳,格式为yyyyMMddHHmmss,如20191001121212

(4)nonce

随机数

(5)content

业务内容,为json格式,并且需要进行url编码,内部的具体信息下面介绍

(6)signature

签名,需要进行url编码,具体生成方式如:Base64_Encode(HmacSHA256(appId + timestamp + nonce + SHA256_HEX(content), AppKey))

业务内容content参数内部具体参数说明:

1:requestTimestamp

报文请求时间,格式为yyyy-MM-dd HH:mm:ss,如2019-10-01 12:12:12

2:merOrderId

商户自己生成的订单号,这里注意:我们需要在我们自己生成的订单号前面加上1017前缀

3:mid

银联商务用户H5支付产品的商户号

4:tid

银联商务用户H5支付产品的终端号

5:instMid

业务类型,直接填入:H5DEFAULT

6:totalAmount

支付总金额,单位为分

7:expireTime

订单过期时间,格式为yyyy-MM-dd HH:mm:ss,如2019-10-02 12:12:12

8:notifyUrl

支付结果通知地址

9:returnUrl

网页跳转地址

三:H5支付的支付宝支付实例


  1. $appId = '10037e6f6a4e6da4016a670fd4530012';
  2. $appKey = 'f7a74b6c02ae4e1e94aaba311c04acf2';
  3. $mid = '898310148160568';
  4. $tid = '88880001';
  5. //业务内容
  6. $time = time();
  7. $content = [
  8. 'requestTimestamp' => date('Y-m-d H:i:s', $time),//报文请求时间
  9. 'merOrderId' => '1017' . date('YmdHis'),//商户订单号
  10. 'mid' => $mid,//商户号
  11. 'tid' => $tid,//终端号
  12. 'instMid' => 'H5DEFAULT',//业务类型
  13. 'totalAmount' => '1',//支付总金额
  14. 'expireTime' => date('Y-m-d H:i:s', strtotime('+1 day', $time)),//过期时间
  15. 'notifyUrl' => '',//支付通知地址
  16. 'returnUrl' => ''//网页跳转地址
  17. ];
  18. $timestamp = date('YmdHis', $time);
  19. //随机数
  20. $str = md5(uniqid(mt_rand(), true));
  21. $uuid = substr($str, 0, 8) . '-';
  22. $uuid .= substr($str, 8, 4) . '-';
  23. $uuid .= substr($str, 12, 4) . '-';
  24. $uuid .= substr($str, 16, 4) . '-';
  25. $uuid .= substr($str, 20, 12);
  26. $nonce = $uuid;
  27. //签名
  28. $hash = bin2hex(hash('sha256', json_encode($content), true));
  29. $hashStr = $appId . $timestamp . $nonce . $hash;
  30. $signature = base64_encode((hash_hmac('sha256', $hashStr, $appKey, true))); //$appKey银联商户H5支付产品的AppKey
  31. $data = [
  32. 'timestamp' => $timestamp,//时间戳
  33. 'authorization' => 'OPEN-FORM-PARAM',//认证方式
  34. 'appId' => $appId,//APPID
  35. 'nonce' => $nonce,//随机数
  36. 'content' => urlencode(json_encode($content)),//业务内容
  37. 'signature' => urlencode($signature),//签名
  38. ];
  39. //接口返回信息
  40. //支付宝:http://58.247.0.18:29015/v1/netpay/trade/h5-pay
  41. //银联在线无卡:http://58.247.0.18:29015/v1/netpay/qmf/h5-pay
  42. //银联:http://58.247.0.18:29015/v1/netpay/uac/order
  43. $options = '';
  44. foreach ($data as $key => $value) {
  45. $options .= $key . '=' . $value .'&';
  46. }
  47. $options = rtrim($options, '&');
  48. //存在转义字符,那么去掉转义
  49. if(get_magic_quotes_gpc()){
  50. $options = stripslashes($options);
  51. }
  52. $url = 'http://58.247.0.18:29015/v1/netpay/trade/h5-pay?' . $options;

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有