相关关键词
关于我们
最新文章
1元云购微信支付功能开发 - 1元云购网站开发
发布日期:2016-11-18 16:03:00
947
1、微信支付的账户配置在程序里面,修改不方便;
2、或者能微信支付,但是微信支付成功后,并不会生成充值订单(账户的资金不变)和云购记录(下单不成功);
3、或者在手机端购买的时候支付方式根本不能选择微信支付。
本站已经完美解决以上问题,以下将1元云购微信支付的开发记录简单介绍下(这里是说微信支付不是微信扫码支付)。
1、数据库方面新增微信支付记录
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:使用统一支付接口,获取prepay_id============//使用统一支付接口$unifiedOrder = new UnifiedOrder_pub();//设置统一支付接口参数//设置必填参数//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发起页面
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有修改,有需要的朋友可以联系本站或者淘宝上购买。淘宝微信支付插件购买地址。