-
Notifications
You must be signed in to change notification settings - Fork 15
/
Qrcode.php
128 lines (119 loc) · 3.64 KB
/
Qrcode.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
<?php
namespace zhangv\unionpay\service;
use zhangv\unionpay\UnionPay;
use \Exception;
/**
* 二维码支付(v2.2)
* @license MIT
* @author zhangv
* @link https://open.unionpay.com/ajweb/product/newProApiList?proId=89
* @method mixed fileDownload($settleDate, $fileType = '00')
*/
class Qrcode extends B2C {
/**
* 二维码申请(主扫)
* @param string $orderId
* @param array $termInfo 终端信息
* @param string $txnAmt 交易金额,若不出现则需要对方输入金额
* @param array $ext 扩展数组
* @return array
*/
public function apply($orderId, $termInfo, $txnAmt = null, $ext = []) {
$params = array_merge(parent::commonParams(),[
'txnType' => UnionPay::TXNTYPE_CONSUME,
'txnSubType' => '07',
'bizType' => UnionPay::BIZTYPE_DEFAULT,
'channelType' => UnionPay::CHANNELTYPE_MOBILE,
'currencyCode' => $this->config['currencyCode'],
'orderId' => $orderId,
'txnTime' => date('YmdHis'),
'txnAmt' => $txnAmt,
],$ext);
$params['signature'] = $this->sign($params);
return $this->post($this->backTransUrl, $params);
}
/**
* 二维码消费(被扫)
* @param string $orderId
* @param string $txnAmt
* @param array $ext
* @param bool $serverSide
* @return array
* @throws Exception
*/
public function pay($orderId, $txnAmt, $ext = [],$serverSide = false) {
if (empty($ext['qrNo'])) {
throw new Exception("qrNo is required.");
}
$params = array_merge(parent::commonParams(),[
'txnType' => UnionPay::TXNTYPE_CONSUME,
'txnSubType' => '06',
'bizType' => UnionPay::BIZTYPE_DEFAULT,
'channelType' => UnionPay::CHANNELTYPE_MOBILE,
'currencyCode' => $this->config['currencyCode'],
'orderId' => $orderId,
'txnTime' => date('YmdHis'),
'txnAmt' => $txnAmt,
],$ext);
$params['signature'] = $this->sign($params);
return $this->post($this->backTransUrl, $params);
}
/**
* 消费撤销
* @param string $orderId
* @param string $origQryId
* @param string $txnAmt
* @param array $ext
* @return mixed
*/
public function payUndo($orderId, $origQryId, $txnAmt, $ext = []) {
$ext['bizType'] = UnionPay::BIZTYPE_DEFAULT;
$ext['channelType'] = UnionPay::CHANNELTYPE_MOBILE;
return parent::payUndo($orderId, $origQryId, $txnAmt, $ext);
}
/**
* 退款
* @param $orderId
* @param $origQryId
* @param $refundAmt
* @param array $ext
* @return mixed
*/
public function refund($orderId, $origQryId, $refundAmt, $ext = []) {
$ext['bizType'] = UnionPay::BIZTYPE_DEFAULT;
$ext['channelType'] = UnionPay::CHANNELTYPE_MOBILE;
return parent::refund($orderId, $origQryId, $refundAmt, $ext);
}
/**
* 交易查询
* @param $orderId
* @param $txnTime
* @param array $ext
* @return mixed
*/
public function query($orderId, $txnTime, $ext = []) {
$ext['bizType'] = UnionPay::BIZTYPE_DEFAULT;
$ext['channelType'] = UnionPay::CHANNELTYPE_MOBILE;
return parent::query($orderId, $txnTime, $ext);
}
/**
* 冲正
* 必须与原始消费在同一天(准确讲是昨日23:00至本日23:00之间)。 冲正交易,仅用于超时无应答等异常场景,只有发生支付系统超时或者支付结果未知时可调用冲正
* @param string $orderId 商户订单号
* @param string $txnTime 原始交易时间戳 格式:YmdHis
* @param array $ext 扩展
* @return mixed
*/
public function reverse($orderId, $txnTime, $ext = []) {
$params = array_merge($this->commonParams(),[
//基础参数
'txnType' => UnionPay::TXNTYPE_REVERSE,
'txnSubType' => '01',
//交易参数
'orderId' => $orderId,
'txnTime' => $txnTime
],$ext);
$params['signature'] = $this->sign($params);
return $this->post($this->backTransUrl, $params);
}
}