1 | <?php |
||
32 | class API extends AbstractAPI |
||
33 | { |
||
34 | /** |
||
35 | * Merchant instance. |
||
36 | * |
||
37 | * @var Merchant |
||
38 | */ |
||
39 | protected $merchant; |
||
40 | |||
41 | // api |
||
42 | const API_SEND = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack'; |
||
43 | const API_SEND_GROUP = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack'; |
||
44 | const API_QUERY = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo'; |
||
45 | const API_PREPARE = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/hbpreorder'; |
||
46 | |||
47 | // LuckyMoney type |
||
48 | const TYPE_NORMAL = 'NORMAL'; |
||
49 | const TYPE_GROUP = 'GROUP'; |
||
50 | |||
51 | // Risk control type. |
||
52 | const RISK_NORMAL = 'NORMAL'; |
||
53 | const RISK_IGN_FREQ_LMT = 'IGN_FREQ_LMT'; |
||
54 | const RISK_IGN_DAY_LMT = 'IGN_DAY_LMT'; |
||
55 | const RISK_IGN_FREQ_DAY_LMT = 'IGN_FREQ_DAY_LMT'; |
||
56 | |||
57 | /** |
||
58 | * API constructor. |
||
59 | * |
||
60 | * @param \EasyWeChat\Payment\Merchant $merchant |
||
61 | */ |
||
62 | 7 | public function __construct(Merchant $merchant) |
|
66 | |||
67 | /** |
||
68 | * Prepare luckymoney. |
||
69 | * |
||
70 | * @param array $params |
||
71 | * |
||
72 | * @return \EasyWeChat\Support\Collection |
||
73 | */ |
||
74 | 1 | public function prepare(array $params) |
|
86 | |||
87 | /** |
||
88 | * Query luckymoney. |
||
89 | * |
||
90 | * @param string $mchBillNo |
||
91 | * |
||
92 | * @return \EasyWeChat\Support\Collection |
||
93 | */ |
||
94 | 1 | public function query($mchBillNo) |
|
104 | |||
105 | /** |
||
106 | * Send LuckyMoney. |
||
107 | * |
||
108 | * @param array $params |
||
109 | * @param string $type |
||
110 | * |
||
111 | * @return \EasyWeChat\Support\Collection |
||
112 | */ |
||
113 | 3 | public function send(array $params, $type = self::TYPE_NORMAL) |
|
121 | |||
122 | /** |
||
123 | * Send normal LuckyMoney. |
||
124 | * |
||
125 | * @param array $params |
||
126 | * |
||
127 | * @return \EasyWeChat\Support\Collection |
||
128 | */ |
||
129 | 1 | public function sendNormal($params) |
|
136 | |||
137 | /** |
||
138 | * Send group luckymoney. |
||
139 | * |
||
140 | * @param array $params |
||
141 | * |
||
142 | * @return \EasyWeChat\Support\Collection |
||
143 | */ |
||
144 | 1 | public function sendGroup($params) |
|
150 | |||
151 | /** |
||
152 | * Merchant setter. |
||
153 | * |
||
154 | * @param Merchant $merchant |
||
155 | * |
||
156 | * @return $this |
||
157 | */ |
||
158 | 1 | public function setMerchant(Merchant $merchant) |
|
162 | |||
163 | /** |
||
164 | * Merchant getter. |
||
165 | * |
||
166 | * @return Merchant |
||
167 | */ |
||
168 | 1 | public function getMerchant() |
|
172 | |||
173 | /** |
||
174 | * Make a API request. |
||
175 | * |
||
176 | * @param string $api |
||
177 | * @param array $params |
||
178 | * @param string $method |
||
179 | * |
||
180 | * @return \EasyWeChat\Support\Collection |
||
181 | */ |
||
182 | 5 | protected function request($api, array $params, $method = 'post') |
|
196 | |||
197 | /** |
||
198 | * Parse Response XML to array. |
||
199 | * |
||
200 | * @param \Psr\Http\Message\ResponseInterface|string $response |
||
201 | * |
||
202 | * @return \EasyWeChat\Support\Collection |
||
203 | */ |
||
204 | 5 | protected function parseResponse($response) |
|
212 | } |
||
213 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: