Notice.php
12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<?php
use Action\WebAction;
use Shopping\PayModel;
use WebPlugin\Pay\PayFactory;
use WebPlugin\Pay\Rspparams;
use WebPlugin\Pay\weixin\PayNotifyCallBack;
use WebPlugin\UdpLog;
/**
* 支付Notice
*/
class NoticeController extends WebAction
{
// 存储的UID键名
const SESSION_UID_KEY = 'payUserid';
public function init() {
parent::init();
}
/**
* 支付宝后台服务器返回,主要是用于补单
*/
public function alipaynoticeAction()
{
$res = $this->getParseResponse($_POST, 2);
UdpLog::info("【支付宝异步】,function:alipaynoticeAction,参数", array('pars' => $_POST, 'res' => $res));
if ($res->payResult != -1) {
$this->payResultProc($res, 2);
echo "success";
}
exit();
}
/**
* 支付宝浏览器端返回
*/
public function alipayreturnAction()
{
$res = $this->getParseResponse($_GET, 2);
UdpLog::info("【支付宝同步】,function:alipayreturnAction,参数", array('pars' => $_GET, 'res' => $res));
$dealResult = $this->payResultProc($res, 2);
$dealResult['payData'] = array('payWay' => '支付宝', 'payWayId' => 2);
$this->commonShowResult($dealResult);
}
/**
* 支付宝二维码支付
*/
public function alibarcodenoticeAction()
{
$res = $this->getParseResponse($_POST, 17);
UdpLog::info("【支付宝二维码支付异步】,function:alibarcodenoticeAction,参数", array('pars' => $_POST, 'res' => $res));
if ($res->payResult != -1) {
$this->payResultProc($res, 17);
echo "success";
}
exit();
}
/**
* 支付宝二维码支付浏览器端返回
*/
public function alibarcodereturnAction()
{
$res = $this->getParseResponse($_GET, 17);
UdpLog::info("【支付宝二维码支付同步】,function:alibarcodereturnAction,参数", array('pars' => $_GET, 'res' => $res));
$dealResult = $this->payResultProc($res, 17);
$dealResult['payData'] = array('payWay' => '支付宝', 'payWayId' => 17);
$this->commonShowResult($dealResult);
}
/**
* 通联支付
*/
public function allinpaynoticeAction()
{
$res = $this->getParseResponse($_POST, 16);
if ($res->payResult != -1) {
$this->payResultProc($res, 16);
echo "success";
}
exit();
}
/**
* 通联支付返回
*/
public function allinpayreturnAction()
{
$res = $this->getParseResponse($_POST, 16);
$dealResult = $this->payResultProc($res, 16);
$dealResult['payData'] = array('payWay' => '通联支付', 'payWayId' => 16);
$this->commonShowResult($dealResult);
}
/**
* 支付宝快捷网关浏览器回复
*/
public function aliexpressgatewayreturnAction()
{
$res = $this->getParseResponse($_GET, 13);
$dealResult = $this->payResultProc($res, 13);
$dealResult['payData'] = array('payWay' => '支付宝', 'payWayId' => 13);
$this->commonShowResult($dealResult);
}
/**
* 支付宝快捷网关自动对账回复
*/
public function aliexpressgatewaynoticeAction()
{
$res = $this->getParseResponse($_POST, 13);
if ($res->payResult != -1) {
$this->payResultProc($res, 13);
echo "success";
}
exit();
}
/*
* 支付宝银行支付回调(用于后台同步)
*/
public function alibanknoticeAction()
{
$res = $this->getParseResponse($_POST, 12);
if ($res->payResult != -1) {
$this->payResultProc($res, 12);
echo "success";
}
exit();
}
/*
* 支付宝银行支付回调(用于前台同步)
*/
public function alibankreturnAction()
{
$res = $this->getParseResponse($_GET, 12);
$dealResult = $this->payResultProc($res, 12);
$dealResult['payData'] = array('payWay' => '银行卡', 'payWayId' => 12);
$this->commonShowResult($dealResult);
}
/**
* 网银信用卡
*/
public function chinabankAction()
{
$res = $this->getParseResponse($_POST, 4);
$dealResult = $this->payResultProc($res, 4);
$dealResult['payData'] = array('payWay' => '网银在线', 'payWayId' => 4);
$this->commonShowResult($dealResult);
}
/**
* 网银在线自动接收
*/
public function chinabankautorevAction()
{
$res = $this->getParseResponse($_POST, 4);
if ($res->payResult != -1) {
$this->payResultProc($res, 4);
echo "ok";
} else {
echo 'error';
}
exit();
}
/**
* 腾讯财付通的回应
*/
public function tenpayAction()
{
$res = $this->getParseResponse($_GET, 1);
$dealResult = $this->payResultProc($res, 1);
$dealResult['payData'] = array('payWay' => '财付通', 'payWayId' => 1);
$this->commonShowResult($dealResult);
}
/**
* 盛付通浏览器返回
* Enter description here ...
*/
public function shengpayreturnAction()
{
$res = $this->getParseResponse($_POST, 11);
$dealResult = $this->payResultProc($res, 11);
$dealResult['payData'] = array('payWay' => '盛付通', 'payWayId' => 11);
$this->commonShowResult($dealResult);
}
/**
* 盛付通服务器端返回
*/
public function shengpaynoticeAction()
{
$res = $this->getParseResponse($_POST, 11);
if ($res->payResult != -1) {
$this->payResultProc($res, 11);
echo "OK";
}
exit();
}
/**
* jsonPcallback响应订单支付状态
*/
public function wechatcallbackAction()
{
$callback = $this->get('callback');
$orderCode = $this->get('ordercode');
$uid = $this->getUid(true);
$response = PayModel::checkWechatPayStatus($uid, $orderCode);
$this->helpJsonCallbackResult($callback, $response['code'], $response['message']);
}
/**
* 微信扫码支付结果商户通知地址
*/
public function wechatqrcodenotifyAction()
{
$uid = $this->getUid();
if (empty($uid)) { // cookie中获取为空时再从之前保存的session中获取
$uid = $this->getSession(self::SESSION_UID_KEY);
$this->setSession(self::SESSION_UID_KEY, null);
}
UdpLog::info("【微信扫码支付结果商户通知地址】,function:wechatqrcodenotifyAction");
$notify = new PayNotifyCallBack($uid);
$notify->handle(false);
}
/**
* 微信扫码支付返回
*/
public function wechatqrcodereturnAction()
{
$dealResult = array(
'code' => 500,
'message' => '支付失败'
);
do {
$orderCode = isset($_GET['order_code']) ? $_GET['order_code'] : 0;
if (empty($orderCode)) {
break;
}
$payment = PayModel::getPaymentById(21);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse(array('orderCode' => $orderCode));
UdpLog::info("【微信扫码支付返回】,function:wechatqrcodereturnAction,参数", array('pars' => $_GET, 'res' => $res));
$dealResult = $this->payResultProc($res, 21);
$dealResult['payData'] = array('payWay' => '微信扫码支付', 'payWayId' => 21);
} while (false);
$this->commonShowResult($dealResult);
}
/**
* 银联web支付返回
*/
public function unionpaywebreturnAction()
{
UdpLog::info("【银联web支付同步返回】,function:unionpaywebreturn,json参数", json_encode($_REQUEST));
$res = $this->getParseResponse($_REQUEST, 25);
$dealResult = $this->payResultProc($res, 25);
$dealResult['payData'] = array('payWay' => '银联在线支付', 'payWayId' => 25);
$this->commonShowResult($dealResult);
}
/**
* 银联支付成功后台回调响应
*/
public function unionpaywebnoticeAction()
{
UdpLog::info("【银联web支付异步返回】,function:unionpaywebnotice,json参数", json_encode($_REQUEST));
$res = $this->getParseResponse($_REQUEST, 25);
if ($res->payResult != -1) {
$this->payResultProc($res, 25);
echo "OK";
}
exit();
}
/**
* 支付宝手机支付(极简)的返回
*/
public function alimobilenoticeminiAction()
{
$res = $this->getParseResponse($_POST, 20);
if ($res->payResult != -1) {
$this->payResultProc($res, 20);
echo "OK";
} else {
echo 'faile';
}
exit();
}
/**
* 获取支付方式类对象
* @param type array $Parameters 回调参数
* @param type int $payment 支付方式
* @return type object
*/
private function getParseResponse($Parameters, $payment)
{
$payment = PayModel::getPaymentById($payment);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($Parameters);
if (empty($res->bankName)) {
$res->bankName = empty($payment['payName']) ? '' : $payment['payName'];
}
if (empty($res->bankCode)) {
$res->bankCode = empty($payment['pay_code']) ? '' : $payment['pay_code'];
}
return $res;
}
/**
* 通用显示结果的方法
* @param array $dealResult
*/
private function commonShowResult($dealResult)
{
$code = $dealResult['code'];
$view = 'wechatqrcodereturn';
$sknArr = array();
$skuArr = array();
if ($dealResult['data']['items']) {
foreach($dealResult['data']['items'] as $val) {
$sknArr[] = $val['product_skn'];
$skuArr[] = $val['product_sku'];
}
}
// 埋点数据
$point = array(
'orderCode' => $dealResult['data']['orderNum'],
'payResult' => 2, // 1 支付成功/2 支付失败
'amount' => $dealResult['data']['pay'],
'payStyle' => $dealResult['payData']['payWayId'],
'proSkn' => implode($sknArr, ','),
'proSku' => implode($skuArr, ','),
);
$data = array(
'headerData' => true,
'payData' => $dealResult['payData'],
'point' => $point
);
if ($code == 200) {
$view = 'index';
$point['payResult'] = 1;// 支付结果
$data = array(
'payNotice' => $dealResult['data'],
'criteo' => array(// 统计代码有关数据
'orderNum' => $dealResult['data']['orderNum'],
'items' => $dealResult['data']['items']
),
'point' => $point
);
}
//头部导航
$this->setSimpleHeader();
$this->_view->display($view, $data);
}
/**
* 处理支付返回的数据
*
* @param Rspparams $payResult 支付返回的结果
* @param $payment 支付方式id
* @return array
*/
private function payResultProc($payResult, $payment)
{
//判断是否登录
$uid = $this->getUid();
if (empty($uid)) { // cookie中获取为空时再从之前保存的session中获取
$uid = $this->getSession(self::SESSION_UID_KEY);
$this->setSession(self::SESSION_UID_KEY, null);
}
$result = array(
'code' => 500,
'message' => '支付失败'
);
if ($payResult->payResult == 200) {
//支付成功
$result = PayModel::procOrderData($uid, $payResult, $payment);
}
return $result;
}
}