相關關鍵詞
關于我們
最新文章
1元云購微信支付功能開發(fā) - 1元云購網站開發(fā)
1元云購是時下比較流行的電子商務模式,1元云購系統(tǒng)現(xiàn)在在網上也比較多,但是大多數(shù)的網站建設源碼是比較老的版本,要么就是沒有微信支付功能,要么就是微信支付功能有缺陷,例如
1、微信支付的賬戶配置在程序里面,修改不方便;
2、或者能微信支付,但是微信支付成功后,并不會生成充值訂單(賬戶的資金不變)和云購記錄(下單不成功);
3、或者在手機端購買的時候支付方式根本不能選擇微信支付。
本站已經完美解決以上問題,以下將1元云購微信支付的開發(fā)記錄簡單介紹下(這里是說微信支付不是微信掃碼支付)。

1、數(shù)據庫方面新增微信支付記錄
INSERT INTO `go_pay` VALUES ('9', '微信支付微信端', 'wxpay_web', '0', 'photo/weixin.gif', '微信支付微信端', '1', 'a:4:{s:5:\"APPID\";a:2:{s:4:\"name\";s:5:\"APPID\";s:3:\"val\";s:18:\"wxf748387954333\";}s:5:\"MCHID\";a:2:{s:4:\"name\";s:11:\"受理商ID\";s:3:\"val\";s:10:\"13800138000\";}s:3:\"KEY\";a:2:{s:4:\"name\";s:9:\"密鑰Key\";s:3:\"val\";s:32:\"s8738478871872782\";}s:9:\"APPSECRET\";a:2:{s:4:\"name\";s:9:\"APPSECRET\";s:3:\"val\";s:32:\"1111111bb3ce66533abb3a2d6b\";}}', '1');
2、微信支付class類
位置system\modules\pay\lib\wxpay_web.class.php
class wxpay_web {private $config;private $code;public function config($config=null){if (!$config ) {$pay = $this->db->GetOne("SELECT * from `@#_pay` where `pay_class` = 'wxpay_web'");$config = array();$config['pay_type_data'] = unserialize($pay['pay_key']);}$this->config = $config;$this->code = $_GET['code'];}public function send_pay(){$config = $this->config;$code = $this->code;include_once dirname(__FILE__)."/wxpay/WxPayPubHelper.php";$jsApi = new JsApi_pub();if (!isset($code)){$url = G_WEB_PATH.'/index.php/pay/wxpay_web_url/?money='.$config['money'].'&out_trade_no='.$config['code'];$url = $jsApi->createOauthUrlForCode(urlencode($url));header("Location: $url");die;}else{$jsApi->setCode($code);$openid = $jsApi->getOpenId();}//=========步驟2:使用統(tǒng)一支付接口,獲取prepay_id============//使用統(tǒng)一支付接口$unifiedOrder = new UnifiedOrder_pub();//設置統(tǒng)一支付接口參數(shù)//設置必填參數(shù)//appid已填,商戶無需重復填寫//mch_id已填,商戶無需重復填寫//noncestr已填,商戶無需重復填寫//spbill_create_ip已填,商戶無需重復填寫//sign已填,商戶無需重復填寫$unifiedOrder->setParameter("openid",$openid);$unifiedOrder->setParameter("body","購買商品");//商品描述$unifiedOrder->setParameter("out_trade_no",$config['code']);//商戶訂單號$unifiedOrder->setParameter("total_fee",$config['money']*100);//總金額*100$unifiedOrder->setParameter("notify_url",$config['NotifyUrl']);//通知地址$unifiedOrder->setParameter("trade_type","JSAPI");//交易類型$prepay_id = $unifiedOrder->getPrepayId();//=========步驟3:使用jsapi調起支付============$jsApi->setPrepayId($prepay_id);$jsApiParameters = $jsApi->getParameters();include('wxpay_web.html.php');}}
3、微信支付jsapi發(fā)起頁面
wxpay_web.html.php 位置system\modules\pay\lib\wxpay_web.html.php
<!DOCTYPE html><html><head><meta http-equiv="content-type" content="text/html;charset=utf-8"/><title>微信安全支付</title><script type="text/javascript">//調用微信JS api 支付function jsApiCall(){WeixinJSBridge.invoke('getBrandWCPayRequest',<?php echo $jsApiParameters; ?>,function(res) {if (res.err_msg == "get_brand_wcpay_request:ok") {location.replace("<?php echo WEB_PATH ?>/mobile/cart/paysuccess");} else if (res.err_msg == "get_brand_wcpay_request:cancel") {location.replace("<?php echo WEB_PATH ?>/pay/wxpay_web_url/payinfo/cancel");} else if (res.err_msg == "get_brand_wcpay_request:fail") {location.replace("<?php echo WEB_PATH ?>/pay/wxpay_web_url/payinfo/fail");} else {location.replace("<?php echo WEB_PATH ?>/pay/wxpay_web_url/payinfo/" + encodeURIComponent(res.err_msg));}});}function callpay(){if (typeof WeixinJSBridge == "undefined"){if( document.addEventListener ){document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);}else if (document.attachEvent){document.attachEvent('WeixinJSBridgeReady', jsApiCall);document.attachEvent('onWeixinJSBridgeReady', jsApiCall);}}else{jsApiCall();}}</script></head><body onLoad="callpay();"></br></br></br></br><div align="center"></div></body></html>
微信支付的回調地址處理程序和pay.class.php有修改,有需要的朋友可以聯(lián)系本站或者淘寶上購買。淘寶微信支付插件購買地址。