-
Notifications
You must be signed in to change notification settings - Fork 15
/
Charge.php
339 lines (312 loc) · 9.43 KB
/
Charge.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
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
<?php
namespace zhangv\unionpay\service;
use zhangv\unionpay\UnionPay;
/**
* 缴费产品
* @license MIT
* @author zhangv
* @link https://open.unionpay.com/ajweb/product/newProApiList?proId=76
* */
class Charge extends UnionPay {
/**
* 前台账单缴费
* @param $orderId
* @param $txnAmt
* @param $bussCode
* @param $billQueryInfo
* @param array $ext
* @return string
*/
public function frontPayBill($orderId, $txnAmt, $bussCode, $billQueryInfo, $ext = []) {
$params = array_merge($this->commonParams(),[
'txnType' => UnionPay::TXNTYPE_PAYBILL,
'txnSubType' => '01',
'frontUrl' => $this->config['returnUrl'],
'orderId' => $orderId,
'txnTime' => date('YmdHis'),
'txnAmt' => $txnAmt,
'currencyCode' => $this->config['currencyCode'],
'bussCode' => $bussCode,// 业务类型号,此处默认取demo演示页面传递的参数
'payTimeout' => date('YmdHis', time() + 15 * 60)
],$ext);
if($billQueryInfo){
$params['billQueryInfo'] = base64_encode($billQueryInfo);// 账单要素,JSON格式
}
// 先查后缴送账单查询应答报文的queryId,直接缴费的不送
if (array_key_exists("origQryId", $ext) && $ext ["origQryId"] != "") {
$params ['origQryId'] = $ext ["origQryId"];
}
$params['signature'] = $this->sign($params);
return $this->createPostForm($params, '银联缴费', $this->jfFrontTransUrl, true);
}
/**
* 后台账单缴费
* @param $orderId
* @param $txnAmt
* @param $bussCode
* @param $billQueryInfo
* @param $accNo
* @param $customerInfo
* @param array $ext
* @return array
*/
public function backPayBill($orderId, $txnAmt, $bussCode, $billQueryInfo, $accNo, $customerInfo, $ext = []) {
$params = array_merge($this->commonParams(),[
'txnType' => UnionPay::TXNTYPE_PAYBILL,
'txnSubType' => '01',
'orderId' => $orderId,
'txnTime' => date('YmdHis'),
'txnAmt' => $txnAmt,
'currencyCode' => $this->config['currencyCode'],
'bussCode' => $bussCode,// 业务类型号,此处默认取demo演示页面传递的参数
'payTimeout' => date('YmdHis', strtotime('+15 minutes')),
'accNo' => $this->encryptData($accNo),
'customerInfo' => $this->encryptCustomerInfo($customerInfo)
],$ext);
if($billQueryInfo){
$params['billQueryInfo'] = base64_encode($billQueryInfo);// 账单要素,JSON格式
}
// 先查后缴送账单查询应答报文的queryId,直接缴费的不送
if (array_key_exists("origQryId", $ext) && $ext ["origQryId"] != "") {
$params ['origQryId'] = $ext ["origQryId"];
}
$params['signature'] = $this->sign($params);
return $this->post($this->jfBackTransUrl, $params);
}
/**
* 账单缴费获取tn
* @param $orderId
* @param $txnAmt
* @param $bussCode
* @param $billQueryInfo
* @param array $ext
* @return array
*/
public function appPayBill($orderId, $txnAmt, $bussCode, $billQueryInfo, $ext = []) {
$params = array_merge($this->commonParams(),[
'txnType' => UnionPay::TXNTYPE_PAYBILL,
'txnSubType' => '01',
'orderId' => $orderId,
'txnTime' => date('YmdHis'),
'txnAmt' => $txnAmt,
'currencyCode' => $this->config['currencyCode'],
'bussCode' => $bussCode,// 业务类型号
],$ext);
if($billQueryInfo){
$params['billQueryInfo'] = base64_encode($billQueryInfo);// 账单要素,JSON格式
}
// 先查后缴送账单查询应答报文的queryId,直接缴费的不送
if (array_key_exists("origQryId", $ext) && $ext ["origQryId"] != "") {
$params ['origQryId'] = $ext ["origQryId"];
}
$params['signature'] = $this->sign($params);
return $this->post($this->jfAppTransUrl, $params);
}
/**
* 账单查询
* @param $orderId
* @param $bussCode
* @param string $billQueryInfo 账单要素, JSON格式
* @param array $ext
* @return array
*/
public function queryBill($orderId, $bussCode, $billQueryInfo, $ext = []) {
$params = array_merge($this->commonParams(),[
'txnType' => UnionPay::TXNTYPE_QUERYBILL,
'txnSubType' => '01',
'orderId' => $orderId,
'txnTime' => date('YmdHis'),
'bussCode' => $bussCode,// 业务类型号
],$ext);
if($billQueryInfo){
$params['billQueryInfo'] = base64_encode($billQueryInfo);
}
// 多次查询送上一笔账单查询应答报文的queryId,正常情况不送。
if (array_key_exists("origQryId", $ext) && $ext ["origQryId"] != "") {
$params ['origQryId'] = $ext ["origQryId"];
}
$params['signature'] = $this->sign($params);
return $this->post($this->jfBackTransUrl, $params);
}
/**
* 前台信用卡还款
* @param $orderId
* @param $txnAmt
* @param string $usr_num 信用卡号
* @param string $usr_nm 持卡人姓名
* @param array $ext
* @return string
*/
public function frontRepay($orderId, $txnAmt, $usr_num, $usr_nm, $ext = []) {
$billQueryInfo = [
"usr_num" => $usr_num,
"usr_num2" => $usr_num,
"usr_nm" => $usr_nm?:''
];
return $this->frontPayBill($orderId, $txnAmt, 'J1_9800_0000_1', json_encode($billQueryInfo), $ext);
}
/**
* 后台信用卡还款
* @param $orderId
* @param $txnAmt
* @param string $usr_num 信用卡号
* @param string $usr_nm 持卡人姓名
* @param $accNo
* @param $customerInfo
* @param array $ext
* @return array
*/
public function backRepay($orderId, $txnAmt, $usr_num, $usr_nm, $accNo, $customerInfo, $ext = []) {
$billQueryInfo = [
"usr_num" => $usr_num,
"usr_num2" => $usr_num,
"usr_nm" => $usr_nm?:''
];
return $this->backPayBill($orderId, $txnAmt, 'J1_9800_0000_1', json_encode($billQueryInfo), $accNo, $customerInfo, $ext);
}
/**
* 信用卡还款获取tn
* @param string $orderId
* @param string $txnAmt
* @param string $usr_num 信用卡号
* @param string $usr_nm 持卡人姓名
* @param array $ext
* @return array
*/
public function appRepay($orderId, $txnAmt, $usr_num, $usr_nm, $ext = []) {
$billQueryInfo = [
"usr_num" => $usr_num,
"usr_num2" => $usr_num,
"usr_nm" => $usr_nm?:''
];
return $this->appPayBill($orderId, $txnAmt, 'J1_9800_0000_1', json_encode($billQueryInfo), $ext);
}
/**
* 账单查询
* @param string $orderId
* @param string $usr_num 信用卡卡号
* @param string $query_month 账单月 YYYYMM
* @param string $usr_nm 信用卡持卡人姓名
* @param array $ext
* @return array
*/
public function queryRepay($orderId, $usr_num, $query_month, $usr_nm, $ext = []) {
$billQueryInfo = [
"usr_num" => $usr_num,
"query_month" => $query_month,
"usr_nm" => $usr_nm
];
return $this->queryBill($orderId, 'J1_9800_0000_1', json_encode($billQueryInfo), $ext);
}
/**
* 前台缴税
* @param $orderId
* @param $txnAmt
* @param $origQryId
* @param array $ext
* @return string
*/
public function frontPayTax($orderId, $txnAmt, $origQryId, $ext = []) {
$ext['origQryId'] = $origQryId;
return $this->frontPayBill($orderId,$txnAmt,'S0_9800_0000',null,$ext);
}
/**
* 后台缴税
* @param $orderId
* @param $txnAmt
* @param $accNo
* @param $customerInfo
* @param array $ext
* @return array
*/
public function backPayTax($orderId, $txnAmt, $origQryId, $accNo, $customerInfo, $ext = []) {
$ext['origQryId'] = $origQryId;
return $this->backPayBill($orderId,$txnAmt,'S0_9800_0000',null, $accNo, $customerInfo, $ext);
}
/**
* 缴税获取tn
* @param $orderId
* @param $txnAmt
* @param $origQryId
* @param array $ext
* @return array
*/
public function appPayTax($orderId, $txnAmt, $origQryId, $ext = []) {
$ext['origQryId'] = $origQryId;
return $this->appPayBill($orderId,$txnAmt,'S0_9800_0000',null, $ext);
}
/**
* 申报
* @param string $orderId
* @param string $usr_num 纳税人识别号
* @param string $col_organ_cd 征收机关代码
* @param string $col_voucher_no 应征凭证序号
* @param string $proc_flg 流程标识
* @param array $ext
* @return array
*/
public function queryTax($orderId, $usr_num, $col_organ_cd, $col_voucher_no, $proc_flg, $ext = []) {
$billQueryInfo = [
"usr_num" => $usr_num,
"col_organ_cd" => $col_organ_cd,
"col_voucher_no" => $col_voucher_no,
"proc_flg" => $proc_flg,
];
return $this->queryBill($orderId,'S0_9800_0000', json_encode($billQueryInfo), $ext);
}
/**
* 交易状态查询
* @param string $orderId
* @param string $txnTime
* @param array $ext
* @return array
* @throws \Exception
*/
public function query($orderId, $txnTime, $ext = []) {
$params = array_merge($this->commonParams(),[
'txnType' => UnionPay::TXNTYPE_QUERY,
'txnSubType' => '00',
'bizType' => '000000',
'channelType' => UnionPay::CHANNELTYPE_PC,
'orderId' => $orderId,
'txnTime' => $txnTime
],$ext);
$params['signature'] = $this->sign($params);
return $this->post($this->jfSingleQueryUrl, $params);
}
/**
* 获取地区列表
* @return mixed
*/
public function areas() {
$url = "https://gateway.95516.com/jiaofei/config/s/areas";
return $this->get($url);
}
/**
* 获取业务目录
* @return mixed
*/
public function categories($category) {
$url = "https://gateway.95516.com/jiaofei/config/s/categories/{$category}";
return $this->get($url);
}
/**
* 获取业务要素
* @return mixed
*/
public function biz($bussCode) {
$url = "https://gateway.95516.com/jiaofei/config/s/biz/{$bussCode}";
return $this->get($url);
}
/**
* 通用配置参数
* @return array
*/
protected function commonParams() {
return array_merge(parent::commonParams(),[
'bizType' => UnionPay::BIZTYPE_CHARGE,
'accessType' => UnionPay::ACCESSTYPE_MERCHANT,
'channelType' => UnionPay::CHANNELTYPE_MOBILE,
]);
}
}