优化代码

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> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId> <artifactId>maven-javadoc-plugin</artifactId>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
</plugin>
</plugins> </plugins>
</build> </build>
</profile> </profile>

View File

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

View File

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

View File

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

View File

@ -26,7 +26,7 @@ public class CashTest extends PayTest {
@Test @Test
public void sendRedpacket() throws WeixinException, IOException { 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", "oyFLst1bqtuTcxK-ojF8hOGtLQao", 1d, 1, "红包测试", "127.0.0.1",
"快来领取红包吧!", "来就送钱"); "快来领取红包吧!", "来就送钱");
RedpacketSendResult result = PAY.sendRedpack( RedpacketSendResult result = PAY.sendRedpack(

View File

@ -50,7 +50,7 @@ public class WeixinTicketCreator extends AbstractTokenCreator {
@Override @Override
public Token createToken() throws WeixinException { public Token createToken() throws WeixinException {
WeixinResponse response = weixinExecutor.get( 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(); JSONObject result = response.getAsJson();
Token token = new Token(result.getString("ticket")); Token token = new Token(result.getString("ticket"));
token.setExpiresIn(result.getIntValue("expires_in")); token.setExpiresIn(result.getIntValue("expires_in"));

View File

@ -19,6 +19,6 @@ public final class URLConsts {
/** /**
* 公众平台jssdk获取token的url * 公众平台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"; + "/ticket/getticket?access_token=%s&type=%s";
} }