微信小程序怎样用PHP实现支付功能

  介绍

这篇文章主要介绍微信小程序怎样用PHP实现支付功能,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

<强>微信小程序支付功能实现PHP实例详解

前端代码:

,wx.request ({   ,,,url:, & # 39; https://www.yourhost.com/weixin/WeiActivity/payJoinfee& # 39;//改成你自己的链接   ,,,头:,{   ,,,,,& # 39;内容类型# 39;:,& # 39;应用程序/x-www-form-urlencoded& # 39;   ,,,},   ,,,方法:& # 39;文章# 39;   成功,,,:,函数(res), {   ,,,,,console.log (res.data);   ,,,,,console.log(& # 39;调起支付& # 39;);   ,,,,,wx.requestPayment ({   ,,,,,,,& # 39;时间戳# 39;:,res.data.timeStamp,   ,,,,,,,& # 39;nonceStr& # 39;:, res.data.nonceStr,   ,,,,,,,& # 39;包# 39;:,res.data.package,   ,,,,,,,& # 39;signType& # 39;:, & # 39; md5 # 39;   ,,,,,,,& # 39;paySign& # 39;:, res.data.paySign,   ,,,,,,,& # 39;成功# 39;:函数(res) {   ,,,,,,,,,console.log(& # 39;成功# 39;);   ,,,,,,,,,wx.showToast ({   ,,,,,,,,,,,标题:,& # 39;支付成功& # 39;,   ,,,,,,,,,,,图标:,& # 39;成功# 39;   ,,,,,,,,,,,时间:3000年   ,,,,,,,,,});   ,,,,,,,},   ,,,,,,,& # 39;失败# 39;:函数(res) {   ,,,,,,,,,console.log(& # 39;失败# 39;);   ,,,,,,,},   ,,,,,,,& # 39;不能# 39;:函数(res) {   ,,,,,,,,,console.log(& # 39;不能# 39;);   ,,,,,,,}   ,,,,,});   ,,,},   ,,,失败:函数(res) {   ,,,,,console.log (res.data)   ,,,}   });才能

<强>后端代码:

//支付费用   ,public  function  payJoinfee () {   ,$ appid=& # 39; wx888888888& # 39;;   ,$ openid=& # 39; oCQwY0Q_pzrQpu8888888& # 39;;   ,$ mch_id=& # 39; 141388888 & # 39;;   ,$关键=& # 39;9 a0a86888888888& # 39;;   ,   ,进口(& # 39;Weixin.Lib.WeixinPay& # 39;);   ,weixinpay 美元;=,new  \ WeixinPay (appid美元,美元openid, mch_id美元,美元键);   ,返回=weixinpay→美元支付();      ,$ this→响应(美元回报,& # 39;json # 39;);   以前,}

<强>微信支付类

& lt; php ?/*   ,*小程序微信支付   ,*/class  WeixinPay {   ,protected  appid美元;   ,protected  mch_id美元;   ,protected 美元关键;   ,protected  openid美元;   ,function  __construct (appid美元,美元openid, mch_id美元,美元键){   ,$ this→appid=$ appid;   ,$ this→openid=$ openid;   ,$ this→mch_id=$ mch_id;   ,$ this→键=$键;   }大敌;   ,public  function 支付(){   ,//统一下单接口   ,返回=这→美元weixinapp ();   ,return 美元返回;   ,}   ,//统一下单接口   ,private  function  unifiedorder () {   ,$ url=& # 39; https://api.mch.weixin.qq.com/pay/unifiedorder& # 39;;   ,$=参数数组(   & # 39;才能appid& # 39;=祝辞;$ this→appid,//小程序ID   & # 39;才能mch_id& # 39;=祝辞;$ this→mch_id,//商户号   & # 39;才能nonce_str& # 39;=祝辞;$ this→createNoncestr()//随机字符串   & # 39;才能身体# 39;=祝辞& # 39;测试& # 39;,//商品描述   & # 39;才能out_trade_no& # 39;=祝辞& # 39;2015450806125346 & # 39;//商户订单号   & # 39;才能total_fee& # 39;=祝辞floatval(0.01 * 100)//总金额,单位,分   & # 39;才能spbill_create_ip& # 39;=祝辞;$ _SERVER [& # 39; REMOTE_ADDR& # 39;],//终端IP   & # 39;才能notify_url& # 39;=祝辞& # 39;http://www.weixin.qq.com/wxpay/pay.php& # 39;//通知地址   & # 39;才能openid # 39;=祝辞;$ this→openid,//用户id   & # 39;才能trade_type& # 39;=祝辞& # 39;jsapi # 39;//交易类型   ,);   ,//统一下单签名   ,$参数[& # 39;符号# 39;]=$这→getSign(参数);   美元,美元xmlData=https://www.yisu.com/zixun/arrayToXml(参数);      美元回报=xmlToArray (postXmlSSLCurl (xmlData, url,美元60));      返回美元返回;   }//微信小程序接口   私有函数weixinapp () {//统一下单接口   $ unifiedorder=$ this -> unifiedorder ();      $=参数数组(   “appId”=> $ this -> appId,//小程序ID   “时间戳”=>“.time() ",//时间戳   “nonceStr”=> $ this -> createNoncestr()//随机串   “包”=>“prepay_id='。美元unifiedorder [' prepay_id '],//数据包   “signType”=>“MD5的//签名方式   );//签名   $参数[' paySign ']=$ this -> getSign(参数);      返回参数美元;   }//作用:产生随机字符串,不长于32位   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

微信小程序怎样用PHP实现支付功能