小程序模板網(wǎng)

小程序與php 實(shí)現(xiàn)微信支付

發(fā)布時(shí)間:2018-04-20 11:30 所屬欄目:小程序開(kāi)發(fā)教程

小程序訪問(wèn)地址: 
payfee.PHP:

 

				
  1. [php] view plain copy
  2. include 'WeixinPay.php';
  3. $appid='';
  4. $openid= $_GET['id'];
  5. $mch_id='';
  6. $key='';
  7. $out_trade_no = $mch_id. time();
  8. $total_fee = $_GET['fee'];
  9. if(empty($total_fee)) //押金
  10. {
  11. $body = "充值押金";
  12. $total_fee = floatval(99*100);
  13. }
  14. else {
  15. $body = "充值余額";
  16. $total_fee = floatval($total_fee*100);
  17. }
  18. $weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee);
  19. $return=$weixinpay->pay();
  20.  
  21. echo json_encode($return);

WeixinPay.php:

 

				
  1. [php] view plain copy
  2. <?php
  3.  
  4.  
  5. /*
  6. * 小程序微信支付
  7. */
  8.  
  9.  
  10. class WeixinPay {
  11.  
  12.  
  13. protected $appid;
  14. protected $mch_id;
  15. protected $key;
  16. protected $openid;
  17. protected $out_trade_no;
  18. protected $body;
  19. protected $total_fee;
  20. function __construct($appid, $openid, $mch_id, $key,$out_trade_no,$body,$total_fee) {
  21. $this->appid = $appid;
  22. $this->openid = $openid;
  23. $this->mch_id = $mch_id;
  24. $this->key = $key;
  25. $this->out_trade_no = $out_trade_no;
  26. $this->body = $body;
  27. $this->total_fee = $total_fee;
  28. }
  29.  
  30.  
  31. public function pay() {
  32. //統(tǒng)一下單接口
  33. $return = $this->weixinapp();
  34. return $return;
  35. }


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開(kāi)源 碼云倉(cāng)庫(kù):starfork
本文地址:http://22321a.com/wxmini/doc/course/23798.html 復(fù)制鏈接 如需定制請(qǐng)聯(lián)系易優(yōu)客服咨詢:800182392 點(diǎn)擊咨詢
QQ在線咨詢