调整部分实体类(*paypackage)中没有按照骆驼命名规则的属性名 & 升级fastjson到1.2.3

This commit is contained in:
jy.hu 2015-01-22 11:19:17 +08:00
parent e113bc3af0
commit 1df0978564
11 changed files with 271 additions and 243 deletions

View File

@ -54,7 +54,7 @@
<xstream.version>1.4.7</xstream.version> <xstream.version>1.4.7</xstream.version>
<httpclient.version>4.2.5</httpclient.version> <httpclient.version>4.2.5</httpclient.version>
<commons.codec.version>1.9</commons.codec.version> <commons.codec.version>1.9</commons.codec.version>
<fastjson.version>1.2.1</fastjson.version> <fastjson.version>1.2.3</fastjson.version>
<jsoup.version>1.7.3</jsoup.version> <jsoup.version>1.7.3</jsoup.version>
<jaxen.version>1.1.6</jaxen.version> <jaxen.version>1.1.6</jaxen.version>
<jedis.version>2.6.0</jedis.version> <jedis.version>2.6.0</jedis.version>

View File

@ -23,7 +23,7 @@ import com.foxinmy.weixin4j.model.Token;
public class RedisTokenHolder implements TokenHolder { public class RedisTokenHolder implements TokenHolder {
private JedisPool jedisPool; private JedisPool jedisPool;
private final TokenCreator tokenCretor; private final TokenCreator tokenCreator;
public final static int MAX_TOTAL = 50; public final static int MAX_TOTAL = 50;
public final static int MAX_IDLE = 5; public final static int MAX_IDLE = 5;
@ -31,11 +31,11 @@ public class RedisTokenHolder implements TokenHolder {
public final static boolean TEST_ON_BORROW = false; public final static boolean TEST_ON_BORROW = false;
public final static boolean TEST_ON_RETURN = true; public final static boolean TEST_ON_RETURN = true;
public RedisTokenHolder(TokenCreator tokenCretor) { public RedisTokenHolder(TokenCreator tokenCreator) {
this("localhost", 6379, tokenCretor); this("localhost", 6379, tokenCreator);
} }
public RedisTokenHolder(String host, int port, TokenCreator tokenCretor) { public RedisTokenHolder(String host, int port, TokenCreator tokenCreator) {
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxTotal(MAX_TOTAL); jedisPoolConfig.setMaxTotal(MAX_TOTAL);
jedisPoolConfig.setMaxIdle(MAX_IDLE); jedisPoolConfig.setMaxIdle(MAX_IDLE);
@ -43,17 +43,17 @@ public class RedisTokenHolder implements TokenHolder {
jedisPoolConfig.setTestOnBorrow(TEST_ON_BORROW); jedisPoolConfig.setTestOnBorrow(TEST_ON_BORROW);
jedisPoolConfig.setTestOnReturn(TEST_ON_RETURN); jedisPoolConfig.setTestOnReturn(TEST_ON_RETURN);
this.jedisPool = new JedisPool(jedisPoolConfig, host, port); this.jedisPool = new JedisPool(jedisPoolConfig, host, port);
this.tokenCretor = tokenCretor; this.tokenCreator = tokenCreator;
} }
public RedisTokenHolder(String host, int port, public RedisTokenHolder(String host, int port,
JedisPoolConfig jedisPoolConfig, TokenCreator tokenCretor) { JedisPoolConfig jedisPoolConfig, TokenCreator tokenCreator) {
this(new JedisPool(jedisPoolConfig, host, port), tokenCretor); this(new JedisPool(jedisPoolConfig, host, port), tokenCreator);
} }
public RedisTokenHolder(JedisPool jedisPool, TokenCreator tokenCretor) { public RedisTokenHolder(JedisPool jedisPool, TokenCreator tokenCreator) {
this.jedisPool = jedisPool; this.jedisPool = jedisPool;
this.tokenCretor = tokenCretor; this.tokenCreator = tokenCreator;
} }
@Override @Override
@ -62,10 +62,10 @@ public class RedisTokenHolder implements TokenHolder {
Jedis jedis = null; Jedis jedis = null;
try { try {
jedis = jedisPool.getResource(); jedis = jedisPool.getResource();
String cacheKey = tokenCretor.getCacheKey(); String cacheKey = tokenCreator.getCacheKey();
String accessToken = jedis.get(cacheKey); String accessToken = jedis.get(cacheKey);
if (StringUtils.isBlank(accessToken)) { if (StringUtils.isBlank(accessToken)) {
token = tokenCretor.createToken(); token = tokenCreator.createToken();
jedis.setex(cacheKey, (int) token.getExpiresIn(), jedis.setex(cacheKey, (int) token.getExpiresIn(),
token.getAccessToken()); token.getAccessToken());
} else { } else {

View File

@ -68,7 +68,8 @@ weixin4j-mp
qr_path=/tmp/weixin/qr qr_path=/tmp/weixin/qr
media_path=/tmp/weixin/media media_path=/tmp/weixin/media
bill_path=/tmp/weixin/bill bill_path=/tmp/weixin/bill
ca_file=/tmp/weixin/xxxxx.p12 | xxxx.pfx # ca证书存放的完整路径 (V2版本后缀为*.pfx,V3版本后缀为*.p12)
ca_file=/tmp/weixin/xxxxx.p12
#classpath路径下:ca_file=classpath:xxxxx.p12 #classpath路径下:ca_file=classpath:xxxxx.p12
3.在项目根目录下执行`mvn package -Prelease`命令后得到jar包,将`weixin4j-mp-full`包或者`weixin4j-base``weixin4j-mp-api`两个包引入到自己的工程. 3.在项目根目录下执行`mvn package -Prelease`命令后得到jar包,将`weixin4j-mp-full`包或者`weixin4j-base``weixin4j-mp-api`两个包引入到自己的工程.

View File

@ -61,7 +61,8 @@ weixin.properties说明
qr_path=/tmp/weixin/qr qr_path=/tmp/weixin/qr
media_path=/tmp/weixin/media media_path=/tmp/weixin/media
bill_path=/tmp/weixin/bill bill_path=/tmp/weixin/bill
ca_file=/tmp/weixin/xxxxx.p12 | xxxx.pfx # ca证书存放的完整路径 (V2版本后缀为*.pfx,V3版本后缀为*.p12)
ca_file=/tmp/weixin/xxxxx.p12
#classpath路径下:ca_file=classpath:xxxxx.p12 #classpath路径下:ca_file=classpath:xxxxx.p12
2.实例化一个`WeixinProxy`对象,调用API,需要强调的是如果只传入appid,appsecret两个参数将无法调用支付相关接口 2.实例化一个`WeixinProxy`对象,调用API,需要强调的是如果只传入appid,appsecret两个参数将无法调用支付相关接口

View File

@ -2,8 +2,7 @@ package com.foxinmy.weixin4j.mp.payment;
import java.util.Date; import java.util.Date;
import org.apache.commons.lang3.StringUtils; import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.model.WeixinMpAccount; import com.foxinmy.weixin4j.model.WeixinMpAccount;
import com.foxinmy.weixin4j.util.RandomUtil; import com.foxinmy.weixin4j.util.RandomUtil;
import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamAlias;
@ -23,36 +22,44 @@ public class MicroPayPackage extends PayPackage {
private static final long serialVersionUID = 8944928173669656177L; private static final long serialVersionUID = 8944928173669656177L;
private String appid; // 微信分配的公众账号 必须 private String appid; // 微信分配的公众账号 必须
private String mch_id; // 微信支付分配的商户号 必须 @XStreamAlias("mch_id")
private String device_info; // 微信支付分配的终端设备号 非必须 @JSONField(name = "mch_id")
private String nonce_str; // 随机字符串,不长于 32 必须 private String mchId; // 微信支付分配的商户号 必须
@XStreamAlias("device_info")
@JSONField(name = "device_info")
private String deviceInfo; // 微信支付分配的终端设备号 非必须
@XStreamAlias("nonce_str")
@JSONField(name = "nonce_str")
private String nonceStr; // 随机字符串,不长于 32 必须
private String sign; // 签名 必须 private String sign; // 签名 必须
private String auth_code; // 扫码支付授权码 ,设备读取用 户微信中的条码或者二维码 信息 @XStreamAlias("auth_code")
@JSONField(name = "auth_code")
private String authCode; // 扫码支付授权码 ,设备读取用 户微信中的条码或者二维码 信息
public MicroPayPackage() { public MicroPayPackage() {
} }
public MicroPayPackage(WeixinMpAccount weixinAccount, String body, public MicroPayPackage(WeixinMpAccount weixinAccount, String body,
String attach, String out_trade_no, double total_fee, String attach, String outTradeNo, double totalFee,
String spbill_create_ip, String auth_code) { String spbillCreateIp, String authCode) {
this(weixinAccount.getId(), weixinAccount.getMchId(), weixinAccount this(weixinAccount.getId(), weixinAccount.getMchId(), weixinAccount
.getDeviceInfo(), RandomUtil.generateString(16), body, attach, .getDeviceInfo(), RandomUtil.generateString(16), body, attach,
out_trade_no, total_fee, spbill_create_ip, null, null, null, outTradeNo, totalFee, spbillCreateIp, null, null, null,
auth_code); authCode);
} }
public MicroPayPackage(String appid, String mch_id, String device_info, public MicroPayPackage(String appid, String mchId, String deviceInfo,
String nonce_str, String body, String attach, String out_trade_no, String nonceStr, String body, String attach, String outTradeNo,
double total_fee, String spbill_create_ip, Date time_start, double totalFee, String spbillCreateIp, Date timeStart,
Date time_expire, String goods_tag, String auth_code) { Date timeExpire, String goodsTag, String authCode) {
super(body, attach, out_trade_no, total_fee, spbill_create_ip, super(body, attach, outTradeNo, totalFee, spbillCreateIp, timeStart,
time_start, time_expire, goods_tag, null); timeExpire, goodsTag, null);
this.appid = appid; this.appid = appid;
this.mch_id = mch_id; this.mchId = mchId;
this.device_info = device_info; this.deviceInfo = deviceInfo;
this.nonce_str = nonce_str; this.nonceStr = nonceStr;
this.auth_code = auth_code; this.authCode = authCode;
} }
public String getAppid() { public String getAppid() {
@ -63,28 +70,28 @@ public class MicroPayPackage extends PayPackage {
this.appid = appid; this.appid = appid;
} }
public String getMch_id() { public String getMchId() {
return mch_id; return mchId;
} }
public void setMch_id(String mch_id) { public void setMchId(String mchId) {
this.mch_id = mch_id; this.mchId = mchId;
} }
public String getDevice_info() { public String getDeviceInfo() {
return device_info; return deviceInfo;
} }
public void setDevice_info(String device_info) { public void setDevice_info(String deviceInfo) {
this.device_info = device_info; this.deviceInfo = deviceInfo;
} }
public String getNonce_str() { public String getNonceStr() {
return nonce_str; return nonceStr;
} }
public void setNonce_str(String nonce_str) { public void setNonceStr(String nonceStr) {
this.nonce_str = nonce_str; this.nonceStr = nonceStr;
} }
public String getSign() { public String getSign() {
@ -95,27 +102,19 @@ public class MicroPayPackage extends PayPackage {
this.sign = sign; this.sign = sign;
} }
public void setBody(String body) { public String getAuthCode() {
super.setBody(StringUtils.isBlank(body) ? "服务费用" : body); return authCode;
} }
public void setNotify_url(String notify_url) { public void setAuthCode(String authCode) {
super.setNotify_url(notify_url); this.authCode = authCode;
}
public String getAuth_code() {
return auth_code;
}
public void setAuth_code(String auth_code) {
this.auth_code = auth_code;
} }
@Override @Override
public String toString() { public String toString() {
return "MicroPayPackage [appid=" + appid + ", mch_id=" + mch_id return "MicroPayPackage [appid=" + appid + ", mchId=" + mchId
+ ", device_info=" + device_info + ", nonce_str=" + nonce_str + ", deviceInfo=" + deviceInfo + ", nonceStr=" + nonceStr
+ ", sign=" + sign + ", auth_code=" + auth_code + ", " + ", sign=" + sign + ", authCode=" + authCode + ", "
+ super.toString() + "]"; + super.toString() + "]";
} }
} }

View File

@ -3,10 +3,13 @@ package com.foxinmy.weixin4j.mp.payment;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.util.DateUtil; import com.foxinmy.weixin4j.util.DateUtil;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/** /**
* 订单信息 * 订单信息
*
* @className PayPackage * @className PayPackage
* @author jy * @author jy
* @date 2014年12月18日 * @date 2014年12月18日
@ -19,17 +22,31 @@ public class PayPackage implements Serializable {
private String body; // 商品描述 必须 private String body; // 商品描述 必须
private String attach; // 附加数据,原样返回 非必须 private String attach; // 附加数据,原样返回 非必须
private String out_trade_no; // 商户系统内部的订单号 ,32 个字符内 可包含字母 ,确保 在商户系统唯一 必须 @XStreamAlias("out_trade_no")
private String total_fee; // 订单总金额,单位为分, 能带小数点 必须 @JSONField(name = "out_trade_no")
private String spbill_create_ip; // 订单生成的机器 IP 必须 private String outTradeNo; // 商户系统内部的订单号 ,32 个字符内 可包含字母 ,确保 在商户系统唯一 必须
private String time_start; // 订单生成时间,格式 yyyyMMddHHmmss, 2009 @XStreamAlias("total_fee")
@JSONField(name = "total_fee")
private String totalFee; // 订单总金额,单位为分, 能带小数点 必须
@XStreamAlias("spbill_create_ip")
@JSONField(name = "spbill_create_ip")
private String spbillCreateIp; // 订单生成的机器 IP 必须
@XStreamAlias("time_start")
@JSONField(name = "time_start")
private String timeStart; // 订单生成时间,格式 yyyyMMddHHmmss, 2009
// 12月25日9点10分10秒表 示为 20091225091010时区 GMT+8 // 12月25日9点10分10秒表 示为 20091225091010时区 GMT+8
// beijing该时间取 自商户服务器 非必须 // beijing该时间取 自商户服务器 非必须
private String time_expire; // 订单失效时间,格式 yyyyMMddHHmmss, 2009 @XStreamAlias("time_expire")
@JSONField(name = "time_expire")
private String timeExpire; // 订单失效时间,格式 yyyyMMddHHmmss, 2009
// 12月27日9点10分10秒表 示为 20091227091010时区 GMT+8 // 12月27日9点10分10秒表 示为 20091227091010时区 GMT+8
// beijing该时间取 自商户服务商品标记 非必须 // beijing该时间取 自商户服务商品标记 非必须
private String goods_tag; // 商品标记,该字段不能随便 ,不使用请填空 非必须 @XStreamAlias("goods_tag")
private String notify_url; // 通知地址接收微信支付成功通知 必须 @JSONField(name = "goods_tag")
private String goodsTag; // 商品标记,该字段不能随便 ,不使用请填空 非必须
@XStreamAlias("notify_url")
@JSONField(name = "notify_url")
private String notifyUrl; // 通知地址接收微信支付成功通知 必须
public String getBody() { public String getBody() {
return body; return body;
@ -47,97 +64,97 @@ public class PayPackage implements Serializable {
this.attach = attach; this.attach = attach;
} }
public String getOut_trade_no() { public String getOutTradeNo() {
return out_trade_no; return outTradeNo;
} }
public void setOut_trade_no(String out_trade_no) { public void setOutTradeNo(String outTradeNo) {
this.out_trade_no = out_trade_no; this.outTradeNo = outTradeNo;
} }
public String getTotal_fee() { public String getTotalFee() {
return total_fee; return totalFee;
} }
public void setTotal_fee(double total_fee) { public void setTotalFee(double totalFee) {
this.total_fee = DateUtil.formaFee2Fen(total_fee); this.totalFee = DateUtil.formaFee2Fen(totalFee);
} }
public String getSpbill_create_ip() { public String getSpbillCreateIp() {
return spbill_create_ip; return spbillCreateIp;
} }
public void setSpbill_create_ip(String spbill_create_ip) { public void setSpbillCreateIp(String spbillCreateIp) {
this.spbill_create_ip = spbill_create_ip; this.spbillCreateIp = spbillCreateIp;
} }
public String getTime_start() { public String getTimeStart() {
return time_start; return timeStart;
} }
public void setTime_start(String time_start) { public void setTimeStart(String timeStart) {
this.time_start = time_start; this.timeStart = timeStart;
} }
public void setTime_expire(String time_expire) { public void setTimeExpire(String timeExpire) {
this.time_expire = time_expire; this.timeExpire = timeExpire;
} }
public void setTime_start(Date time_start) { public void setTimeStart(Date timeStart) {
this.time_start = time_start != null ? DateUtil this.timeStart = timeStart != null ? DateUtil
.fortmat2yyyyMMddHHmmss(time_start) : null; .fortmat2yyyyMMddHHmmss(timeStart) : null;
} }
public String getTime_expire() { public String getTimeExpire() {
return time_expire; return timeExpire;
} }
public void setTime_expire(Date time_expire) { public void setTimeExpire(Date timeExpire) {
this.time_expire = time_expire != null ? DateUtil this.timeExpire = timeExpire != null ? DateUtil
.fortmat2yyyyMMddHHmmss(time_expire) : null; .fortmat2yyyyMMddHHmmss(timeExpire) : null;
} }
public String getGoods_tag() { public String getGoodsTag() {
return goods_tag; return goodsTag;
} }
public void setGoods_tag(String goods_tag) { public void setGoodsTag(String goodsTag) {
this.goods_tag = goods_tag; this.goodsTag = goodsTag;
} }
public String getNotify_url() { public String getNotifyUrl() {
return notify_url; return notifyUrl;
} }
public void setNotify_url(String notify_url) { public void setNotifyUrl(String notifyUrl) {
this.notify_url = notify_url; this.notifyUrl = notifyUrl;
} }
public PayPackage() { public PayPackage() {
} }
public PayPackage(String body, String attach, String out_trade_no, public PayPackage(String body, String attach, String outTradeNo,
double total_fee, String spbill_create_ip, Date time_start, double totalFee, String spbillCreateIp, Date timeStart,
Date time_expire, String goods_tag, String notify_url) { Date timeExpire, String goodsTag, String notifyUrl) {
this.body = body; this.body = body;
this.attach = attach; this.attach = attach;
this.out_trade_no = out_trade_no; this.outTradeNo = outTradeNo;
this.total_fee = DateUtil.formaFee2Fen(total_fee); this.totalFee = DateUtil.formaFee2Fen(totalFee);
this.spbill_create_ip = spbill_create_ip; this.spbillCreateIp = spbillCreateIp;
this.time_start = time_start != null ? DateUtil this.timeStart = timeStart != null ? DateUtil
.fortmat2yyyyMMddHHmmss(time_start) : null; .fortmat2yyyyMMddHHmmss(timeStart) : null;
this.time_expire = time_expire != null ? DateUtil this.timeExpire = timeExpire != null ? DateUtil
.fortmat2yyyyMMddHHmmss(time_expire) : null; .fortmat2yyyyMMddHHmmss(timeExpire) : null;
this.goods_tag = goods_tag; this.goodsTag = goodsTag;
this.notify_url = notify_url; this.notifyUrl = notifyUrl;
} }
@Override @Override
public String toString() { public String toString() {
return "body=" + body + ", attach=" + attach + ", out_trade_no=" return "PayPackage [body=" + body + ", attach=" + attach
+ out_trade_no + ", total_fee=" + total_fee + ", outTradeNo=" + outTradeNo + ", totalFee=" + totalFee
+ ", spbill_create_ip=" + spbill_create_ip + ", time_start=" + ", spbillCreateIp=" + spbillCreateIp + ", timeStart="
+ time_start + ", time_expire=" + time_expire + ", goods_tag=" + timeStart + ", timeExpire=" + timeExpire + ", goodsTag="
+ goods_tag + ", notify_url=" + notify_url; + goodsTag + ", notifyUrl=" + notifyUrl + "]";
} }
} }

View File

@ -182,7 +182,7 @@ public class PayUtil {
WeixinMpAccount weixinAccount) throws PayException { WeixinMpAccount weixinAccount) throws PayException {
PayPackageV3 payPackage = new PayPackageV3(weixinAccount, openId, body, PayPackageV3 payPackage = new PayPackageV3(weixinAccount, openId, body,
orderNo, orderFee, ip, TradeType.JSAPI); orderNo, orderFee, ip, TradeType.JSAPI);
payPackage.setNotify_url(notifyUrl); payPackage.setNotifyUrl(notifyUrl);
return createPayJsRequestJsonV3(payPackage, weixinAccount); return createPayJsRequestJsonV3(payPackage, weixinAccount);
} }
@ -308,7 +308,7 @@ public class PayUtil {
/** /**
* 创建V3.x NativePay支付链接 * 创建V3.x NativePay支付链接
* *
* @param weixinConfig * @param weixinAccount
* 支付配置信息 * 支付配置信息
* @param productId * @param productId
* 与订单ID等价 * 与订单ID等价

View File

@ -2,10 +2,10 @@ package com.foxinmy.weixin4j.mp.payment.v2;
import java.util.Date; import java.util.Date;
import org.apache.commons.lang3.StringUtils; import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.mp.payment.PayPackage; import com.foxinmy.weixin4j.mp.payment.PayPackage;
import com.foxinmy.weixin4j.util.DateUtil; import com.foxinmy.weixin4j.util.DateUtil;
import com.thoughtworks.xstream.annotations.XStreamAlias;
/** /**
* V2支付的订单详情 * V2支付的订单详情
@ -21,30 +21,36 @@ public class PayPackageV2 extends PayPackage {
private static final long serialVersionUID = 5557542103637795834L; private static final long serialVersionUID = 5557542103637795834L;
// 银行通道类型 固定为"WX" 非空 // 银行通道类型 固定为"WX" 非空
private String bank_type; @XStreamAlias("bank_type")
@JSONField(name = "bank_type")
private String bankType;
// 商户号 注册时分配的财付通商户号 非空 // 商户号 注册时分配的财付通商户号 非空
private String partner; private String partner;
// 支付币种 默认值是"1" 非空 // 支付币种 默认值是"1" 非空
private String fee_type; @XStreamAlias("fee_type")
@JSONField(name = "fee_type")
private String feeType;
// 物流费用 可为空 如果有值,必须保 transport_fee + product_fee=total_fee传进来的参数按照实际金额即可 // 物流费用 可为空 如果有值,必须保 transport_fee + product_fee=total_fee传进来的参数按照实际金额即可
// 也就是元为单位 // 也就是元为单位
private String transport_fee; @XStreamAlias("transport_fee")
@JSONField(name = "transport_fee")
private String transportFee;
// 商品费用 可为空 商品费用,单位为分如果有值,必须保 transport_fee + // 商品费用 可为空 商品费用,单位为分如果有值,必须保 transport_fee +
// product_fee=total_fee;传进来的参数按照实际金额即可 也就是元为单位 // product_fee=total_fee;传进来的参数按照实际金额即可 也就是元为单位
private String product_fee; @XStreamAlias("product_fee")
@JSONField(name = "product_fee")
private String productFee;
// 传入参数字符编码 取值范围:"GBK""UTF-8",默认:"GBK" 可为空 // 传入参数字符编码 取值范围:"GBK""UTF-8",默认:"GBK" 可为空
private String input_charset; @XStreamAlias("input_charset")
@JSONField(name = "input_charset")
private String inputCharset;
public String getBank_type() { public String getBankType() {
return bank_type; return bankType;
} }
public void setBank_type(String bank_type) { public void setBank_type(String bankType) {
this.bank_type = bank_type; this.bankType = bankType;
}
public void setBody(String body) {
super.setBody(StringUtils.isBlank(body) ? "服务费用" : body);
} }
public String getPartner() { public String getPartner() {
@ -55,86 +61,82 @@ public class PayPackageV2 extends PayPackage {
this.partner = partner; this.partner = partner;
} }
public String getFee_type() { public String getFeeType() {
return fee_type; return feeType;
} }
public void setFee_type(String fee_type) { public void setFeeType(String feeType) {
this.fee_type = fee_type; this.feeType = feeType;
} }
public void setNotify_url(String notify_url) { public String getTransportFee() {
super.setNotify_url(notify_url); return transportFee;
} }
public String getTransport_fee() { public void setTransportFee(double transportFee) {
return transport_fee; this.transportFee = DateUtil.formaFee2Fen(transportFee);
} }
public void setTransport_fee(double transport_fee) { public String getProductFee() {
this.transport_fee = DateUtil.formaFee2Fen(transport_fee); return productFee;
} }
public String getProduct_fee() { public void setProductFee(double productFee) {
return product_fee; this.productFee = DateUtil.formaFee2Fen(productFee);
} }
public void setProduct_fee(double product_fee) { public String getInputCharset() {
this.product_fee = DateUtil.formaFee2Fen(product_fee); return inputCharset;
} }
public String getInput_charset() { public void setInput_charset(String inputCharset) {
return input_charset; this.inputCharset = inputCharset;
}
public void setInput_charset(String input_charset) {
this.input_charset = input_charset;
} }
public PayPackageV2() { public PayPackageV2() {
this.bank_type = "WX"; this.bankType = "WX";
this.fee_type = "1"; this.feeType = "1";
this.input_charset = "UTF-8"; this.inputCharset = "UTF-8";
} }
public PayPackageV2(String out_trade_no, double total_fee, public PayPackageV2(String outTradeNo, double totalFee,
String spbill_create_ip) { String spbillCreateIp) {
this(null, null, null, out_trade_no, total_fee, null, spbill_create_ip, this(null, null, null, outTradeNo, totalFee, null, spbillCreateIp,
null, null, 0d, 0d, null); null, null, 0d, 0d, null);
} }
public PayPackageV2(String body, String out_trade_no, double total_fee, public PayPackageV2(String body, String outTradeNo, double totalFee,
String notify_url, String spbill_create_ip) { String notifyUrl, String spbillCreateIp) {
this(body, null, null, out_trade_no, total_fee, notify_url, this(body, null, null, outTradeNo, totalFee, notifyUrl, spbillCreateIp,
spbill_create_ip, null, null, 0d, 0d, null); null, null, 0d, 0d, null);
} }
public PayPackageV2(String body, String partner, String out_trade_no, public PayPackageV2(String body, String partner, String outTradeNo,
double total_fee, String notify_url, String spbill_create_ip) { double totalFee, String notifyUrl, String spbillCreateIp) {
this(body, null, partner, out_trade_no, total_fee, notify_url, this(body, null, partner, outTradeNo, totalFee, notifyUrl,
spbill_create_ip, null, null, 0d, 0d, null); spbillCreateIp, null, null, 0d, 0d, null);
} }
public PayPackageV2(String body, String attach, String partner, public PayPackageV2(String body, String attach, String partner,
String out_trade_no, double total_fee, String notify_url, String outTradeNo, double totalFee, String notifyUrl,
String spbill_create_ip, Date time_start, Date time_expire, String spbillCreateIp, Date timeStart, Date timeExpire,
double transport_fee, double product_fee, String goods_tag) { double transportFee, double productFee, String goodsTag) {
super(body, attach, out_trade_no, total_fee, spbill_create_ip, super(body, attach, outTradeNo, totalFee, spbillCreateIp, timeStart,
time_start, time_expire, goods_tag, notify_url); timeExpire, goodsTag, notifyUrl);
this.bank_type = "WX"; this.bankType = "WX";
this.fee_type = "1"; this.feeType = "1";
this.input_charset = "UTF-8"; this.inputCharset = "UTF-8";
this.transport_fee = transport_fee > 0d ? DateUtil this.transportFee = transportFee > 0d ? DateUtil
.formaFee2Fen(transport_fee) : null; .formaFee2Fen(transportFee) : null;
this.product_fee = product_fee > 0 ? DateUtil.formaFee2Fen(product_fee) this.productFee = productFee > 0 ? DateUtil.formaFee2Fen(productFee)
: null; : null;
} }
@Override @Override
public String toString() { public String toString() {
return "PayPackageV2 [bank_type=" + bank_type + ", partner=" + partner return "PayPackageV2 [bankType=" + bankType + ", partner=" + partner
+ ", fee_type=" + fee_type + ", transport_fee=" + transport_fee + ", feeType=" + feeType + ", transportFee=" + transportFee
+ ", product_fee=" + product_fee + ", input_charset=" + ", productFee=" + productFee + ", inputCharset="
+ input_charset + ", " + super.toString() + "]"; + inputCharset + ", " + super.toString() + "]";
} }
} }

View File

@ -55,7 +55,7 @@ public class NativePayResponseV3 extends ApiResult {
throws PayException { throws PayException {
super.setReturnCode(Consts.SUCCESS); super.setReturnCode(Consts.SUCCESS);
this.setResultCode(Consts.SUCCESS); this.setResultCode(Consts.SUCCESS);
this.setMchId(payPackage.getMch_id()); this.setMchId(payPackage.getMchId());
this.setAppId(payPackage.getAppid()); this.setAppId(payPackage.getAppid());
this.setNonceStr(RandomUtil.generateString(16)); this.setNonceStr(RandomUtil.generateString(16));
this.prePay = PayUtil.createPrePay(payPackage, paysignKey); this.prePay = PayUtil.createPrePay(payPackage, paysignKey);

View File

@ -4,6 +4,7 @@ import java.util.Date;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.model.WeixinMpAccount; import com.foxinmy.weixin4j.model.WeixinMpAccount;
import com.foxinmy.weixin4j.mp.payment.PayPackage; import com.foxinmy.weixin4j.mp.payment.PayPackage;
import com.foxinmy.weixin4j.mp.type.TradeType; import com.foxinmy.weixin4j.mp.type.TradeType;
@ -11,7 +12,7 @@ import com.foxinmy.weixin4j.util.RandomUtil;
import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamAlias;
/** /**
* V3支付的订单详情</br> 注意: <font color="red">total_fee字段传入时单位为元,创建支付时会转换为分</font> * V3支付的订单详情</br> 注意: <font color="red">totalFee字段传入时单位为元,创建支付时会转换为分</font>
* *
* @className PayPackageV3 * @className PayPackageV3
* @author jy * @author jy
@ -25,48 +26,58 @@ public class PayPackageV3 extends PayPackage {
private static final long serialVersionUID = 8944928173669656177L; private static final long serialVersionUID = 8944928173669656177L;
private String appid; // 微信分配的公众账号 必须 private String appid; // 微信分配的公众账号 必须
private String mch_id; // 微信支付分配的商户号 必须 @XStreamAlias("mch_id")
private String device_info; // 微信支付分配的终端设备号 非必须 @JSONField(name = "mch_id")
private String nonce_str; // 随机字符串,不长于 32 必须 private String mchId; // 微信支付分配的商户号 必须
@XStreamAlias("device_info")
@JSONField(name = "device_info")
private String deviceInfo; // 微信支付分配的终端设备号 非必须
@XStreamAlias("nonce_str")
@JSONField(name = "nonce_str")
private String nonceStr; // 随机字符串,不长于 32 必须
private String sign; // 签名 必须 private String sign; // 签名 必须
private String trade_type; // 交易类型JSAPINATIVEAPP 必须 @XStreamAlias("trade_type")
@JSONField(name = "trade_type")
private String tradeType; // 交易类型JSAPINATIVEAPP 必须
private String openid; // 用户在商户 appid 下的唯一 标识, trade_type JSAPI ,此参数必传 private String openid; // 用户在商户 appid 下的唯一 标识, trade_type JSAPI ,此参数必传
private String product_id; // 只在 trade_type NATIVE 时需要填写 非必须 @XStreamAlias("product_id")
@JSONField(name = "product_id")
private String productId; // 只在 trade_type NATIVE 时需要填写 非必须
public PayPackageV3() { public PayPackageV3() {
} }
public PayPackageV3(WeixinMpAccount weixinAccount, String openId, public PayPackageV3(WeixinMpAccount weixinAccount, String openId,
String body, String out_trade_no, double total_fee, String body, String outTradeNo, double totalFee,
String spbill_create_ip, TradeType tradeType) { String spbillCreateIp, TradeType tradeType) {
this(weixinAccount, openId, body, null, out_trade_no, total_fee, null, this(weixinAccount, openId, body, null, outTradeNo, totalFee, null,
spbill_create_ip, tradeType); spbillCreateIp, tradeType);
} }
public PayPackageV3(WeixinMpAccount weixinAccount, String openId, public PayPackageV3(WeixinMpAccount weixinAccount, String openId,
String body, String attach, String out_trade_no, double total_fee, String body, String attach, String outTradeNo, double totalFee,
String notify_url, String spbill_create_ip, TradeType tradeType) { String notifyUrl, String spbillCreateIp, TradeType tradeType) {
this(weixinAccount.getId(), weixinAccount.getMchId(), weixinAccount this(weixinAccount.getId(), weixinAccount.getMchId(), weixinAccount
.getDeviceInfo(), RandomUtil.generateString(16), body, attach, .getDeviceInfo(), RandomUtil.generateString(16), body, attach,
out_trade_no, total_fee, spbill_create_ip, null, null, null, outTradeNo, totalFee, spbillCreateIp, null, null, null,
notify_url, tradeType, openId, null); notifyUrl, tradeType, openId, null);
} }
public PayPackageV3(String appid, String mch_id, String device_info, public PayPackageV3(String appid, String mchId, String deviceInfo,
String nonce_str, String body, String attach, String out_trade_no, String nonceStr, String body, String attach, String outTradeNo,
double total_fee, String spbill_create_ip, Date time_start, double totalFee, String spbillCreateIp, Date timeStart,
Date time_expire, String goods_tag, String notify_url, Date timeExpire, String goodsTag, String notifyUrl,
TradeType tradeType, String openid, String product_id) { TradeType tradeType, String openid, String productId) {
super(body, attach, out_trade_no, total_fee, spbill_create_ip, super(body, attach, outTradeNo, totalFee, spbillCreateIp, timeStart,
time_start, time_expire, goods_tag, notify_url); timeExpire, goodsTag, notifyUrl);
this.appid = appid; this.appid = appid;
this.mch_id = mch_id; this.mchId = mchId;
this.device_info = device_info; this.deviceInfo = deviceInfo;
this.nonce_str = nonce_str; this.nonceStr = nonceStr;
this.trade_type = tradeType.name(); this.tradeType = tradeType.name();
this.openid = openid; this.openid = openid;
this.product_id = product_id; this.productId = productId;
} }
public String getAppid() { public String getAppid() {
@ -77,28 +88,28 @@ public class PayPackageV3 extends PayPackage {
this.appid = appid; this.appid = appid;
} }
public String getMch_id() { public String getMchId() {
return mch_id; return mchId;
} }
public void setMch_id(String mch_id) { public void setMchId(String mchId) {
this.mch_id = mch_id; this.mchId = mchId;
} }
public String getDevice_info() { public String getDeviceInfo() {
return device_info; return deviceInfo;
} }
public void setDevice_info(String device_info) { public void setDeviceInfo(String deviceInfo) {
this.device_info = device_info; this.deviceInfo = deviceInfo;
} }
public String getNonce_str() { public String getNonceStr() {
return nonce_str; return nonceStr;
} }
public void setNonce_str(String nonce_str) { public void setNonceStr(String nonceStr) {
this.nonce_str = nonce_str; this.nonceStr = nonceStr;
} }
public String getSign() { public String getSign() {
@ -113,16 +124,12 @@ public class PayPackageV3 extends PayPackage {
super.setBody(StringUtils.isBlank(body) ? "服务费用" : body); super.setBody(StringUtils.isBlank(body) ? "服务费用" : body);
} }
public void setNotify_url(String notify_url) { public String getTradeType() {
super.setNotify_url(notify_url); return tradeType;
} }
public String getTrade_type() { public void setTradeType(TradeType tradeType) {
return trade_type; this.tradeType = tradeType.name();
}
public void setTrade_type(TradeType tradeType) {
this.trade_type = tradeType.name();
} }
public String getOpenid() { public String getOpenid() {
@ -133,20 +140,20 @@ public class PayPackageV3 extends PayPackage {
this.openid = openid; this.openid = openid;
} }
public String getProduct_id() { public String getProductId() {
return product_id; return productId;
} }
public void setProduct_id(String product_id) { public void setProductId(String productId) {
this.product_id = product_id; this.productId = productId;
} }
@Override @Override
public String toString() { public String toString() {
return "PayPackageV3 [appid=" + appid + ", mch_id=" + mch_id return "PayPackageV3 [appid=" + appid + ", mchId=" + mchId
+ ", device_info=" + device_info + ", nonce_str=" + nonce_str + ", deviceInfo=" + deviceInfo + ", nonceStr=" + nonceStr
+ ", sign=" + sign + ", trade_type=" + trade_type + ", openid=" + ", sign=" + sign + ", tradeType=" + tradeType + ", openid="
+ openid + ", product_id=" + product_id + ", " + openid + ", productId=" + productId + ", " + super.toString()
+ super.toString() + "]"; + "]";
} }
} }

View File

@ -153,7 +153,7 @@ public class PayAction {
public String jsNotifyV3(InputStream inputStream) { public String jsNotifyV3(InputStream inputStream) {
com.foxinmy.weixin4j.mp.payment.v3.Order order = XmlStream.get( com.foxinmy.weixin4j.mp.payment.v3.Order order = XmlStream.get(
inputStream, com.foxinmy.weixin4j.mp.payment.v3.Order.class); inputStream, com.foxinmy.weixin4j.mp.payment.v3.Order.class);
log.info("jaapi_notify_order_info:", order); log.info("jsapi_notify_order_info:", order);
String sign = order.getSign(); String sign = order.getSign();
order.setSign(null); order.setSign(null);
WeixinMpAccount weixinAccount = ConfigUtil.getWeixinMpAccount(); WeixinMpAccount weixinAccount = ConfigUtil.getWeixinMpAccount();
@ -163,6 +163,7 @@ public class PayAction {
if (!sign.equals(valid_sign)) { if (!sign.equals(valid_sign)) {
return XmlStream.to(new XmlResult(Consts.FAIL, "签名错误")); return XmlStream.to(new XmlResult(Consts.FAIL, "签名错误"));
} }
// 处理业务逻辑
return XmlStream.to(new XmlResult(Consts.SUCCESS, "")); return XmlStream.to(new XmlResult(Consts.SUCCESS, ""));
} }
@ -233,7 +234,7 @@ public class PayAction {
// 生成Package // 生成Package
PayPackageV3 payPackage = new PayPackageV3(weixinAccount, "用户openid", PayPackageV3 payPackage = new PayPackageV3(weixinAccount, "用户openid",
"商品描述", "系统内部订单号", 1d, "IP地址", TradeType.NATIVE); "商品描述", "系统内部订单号", 1d, "IP地址", TradeType.NATIVE);
payPackage.setProduct_id(payNotify.getProductId()); payPackage.setProductId(payNotify.getProductId());
if (!sign.equals(valid_sign)) { if (!sign.equals(valid_sign)) {
// 校验失败 // 校验失败
NativePayResponseV3 payReponse = new NativePayResponseV3("签名失败", NativePayResponseV3 payReponse = new NativePayResponseV3("签名失败",