Redpack::getHbInfo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 6
ccs 6
cts 6
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
namespace zhangv\wechat\pay\service;
3
use \zhangv\wechat\pay\WechatPay;
4
use \Exception;
5
6
/**
7
 * 现金红包
8
 * @license MIT
9
 * @zhangv
10
 * @link https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_1
11
 *
12
 */
13
class Redpack extends WechatPay {
14
15
	/**
16
	 * 发放普通红包
17
	 * @param $mch_billno string 商户订单号
18
	 * @param $send_name string 商户名称
19
	 * @param $re_openid string 用户openid
20
	 * @param $total_amount int 付款金额 单位分
21
	 * @param $total_num int 红包发放总人数
22
	 * @param $wishing string 红包祝福语
23
	 * @param $act_name string 活动名称
24
	 * @param $remark string 备注
25
	 * @param $scene_id string 场景id,发放红包使用场景,红包金额大于200时必传 PRODUCT_1:商品促销 PRODUCT_2:抽奖 PRODUCT_3:虚拟物品兑奖 PRODUCT_4:企业内部福利 PRODUCT_5:渠道分润 PRODUCT_6:保险回馈 PRODUCT_7:彩票派奖 PRODUCT_8:税务刮奖
26
	 * @param $riskinfo string 活动信息
27
	 * @param $consume_mch_id string 资金授权商户号
28
	 * @return array
29
	 * @throws Exception
30
	 */
31 2
	public function sendRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){
32 2
		$data = array();
33 2
		$data["wxappid"] = $this->config["app_id"];
34 2
		$data["mch_billno"] = $mch_billno;
35 2
		$data["send_name"] = $send_name;
36 2
		$data["re_openid"] = $re_openid;
37 2
		$data["total_amount"] = $total_amount;
38 2
		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000");
39 2
		$data["total_num"] = $total_num;
40 2
		$data["wishing"] = $wishing;
41 2
		$data["act_name"] = $act_name;
42 2
		$data["remark"] = $remark;
43 2
		$data["scene_id"] = $scene_id;
44 2
		$data["riskinfo"] = $riskinfo;
45 2
		$data["consume_mch_id"] = $consume_mch_id;
46 2
		return$this->post(self::URL_SENDREDPACK, $data, true);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->post(self:...NDREDPACK, $data, true) also could return the type string|true which is incompatible with the documented return type array.
Loading history...
47
	}
48
49
	/**
50
	 * 发放裂变红包
51
	 * @param $mch_billno string 商户订单号
52
	 * @param $send_name string 商户名称
53
	 * @param $re_openid string 用户openid
54
	 * @param $total_amount int 付款金额 单位分
55
	 * @param $total_num int 红包发放总人数
56
	 * @param $wishing string 红包祝福语
57
	 * @param $act_name string 活动名称
58
	 * @param $remark string 备注
59
	 * @param $scene_id string 场景id,发放红包使用场景,红包金额大于200时必传 PRODUCT_1:商品促销 PRODUCT_2:抽奖 PRODUCT_3:虚拟物品兑奖 PRODUCT_4:企业内部福利 PRODUCT_5:渠道分润 PRODUCT_6:保险回馈 PRODUCT_7:彩票派奖 PRODUCT_8:税务刮奖
60
	 * @param $riskinfo string 活动信息
61
	 * @param $consume_mch_id string 资金授权商户号
62
	 * @return array
63
	 * @throws Exception
64
	 */
65 2
	public function sendGroupRedPack($mch_billno,$send_name,$re_openid,$total_amount,$total_num,$wishing,$act_name,$remark,$scene_id = '',$riskinfo = '',$consume_mch_id = ''){
66 2
		$data = array();
67 2
		$data["wxappid"] = $this->config["app_id"];//NOTE: WXappid
68 2
		$data["mch_billno"] = $mch_billno;
69 2
		$data["send_name"] = $send_name;
70 2
		$data["re_openid"] = $re_openid;
71 2
		$data["total_amount"] = $total_amount;
72 2
		if($total_amount > 20000 && trim($scene_id)=='') throw new Exception("scene_id is required when total_amount beyond 20000(200rmb)");
73 2
		$data["total_num"] = $total_num;
74 2
		$data["amt_type"] = 'ALL_RAND'; //红包金额设置方式 ALL_RAND—全部随机
75 2
		$data["wishing"] = $wishing;
76 2
		$data["act_name"] = $act_name;
77 2
		$data["remark"] = $remark;
78 2
		$data["scene_id"] = $scene_id;
79 2
		$data["riskinfo"] = $riskinfo;
80 2
		$data["consume_mch_id"] = $consume_mch_id;
81 2
		return $this->post(self::URL_SENDGROUPREDPACK, $data, true);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->post(self:...UPREDPACK, $data, true) also could return the type string|true which is incompatible with the documented return type array.
Loading history...
82
	}
83
84
	/**
85
	 * 查询红包记录
86
	 * @param $mch_billno string 商户订单号
87
	 * @return array
88
	 * @throws Exception
89
	 */
90 2
	public function getHbInfo($mch_billno){
91 2
		$data = array();
92 2
		$data["mch_billno"] = $mch_billno;
93 2
		$data["appid"] = $this->config["app_id"];
94 2
		$data["bill_type"] = 'MCHT'; //MCHT:通过商户订单号获取红包信息。
95 2
		return $this->post(self::URL_GETHBINFO, $data, true);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->post(self:...GETHBINFO, $data, true) also could return the type string|true which is incompatible with the documented return type array.
Loading history...
96
	}
97
98
}