Order.php
5.4 KB
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
<?php
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目:https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WePay;
use WeChat\Contracts\BasicWePay;
use WeChat\Contracts\Tools;
/**
* 微信商户订单
* Class Order
* @package WePay
*/
class Order extends BasicWePay
{
/**
* 统一下单
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function create(array $options)
{
$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
return $this->callPostApi($url, $options, false, 'MD5');
}
/**
* 刷卡支付
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function micropay(array $options)
{
$url = 'https://api.mch.weixin.qq.com/pay/micropay';
return $this->callPostApi($url, $options, false, 'MD5');
}
/**
* 查询订单
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function query(array $options)
{
$url = 'https://api.mch.weixin.qq.com/pay/orderquery';
return $this->callPostApi($url, $options);
}
/**
* 关闭订单
* @param string $outTradeNo 商户订单号
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function close($outTradeNo)
{
$url = 'https://api.mch.weixin.qq.com/pay/closeorder';
return $this->callPostApi($url, ['out_trade_no' => $outTradeNo]);
}
/**
* 创建JsApi及H5支付参数
* @param string $prepayId 统一下单预支付码
* @return array
*/
public function jsapiParams($prepayId)
{
$option = [];
$option["appId"] = $this->config->get('appid');
$option["timeStamp"] = (string)time();
$option["nonceStr"] = Tools::createNoncestr();
$option["package"] = "prepay_id={$prepayId}";
$option["signType"] = "MD5";
$option["paySign"] = $this->getPaySign($option, 'MD5');
$option['timestamp'] = $option['timeStamp'];
return $option;
}
/**
* 获取支付规则二维码
* @param string $productId 商户定义的商品id或者订单号
* @return string
*/
public function qrcParams($productId)
{
$data = [
'appid' => $this->config->get('appid'),
'mch_id' => $this->config->get('mch_id'),
'time_stamp' => (string)time(),
'nonce_str' => Tools::createNoncestr(),
'product_id' => (string)$productId,
];
$data['sign'] = $this->getPaySign($data, 'MD5');
return "weixin://wxpay/bizpayurl?" . http_build_query($data);
}
/**
* 获取微信App支付秘需参数
* @param string $prepayId 统一下单预支付码
* @return array
*/
public function appParams($prepayId)
{
$data = [
'appid' => $this->config->get('appid'),
'partnerid' => $this->config->get('mch_id'),
'prepayid' => (string)$prepayId,
'package' => 'Sign=WXPay',
'timestamp' => (string)time(),
'noncestr' => Tools::createNoncestr(),
];
$data['sign'] = $this->getPaySign($data, 'MD5');
return $data;
}
/**
* 刷卡支付 撤销订单
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function reverse(array $options)
{
$url = 'https://api.mch.weixin.qq.com/secapi/pay/reverse';
return $this->callPostApi($url, $options, true);
}
/**
* 刷卡支付 授权码查询openid
* @param string $authCode 扫码支付授权码,设备读取用户微信中的条码或者二维码信息
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function queryAuthCode($authCode)
{
$url = 'https://api.mch.weixin.qq.com/tools/authcodetoopenid';
return $this->callPostApi($url, ['auth_code' => $authCode]);
}
/**
* 刷卡支付 交易保障
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function report(array $options)
{
$url = 'https://api.mch.weixin.qq.com/payitil/report';
return $this->callPostApi($url, $options);
}
}