幽灵资源网 Design By www.bzswh.com
本文实例为大家分享了thinkphp5微信扫码支付的具体代码,供大家参考,具体内容如下
配置WxPay.Config.php
控制器
//微信支付
//参数 订单 价格
public function wxPay($order_number,$money)
{
header("Content-type:text/html;charset=utf-8");
//require_once VENDOR_PATH.'/alipaymobile/config.php';
require_once VENDOR_PATH.'/wxpay/WxPay.Api.php';//引入微信支付
require_once VENDOR_PATH.'/wxpay/WxPay.Notify.php';
require_once VENDOR_PATH.'/wxpay/phpqrcode/phpqrcode.php';
$input = new \WxPayUnifiedOrder();//统一下单
$config = new \WxPayConfig();//配置参数
$notify = new \QRcode();
//$paymoney = input('post.paymoney'); //支付金额
$paymoney = $money; //测试写死
//$paymoney = 0.01; //测试写死
//$str = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);//生成订单号
$out_trade_no = $order_number; //商户订单号(自定义)
$goods_name = '扫码支付'.$paymoney.'元'; //商品名称(自定义)
$input->SetBody($goods_name);
$input->SetAttach($goods_name);
$input->SetOut_trade_no($out_trade_no);
$input->SetTotal_fee($paymoney*100);//金额乘以100
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag("test");
//回调地址 注意能访问
$input->SetNotify_url("http://www.域名.com/index.php/index/index/wxpaynotifyurl"); //回调地址
$input->SetTrade_type("NATIVE");
$input->SetProduct_id('123456789');//商品id
$result = \WxPayApi::unifiedOrder($config, $input);
if($result['result_code']=='SUCCESS' && $result['return_code']=='SUCCESS') {
$url = $result["code_url"];
$this->assign('money',$paymoney);
$this->assign('url',$url);
$this->assign('num',$out_trade_no);
//映射视图 微信二维码需要自己生成
return view("../../../template/wxpay");
}else{
$this->error('参数错误');
}
// return view();
}
视图 生成二维码 进行扫描付款
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>微信支付页面</title>
<style>
.wxsm{ width:1200px; margin:0 auto; overflow:hidden;}
.wxsmt{ width:100%; height:40px; border-bottom:1px solid #ccc;}
.wxsmt h2{ font-size:14px; line-height:40px; color:#232323; font-weight:400; text-align:center;}
.wxsmc{ width:100%; overflow:hidden;}
.smcr{ overflow:hidden; margin:0 auto; }
.smcr h2{ font-size:14px; font-weight:400; line-height:40px; text-align:center;}
.smcr h2 span{ font-size:20px; color:#f23535;}
.smcrb{ width:100%; overflow:hidden;;}
.smm{ width:218px; height:284px; border:1px solid #3cb035; background:#3cb035; margin:0 auto}
.smm img{ width:218px; height:218px; background:#fff;}
.smm span{ display:block; color:#fff; line-height:66px; text-align:center;}
</style>
<script src="/UploadFiles/2021-04-02/jquery-1.10.1.min.js">
支付回调
public function wxpaynotifyurl()
{
//$xml = $GLOBALS['HTTP_RAW_POST_DATA']; //返回的xml
$xml = file_get_contents("php://input");
//$results = db('fund') -> where('id',1) -> update(['a'=>$xml]);exit();
$xmlArr = $this->Init($xml);
file_put_contents(dirname(__FILE__).'/xml.txt',$xml); //记录日志 支付成功后查看xml.txt文件是否有内容 如果有xml格式文件说明回调成功
$out_trade_no=$xmlArr['out_trade_no']; //订单号
$total_fee=$xmlArr['total_fee']/100; //回调回来的xml文件中金额是以分为单位的
$result_code=$xmlArr['result_code']; //状态
//$result = db('order') -> where(['order' => $out_trade_no]) -> find();
//if($result['price'] == $total_fee){
if($result_code=='SUCCESS'){ //数据库操作
//处理数据库操作 例如修改订单状态 给账户充值等等
echo 'SUCCESS'; //返回成功给微信端 一定要带上不然微信会一直回调8次
exit;
}else{ //失败
return false;
exit;
}
}
public function Init($xml)
{
$array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $array_data;
}
简单的写了一下 能实现简单的thinkphp5+微信扫码支付的大体流程 若有有问题的地方 还请各位大神指点
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
幽灵资源网 Design By www.bzswh.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
幽灵资源网 Design By www.bzswh.com
暂无评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
