-
Notifications
You must be signed in to change notification settings - Fork 15
/
Direct.php
269 lines (256 loc) · 7.56 KB
/
Direct.php
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
<?php
namespace zhangv\unionpay\service;
use zhangv\unionpay\UnionPay;
/**
* 无跳转支付(标准版)
* @license MIT
* @author zhangv
* @link https://open.unionpay.com/ajweb/product/newProDetail?proId=2&cataId=20
* @method mixed updatePublicKey($orderId, $ext = [])
* @method mixed query($orderId, $txnTime, $ext = [])
* @method mixed fileDownload($settleDate, $fileType)
*/
class Direct extends UnionPay {
/**
* 后台开通(需要用申请的商户号,并授权后方可测试)
* @param $orderId
* @param $accNo
* @param $customerInfo
* @param array $ext
* @return mixed
*/
public function backOpen($orderId, $accNo, $customerInfo, $ext = []) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_DIRECTOPEN,
'txnSubType' => '00',
//交易参数
'orderId' => $orderId,
'accNo' => $this->encryptData($accNo),
'customerInfo' => $this->encryptCustomerInfo($customerInfo),
'txnTime' => date('YmdHis'),
],$ext);
$params['signature'] = $this->sign($params);
return $this->post($this->backTransUrl, $params);
}
/**
* 前台开通
* @param $orderId
* @param $accNo
* @param $customerInfo
* @param array $ext
* @return string
*/
public function frontOpen($orderId, $accNo, $customerInfo, $ext = []) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_DIRECTOPEN,
'txnSubType' => '00',
//交易参数
'orderId' => $orderId,
'accNo' => $this->encryptData($accNo),
'customerInfo' => $this->encryptCustomerInfo($customerInfo),
'txnTime' => date('YmdHis'),
'accType' => '01',
'frontUrl' => $this->config['openReturnUrl'],
'backUrl' => $this->config['openNotifyUrl'],
'payTimeout' => '',
],$ext);
$params['signature'] = $this->sign($params);
$result = $this->createPostForm($params, '开通',null, true);
return $result;
}
/**
* 无跳转开通异步通知处理
* @param array $notifyData
* @param callable $callback
* @param bool $validate
* @return mixed
* @throws \Exception
*/
public function onOpenNotify(array $notifyData, callable $callback, bool $validate = true) {
return parent::onOpenNotify($notifyData,$callback,$validate);
}
/**
* 查询开通
* @param $orderId
* @param $accNo
* @param $ext
* @return array
*/
public function queryOpen($orderId, $accNo, $ext = []) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_QUERYOPEN,
'txnSubType' => '00',
//交易参数
'orderId' => $orderId,
'accNo' => $this->encryptData($accNo),
'txnTime' => date('YmdHis'),
],$ext);
$params['signature'] = $this->sign($params);
return $this->post($this->backTransUrl, $params);
}
/**
* 发送短信验证码(开通、支付、预授权...)
* @link https://open.unionpay.com/ajweb/product/newProApiShow?proId=2&apiId=93
* @param $orderId
* @param $accNo
* @param $customerInfo
* @param $smsType
* @param array $ext
* @return array
*/
public function sms($orderId, $accNo, $customerInfo, $smsType = Direct::SMSTYPE_OPEN, $ext = []):array{
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_AUTHENTICATE,
'txnSubType' => $smsType,
//交易参数
'orderId' => $orderId,
'accNo' => $this->encryptData($accNo),
'txnTime' => date('YmdHis'),
'customerInfo' => $this->encryptCustomerInfo($customerInfo)
],$ext);
$params['signature'] = $this->sign($params);
return $this->post($this->backTransUrl, $params);
}
/**
* 支付
* @param $orderId
* @param $txnAmt
* @param $accNo
* @param $customerInfo
* @param array $ext
* @return array
*/
public function pay($orderId, $txnAmt, $accNo, $customerInfo, $ext = []) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_CONSUME,
'txnSubType' => '01',
'currencyCode' => $this->config['currencyCode'],
//交易参数
'orderId' => $orderId,
'txnAmt' => $txnAmt,
'accNo' => $this->encryptData($accNo),
'customerInfo' => $this->encryptCustomerInfo($customerInfo),
'txnTime' => date('YmdHis')
],$ext);
$params['signature'] = $this->sign($params);
return $this->post($this->backTransUrl, $params);
}
/**
* 分期付款
* @param string $orderId
* @param string $txnAmt
* @param string $accNo
* @param array $customerInfo
* @param string $installmentInfo
* @param array $ext
* @return array
*/
public function payByInstallment($orderId, $txnAmt, $accNo, $customerInfo, $installmentInfo, $ext = []) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_CONSUME,
'txnSubType' => '03',
'currencyCode' => $this->config['currencyCode'],
//交易参数
'orderId' => $orderId,
'txnAmt' => $txnAmt,
'accNo' => $this->encryptData($accNo),
'customerInfo' => $this->encryptCustomerInfo($customerInfo),
'txnTime' => date('YmdHis'),
'backUrl' => $this->config['notifyUrl'],
//分期付款用法(商户自行设计分期付款展示界面):
//【生产环境】支持的银行列表清单请联系银联业务运营接口人索要
'instalTransInfo' => $installmentInfo
],$ext);
$params['signature'] = $this->sign($params);
return $this->post($this->backTransUrl, $params);
}
/**
* 前台开通并支付
* @param string $orderId
* @param string $accNo
* @param array $customerInfo
* @param array $ext
* @return string
*/
public function frontOpenPay($orderId, $txnAmt, $accNo, $customerInfo, $ext = []) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_CONSUME,
'txnSubType' => '01',
'currencyCode' => $this->config['currencyCode'],
//交易参数
'orderId' => $orderId,
'txnAmt' => $txnAmt,
'accNo' => $this->encryptData($accNo),
'customerInfo' => $this->encryptCustomerInfo($customerInfo),
'txnTime' => date('YmdHis'),
'accType' => '01',
'frontUrl' => $this->config['openReturnUrl'],
'backUrl' => $this->config['openNotifyUrl'],
'payTimeout' => ''
],$ext);
$params['signature'] = $this->sign($params);
return $this->createPostForm($params, '开通并支付',null,true);
}
/**
* 支付撤销
* @param $orderId
* @param $origQryId
* @param $txnAmt
* @param array $ext
* @return array
*/
public function payUndo($orderId, $origQryId, $txnAmt, $ext = []) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_CONSUMEUNDO,
'txnSubType' => '01',
//交易参数
'orderId' => $orderId,
'txnAmt' => $txnAmt,
'origQryId' => $origQryId,
'txnTime' => date('YmdHis')
],$ext);
$params['signature'] = $this->sign($params);
return $this->post($this->backTransUrl, $params);
}
/**
* 退款
* @param $orderId
* @param $origQryId
* @param $txnAmt
* @param array $ext
* @return array
*/
public function refund($orderId, $origQryId, $txnAmt, $ext = []) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_REFUND,
'txnSubType' => '00',
//交易参数
'orderId' => $orderId,
'txnAmt' => $txnAmt,
'origQryId' => $origQryId,
'txnTime' => date('YmdHis')
],$ext);
$params['signature'] = $this->sign($params);
return $this->post($this->backTransUrl, $params);
}
/**
* 通用配置参数
* @return array
*/
protected function commonParams() {
return array_merge(parent::commonParams(),[
'bizType' => UnionPay::BIZTYPE_DIRECT,
'accessType' => UnionPay::ACCESSTYPE_MERCHANT,
'channelType' => UnionPay::CHANNELTYPE_PC,
]);
}
}