对裂变红包的支持 & 去除废弃的字段

This commit is contained in:
jinyu 2016-01-15 15:15:55 +08:00
parent efa08c3bf4
commit 2a6e5eec70
5 changed files with 65 additions and 127 deletions

View File

@ -72,8 +72,9 @@ public class CashApi {
try {
WeixinRequestExecutor weixinExecutor = new WeixinSSLRequestExecutor(
weixinAccount.getMchId(), ca);
response = weixinExecutor.post(PayURLConsts.MCH_REDPACKSEND_URL,
param);
response = weixinExecutor
.post(redpacket.getTotalNum() > 1 ? PayURLConsts.MCH_REDPACK_GROUPSEND_URL
: PayURLConsts.MCH_REDPACKSEND_URL, param);
} finally {
if (ca != null) {
try {
@ -108,7 +109,8 @@ public class CashApi {
para.put("bill_type", "MCHT");
para.put("appid", weixinAccount.getId());
para.put("mch_billno", outTradeNo);
String sign = DigestUtil.paysignMd5(para, weixinAccount.getPaySignKey());
String sign = DigestUtil
.paysignMd5(para, weixinAccount.getPaySignKey());
para.put("sign", sign);
String param = XmlStream.map2xml(para);
WeixinResponse response = null;

View File

@ -69,10 +69,15 @@ public final class PayURLConsts {
public static final String MCH_PAYREPORT_URL = MCH_BASE_URL
+ "/payitil/report";
/**
* 发送现金红包(商户平台)
* 发送现金红包-普通红包(商户平台)
*/
public static final String MCH_REDPACKSEND_URL = MCH_BASE_URL
+ "/mmpaymkttransfers/sendredpack";
/**
* 发送现金红包-裂变红包(商户平台)
*/
public static final String MCH_REDPACK_GROUPSEND_URL = MCH_BASE_URL
+ "/mmpaymkttransfers/sendgroupredpack";
/**
* 查询现金红包(商户平台)
*/

View File

@ -18,7 +18,9 @@ import com.foxinmy.weixin4j.util.DateUtil;
* @date 2015年3月28日
* @since JDK 1.6
* @see <a
* href="http://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=13_1">红包简介</a>
* href="http://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=13_1">普通红包</a>
* @see <a
* href="https://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=16_1">裂变红包</a>
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@ -31,12 +33,6 @@ public class Redpacket implements Serializable {
@XmlElement(name = "mch_billno")
@JSONField(name = "mch_billno")
private String outTradeNo;
/**
* 提供方名称 必填
*/
@XmlElement(name = "nick_name")
@JSONField(name = "nick_name")
private String nickName;
/**
* 红包发送者名称 必填
*/
@ -55,24 +51,18 @@ public class Redpacket implements Serializable {
@XmlElement(name = "total_amount")
@JSONField(name = "total_amount")
private String totalAmount;
/**
* 最小红包金额单位分
*/
@XmlElement(name = "min_value")
@JSONField(name = "min_value")
private String minValue;
/**
* 最大红包金额单位分 最小金额等于最大金额 min_value=max_value =total_amount
*/
@XmlElement(name = "max_value")
@JSONField(name = "max_value")
private String maxValue;
/**
* 红包发放总人数
*/
@XmlElement(name = "total_num")
@JSONField(name = "total_num")
private int totalNum;
/**
* 红包金额设置方式(裂变红包) ALL_RAND全部随机,商户指定总金额和红包发放总人数由微信支付随机计算出各红包金额
*/
@XmlElement(name = "amt_type")
@JSONField(name = "amt_type")
private String amtType;
/**
* 红包祝福语
*/
@ -93,30 +83,6 @@ public class Redpacket implements Serializable {
* 备注
*/
private String remark;
/**
* 商户logo的url 非必填
*/
@XmlElement(name = "logo_imgurl")
@JSONField(name = "logo_imgurl")
private String logoUrl;
/**
* 分享文案 非必填
*/
@XmlElement(name = "share_content")
@JSONField(name = "share_content")
private String shareContent;
/**
* 分享链接 非必填
*/
@XmlElement(name = "share_url")
@JSONField(name = "share_url")
private String shareUrl;
/**
* 分享的图片 非必填
*/
@XmlElement(name = "share_imgurl")
@JSONField(name = "share_imgurl")
private String shareImageUrl;
protected Redpacket() {
// jaxb required
@ -127,32 +93,29 @@ public class Redpacket implements Serializable {
*
* @param outTradeNo
* 商户侧一天内不可重复的订单号 接口根据商户订单号支持重入 如出现超时可再调用
* @param nickName
* 提供方名称
* @param sendName
* 红包发送者名称
* @param openid
* 接受收红包的用户的openid
* @param totalAmount
* 付款金额 <font color="red">单位为元,自动格式化为分</font>
* @param totalNum
* 红包发放总人数 大于1视为裂变红包
*/
public Redpacket(String outTradeNo, String nickName, String sendName,
String openid, double totalAmount) {
public Redpacket(String outTradeNo, String sendName, String openid,
double totalAmount, int totalNum) {
this.outTradeNo = outTradeNo;
this.nickName = nickName;
this.sendName = sendName;
this.openid = openid;
this.totalAmount = DateUtil.formaFee2Fen(totalAmount);
this.totalNum = totalNum;
this.amtType = totalNum > 1 ? "ALL_RAND" : null;
}
public String getOutTradeNo() {
return outTradeNo;
}
public String getNickName() {
return nickName;
}
public String getSendName() {
return sendName;
}
@ -165,42 +128,10 @@ public class Redpacket implements Serializable {
return totalAmount;
}
public String getMinValue() {
return minValue;
}
/**
* <font color="red">单位为元,自动格式化为分</font>
*
* @param minValue
* 最小红包 单位为元
*/
public void setMinValue(double minValue) {
this.minValue = DateUtil.formaFee2Fen(minValue);
}
public String getMaxValue() {
return maxValue;
}
/**
* <font color="red">单位为元,自动格式化为分</font>
*
* @param minValue
* 最大红包 单位为元
*/
public void setMaxValue(double maxValue) {
this.maxValue = DateUtil.formaFee2Fen(maxValue);
}
public int getTotalNum() {
return totalNum;
}
public void setTotalNum(int totalNum) {
this.totalNum = totalNum;
}
public String getWishing() {
return wishing;
}
@ -209,6 +140,14 @@ public class Redpacket implements Serializable {
this.wishing = wishing;
}
public String getAmtType() {
return amtType;
}
public void setAmtType(String amtType) {
this.amtType = amtType;
}
public String getClientIp() {
return clientIp;
}
@ -233,47 +172,12 @@ public class Redpacket implements Serializable {
this.remark = remark;
}
public String getLogoUrl() {
return logoUrl;
}
public void setLogoUrl(String logoUrl) {
this.logoUrl = logoUrl;
}
public String getShareContent() {
return shareContent;
}
public void setShareContent(String shareContent) {
this.shareContent = shareContent;
}
public String getShareUrl() {
return shareUrl;
}
public void setShareUrl(String shareUrl) {
this.shareUrl = shareUrl;
}
public String getShareImageUrl() {
return shareImageUrl;
}
public void setShareImageUrl(String shareImageUrl) {
this.shareImageUrl = shareImageUrl;
}
@Override
public String toString() {
return "Redpacket [ nickName=" + nickName + ", sendName=" + sendName
+ ", openid=" + openid + ", totalAmount=" + totalAmount
+ ", minValue=" + minValue + ", maxValue=" + maxValue
return "Redpacket [ sendName=" + sendName + ", openid=" + openid
+ ", amtType=" + amtType + ", totalAmount=" + totalAmount
+ ", totalNum=" + totalNum + ", wishing=" + wishing
+ ", clientIp=" + clientIp + ", actName=" + actName
+ ", remark=" + remark + ", logoUrl=" + logoUrl
+ ", shareContent=" + shareContent + ", shareUrl=" + shareUrl
+ ", shareImageUrl=" + shareImageUrl + "]";
+ ", remark=" + remark + "]";
}
}

View File

@ -44,7 +44,6 @@ public class RedpacketRecord extends XmlResult {
@XmlElement(name = "mch_id")
@JSONField(name = "mch_id")
private String mchId;
/**
* 红包单号
*/

View File

@ -1,5 +1,7 @@
package com.foxinmy.weixin4j.payment.mch;
import java.util.Date;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
@ -7,6 +9,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.http.weixin.XmlResult;
import com.foxinmy.weixin4j.util.DateUtil;
/**
* 发送红包结果
@ -52,6 +55,18 @@ public class RedpacketSendResult extends XmlResult {
@XmlElement(name = "total_amount")
@JSONField(name = "total_amount")
private int totalAmount;
/**
* 发放成功时间
*/
@XmlElement(name = "send_time")
@JSONField(name = "send_time")
private String sendTime;
/**
* 微信单号
*/
@XmlElement(name = "send_listid")
@JSONField(name = "send_listid")
private String sendListid;
protected RedpacketSendResult() {
// jaxb required
@ -87,6 +102,19 @@ public class RedpacketSendResult extends XmlResult {
return totalAmount / 100d;
}
public String getSendTime() {
return sendTime;
}
@JSONField(serialize = false)
public Date getFormatSendTime() {
return DateUtil.parse2yyyyMMddHHmmss(sendTime);
}
public String getSendListid() {
return sendListid;
}
@Override
public String toString() {
return "RedpacketSendResult [appId=" + appId + ", mchId=" + mchId