@@ 55-99 (lines=45) @@ | ||
52 | } |
|
53 | return self._post('mmpaymkttransfers/sendredpack', data=data) |
|
54 | ||
55 | def send_group(self, user_id, total_amount, send_name, act_name, wishing, |
|
56 | remark, total_num, client_ip=None, amt_type="ALL_RAND", |
|
57 | out_trade_no=None, scene_id=None, consume_mch_id=None): |
|
58 | """ |
|
59 | 发送裂变红包 |
|
60 | ||
61 | :param user_id: 接收红包的用户在公众号下的 openid |
|
62 | :param total_amount: 红包金额,单位分 |
|
63 | :param send_name: 商户名称 |
|
64 | :param act_name: 活动名称 |
|
65 | :param wishing: 红包祝福语 |
|
66 | :param remark: 备注 |
|
67 | :param total_num: 红包发放总人数 |
|
68 | :param client_ip: 可选,调用接口的机器 IP 地址 |
|
69 | :param amt_type: 可选,红包金额设置方式 |
|
70 | ALL_RAND—全部随机,商户指定总金额和红包发放总人数,由微信支付随机计算出各红包金额 |
|
71 | :param out_trade_no: 可选,商户订单号,默认会自动生成 |
|
72 | :param scene_id: 可选,发放红包使用场景,红包金额大于200时必传 |
|
73 | :param consume_mch_id: 可选,资金授权商户号。服务商替特约商户发放时使用 |
|
74 | :return: 返回的结果数据字典 |
|
75 | """ |
|
76 | if not out_trade_no: |
|
77 | now = datetime.now() |
|
78 | out_trade_no = '{0}{1}{2}'.format( |
|
79 | self._client.mch_id, |
|
80 | now.strftime('%Y%m%d%H%M%S'), |
|
81 | random.randint(1000, 10000) |
|
82 | ) |
|
83 | data = { |
|
84 | 'wxappid': self.appid, |
|
85 | 're_openid': user_id, |
|
86 | 'total_amount': total_amount, |
|
87 | 'send_name': send_name, |
|
88 | 'act_name': act_name, |
|
89 | 'wishing': wishing, |
|
90 | 'remark': remark, |
|
91 | 'total_num': total_num, |
|
92 | 'client_ip': client_ip or get_external_ip(), |
|
93 | 'amt_type': amt_type, |
|
94 | 'mch_billno': out_trade_no, |
|
95 | 'scene_id': scene_id, |
|
96 | 'risk_info': None, |
|
97 | 'consume_mch_id': consume_mch_id |
|
98 | } |
|
99 | return self._post('mmpaymkttransfers/sendgroupredpack', data=data) |
|
100 | ||
101 | def query(self, out_trade_no, bill_type='MCHT'): |
|
102 | """ |
|
@@ 12-53 (lines=42) @@ | ||
9 | ||
10 | class WeChatRedpack(BaseWeChatPayAPI): |
|
11 | ||
12 | def send(self, user_id, total_amount, send_name, act_name, |
|
13 | wishing, remark, total_num=1, client_ip=None, |
|
14 | out_trade_no=None, scene_id=None, consume_mch_id=None): |
|
15 | """ |
|
16 | 发送现金红包 |
|
17 | ||
18 | :param user_id: 接收红包的用户在公众号下的 openid |
|
19 | :param total_amount: 红包金额,单位分 |
|
20 | :param send_name: 商户名称 |
|
21 | :param act_name: 活动名称 |
|
22 | :param wishing: 红包祝福语 |
|
23 | :param remark: 备注 |
|
24 | :param client_ip: 可选,调用接口的机器 IP 地址 |
|
25 | :param total_num: 可选,红包发放总人数,默认为 1 |
|
26 | :param out_trade_no: 可选,商户订单号,默认会自动生成 |
|
27 | :param scene_id: 可选,发放红包使用场景,红包金额大于200时必传 |
|
28 | :param consume_mch_id: 可选,资金授权商户号。服务商替特约商户发放时使用 |
|
29 | :return: 返回的结果数据字典 |
|
30 | """ |
|
31 | if not out_trade_no: |
|
32 | now = datetime.now() |
|
33 | out_trade_no = '{0}{1}{2}'.format( |
|
34 | self.mch_id, |
|
35 | now.strftime('%Y%m%d%H%M%S'), |
|
36 | random.randint(1000, 10000) |
|
37 | ) |
|
38 | data = { |
|
39 | 'wxappid': self.appid, |
|
40 | 're_openid': user_id, |
|
41 | 'total_amount': total_amount, |
|
42 | 'send_name': send_name, |
|
43 | 'act_name': act_name, |
|
44 | 'wishing': wishing, |
|
45 | 'remark': remark, |
|
46 | 'client_ip': client_ip or get_external_ip(), |
|
47 | 'total_num': total_num, |
|
48 | 'mch_billno': out_trade_no, |
|
49 | 'scene_id': scene_id, |
|
50 | 'risk_info': None, |
|
51 | 'consume_mch_id': consume_mch_id |
|
52 | } |
|
53 | return self._post('mmpaymkttransfers/sendredpack', data=data) |
|
54 | ||
55 | def send_group(self, user_id, total_amount, send_name, act_name, wishing, |
|
56 | remark, total_num, client_ip=None, amt_type="ALL_RAND", |