调整部分实体类(*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>
<httpclient.version>4.2.5</httpclient.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>
<jaxen.version>1.1.6</jaxen.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 {
private JedisPool jedisPool;
private final TokenCreator tokenCretor;
private final TokenCreator tokenCreator;
public final static int MAX_TOTAL = 50;
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_RETURN = true;
public RedisTokenHolder(TokenCreator tokenCretor) {
this("localhost", 6379, tokenCretor);
public RedisTokenHolder(TokenCreator tokenCreator) {
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.setMaxTotal(MAX_TOTAL);
jedisPoolConfig.setMaxIdle(MAX_IDLE);
@ -43,17 +43,17 @@ public class RedisTokenHolder implements TokenHolder {
jedisPoolConfig.setTestOnBorrow(TEST_ON_BORROW);
jedisPoolConfig.setTestOnReturn(TEST_ON_RETURN);
this.jedisPool = new JedisPool(jedisPoolConfig, host, port);
this.tokenCretor = tokenCretor;
this.tokenCreator = tokenCreator;
}
public RedisTokenHolder(String host, int port,
JedisPoolConfig jedisPoolConfig, TokenCreator tokenCretor) {
this(new JedisPool(jedisPoolConfig, host, port), tokenCretor);
JedisPoolConfig jedisPoolConfig, TokenCreator tokenCreator) {
this(new JedisPool(jedisPoolConfig, host, port), tokenCreator);
}
public RedisTokenHolder(JedisPool jedisPool, TokenCreator tokenCretor) {
public RedisTokenHolder(JedisPool jedisPool, TokenCreator tokenCreator) {
this.jedisPool = jedisPool;
this.tokenCretor = tokenCretor;
this.tokenCreator = tokenCreator;
}
@Override
@ -62,10 +62,10 @@ public class RedisTokenHolder implements TokenHolder {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
String cacheKey = tokenCretor.getCacheKey();
String cacheKey = tokenCreator.getCacheKey();
String accessToken = jedis.get(cacheKey);
if (StringUtils.isBlank(accessToken)) {
token = tokenCretor.createToken();
token = tokenCreator.createToken();
jedis.setex(cacheKey, (int) token.getExpiresIn(),
token.getAccessToken());
} else {

View File

@ -68,7 +68,8 @@ weixin4j-mp
qr_path=/tmp/weixin/qr
media_path=/tmp/weixin/media
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
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
media_path=/tmp/weixin/media
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
2.实例化一个`WeixinProxy`对象,调用API,需要强调的是如果只传入appid,appsecret两个参数将无法调用支付相关接口

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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