优化代码

This commit is contained in:
jinyu 2016-05-20 16:36:25 +08:00
parent c634f08268
commit 75fc4edb39
9 changed files with 55 additions and 47 deletions

View File

@ -229,6 +229,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>

View File

@ -45,6 +45,10 @@ public class WeixinException extends Exception {
return desc;
}
public String getErrorText() {
return WeixinErrorUtil.getText(code);
}
@Override
public String getMessage() {
StringBuilder buf = new StringBuilder();

View File

@ -62,12 +62,12 @@ public class Button implements Serializable {
}
/**
* 创建一个菜单(一级菜单)
* 创建一个菜单
*
* @param name
* 菜单显示的
* 菜单
* @param subButtons
* 二级菜单
* 二级菜单列表
*/
public Button(String name, Button... subButtons) {
this.name = name;
@ -75,14 +75,14 @@ public class Button implements Serializable {
}
/**
* 创建一个菜单(二级菜单)
* 创建一个菜单
*
* @param name
* 菜单显示的
* 菜单
* @param content
* 当buttonType为view时content设置为url,否则为key.
* 菜单内容
* @param type
* 按钮类型
* 菜单类型
*/
public Button(String name, String content, ButtonType type) {
this.name = name;

View File

@ -6,7 +6,6 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.model.WeixinPayAccount;
import com.foxinmy.weixin4j.util.DateUtil;
/**
@ -26,19 +25,7 @@ import com.foxinmy.weixin4j.util.DateUtil;
public class Redpacket extends MerchantResult {
private static final long serialVersionUID = -7021352305575714281L;
/**
* 服务商模式下触达用户时的appid(可填服务商自己的appid或子商户的appid)服务商模式下必填
* 服务商模式下填入的子商户appid必须在微信支付商户平台中先录入否则会校验不过 非必须
*/
@XmlElement(name = "msgappid")
@JSONField(name = "msgappid")
private String subMsgId;
/**
* 扣钱方mchid,常规模式下无效服务商模式下选填服务商模式下不填默认扣子商户的钱.非必须
*/
@XmlElement(name = "consume_mch_id")
@JSONField(name = "consume_mch_id")
private String consumeMchId;
/**
* 商户订单号每个订单号必须唯一 组成 mch_id+yyyymmdd+10位一天内不能重复的数字
*/
@ -96,6 +83,20 @@ public class Redpacket extends MerchantResult {
*/
private String remark;
/**
* 服务商模式下触达用户时的appid(可填服务商自己的appid或子商户的appid)服务商模式下必填
* 服务商模式下填入的子商户appid必须在微信支付商户平台中先录入否则会校验不过 非必须
*/
@XmlElement(name = "msgappid")
@JSONField(name = "msgappid")
private String msgAppId;
/**
* 扣钱方mchid,常规模式下无效服务商模式下选填服务商模式下不填默认扣子商户的钱.非必须
*/
@XmlElement(name = "consume_mch_id")
@JSONField(name = "consume_mch_id")
private String consumeMchId;
protected Redpacket() {
// jaxb required
}
@ -122,9 +123,9 @@ public class Redpacket extends MerchantResult {
* @param remark
* 备注 必填
*/
public Redpacket(WeixinPayAccount weixinPayAccount, String outTradeNo,
String sendName, String openid, double totalAmount, int totalNum,
String wishing, String clientIp, String actName, String remark) {
public Redpacket(String outTradeNo, String sendName, String openid,
double totalAmount, int totalNum, String wishing, String clientIp,
String actName, String remark) {
this(null, null, outTradeNo, sendName, openid, totalAmount, totalNum,
wishing, clientIp, actName, remark);
}
@ -132,12 +133,11 @@ public class Redpacket extends MerchantResult {
/**
* 红包 完整参数
*
* @param subMchId
* 子商户商户号 非必填
* @param subMsgId
* 触达用户appid 非必填
* @param msgAppId
* 触达用户appid 服务商模式下触达用户时的appid(可填服务商自己的appid或子商户的appid)服务商模式下必填
* 服务商模式下填入的子商户appid必须在微信支付商户平台中先录入否则会校验不过
* @param consumeMchId
* 扣钱方mchid 非必填
* 常规模式下无效服务商模式下选填服务商模式下不填默认扣子商户的钱
* @param outTradeNo
* 商户侧一天内不可重复的订单号 接口根据商户订单号支持重入 如出现超时可再调用 必填
* @param sendName
@ -157,10 +157,10 @@ public class Redpacket extends MerchantResult {
* @param remark
* 备注 必填
*/
public Redpacket(String subMsgId, String consumeMchId, String outTradeNo,
public Redpacket(String msgAppId, String consumeMchId, String outTradeNo,
String sendName, String openid, double totalAmount, int totalNum,
String wishing, String clientIp, String actName, String remark) {
this.subMsgId = subMsgId;
this.msgAppId = msgAppId;
this.consumeMchId = consumeMchId;
this.outTradeNo = outTradeNo;
this.sendName = sendName;
@ -216,7 +216,7 @@ public class Redpacket extends MerchantResult {
@Override
public String toString() {
return "Redpacket [subMsgId=" + subMsgId + ", consumeMchId="
return "Redpacket [msgAppId=" + msgAppId + ", consumeMchId="
+ consumeMchId + ", outTradeNo=" + outTradeNo + ", sendName="
+ sendName + ", openid=" + openid + ", totalAmount="
+ totalAmount + ", totalNum=" + totalNum + ", amtType="

View File

@ -26,7 +26,7 @@ public class CashTest extends PayTest {
@Test
public void sendRedpacket() throws WeixinException, IOException {
Redpacket redpacket = new Redpacket(ACCOUNT, "HB001", "无忧钱庄",
Redpacket redpacket = new Redpacket("HB001", "无忧钱庄",
"oyFLst1bqtuTcxK-ojF8hOGtLQao", 1d, 1, "红包测试", "127.0.0.1",
"快来领取红包吧!", "来就送钱");
RedpacketSendResult result = PAY.sendRedpack(

View File

@ -50,7 +50,7 @@ public class WeixinTicketCreator extends AbstractTokenCreator {
@Override
public Token createToken() throws WeixinException {
WeixinResponse response = weixinExecutor.get(
String.format(URLConsts.TICKET_URL, weixinTokenHolder.getToken().getAccessToken(), ticketType.name()));
String.format(URLConsts.JS_TICKET_URL, weixinTokenHolder.getToken().getAccessToken(), ticketType.name()));
JSONObject result = response.getAsJson();
Token token = new Token(result.getString("ticket"));
token.setExpiresIn(result.getIntValue("expires_in"));

View File

@ -19,6 +19,6 @@ public final class URLConsts {
/**
* 公众平台jssdk获取token的url
*/
public static final String TICKET_URL = BASE_URL
public static final String JS_TICKET_URL = BASE_URL
+ "/ticket/getticket?access_token=%s&type=%s";
}