|
@@ -2,8 +2,12 @@ |
|
@@ -2,8 +2,12 @@ |
2
|
|
2
|
|
3
|
namespace app\index\controller;
|
3
|
namespace app\index\controller;
|
4
|
|
4
|
|
|
|
5
|
+use addons\litestore\model\Litestoreorder;
|
|
|
6
|
+use addons\third\model\Third;
|
|
|
7
|
+use addons\wechat\library\Config as ConfigService;
|
5
|
use app\common\controller\Frontend;
|
8
|
use app\common\controller\Frontend;
|
6
|
use EasyWeChat\Foundation\Application;
|
9
|
use EasyWeChat\Foundation\Application;
|
|
|
10
|
+use EasyWeChat\Foundation\Application as WXPAY_APP;
|
7
|
use think\Db;
|
11
|
use think\Db;
|
8
|
use think\Lang;
|
12
|
use think\Lang;
|
9
|
|
13
|
|
|
@@ -14,9 +18,16 @@ use think\Lang; |
|
@@ -14,9 +18,16 @@ use think\Lang; |
14
|
class Ajax extends Frontend
|
18
|
class Ajax extends Frontend
|
15
|
{
|
19
|
{
|
16
|
|
20
|
|
17
|
- protected $noNeedLogin = ['lang','refund_notify'];
|
21
|
+ protected $noNeedLogin = ['lang','callback_for_wxgzh','refund_notify'];
|
18
|
protected $noNeedRight = ['*'];
|
22
|
protected $noNeedRight = ['*'];
|
19
|
protected $layout = '';
|
23
|
protected $layout = '';
|
|
|
24
|
+ public function _initialize()
|
|
|
25
|
+ {
|
|
|
26
|
+ parent::_initialize();
|
|
|
27
|
+ $this->user_id = $this->auth->id;
|
|
|
28
|
+ $this->model = new Litestoreorder;
|
|
|
29
|
+
|
|
|
30
|
+ }
|
20
|
|
31
|
|
21
|
/**
|
32
|
/**
|
22
|
* 加载语言包
|
33
|
* 加载语言包
|
|
@@ -38,10 +49,66 @@ class Ajax extends Frontend |
|
@@ -38,10 +49,66 @@ class Ajax extends Frontend |
38
|
}
|
49
|
}
|
39
|
|
50
|
|
40
|
/**
|
51
|
/**
|
|
|
52
|
+ * 支付结果回调
|
|
|
53
|
+ */
|
|
|
54
|
+ public function callback_for_wxgzh(){
|
|
|
55
|
+ $this->init_wx_pay_for_gzh(false);
|
|
|
56
|
+ $response = $this->wxapp->payment->handleNotify(function($notify, $successful){
|
|
|
57
|
+ $order = $this->model->payDetail($notify->out_trade_no);
|
|
|
58
|
+
|
|
|
59
|
+ if (empty($order)) { // 如果订单不存在
|
|
|
60
|
+ return true;
|
|
|
61
|
+ //return 'Order not exist.'; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
|
|
|
62
|
+ }
|
|
|
63
|
+ if ($successful) {
|
|
|
64
|
+ $order->updatePayStatus($notify->transaction_id);
|
|
|
65
|
+ }
|
|
|
66
|
+
|
|
|
67
|
+ return true; // 返回处理完成
|
|
|
68
|
+ });
|
|
|
69
|
+
|
|
|
70
|
+ $response->send();
|
|
|
71
|
+ }
|
|
|
72
|
+
|
|
|
73
|
+ private function init_wx_pay_for_gzh($Ischeck=false){
|
|
|
74
|
+ //这里首先判断 此用户是否绑定了微信公众号
|
|
|
75
|
+ if($Ischeck){
|
|
|
76
|
+ $third = Third::where(['user_id' => $this->user_id, 'platform' => 'wechat'])->find();
|
|
|
77
|
+ if(!$third){
|
|
|
78
|
+ //从这里自动绑定微信公众号的账户
|
|
|
79
|
+ $this->error('您未绑定微信号',null,1008);
|
|
|
80
|
+ }
|
|
|
81
|
+ }
|
|
|
82
|
+
|
|
|
83
|
+ $config = get_addon_config('litestore');
|
|
|
84
|
+
|
|
|
85
|
+ $third_config = get_addon_config('third');
|
|
|
86
|
+ $third_options = array_intersect_key($third_config, array_flip(['wechat']));
|
|
|
87
|
+ $third_options = $third_options['wechat'];
|
|
|
88
|
+
|
|
|
89
|
+ $options = [
|
|
|
90
|
+ 'debug' => true,
|
|
|
91
|
+ 'log' => [
|
|
|
92
|
+ 'level' => 'debug',
|
|
|
93
|
+ 'file' => '/tmp/easywechat.log',
|
|
|
94
|
+ ],
|
|
|
95
|
+ 'app_id' => $third_options['app_id'],
|
|
|
96
|
+ 'secret' => $third_options['app_secret'],
|
|
|
97
|
+ 'payment' => [
|
|
|
98
|
+ 'merchant_id' => $config['MCHIDGZH'],
|
|
|
99
|
+ 'key' => $config['APIKEYGZH'],
|
|
|
100
|
+ 'notify_url' => \think\Request::instance()->domain().addon_url('litestore/api.order/callback_for_wxgzh'),
|
|
|
101
|
+ ],
|
|
|
102
|
+
|
|
|
103
|
+ ];
|
|
|
104
|
+ $this->wxapp = new WXPAY_APP($options);
|
|
|
105
|
+ }
|
|
|
106
|
+
|
|
|
107
|
+ /**
|
41
|
* 退款结果回调
|
108
|
* 退款结果回调
|
42
|
*/
|
109
|
*/
|
43
|
public function refund_notify() {
|
110
|
public function refund_notify() {
|
44
|
- $app = new Application();
|
111
|
+ $app = new Application(ConfigService::load());
|
45
|
$response = $app->payment->handleRefundNotify(function ($message, $reqInfo) {
|
112
|
$response = $app->payment->handleRefundNotify(function ($message, $reqInfo) {
|
46
|
// Log::write(date('Y-m-d H:i') . '订单退款操作,返回数据:' . json_encode($message, JSON_UNESCAPED_UNICODE), 'order_refund');
|
113
|
// Log::write(date('Y-m-d H:i') . '订单退款操作,返回数据:' . json_encode($message, JSON_UNESCAPED_UNICODE), 'order_refund');
|
47
|
// 其中 $message['req_info'] 获取到的是加密解密信息
|
114
|
// 其中 $message['req_info'] 获取到的是加密解密信息
|