微信支付v3版PHP解密代码如何改写为长尾词?
- 内容介绍
- 文章标签
- 相关推荐
本文共计861个文字,预计阅读时间需要4分钟。
微信支付V3版本小程序支持支付+PHP签名、验签、数据解密代码分享,微信支付V3版+PHP解密代码+数据解密需用到sodium扩展,大部分PHP版本需安装,证书序列号可在https://myssl.com/c查看
微信支付V3版本小程序支付 php签名,验签,数据解密代码分享微信支付v3版 php解密解密代码
数据解密需要用到sodium扩展 大部分php版本需要安装
证书序列号可以在这里查看myssl.com/cert_decode.html
我用的php7.4版本
直接上代码:
//微信原生支付 class Wxpay { /* * 支付(小程序支付) * @param type $sn 订单编号 * @param type $money 金额 * @param type $openid 用户小程序openid * @return type */ public static function getPayParam($sn, $money, $openid) { $url = 'api.mch.weixin.qq.com/v3/pay/transactions/jsapi'; $notify_url = url('/api/weixin/notify'); $data = []; $data['appid'] = Action::config(CONFIG_WXXCX, 'app_id'); $data['mchid'] = Action::config(CONFIG_WXXCX, 'mchid'); //商户号 $data['description'] = 'xxx'; //描述? $data['out_trade_no'] = $sn; //商户系统内部订单号 $data['time_expire'] = date('Y-m-d') . 'T' . date('H:i:s', (time() + 1800)) . '+08:00'; //订单失效时间2018-06-08T10:34:56+08:00 $data['notify_url'] = $notify_url; //异步通知接口地址 $data['amount'] = ['total' => $money * 100, 'currency' => 'CNY']; //金额 $data['payer'] = ['openid' => $openid]; //用户 $re = self::wxCurl($url, $data, 'POST'); if (!isset($re['prepay_id'])) { api_fail('参数获取失败'); } $result = []; $result['appId'] = Action::config(CONFIG_WXXCX, 'app_id'); $result['timeStamp'] = (string)time(); $result['nonceStr'] = uniqid(); $result['package'] = 'prepay_id=' . $re['prepay_id']; $result['signType'] = 'RSA'; $result['paySign'] = self::getPaySign($result); return $result; } /** * 查询订单 * @param type $sn */ public static function select($sn, $return = false) { $mchid = Action::config(CONFIG_WXXCX, 'mchid'); //商户号 $url = 'api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/' . $sn . '?mchid=' . $mchid; $re = self::wxCurl($url, [], 'GET'); if ($return) { return $re; } if (isset($re['trade_state']) && $re['trade_state'] == 'SUCCESS') { return true; } return false; } /** * 关闭订单 * @param type $sn */ public static function close($sn) { $mchid = Action::config(CONFIG_WXXCX, 'mchid'); //商户号 $url = 'api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/' . $sn . '/close'; $re = self::wxCurl($url, ['mchid'=>$mchid], 'POST'); return true; } /** * 退款 * @param type $sn */ public static function refund($order_sn,$refund_sn,$total,$refund,$msg='退款') { $url='api.mch.weixin.qq.com/v3/refund/domestic/refunds'; $data=[]; $data['notify_url']=url('ag/weixin/notify_refund'); $data['out_trade_no']=$order_sn;//订单号 $data['out_refund_no']=$refund_sn;//退款单号 $data['reason']=$msg; $data['amount']=['refund'=>$refund*100,'total'=>$total*100,'currency'=>'CNY']; $re = self::wxCurl($url, $data, 'POST'); return $re; } //请求 public static function wxCurl($url, $data = [], $method = 'GET') { $Authorization = self::getReSign($url, $data, $method); $header = [ 'Content-Type: application/json', 'Accept: application/json', 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.63', 'Authorization: ' . $Authorization ]; $redata = $data ? json_encode($data) : ''; $res = reCurl($url, $redata, $header); return $res ? json_decode($res, true) : []; } //后端请求签名 public static function getReSign($url, $data, $method = 'GET') { $url_parts = parse_url($url); $canonical_url = ($url_parts['path'] . (!empty($url_parts['query']) ? "?${url_parts['query']}" : "")); $api.mch.weixin.qq.com/v3/certificates'; $re = self::wxCurl($url, [], 'GET'); if (!isset($re['data'])) { api_fail('获取证书失败'); } $ciphertext = $re['data'][0]['encrypt_certificate']['ciphertext']; $associatedData = $re['data'][0]['encrypt_certificate']['associated_data']; $nonceStr = $re['data'][0]['encrypt_certificate']['nonce']; $data = self::decryptToString($ciphertext, $associatedData, $nonceStr); if (!$data) { api_fail('获取证书解密失败'); } file_put_contents(BASE_PATH . '/cert/wx_public_cert.pem', $data); return $data; } }
以上就是分享微信支付v3版 php解密解密代码的详细内容,更多请关注自由互联其它相关文章!
本文共计861个文字,预计阅读时间需要4分钟。
微信支付V3版本小程序支持支付+PHP签名、验签、数据解密代码分享,微信支付V3版+PHP解密代码+数据解密需用到sodium扩展,大部分PHP版本需安装,证书序列号可在https://myssl.com/c查看
微信支付V3版本小程序支付 php签名,验签,数据解密代码分享微信支付v3版 php解密解密代码
数据解密需要用到sodium扩展 大部分php版本需要安装
证书序列号可以在这里查看myssl.com/cert_decode.html
我用的php7.4版本
直接上代码:
//微信原生支付 class Wxpay { /* * 支付(小程序支付) * @param type $sn 订单编号 * @param type $money 金额 * @param type $openid 用户小程序openid * @return type */ public static function getPayParam($sn, $money, $openid) { $url = 'api.mch.weixin.qq.com/v3/pay/transactions/jsapi'; $notify_url = url('/api/weixin/notify'); $data = []; $data['appid'] = Action::config(CONFIG_WXXCX, 'app_id'); $data['mchid'] = Action::config(CONFIG_WXXCX, 'mchid'); //商户号 $data['description'] = 'xxx'; //描述? $data['out_trade_no'] = $sn; //商户系统内部订单号 $data['time_expire'] = date('Y-m-d') . 'T' . date('H:i:s', (time() + 1800)) . '+08:00'; //订单失效时间2018-06-08T10:34:56+08:00 $data['notify_url'] = $notify_url; //异步通知接口地址 $data['amount'] = ['total' => $money * 100, 'currency' => 'CNY']; //金额 $data['payer'] = ['openid' => $openid]; //用户 $re = self::wxCurl($url, $data, 'POST'); if (!isset($re['prepay_id'])) { api_fail('参数获取失败'); } $result = []; $result['appId'] = Action::config(CONFIG_WXXCX, 'app_id'); $result['timeStamp'] = (string)time(); $result['nonceStr'] = uniqid(); $result['package'] = 'prepay_id=' . $re['prepay_id']; $result['signType'] = 'RSA'; $result['paySign'] = self::getPaySign($result); return $result; } /** * 查询订单 * @param type $sn */ public static function select($sn, $return = false) { $mchid = Action::config(CONFIG_WXXCX, 'mchid'); //商户号 $url = 'api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/' . $sn . '?mchid=' . $mchid; $re = self::wxCurl($url, [], 'GET'); if ($return) { return $re; } if (isset($re['trade_state']) && $re['trade_state'] == 'SUCCESS') { return true; } return false; } /** * 关闭订单 * @param type $sn */ public static function close($sn) { $mchid = Action::config(CONFIG_WXXCX, 'mchid'); //商户号 $url = 'api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/' . $sn . '/close'; $re = self::wxCurl($url, ['mchid'=>$mchid], 'POST'); return true; } /** * 退款 * @param type $sn */ public static function refund($order_sn,$refund_sn,$total,$refund,$msg='退款') { $url='api.mch.weixin.qq.com/v3/refund/domestic/refunds'; $data=[]; $data['notify_url']=url('ag/weixin/notify_refund'); $data['out_trade_no']=$order_sn;//订单号 $data['out_refund_no']=$refund_sn;//退款单号 $data['reason']=$msg; $data['amount']=['refund'=>$refund*100,'total'=>$total*100,'currency'=>'CNY']; $re = self::wxCurl($url, $data, 'POST'); return $re; } //请求 public static function wxCurl($url, $data = [], $method = 'GET') { $Authorization = self::getReSign($url, $data, $method); $header = [ 'Content-Type: application/json', 'Accept: application/json', 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.63', 'Authorization: ' . $Authorization ]; $redata = $data ? json_encode($data) : ''; $res = reCurl($url, $redata, $header); return $res ? json_decode($res, true) : []; } //后端请求签名 public static function getReSign($url, $data, $method = 'GET') { $url_parts = parse_url($url); $canonical_url = ($url_parts['path'] . (!empty($url_parts['query']) ? "?${url_parts['query']}" : "")); $api.mch.weixin.qq.com/v3/certificates'; $re = self::wxCurl($url, [], 'GET'); if (!isset($re['data'])) { api_fail('获取证书失败'); } $ciphertext = $re['data'][0]['encrypt_certificate']['ciphertext']; $associatedData = $re['data'][0]['encrypt_certificate']['associated_data']; $nonceStr = $re['data'][0]['encrypt_certificate']['nonce']; $data = self::decryptToString($ciphertext, $associatedData, $nonceStr); if (!$data) { api_fail('获取证书解密失败'); } file_put_contents(BASE_PATH . '/cert/wx_public_cert.pem', $data); return $data; } }
以上就是分享微信支付v3版 php解密解密代码的详细内容,更多请关注自由互联其它相关文章!

