forked from zhangv/union-pay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Token.php
176 lines (165 loc) · 4.86 KB
/
Token.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
<?php
namespace zhangv\unionpay\service;
use zhangv\unionpay\UnionPay;
/**
* 无跳转支付(Token版)
* @license MIT
* @author zhangv
* @link https://open.unionpay.com/ajweb/product/newProApiList?proId=2
* @method mixed updatePublicKey($orderId, $ext = [])
* @method mixed query($orderId, $txnTime, $ext = [])
* @method mixed fileDownload($settleDate, $fileType)
* @method mixed refund($orderId, $origQryId, $txnAmt, $ext = [])
* @method mixed payUndo($orderId, $origQryId, $txnAmt, $ext = [])
* @method mixed frontOpenPay($orderId, $txnAmt, $accNo, $customerInfo, $ext = [])
* @method mixed payByInstallment($orderId, $txnAmt, $accNo, $customerInfo, $installmentInfo, $ext = [])
* @method mixed onOpenNotify(array $notifyData, callable $callback, bool $validate = true)
*/
class Token extends Direct {
/**
* 申请token
* @param $orderId
* @param $tokenPayData
* @param array $ext
* @return mixed
*/
public function applyToken($orderId, $tokenPayData, $ext = []) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_APPLYTOKEN,
'txnSubType' => '05',
//交易参数
'orderId' => $orderId,
'tokenPayData' => $tokenPayData,
'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 mixed
*/
public function backOpen($orderId, $accNo, $customerInfo, $ext = []) {
$ext['bizType'] = UnionPay::BIZTYPE_TOKEN;
return parent::backOpen($orderId, $accNo, $customerInfo, $ext);
}
/**
* 前台开通
* @param $orderId
* @param $accNo
* @param $customerInfo
* @param array $ext
* @return string
*/
public function frontOpen($orderId, $accNo, $customerInfo, $ext = []) {
$ext['bizType'] = UnionPay::BIZTYPE_TOKEN;
return parent::frontOpen($orderId, $accNo, $customerInfo, $ext);
}
/**
* 查询开通
* @param $orderId
* @param $accNo
* @param array $ext
* @return array
*/
public function queryOpen($orderId, $accNo, $ext = []) {
$ext['bizType'] = UnionPay::BIZTYPE_TOKEN;
return parent::queryOpen($orderId, $accNo, $ext);
}
/**
* 删除token
* @param string $orderId
* @param string $tokenPayData
* @return array
*/
public function deleteToken($orderId, $tokenPayData) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_DELETETOKEN,
'txnSubType' => '01',
'backUrl' => null,
// 'certId' => null,
//交易参数
'orderId' => $orderId,
'tokenPayData' => $tokenPayData,
'txnTime' => date('YmdHis')
]);
$params['signature'] = $this->sign($params);
return $this->post($this->backTransUrl, $params);
}
/**
* 更新token
* @param string $orderId
* @param array $customerInfo
* @param string $tokenPayData
* @return array
*/
public function updateToken($orderId, $customerInfo, $tokenPayData) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_APPLYTOKEN,
'txnSubType' => '03',
'backUrl' => null,
'certId' => null,
//交易参数
'orderId' => $orderId,
'tokenPayData' => $tokenPayData,
'customerInfo' => $this->encryptCustomerInfo($customerInfo),
'txnTime' => date('YmdHis')
]);
$params['signature'] = $this->sign($params);
return $this->post($this->backTransUrl, $params);
}
/**
* 发送短信验证码(开通、支付、预授权)
* @param string $orderId
* @param string $accNo
* @param string $customerInfo
* @param string $smsType
* @param array $ext
* @return array
*/
public function sms($orderId, $accNo, $customerInfo, $smsType = Direct::SMSTYPE_OPEN, $ext = []):array{
$ext['bizType'] = UnionPay::BIZTYPE_TOKEN;
return parent::sms($orderId, $accNo, $customerInfo, $smsType, $ext);
}
/**
* 使用Token支付
* @param $orderId
* @param $txnAmt
* @param array $ext
* @return array
*/
public function payByToken($orderId, $txnAmt, $tokenPayData, $customerInfo, $ext = []) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_CONSUME,
'txnSubType' => '01',
'currencyCode' => $this->config['currencyCode'],
//交易参数
'orderId' => $orderId,
'txnAmt' => $txnAmt,
'tokenPayData' => $tokenPayData,
'customerInfo' => $this->encryptCustomerInfo($customerInfo),
'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_TOKEN,
'accessType' => UnionPay::ACCESSTYPE_MERCHANT,
'channelType' => UnionPay::CHANNELTYPE_PC,
]);
}
}