小程序模板网

小程序与php 实现微信支付

小程序访问地址: 
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. //统一下单接口
  33. $return = $this->weixinapp();
  34. return $return;
  35. }


易优小程序(企业版)+灵活api+前后代码开源 码云仓库:starfork
本文地址:https://www.eyoucms.com/wxmini/doc/course/23798.html 复制链接 如需定制请联系易优客服咨询:800182392 点击咨询
QQ在线咨询