This article mainly introduces the WeChat payment plug-in implemented by Thinkphp and onethink in detail. Interested friends can refer to the WeChat payment plug-in implemented by
thinkPHP and WeChat to call WeChat in WeChat. jssdk implements payment, here are the detailed codes and tutorials, see here for details:
//实现的Wxpay钩子方法 public function Wxpay($param){ require './Addons/Wxpay/WxPayPubHelper/WxPayPubHelper.php'; $jsApi = new \JsApi_pub(); //=========步骤1:网页授权获取用户openid============ if (!isset($_GET['code'])) { //触发微信返回code码 $url = $jsApi->createOauthUrlForCode(\WxPayConf_pub::JS_API_CALL_URL.'/order_id/'.$param['order_id']); Header("Location: $url"); }else { $order_id = $param['order_id']; $info = M('Order')->where('id='.$order_id)->find(); if(empty($info) || $info['is_pay'] == 1){ dump('该订单不存在或已支付'.$order_id); exit(); } $this->assign('info', $info); $a = $info['money']; $b = 100; $c = $a * $b; //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } //=========步骤2:使用统一支付接口,获取prepay_id============ //使用统一支付接口 $unifiedOrder = new \UnifiedOrder_pub(); $unifiedOrder->setParameter("openid","$openid");//商品描述 $unifiedOrder->setParameter("body","在线预订");//商品描述 //自定义订单号,此处仅作举例 $timeStamp = time(); // $out_trade_no = \WxPayConf_pub::APPID."$timeStamp"; $out_trade_no = $info['ordersn']; $unifiedOrder->setParameter("out_trade_no", "$out_trade_no");//商户订单号 $unifiedOrder->setParameter("total_fee", "$c");//总金额 $unifiedOrder->setParameter("notify_url",\WxPayConf_pub::NOTIFY_URL.'/order_id/'.$param['order_id']);//通知地址 $unifiedOrder->setParameter("trade_type","JSAPI");//交易类型 $prepay_id = $unifiedOrder->getPrepayId(); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); $this->assign('jsApiParameters', $jsApiParameters); $this->display('pay'); }
The above is the entire content of this article, I hope it will help everyone learn PHP Programming helps.
For more articles related to Thinkphp and onethink implementing the WeChat payment plug-in, please pay attention to the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
