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:
//實(shí)現(xiàn)的Wxpay鉤子方法 public function Wxpay($param){ require './Addons/Wxpay/WxPayPubHelper/WxPayPubHelper.php'; $jsApi = new \JsApi_pub(); //=========步驟1:網(wǎng)頁(yè)授權(quán)獲取用戶openid============ if (!isset($_GET['code'])) { //觸發(fā)微信返回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:使用統(tǒng)一支付接口,獲取prepay_id============ //使用統(tǒng)一支付接口 $unifiedOrder = new \UnifiedOrder_pub(); $unifiedOrder->setParameter("openid","$openid");//商品描述 $unifiedOrder->setParameter("body","在線預(yù)訂");//商品描述 //自定義訂單號(hào),此處僅作舉例 $timeStamp = time(); // $out_trade_no = \WxPayConf_pub::APPID."$timeStamp"; $out_trade_no = $info['ordersn']; $unifiedOrder->setParameter("out_trade_no", "$out_trade_no");//商戶訂單號(hào) $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調(diào)起支付============ $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

Undress AI Tool
Undress images for free

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

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

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
