Home> php教程> php手册> body text

TP combined with WeChat scan code payment mode 2

WBOY
Release: 2016-09-23 03:29:56
Original
1364 people have browsed it

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
$goodsid=time();
$order = time();
$notify = new \NativePay();
$input = new \WxPayUnifiedOrder(); //调用统一下单类
$input->SetBody($body);//这是商品标题
$input->SetAttach($body);
$input->SetOut_trade_no($goodsid);//这是单号
$input->SetTotal_fee($money*100);//这是金额,微信金额是按分计算,所以要 *100
//$input->SetTotal_fee("1");
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 7200));
$input->SetNotify_url('http://'.$_SERVER['HTTP_HOST'].U('Member/notify'));
$input->SetTrade_type("NATIVE");
$input->SetProduct_id($goodsid);
$out_trade_no = $input->GetOut_trade_no();
$result = $notify->GetPayUrl($input);
$url = $result["code_url"];//这就是返回的二维码地址,要在前端生成二维码
$arr['out_trade_no']=$out_trade_no;
$arr['code_url']=$url;
$arr['order']=$order;
以下是生成二维码的jquery,先引入生成二维码的js,也可以用其他方法[js文件我会打包]
window.onload = function(){
var c_url="";
   qr_code(c_url);
};
//生成二维码
function qr_code(url,out_trade_no,order){
if(url){
//参数1表示图像大小,取值范围1-10;参数2表示质量,取值范围'L','M','Q','H'
var qr = qrcode(10, 'M');
qr.addData(url);
qr.make();
var code=document.createElement('DIV');
code.innerHTML = qr.createImgTag();
var element=document.getElementById("code_url");
element.appendChild(code);
}
}
//生成的二维码会出现在这里

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(){
setInterval(function(){check()}, 3000); //Execute ajax every three seconds
Function check(){
var out_trade_no = $("#code_url").attr('out_trade_no');
var order = $("#code_url").attr('order');
$.ajax({
type: "post",
   url: '{:U("Member/orderquery")}', //Request function
async: false,
Data: {'out_trade_no':out_trade_no,'order':order},
DataType: "json",
Success: function (data) {
if (data.status) {
layer.msg(data.info,{btn:'OK'},function(){
Parent.location.reload(); })
}else{
result = false;
}
}
});
}
})
Here is the requested program code (the actions performed after successful payment can be modified according to your needs)

//Check if payment is completedTP combined with WeChat scan code payment mode 2Public function orderquery($out_trade_no=null, $orderid=null){$out_trade_no = $_POST['out_trade_no'];
$order = $_POST['order'];
If(isset($out_trade_no) && $out_trade_no != ""){
$out_trade_no = $_REQUEST["out_trade_no"];
$input = new WxPayOrderQuery();
$input->SetOut_trade_no($out_trade_no);
$result = WxPayApi::orderQuery($input);
}
$cash_fee=$result['cash_fee']/100;//Payment amount
/*Determine whether payment is successful*/
if ( $data=array('goodsid'=>$result['out_trade_no'],'status'=>1,'pay_type'=>2);
$cz=M('cz_records')->where($data)->find();
if($cz){
if(M('cz_records')->where($data)->save(array('money'=>$cash_fee,'transaction_id'=>$result['transaction_id'],'status'= >2))){
if($this->set_money($cz['uid'],$cz['type'],C('date'),$cz['money'],$cz['transaction_id'])){
$ This-& gt; success ('Successful payment:'. $ Cash_fee. 'Yuan');
}
}
}
} }
Password to decompress the compressed package: www.renweinet.net



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

source:php.cn
Statement of this Website
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
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!