View Javadoc
1   package com.foxinmy.weixin4j.payment.mch;
2   
3   import javax.xml.bind.annotation.XmlAccessType;
4   import javax.xml.bind.annotation.XmlAccessorType;
5   import javax.xml.bind.annotation.XmlElement;
6   import javax.xml.bind.annotation.XmlRootElement;
7   
8   import com.alibaba.fastjson.annotation.JSONField;
9   import com.foxinmy.weixin4j.type.mch.RedpacketSceneType;
10  import com.foxinmy.weixin4j.util.DateUtil;
11  
12  /**
13   * 红包
14   *
15   * @className Redpacket
16   * @author jinyu(foxinmy@gmail.com)
17   * @date 2015年3月28日
18   * @since JDK 1.6
19   * @see <a
20   *      href="https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_1">普通红包</a>
21   * @see <a
22   *      href="https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=16_1">裂变红包</a>
23   * @deprecated 迁移到子模块weixin4j-pay
24   */
25  @Deprecated
26  @XmlRootElement
27  @XmlAccessorType(XmlAccessType.FIELD)
28  public class Redpacket extends MerchantResult {
29  
30  	private static final long serialVersionUID = -7021352305575714281L;
31  
32  	/**
33  	 * 商户订单号(每个订单号必须唯一) 组成: mch_id+yyyymmdd+10位一天内不能重复的数字。
34  	 */
35  	@XmlElement(name = "mch_billno")
36  	@JSONField(name = "mch_billno")
37  	private String outTradeNo;
38  	/**
39  	 * 接受收红包的用户的openid 必填
40  	 */
41  	@XmlElement(name = "re_openid")
42  	@JSONField(name = "re_openid")
43  	private String openId;
44  	/**
45  	 * 红包发送者名称 必填
46  	 */
47  	@XmlElement(name = "send_name")
48  	@JSONField(name = "send_name")
49  	private String sendName;
50  	/**
51  	 * 付款金额,单位分
52  	 */
53  	@XmlElement(name = "total_amount")
54  	@JSONField(name = "total_amount")
55  	private int totalAmount;
56  	/**
57  	 * 红包发放总人数
58  	 */
59  	@XmlElement(name = "total_num")
60  	@JSONField(name = "total_num")
61  	private int totalNum;
62  	/**
63  	 * 红包金额设置方式(裂变红包) ALL_RAND—全部随机,商户指定总金额和红包发放总人数,由微信支付随机计算出各红包金额
64  	 */
65  	@XmlElement(name = "amt_type")
66  	@JSONField(name = "amt_type")
67  	private String amtType;
68  	/**
69  	 * 红包祝福语
70  	 */
71  	private String wishing;
72  	/**
73  	 * ip地址
74  	 */
75  	@XmlElement(name = "client_ip")
76  	@JSONField(name = "client_ip")
77  	private String clientIp;
78  	/**
79  	 * 活动名称
80  	 */
81  	@XmlElement(name = "act_name")
82  	@JSONField(name = "act_name")
83  	private String actName;
84  	/**
85  	 * 备注
86  	 */
87  	private String remark;
88  
89  	/**
90  	 * 服务商模式下触达用户时的appid(可填服务商自己的appid或子商户的appid),服务商模式下必填,
91  	 * 服务商模式下填入的子商户appid必须在微信支付商户平台中先录入,否则会校验不过。 非必须
92  	 */
93  	@XmlElement(name = "msgappid")
94  	@JSONField(name = "msgappid")
95  	private String msgAppId;
96  	/**
97  	 * 扣钱方mchid,常规模式下无效,服务商模式下选填,服务商模式下不填默认扣子商户的钱.非必须
98  	 */
99  	@XmlElement(name = "consume_mch_id")
100 	@JSONField(name = "consume_mch_id")
101 	private String consumeMchId;
102 	/**
103 	 * 发放红包使用场景,红包金额大于200时必传
104 	 */
105 	@XmlElement(name = "scene_id")
106 	@JSONField(name = "scene_id")
107 	private RedpacketSceneType sceneType;
108 	/**
109 	 * 活动信息
110 	 */
111 	@XmlElement(name = "risk_info")
112 	@JSONField(name = "risk_info")
113 	private String risk;
114 
115 	protected Redpacket() {
116 		// jaxb required
117 	}
118 
119 	/**
120 	 * 红包
121 	 *
122 	 * @param outTradeNo
123 	 *            商户侧一天内不可重复的订单号 接口根据商户订单号支持重入 如出现超时可再调用 必填
124 	 * @param openId
125 	 *            接受收红包的用户的openid 必填
126 	 * @param sendName
127 	 *            红包发送者名称 必填
128 	 * @param totalAmount
129 	 *            付款金额 <font color="red">单位为元,自动格式化为分</font> 必填
130 	 * @param totalNum
131 	 *            红包发放总人数 大于1视为裂变红包 必填
132 	 * @param wishing
133 	 *            红包祝福语 必填
134 	 * @param clientIp
135 	 *            Ip地址 必填
136 	 * @param actName
137 	 *            活动名称 必填
138 	 * @param remark
139 	 *            备注 必填
140 	 */
141 	public Redpacket(String outTradeNo, String openId, String sendName,
142 			double totalAmount, int totalNum, String wishing, String clientIp,
143 			String actName, String remark) {
144 		this.outTradeNo = outTradeNo;
145 		this.openId = openId;
146 		this.sendName = sendName;
147 		this.totalAmount = DateUtil.formatYuan2Fen(totalAmount);
148 		this.totalNum = totalNum;
149 		this.wishing = wishing;
150 		this.clientIp = clientIp;
151 		this.actName = actName;
152 		this.remark = remark;
153 		this.amtType = totalNum > 1 ? "ALL_RAND" : null;
154 	}
155 
156 	/**
157 	 * 批量发送时可能需要
158 	 * 
159 	 * @param outTradeNo
160 	 *            订单号
161 	 * @param openId
162 	 *            用户ID
163 	 * @return 红包实体
164 	 */
165 	public Redpacket copy(String outTradeNo, String openId) {
166 		Redpacket readpacket = new Redpacket(outTradeNo, openId, sendName,
167 				totalAmount, totalNum, wishing, clientIp, actName, remark);
168 		readpacket.setMsgAppId(msgAppId);
169 		readpacket.setConsumeMchId(consumeMchId);
170 		readpacket.setSceneType(sceneType);
171 		readpacket.setRisk(risk);
172 		return readpacket;
173 	}
174 
175 	public String getOutTradeNo() {
176 		return outTradeNo;
177 	}
178 
179 	public String getOpenId() {
180 		return openId;
181 	}
182 
183 	public String getSendName() {
184 		return sendName;
185 	}
186 
187 	public int getTotalAmount() {
188 		return totalAmount;
189 	}
190 
191 	/**
192 	 * <font color="red">调用接口获取单位为分,get方法转换为元方便使用</font>
193 	 * 
194 	 * @return 元单位
195 	 */
196 	@JSONField(serialize = false)
197 	public double getFormatTotalAmount() {
198 		return totalAmount / 100d;
199 	}
200 
201 	public int getTotalNum() {
202 		return totalNum;
203 	}
204 
205 	public String getWishing() {
206 		return wishing;
207 	}
208 
209 	public String getAmtType() {
210 		return amtType;
211 	}
212 
213 	public String getClientIp() {
214 		return clientIp;
215 	}
216 
217 	public String getActName() {
218 		return actName;
219 	}
220 
221 	public String getRemark() {
222 		return remark;
223 	}
224 
225 	public String getMsgAppId() {
226 		return msgAppId;
227 	}
228 
229 	public void setMsgAppId(String msgAppId) {
230 		this.msgAppId = msgAppId;
231 	}
232 
233 	public String getConsumeMchId() {
234 		return consumeMchId;
235 	}
236 
237 	public void setConsumeMchId(String consumeMchId) {
238 		this.consumeMchId = consumeMchId;
239 	}
240 
241 	public RedpacketSceneType getSceneType() {
242 		return sceneType;
243 	}
244 
245 	public void setSceneType(RedpacketSceneType sceneType) {
246 		this.sceneType = sceneType;
247 	}
248 
249 	public String getRisk() {
250 		return risk;
251 	}
252 
253 	public void setRisk(String risk) {
254 		this.risk = risk;
255 	}
256 
257 	public void setRisk(RedpacketRisk risk) {
258 		this.risk = risk.toContent();
259 	}
260 
261 	@Override
262 	public String toString() {
263 		return "Redpacket [outTradeNo=" + outTradeNo + ", openId=" + openId
264 				+ ", sendName=" + sendName + ", totalAmount=" + totalAmount
265 				+ ", totalNum=" + totalNum + ", amtType=" + amtType
266 				+ ", wishing=" + wishing + ", clientIp=" + clientIp
267 				+ ", actName=" + actName + ", remark=" + remark + ", msgAppId="
268 				+ msgAppId + ", consumeMchId=" + consumeMchId + ", sceneType="
269 				+ sceneType + ", risk=" + risk + ", " + super.toString() + "]";
270 	}
271 }