1 | <?php |
||
22 | class LuckMoney |
||
23 | { |
||
24 | /** |
||
25 | * 发送现金红包 |
||
26 | */ |
||
27 | const API_SEND = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack'; |
||
28 | |||
29 | /** |
||
30 | * 发送裂变红包 |
||
31 | */ |
||
32 | const API_GROUP_SEND = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack'; |
||
33 | |||
34 | /** |
||
35 | * 红包查询 |
||
36 | */ |
||
37 | const API_QUERY = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo'; |
||
38 | |||
39 | /** |
||
40 | * 红包预下单接口 |
||
41 | */ |
||
42 | const API_PREORDER = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/hbpreorder'; |
||
43 | |||
44 | const TYPE_CASH_LUCK_MONEY = 'NORMAL'; //红包类型,现金红包 |
||
45 | const TYPE_GROUP_LUCK_MONEY = 'GROUP'; //红包类型,裂变红包 |
||
46 | |||
47 | |||
48 | |||
49 | /** |
||
50 | * 商户信息 |
||
51 | * |
||
52 | * @var Business |
||
53 | */ |
||
54 | protected $business; |
||
55 | |||
56 | public function __construct(Business $business) |
||
62 | |||
63 | /** |
||
64 | * 设置商户 |
||
65 | * |
||
66 | * @param Business $business |
||
67 | * |
||
68 | * @return $this |
||
69 | */ |
||
70 | public function setBusiness(Business $business) |
||
77 | |||
78 | /** |
||
79 | * 红包预下单,主要用于摇一摇红包活动 |
||
80 | * |
||
81 | * <pre> |
||
82 | * $data: |
||
83 | * { |
||
84 | * "mch_billno": "198374613512", |
||
85 | * "send_name":"某某公司", |
||
86 | * "hb_type":"某某公司", |
||
87 | * "total_amount": 1000, |
||
88 | * "total_num": 1, |
||
89 | * "wishing": "祝福语", |
||
90 | * "act_name": "活动名称", |
||
91 | * "remark": "红包备注", |
||
92 | * "risk_cntl": "NORMAL", |
||
93 | * } |
||
94 | * </pre> |
||
95 | * |
||
96 | * @param array $data |
||
97 | * |
||
98 | * @return array |
||
99 | */ |
||
100 | public function preOrder(array $data) |
||
141 | |||
142 | /** |
||
143 | * 发送红包 |
||
144 | * |
||
145 | * <pre> |
||
146 | * $data: |
||
147 | * { |
||
148 | * "mch_billno": "198374613512", |
||
149 | * "send_name":"某某公司", |
||
150 | * "re_openid": "oJCvDjjQKx5LMtM_1kjK0gGQLsew", |
||
151 | * "total_amount": 1000, |
||
152 | * "wishing": "祝福语", |
||
153 | * "act_name": "活动名称", |
||
154 | * "total_num": 1, |
||
155 | * "remark": "红包备注" |
||
156 | * } |
||
157 | * </pre> |
||
158 | * |
||
159 | * @param array $data |
||
160 | * @param int $type |
||
161 | * |
||
162 | * @return array |
||
163 | */ |
||
164 | public function send(array $data, $type = self::TYPE_CASH_LUCK_MONEY) |
||
212 | |||
213 | /** |
||
214 | * 发送普通红包 |
||
215 | * |
||
216 | * <pre> |
||
217 | * $data: |
||
218 | * { |
||
219 | * "mch_billno": "198374613512", |
||
220 | * "send_name":"某某公司", |
||
221 | * "re_openid": "oJCvDjjQKx5LMtM_1kjK0gGQLsew", |
||
222 | * "total_amount": 1000, |
||
223 | * "wishing": "祝福语", |
||
224 | * "act_name": "活动名称", |
||
225 | * "total_num": 1, |
||
226 | * "remark": "红包备注" |
||
227 | * } |
||
228 | * </pre> |
||
229 | * |
||
230 | * @param array $data |
||
231 | * |
||
232 | * @return array |
||
233 | */ |
||
234 | public function sendNormal(array $data) |
||
238 | |||
239 | /** |
||
240 | * 发送裂变红包 |
||
241 | * |
||
242 | * <pre> |
||
243 | * $data: |
||
244 | * { |
||
245 | * "mch_billno": "198374613512", |
||
246 | * "send_name":"某某公司", |
||
247 | * "re_openid": "oJCvDjjQKx5LMtM_1kjK0gGQLsew", |
||
248 | * "total_amount": 1000, |
||
249 | * "wishing": "祝福语", |
||
250 | * "act_name": "活动名称", |
||
251 | * "total_num": 1, |
||
252 | * "remark": "红包备注" |
||
253 | * } |
||
254 | * </pre> |
||
255 | * |
||
256 | * @param array $data |
||
257 | * |
||
258 | * @return array |
||
259 | */ |
||
260 | public function sendGroup(array $data) |
||
264 | |||
265 | /** |
||
266 | * 查询红包信息 |
||
267 | * |
||
268 | * @param string $mchBillNumber |
||
269 | * |
||
270 | * @return array |
||
271 | */ |
||
272 | public function query($mchBillNumber) |
||
310 | } |
||
311 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.