-
Notifications
You must be signed in to change notification settings - Fork 15
/
B2C.php
233 lines (219 loc) · 6.53 KB
/
B2C.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
<?php
namespace zhangv\unionpay\service;
use zhangv\unionpay\UnionPay;
/**
* 网关支付
* @license MIT
* @author zhangv
* @link https://open.unionpay.com/ajweb/product/newProApiList?proId=1
* @method mixed updatePublicKey($orderId, $ext = [])
* @method mixed query($orderId, $txnTime, $ext = [])
* @method mixed fileDownload($settleDate, $fileType = '00')
*/
class B2C extends UnionPay {
/**
* 前台支付
* @param $orderId
* @param $txnAmt
* @param array $ext
* @param bool $serverSide 是否后台提交 与前台支付的差别在于直接在服务器后端完成向银联的提交,都存在超时的可能
* @return string
*/
public function pay($orderId, $txnAmt, $ext = [], $serverSide = false) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_CONSUME,
'txnSubType' => '01',
'currencyCode' => $this->config['currencyCode'],
'defaultPayType' => '0001', //默认支付方式
//交易参数
'orderId' => $orderId,
'frontUrl' => $this->config['returnUrl'],
'txnAmt' => $txnAmt,
'txnTime' => date('YmdHis'),
],$ext);
$params['signature'] = $this->sign($params);
return $this->createPostForm($params,'支付',$this->frontTransUrl, $serverSide);
}
/**
* 消费撤销
* @param string $orderId
* @param string $origQryId
* @param string $txnAmt
* @param array $ext
* @return mixed
*/
public function payUndo($orderId, $origQryId, $txnAmt, $ext = []) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_CONSUMEUNDO,
'txnSubType' => '00',
//交易参数
'orderId' => $orderId,
'origQryId' => $origQryId,
'txnAmt' => $txnAmt,
'txnTime' => date('YmdHis'),
],$ext);
$params['signature'] = $this->sign($params);
return $this->post($this->backTransUrl, $params);
}
/**
* 退款
* @param $orderId
* @param $origQryId
* @param $refundAmt
* @param array $ext
* @return mixed
*/
public function refund($orderId, $origQryId, $refundAmt, $ext = []) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_REFUND,
'txnSubType' => '00',
//交易参数
'orderId' => $orderId,
'origQryId' => $origQryId,
'txnAmt' => $refundAmt,
'txnTime' => date('YmdHis'),
],$ext);
$params['signature'] = $this->sign($params);
return $this->post($this->backTransUrl, $params);
}
/**
* 预授权
* @param $orderId
* @param $amt
* @param $orderDesc
* @param array $ext
* @return mixed
*/
public function preAuth($orderId, $amt, $orderDesc, $ext = [], $serverSide = false) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_PREAUTH,
'txnSubType' => '01',
'currencyCode' => $this->config['currencyCode'],
//交易参数
'orderId' => $orderId,
'frontUrl' => $this->config['returnUrl'],
'txnAmt' => $amt,
'txnTime' => date('YmdHis'),
'orderDesc' => $orderDesc,
],$ext);
$params['signature'] = $this->sign($params);
return $this->createPostForm($params,'预授权',$this->frontTransUrl, $serverSide);
}
/**
* 预授权撤销
* @param $orderId
* @param $origQryId
* @param $txnAmt
* @param array $ext
* @return array
*/
public function preAuthUndo($orderId, $origQryId, $txnAmt, $ext = []) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_PREAUTHUNDO,
'txnSubType' => '00',
'bizType' => '000000', //overwrite
'currencyCode' => $this->config['currencyCode'],
//交易参数
'orderId' => $orderId,
'origQryId' => $origQryId, //原预授权的queryId,可以从查询接口或者通知接口中获取
'txnAmt' => $txnAmt, //交易金额,需和原预授权一致
'txnTime' => date('YmdHis'),
],$ext);
$params['signature'] = $this->sign($params);
return $this->post($this->backTransUrl, $params);
}
/**
* 预授权完成
* @param $orderId
* @param $origQryId
* @param $amt
* @param array $ext
* @return array
*/
public function preAuthFinish($orderId, $origQryId, $amt, $ext = []) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_PREAUTHFINISH,
'txnSubType' => '00',
//交易参数
'orderId' => $orderId,
'origQryId' => $origQryId, //原预授权的queryId,可以从查询接口或者通知接口中获取
'txnAmt' => $amt, //交易金额,需和原预授权一致
'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 preAuthFinishUndo($orderId, $origQryId, $txnAmt, $ext = []) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_PREAUTHFINISHUNDO,
'txnSubType' => '00',
'bizType' => '000000',//overwrite
//交易参数
'orderId' => $orderId,
'origQryId' => $origQryId, //原预授权的queryId,可以从查询接口或者通知接口中获取
'txnAmt' => $txnAmt, //交易金额,需和原预授权一致
'txnTime' => date('YmdHis'),
],$ext);
$params['signature'] = $this->sign($params);
return $this->post($this->backTransUrl, $params);
}
/**
* 支付异步通知处理
* @param array $notifyData
* @param callable $callback
* @param bool $validate
* @return mixed
* @throws \Exception
*/
public function onPayNotify(array $notifyData, callable $callback, bool $validate = true) {
return parent::onPayNotify($notifyData,$callback,$validate);
}
/**
* 退款异步通知处理
* @param array $notifyData
* @param callable $callback
* @param bool $validate
* @return mixed
* @throws \Exception
*/
public function onRefundNotify(array $notifyData, callable $callback, bool $validate = true) {
return parent::onRefundNotify($notifyData,$callback,$validate);
}
/**
* 消费撤销异步通知处理
* @param array $notifyData
* @param callable $callback
* @param bool $validate
* @return mixed
* @throws \Exception
*/
public function onPayUndoNotify(array $notifyData, callable $callback, bool $validate = true) {
return parent::onPayUndoNotify($notifyData,$callback,$validate);
}
/**
* 通用配置参数
* @return array
*/
protected function commonParams() {
return array_merge(parent::commonParams(),[
'bizType' => UnionPay::BIZTYPE_B2C,
'accessType' => UnionPay::ACCESSTYPE_MERCHANT,
'channelType' => UnionPay::CHANNELTYPE_PC,
]);
}
}