Home  >  Article  >  php教程  >  TP combined with WeChat scan code payment mode 2

TP combined with WeChat scan code payment mode 2

WBOY
WBOYOriginal
2016-09-23 03:29:561427browse

tp结合微信扫码支付模式二
首先引入微信下载的类,可以用我打包的,名称我修改了的
TP combined with WeChat scan code payment mode 2
把微信类放到thinkphp核心框架的Library\Vendor\下面
在微信类的Config.php 文件里面配置数据
TP combined with WeChat scan code payment mode 2
然后在要使用的模块中调用
TP combined with WeChat scan code payment mode 2
然后在获取支付二维码的方法中写
TP combined with WeChat scan code payment mode 2$money=1<br> $goodsid=time();<br> $order = time();<br> $notify = new \NativePay();<br> $input = new \WxPayUnifiedOrder(); //调用统一下单类<br> $input->SetBody($body);//这是商品标题<br> $input->SetAttach($body);<br> $input->SetOut_trade_no($goodsid);//这是单号<br> $input->SetTotal_fee($money*100);//这是金额,微信金额是按分计算,所以要   *100<br> //$input->SetTotal_fee("1");<br> $input->SetTime_start(date("YmdHis"));<br> $input->SetTime_expire(date("YmdHis", time() + 7200));<br> $input->SetNotify_url('http://'.$_SERVER['HTTP_HOST'].U('Member/notify'));<br> $input->SetTrade_type("NATIVE");<br> $input->SetProduct_id($goodsid);<br> $out_trade_no = $input->GetOut_trade_no();<br> $result = $notify->GetPayUrl($input);<br> $url = $result["code_url"];//这就是返回的二维码地址,要在前端生成二维码<br> $arr['out_trade_no']=$out_trade_no;<br> $arr['code_url']=$url;<br> $arr['order']=$order; 以下是生成二维码的jquery,先引入生成二维码的js,也可以用其他方法[js文件我会打包]
window.onload = function(){<br>     var c_url="<?php echo $arr[&#039;code_url&#039;];?>";<br>    qr_code(c_url);<br> };<br> //生成二维码<br> function qr_code(url,out_trade_no,order){<br>     if(url){<br>         //参数1表示图像大小,取值范围1-10;参数2表示质量,取值范围'L','M','Q','H'<br>         var qr = qrcode(10, 'M');<br>         qr.addData(url);<br>         qr.make();<br>         var code=document.createElement('DIV');<br>         code.innerHTML = qr.createImgTag();<br>         var element=document.getElementById("code_url");<br>         element.appendChild(code);    <br>     }    <br> }<br> //生成的二维码会出现在这里<br> <div></div>TP combined with WeChat scan code payment mode 2

Then it is judged whether the user has scanned the code to pay
I put an asynchronous code that queries every 3 seconds on the page where the QR code is generated$(function(){<br> setInterval(function(){check()}, 3000); //Execute ajax every three seconds<br> Function check(){<br>         var out_trade_no = $("#code_url").attr('out_trade_no');<br>       var order = $("#code_url").attr('order');<br>           $.ajax({<br>            type: "post",<br>    url: '{:U("Member/orderquery")}', //Request function<br> async: false,<br> Data: {'out_trade_no':out_trade_no,'order':order},<br> DataType: "json",<br> Success: function (data) {<br>                                                                                                                                                                                                                                              if (data.status) {<br> layer.msg(data.info,{btn:'OK'},function(){<br>                                                                                                                                                                                       Parent.location.reload();                                                                                                                                                                                 })<br>                                                                                                                                                                                                                                                                     }else{<br>                    result = false;<br>                  }<br>             }<br>          });<br> }<br> })<br>Here is the requested program code (the actions performed after successful payment can be modified according to your needs)<br>
//Check if payment is completedTP combined with WeChat scan code payment mode 2 Public function orderquery($out_trade_no=null, $orderid=null){         $out_trade_no = $_POST['out_trade_no'];<br>        $order = $_POST['order'];<br> If(isset($out_trade_no) && $out_trade_no != ""){<br>            $out_trade_no = $_REQUEST["out_trade_no"];<br>            $input = new WxPayOrderQuery();<br>               $input->SetOut_trade_no($out_trade_no);<br>            $result = WxPayApi::orderQuery($input);<br>        }<br>         $cash_fee=$result['cash_fee']/100;//Payment amount<br> /*Determine whether payment is successful*/<br>                                                                                                                                                                                                                                                                                                        if (               $data=array('goodsid'=>$result['out_trade_no'],'status'=>1,'pay_type'=>2);<br>                $cz=M('cz_records')->where($data)->find();<br>               if($cz){<br>if(M('cz_records')->where($data)->save(array('money'=>$cash_fee,'transaction_id'=>$result['transaction_id'],'status'= >2))){<br> if($this->set_money($cz['uid'],$cz['type'],C('date'),$cz['money'],$cz['transaction_id'])){ <br> $ This-& gt; success ('Successful payment:'. $ Cash_fee. 'Yuan'); <br>                             }<br>                                                                                               }<br>        }<br> } }<br>Password to decompress the compressed package: www.renweinet.net


WeChat scan code payment.zip TP combined with WeChat scan code payment mode 2( 23.33 KB Download: 0 times )

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn