微信支付小程序v3后端PHP代码如何实现?

2026-04-17 23:261阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计495个文字,预计阅读时间需要2分钟。

微信支付小程序v3后端PHP代码如何实现?

微信支付+小程序(v3)- PHP完整后端代码,踩坑太多,不多说,直接上完整后端代码:php

微信支付 小程序 (v3)- PHP 完整后端代码

踩坑太多,不多说,直接上完整后端代码

<?php header('Content-type:text/html; Charset=utf-8'); ini_set('date.timezone','Asia/Shanghai'); $data_s = file_get_contents('php://input'); $data_s = json_decode($data_s,true); //统一下单 function wechartAddOrder($name,$ordernumber,$money,$openid,$timeStamp,$noncestr){ $url = "api.mch.weixin.qq.com/v3/pay/transactions/jsapi"; $urlarr = parse_url($url); $appid = '小程序APPID';//appID $mchid = '微信支付商户ID';//商户ID $xlid = '微信支付公钥序列号';//秘钥序列号 可在这个网址中查询 myssl.com/cert_decode.html $data = array(); $time = $timeStamp; $data['appid'] = $appid; $data['mchid'] = $mchid; $data['description'] = $name;//商品描述 $data['out_trade_no'] = $ordernumber;//订单编号 $data['notify_url'] = "你的域名/你的支付目录路径/notify.php";//回调接口 需根据自己的情况修改 $data['amount']['total'] = intval($money * 1);//金额 单位 分 $data['payer']['openid'] = $openid;//用户openID $data = json_encode($data); $key = getSign($data,$urlarr['path'],$noncestr,$time);//签名 $token = sprintf('mchid="%s",serial_no="%s",nonce_str="%s",timestamp="%d",signature="%s"',$mchid,$xlid,$noncestr,$time,$key);//头部信息 $header = array( 'Content-Type:'.'application/json; charset=UTF-8', 'Accept:application/json', 'User-Agent:*/*', 'Authorization: WECHATPAY2-SHA256-RSA2048 '.$token ); $ret = curl_post_input'); $data_s = json_decode($data_s,true); if(empty($data_s['out_trade_no'])){ exit; } $out_trade_no = $data_s['out_trade_no'];//订单号 $merchant_id = '商户ID';//商户ID $mch_private_key = file_get_contents('apiclient_key.pem');//在商户平台下载的秘钥 $xlid = '微信支付公钥序列号';//秘钥序列号 可在这个网址中查询 myssl.com/cert_decode.html $url = 'api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/'.$out_trade_no.'?mchid='.$merchant_id; $url_parts = parse_url($url); $csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-b5506197d8.css"/>

以上就是关于微信支付小程序v3的详细内容,更多请关注自由互联其它相关文章!

微信支付小程序v3后端PHP代码如何实现?

本文共计495个文字,预计阅读时间需要2分钟。

微信支付小程序v3后端PHP代码如何实现?

微信支付+小程序(v3)- PHP完整后端代码,踩坑太多,不多说,直接上完整后端代码:php

微信支付 小程序 (v3)- PHP 完整后端代码

踩坑太多,不多说,直接上完整后端代码

<?php header('Content-type:text/html; Charset=utf-8'); ini_set('date.timezone','Asia/Shanghai'); $data_s = file_get_contents('php://input'); $data_s = json_decode($data_s,true); //统一下单 function wechartAddOrder($name,$ordernumber,$money,$openid,$timeStamp,$noncestr){ $url = "api.mch.weixin.qq.com/v3/pay/transactions/jsapi"; $urlarr = parse_url($url); $appid = '小程序APPID';//appID $mchid = '微信支付商户ID';//商户ID $xlid = '微信支付公钥序列号';//秘钥序列号 可在这个网址中查询 myssl.com/cert_decode.html $data = array(); $time = $timeStamp; $data['appid'] = $appid; $data['mchid'] = $mchid; $data['description'] = $name;//商品描述 $data['out_trade_no'] = $ordernumber;//订单编号 $data['notify_url'] = "你的域名/你的支付目录路径/notify.php";//回调接口 需根据自己的情况修改 $data['amount']['total'] = intval($money * 1);//金额 单位 分 $data['payer']['openid'] = $openid;//用户openID $data = json_encode($data); $key = getSign($data,$urlarr['path'],$noncestr,$time);//签名 $token = sprintf('mchid="%s",serial_no="%s",nonce_str="%s",timestamp="%d",signature="%s"',$mchid,$xlid,$noncestr,$time,$key);//头部信息 $header = array( 'Content-Type:'.'application/json; charset=UTF-8', 'Accept:application/json', 'User-Agent:*/*', 'Authorization: WECHATPAY2-SHA256-RSA2048 '.$token ); $ret = curl_post_input'); $data_s = json_decode($data_s,true); if(empty($data_s['out_trade_no'])){ exit; } $out_trade_no = $data_s['out_trade_no'];//订单号 $merchant_id = '商户ID';//商户ID $mch_private_key = file_get_contents('apiclient_key.pem');//在商户平台下载的秘钥 $xlid = '微信支付公钥序列号';//秘钥序列号 可在这个网址中查询 myssl.com/cert_decode.html $url = 'api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/'.$out_trade_no.'?mchid='.$merchant_id; $url_parts = parse_url($url); $csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-b5506197d8.css"/>

以上就是关于微信支付小程序v3的详细内容,更多请关注自由互联其它相关文章!

微信支付小程序v3后端PHP代码如何实现?