|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* 差异比较 |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Omnipay\MyCard\Message; |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
use DateTime; |
|
10
|
|
|
use DateTimeZone; |
|
11
|
|
|
use Omnipay\MyCard\Exception\DefaultException; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Request as HttpRequest; |
|
13
|
|
|
|
|
14
|
|
|
class CompareTransaction |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
protected $data; |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
protected $allowedIp = [ |
|
21
|
|
|
'210.71.189.165', |
|
22
|
|
|
'218.32.37.148', |
|
23
|
|
|
]; |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
protected $httpRequest; |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
public function __construct() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->httpRequest = HttpRequest::createFromGlobals(); |
|
32
|
|
|
if (!in_array($this->httpRequest->getClientIp(), $this->allowedIp)) { |
|
33
|
|
|
$this->error(); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
public function getParams() |
|
39
|
|
|
{ |
|
40
|
|
|
return [ |
|
41
|
|
|
'card' => $this->httpRequest->get('MyCardTradeNo'), |
|
42
|
|
|
'startTime' => strtotime($this->httpRequest->get('StartDateTime')), |
|
43
|
|
|
'endTime' => strtotime($this->httpRequest->get('EndDateTime')), |
|
44
|
|
|
]; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* 设置数据 |
|
50
|
|
|
* INGAME: 卡片儲值; COSTPOINT: 會員扣點; (Billing): 其他代碼為小額付費之付費方式 |
|
51
|
|
|
* $data = [ |
|
52
|
|
|
* [ |
|
53
|
|
|
* 'type' => 'INGAME', |
|
54
|
|
|
* 'transactionId' => '厂商交易号', |
|
55
|
|
|
* 'transactionReference' => 'MyCard交易号', |
|
56
|
|
|
* 'card' => 'MC341432533', |
|
57
|
|
|
* 'amount' => 50, |
|
58
|
|
|
* 'currency' => 'TWD', |
|
59
|
|
|
* 'account' => '888888', |
|
60
|
|
|
* 'time' => 1500000000, |
|
61
|
|
|
* ] |
|
62
|
|
|
* ] |
|
63
|
|
|
* |
|
64
|
|
|
* @param array $data |
|
65
|
|
|
* @return $this |
|
66
|
|
|
*/ |
|
67
|
|
|
public function setData(array $data = []) |
|
68
|
|
|
{ |
|
69
|
|
|
$dateTime = new DateTime(); |
|
70
|
|
|
$dateTime->setTimezone(new DateTimeZone('Asia/Taipei')); |
|
71
|
|
|
|
|
72
|
|
|
foreach ($data as $value) { |
|
73
|
|
|
$dateTime->setTimestamp($value['time']); |
|
74
|
|
|
$this->data .= |
|
75
|
|
|
$value['type'] . ',' . |
|
76
|
|
|
$value['transactionReference'] . ',' . |
|
77
|
|
|
$value['card'] . ',' . |
|
78
|
|
|
$value['transactionId'] . ',' . |
|
79
|
|
|
$value['account'] . ',' . |
|
80
|
|
|
$value['amount'] . ',' . |
|
81
|
|
|
$value['currency'] . ',' . |
|
82
|
|
|
$dateTime->format('Y-m-d\TH:i:s') . |
|
83
|
|
|
"<BR>\r\n"; |
|
84
|
|
|
}; |
|
85
|
|
|
return $this; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
public function send() |
|
90
|
|
|
{ |
|
91
|
|
|
exit($this->data); |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
public function error() |
|
96
|
|
|
{ |
|
97
|
|
|
throw new DefaultException('IP Not Allowed'); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
} |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.