From 3904ff73741e15e06b11c5d976f51ed9bd97bd82 Mon Sep 17 00:00:00 2001 From: lihan <3398341942@qq.com> Date: Wed, 10 Oct 2018 13:21:43 +0800 Subject: [PATCH] 部署微信环境 --- app/cart/controller/ZjCartController.php | 5 ++++- app/pay/controller/PayController.php | 15 ++++++++------- data/conf/config.php | 7 +++++++ public/themes/simpleboot3/cart/zj_cart/order_confirm.html | 22 +++++++++++++++++++++- simplewind/extend/Payment.php | 2 +- simplewind/extend/WeChatCommon.php | 4 ++-- 6 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 data/conf/config.php diff --git a/app/cart/controller/ZjCartController.php b/app/cart/controller/ZjCartController.php index 7767f79..bf364d0 100644 --- a/app/cart/controller/ZjCartController.php +++ b/app/cart/controller/ZjCartController.php @@ -143,6 +143,8 @@ class ZjCartController extends HomeBaseController } } } + require_once EXTEND_PATH.'/WeChatCommon.php'; + $wx =new \WeChatCommon(); return $this->fetch('order_confirm', [ 'data' => $data, 'address' => $address, @@ -152,7 +154,8 @@ class ZjCartController extends HomeBaseController 'default_address' => $default_address, 'total_num' => $total_num, 'total_price' => $total_price, - 'caid' => $data[0]['caid'] + 'caid' => $data[0]['caid'], + //'js_sdk' => $wx->js_sdk() ]); } diff --git a/app/pay/controller/PayController.php b/app/pay/controller/PayController.php index 8741587..22e63d4 100644 --- a/app/pay/controller/PayController.php +++ b/app/pay/controller/PayController.php @@ -11,6 +11,8 @@ class PayController extends HomeBaseController parent::_initialize(); // TODO: Change the autogenerated stub if (empty(session('user.id'))) { $this->error('登录失败'); + } else { + require_once EXTEND_PATH . '/Payment.php'; } } @@ -68,7 +70,11 @@ class PayController extends HomeBaseController ]; $this->wxPay($info); } + } else { + Db::rollback(); } + } else { + Db::rollback(); } } } @@ -76,19 +82,14 @@ class PayController extends HomeBaseController //微信支付 public function wxPay($info) { - require_once EXTEND_PATH . '/Payment.php'; $pay = new \Payment($info['attach'], $info['openid'], $info['body'], $info['total_fee']); $this->success('微信支付', '', $pay->pay()); } - public function notify() { - require_once EXTEND_PATH . '/Payment.php'; + public function notify() + { $pay = new \Payment(); $pay->handleNotify(); } - public function jifen() { - - } - } \ No newline at end of file diff --git a/data/conf/config.php b/data/conf/config.php new file mode 100644 index 0000000..3803ea1 --- /dev/null +++ b/data/conf/config.php @@ -0,0 +1,7 @@ +<?php +return [ + 'AppID' => 'wx1d5467ad61a2070c', + 'AppSecret' => '85aefa43e70b9daa273b2eea168397bc', + 'Key' => 'Fj4LDtdT8PY6MGcC9eI9n1I1qYdd8KU7', + 'MchId' => '1263633001' +]; \ No newline at end of file diff --git a/public/themes/simpleboot3/cart/zj_cart/order_confirm.html b/public/themes/simpleboot3/cart/zj_cart/order_confirm.html index c315a50..16406e2 100644 --- a/public/themes/simpleboot3/cart/zj_cart/order_confirm.html +++ b/public/themes/simpleboot3/cart/zj_cart/order_confirm.html @@ -10,6 +10,7 @@ <link rel="stylesheet" href="__INDEX__/css/order.css"> <link rel="stylesheet" href="__INDEX__/css/swiper.min.css"> <script type="text/javascript" src="__INDEX__/js/base.js" charset="utf-8"></script> + <script src="http://res2.wx.qq.com/open/js/jweixin-1.4.0.js"></script> <title>确认订单</title> <style> .entermoney{ @@ -244,7 +245,16 @@ success: function (data) { if(data.data === true) { - console.log(data.msg); + wx.chooseWXPay({ + timestamp: 0, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符 + nonceStr: '', // 支付签名随机串,不长于 32 位 + package: '', // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*) + signType: '', // 签名方式,默认为'SHA1',使用新版支付需传入'MD5' + paySign: '', // 支付签名 + success: function (res) { + // 支付成功后的回调函数 + } + }); } } }) @@ -276,6 +286,16 @@ address_id = id; }) + wx.config({ + debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 + appId: '', // 必填,公众号的唯一标识 + timestamp: '', // 必填,生成签名的时间戳 + nonceStr: '', // 必填,生成签名的随机串 + signature: '',// 必填,签名 + jsApiList: [ + 'chooseWXPay' + ] // 必填,需要使用的JS接口列表 + }); </script> </html> diff --git a/simplewind/extend/Payment.php b/simplewind/extend/Payment.php index ac9c63a..b9ab763 100644 --- a/simplewind/extend/Payment.php +++ b/simplewind/extend/Payment.php @@ -48,7 +48,7 @@ class Payment { 'out_trade_no' => config('MchId').time(), 'total_fee' => $this->total_fee, 'spbill_create_ip' => '114.215.223.17', //终端IP - 'notify_url' => '', + 'notify_url' => 'http://integral.w.bronet.cn/pay/Pay/notify', 'openid' => $this->openid, 'trade_type' => 'JSAPI',//交易类型 'attach' => $this->attach diff --git a/simplewind/extend/WeChatCommon.php b/simplewind/extend/WeChatCommon.php index 174c365..f015e4d 100644 --- a/simplewind/extend/WeChatCommon.php +++ b/simplewind/extend/WeChatCommon.php @@ -146,12 +146,12 @@ class WeChatCommon { */ public function js_sdk(){ $timestamp=time(); - $string='jsapi_ticket='.$this->get_jsapi_ticket().'&noncestr='.config('nonceStr').'×tamp='.$timestamp.'&url='.'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; + $string='jsapi_ticket='.$this->get_jsapi_ticket().'&noncestr=je9omv03bc5ryqz1×tamp='.$timestamp.'&url='.'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $signature=sha1($string); return array( 'appId' => config('AppId'), 'timestamp' => $timestamp, - 'nonceStr' => config('nonceStr'), + 'nonceStr' => 'je9omv03bc5ryqz1', 'signature' => $signature, ); } -- libgit2 0.24.0