這篇文章主要為大家詳細(xì)介紹了thinkphp和onethink實(shí)現(xiàn)微信支付插件,感興趣的小伙伴們可以參考一下
thinkPHP和微支付實(shí)現(xiàn)的微信支付插件,在微信中調(diào)用微信jssdk實(shí)現(xiàn)支付,這里有詳細(xì)的代碼和教程,具體看這里:
//實(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'); }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)PHP程序設(shè)計(jì)有所幫助。
更多Thinkphp和onethink實(shí)現(xiàn)微信支付插件相關(guān)文章請(qǐng)關(guān)注PHP中文網(wǎng)!
立即學(xué)習(xí)“PHP免費(fèi)學(xué)習(xí)筆記(深入)”;
微信是一款手機(jī)通信軟件,支持通過(guò)手機(jī)網(wǎng)絡(luò)發(fā)送語(yǔ)音短信、視頻、圖片和文字。微信可以單聊及群聊,還能根據(jù)地理位置找到附近的人,帶給大家全新的移動(dòng)溝通體驗(yàn),有需要的小伙伴快來(lái)保存下載體驗(yàn)吧!
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://m.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)