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

吾爱主题 阅读:161 2021-08-31 16:16:00 评论:0

银联商务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支付的支付宝支付实例

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

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

原文链接:https://segmentfault.com/a/1190000020661486

可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

【腾讯云】云服务器产品特惠热卖中
搜索
标签列表
    关注我们

    了解等多精彩内容