优化代码

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

@ -10,7 +10,7 @@ import com.foxinmy.weixin4j.logging.InternalLoggerFactory;
/**
* API基础
*
*
* @className BaseApi
* @author jinyu(foxinmy@gmail.com)
* @date 2014年9月26日
@ -22,7 +22,7 @@ public abstract class BaseApi {
protected final InternalLogger logger = InternalLoggerFactory
.getInstance(getClass());
protected final WeixinRequestExecutor weixinExecutor;
protected abstract ResourceBundle weixinBundle();

View File

@ -5,7 +5,7 @@ import com.foxinmy.weixin4j.util.WeixinErrorUtil;
/**
* 调用微信接口抛出的异常
*
*
* @className WeixinException
* @author jinyu(foxinmy@gmail.com)
* @date 2014年4月10日
@ -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

@ -14,7 +14,7 @@ import com.foxinmy.weixin4j.type.ButtonType;
* 目前自定义菜单最多包括3个一级菜单,每个一级菜单最多包含5个二级菜单,一级菜单最多4个汉字,二级菜单最多7个汉字,多出来的部分将会以"..."代替
* 请注意,创建自定义菜单后,由于微信客户端缓存,需要24小时微信客户端才会展现出来,建议测试时可以尝试取消关注公众账号后再次关注,则可以看到创建后的效果
* </p>
*
*
* @className Button
* @author jinyu(foxinmy@gmail.com)
* @date 2014年4月5日
@ -32,7 +32,7 @@ public class Button implements Serializable {
/**
* 菜单类型 </br> <font color="red">
* 公众平台官网上能够设置的菜单类型有viewtextimgphotovideovoice </font>
*
*
* @see com.foxinmy.weixin4j.type.ButtonType
*/
private ButtonType type;
@ -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,12 +6,11 @@ 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;
/**
* 红包
*
*
* @className Redpacket
* @author jinyu(foxinmy@gmail.com)
* @date 2015年3月28日
@ -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,13 +83,27 @@ 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
}
/**
* 红包
*
*
* @param outTradeNo
* 商户侧一天内不可重复的订单号 接口根据商户订单号支持重入 如出现超时可再调用 必填
* @param sendName
@ -122,22 +123,21 @@ 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);
}
/**
* 红包 完整参数
*
* @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

@ -14,7 +14,7 @@ import com.foxinmy.weixin4j.model.Token;
/**
* 用Redis保存Token信息(推荐使用)
*
*
* @className RedisTokenStorager
* @author jinyu(foxinmy@gmail.com)
* @date 2015年1月9日

View File

@ -15,7 +15,7 @@ import com.foxinmy.weixin4j.type.CorpPaymentCheckNameType;
/**
* 现金发放测试
*
*
* @className CashTest
* @author jinyu(foxinmy@gmail.com)
* @date 2015年4月1日
@ -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";
}