【非常重要】:weixin4j-base->主要调整了PayPackage构造函数:从主到次
This commit is contained in:
parent
d3cbc3dd21
commit
0d7069036b
16
CHANGE.md
16
CHANGE.md
@ -496,3 +496,19 @@
|
||||
* 2015-11-20
|
||||
|
||||
+ weixin4j-qy:新增客服消息
|
||||
|
||||
* 2015-11-23
|
||||
|
||||
+ weixin4j-base:PayException重命名为WeixinPayException
|
||||
|
||||
+ weixin4j-base:调整PayPackageV2构造函数:从主到次
|
||||
|
||||
+ weixin4j-base:调整PayUtil2#createPayJsRequestJsonV2参数位置:从主到次
|
||||
|
||||
+ weixin4j-base:调整MicroPayPackage构造函数:从主到次
|
||||
|
||||
+ weixin4j-base:调整MicroPayPackage构造函数:从主到次
|
||||
|
||||
+ weixin4j-base:调整PayUtil#createPayJsRequestJson参数位置:从主到次
|
||||
|
||||
+ weixin4j-base:调整PayUtil#createNativePayRequestURL参数位置:从主到次
|
||||
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j</artifactId>
|
||||
<version>1.6.3</version>
|
||||
<version>1.6.4</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>weixin4j</name>
|
||||
<url>https://github.com/foxinmy/weixin4j</url>
|
||||
|
||||
@ -69,3 +69,20 @@
|
||||
* 2015-09-27
|
||||
|
||||
+ 新增手动刷新token方法
|
||||
|
||||
|
||||
* 2015-11-23
|
||||
|
||||
+ PayException重命名为WeixinPayException
|
||||
|
||||
+ 调整PayPackageV2构造函数:从主到次
|
||||
|
||||
+ 调整PayUtil2#createPayJsRequestJsonV2参数位置:从主到次
|
||||
|
||||
+ 调整MicroPayPackage构造函数:从主到次
|
||||
|
||||
+ 调整MicroPayPackage构造函数:从主到次
|
||||
|
||||
+ 调整PayUtil#createPayJsRequestJson参数位置:从主到次
|
||||
|
||||
+ 调整PayUtil#createNativePayRequestURL参数位置:从主到次
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j</artifactId>
|
||||
<version>1.6.3</version>
|
||||
<version>1.6.4</version>
|
||||
</parent>
|
||||
<artifactId>weixin4j-base</artifactId>
|
||||
<name>weixin4j-base</name>
|
||||
|
||||
@ -3,20 +3,20 @@ package com.foxinmy.weixin4j.exception;
|
||||
/**
|
||||
* 调用微信支付抛出的异常
|
||||
*
|
||||
* @className PayException
|
||||
* @className WeixinPayException
|
||||
* @author jy
|
||||
* @date 2014年10月28日
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class PayException extends WeixinException {
|
||||
public class WeixinPayException extends WeixinException {
|
||||
private static final long serialVersionUID = 7148145661883468514L;
|
||||
|
||||
public PayException(String errorMsg) {
|
||||
public WeixinPayException(String errorMsg) {
|
||||
super(errorMsg);
|
||||
}
|
||||
|
||||
public PayException(String errorCode, String errorMsg) {
|
||||
public WeixinPayException(String errorCode, String errorMsg) {
|
||||
super(errorCode, errorMsg);
|
||||
}
|
||||
}
|
||||
@ -59,31 +59,36 @@ public class MicroPayPackage extends PayPackage {
|
||||
@XmlElement(name = "auth_code")
|
||||
@JSONField(name = "auth_code")
|
||||
private String authCode;
|
||||
/**
|
||||
* 指定支付方式:no_credit--指定不能使用信用卡支付
|
||||
*/
|
||||
@XmlElement(name = "limit_pay")
|
||||
@JSONField(name = "limit_pay")
|
||||
private String limitPay;
|
||||
|
||||
protected MicroPayPackage() {
|
||||
// jaxb required
|
||||
}
|
||||
|
||||
public MicroPayPackage(WeixinPayAccount weixinAccount, String body,
|
||||
String attach, String outTradeNo, double totalFee,
|
||||
String spbillCreateIp, String authCode) {
|
||||
public MicroPayPackage(WeixinPayAccount weixinAccount, String authCode,
|
||||
String body, String outTradeNo, double totalFee, String createIp) {
|
||||
this(weixinAccount.getId(), weixinAccount.getMchId(), weixinAccount
|
||||
.getDeviceInfo(), RandomUtil.generateString(16), body, attach,
|
||||
outTradeNo, totalFee, spbillCreateIp, null, null, null,
|
||||
authCode);
|
||||
.getDeviceInfo(), authCode, body, outTradeNo, totalFee,
|
||||
createIp, null, null, null, null, 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);
|
||||
String authCode, String body, String outTradeNo, double totalFee,
|
||||
String createIp, String attach, Date timeStart, Date timeExpire,
|
||||
String goodsTag, String limitPay) {
|
||||
super(body, outTradeNo, totalFee, null, createIp, null, timeStart,
|
||||
timeExpire, goodsTag);
|
||||
this.appId = appId;
|
||||
this.mchId = mchId;
|
||||
this.deviceInfo = deviceInfo;
|
||||
this.nonceStr = nonceStr;
|
||||
this.nonceStr = RandomUtil.generateString(16);
|
||||
this.authCode = authCode;
|
||||
this.limitPay = limitPay;
|
||||
}
|
||||
|
||||
public String getAppId() {
|
||||
@ -118,6 +123,14 @@ public class MicroPayPackage extends PayPackage {
|
||||
this.authCode = authCode;
|
||||
}
|
||||
|
||||
public String getLimitPay() {
|
||||
return limitPay;
|
||||
}
|
||||
|
||||
public void setLimitPay(String limitPay) {
|
||||
this.limitPay = limitPay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MicroPayPackage [appId=" + appId + ", mchId=" + mchId
|
||||
|
||||
@ -34,10 +34,6 @@ public class PayPackage implements Serializable {
|
||||
* 商品详情 非必须
|
||||
*/
|
||||
private String detail;
|
||||
/**
|
||||
* 附加数据,原样返回 非必须
|
||||
*/
|
||||
private String attach;
|
||||
/**
|
||||
* 商户系统内部的订单号 ,32 个字符内 、可包含字母 ,确保 在商户系统唯一 必须
|
||||
*/
|
||||
@ -50,12 +46,22 @@ public class PayPackage implements Serializable {
|
||||
@XmlElement(name = "total_fee")
|
||||
@JSONField(name = "total_fee")
|
||||
private String totalFee;
|
||||
/**
|
||||
* 通知地址接收微信支付成功通知 必须
|
||||
*/
|
||||
@XmlElement(name = "notify_url")
|
||||
@JSONField(name = "notify_url")
|
||||
private String notifyUrl;
|
||||
/**
|
||||
* 订单生成的机器 IP 必须
|
||||
*/
|
||||
@XmlElement(name = "spbill_create_ip")
|
||||
@JSONField(name = "spbill_create_ip")
|
||||
private String createIp;
|
||||
/**
|
||||
* 附加数据,原样返回 非必须
|
||||
*/
|
||||
private String attach;
|
||||
/**
|
||||
* 订单生成时间,格式为 yyyyMMddHHmmss,如 2009 年 12月25日9点10分10秒表示为 20091225091010。时区 为
|
||||
* GMT+8 beijing。该时间取 自商户服务器 非必须
|
||||
@ -76,12 +82,48 @@ public class PayPackage implements Serializable {
|
||||
@XmlElement(name = "goods_tag")
|
||||
@JSONField(name = "goods_tag")
|
||||
private String goodsTag;
|
||||
|
||||
protected PayPackage() {
|
||||
// jaxb required
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知地址接收微信支付成功通知 必须
|
||||
* 订单对象
|
||||
*
|
||||
* @param body
|
||||
* 订单描述
|
||||
* @param outTradeNo
|
||||
* 商户内部ID
|
||||
* @param totalFee
|
||||
* 订单总额 <font color="red">单位为元</font>
|
||||
* @param notifyUrl
|
||||
* 回调地址
|
||||
* @param createIp
|
||||
* 生成订单数据的机器IP
|
||||
* @param attach
|
||||
* 附加数据
|
||||
* @param timeStart
|
||||
* 订单生成时间
|
||||
* @param timeExpire
|
||||
* 订单失效时间
|
||||
* @param goodsTag
|
||||
* 订单标记
|
||||
*/
|
||||
@XmlElement(name = "notify_url")
|
||||
@JSONField(name = "notify_url")
|
||||
private String notifyUrl;
|
||||
public PayPackage(String body, String outTradeNo, double totalFee,
|
||||
String notifyUrl, String createIp, String attach, Date timeStart,
|
||||
Date timeExpire, String goodsTag) {
|
||||
this.body = body;
|
||||
this.outTradeNo = outTradeNo;
|
||||
this.totalFee = DateUtil.formaFee2Fen(totalFee);
|
||||
this.notifyUrl = notifyUrl;
|
||||
this.createIp = createIp;
|
||||
this.attach = attach;
|
||||
this.timeStart = timeStart != null ? DateUtil
|
||||
.fortmat2yyyyMMddHHmmss(timeStart) : null;
|
||||
this.timeExpire = timeExpire != null ? DateUtil
|
||||
.fortmat2yyyyMMddHHmmss(timeExpire) : null;
|
||||
this.goodsTag = goodsTag;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
@ -99,14 +141,6 @@ public class PayPackage implements Serializable {
|
||||
this.detail = detail;
|
||||
}
|
||||
|
||||
public String getAttach() {
|
||||
return attach;
|
||||
}
|
||||
|
||||
public void setAttach(String attach) {
|
||||
this.attach = attach;
|
||||
}
|
||||
|
||||
public String getOutTradeNo() {
|
||||
return outTradeNo;
|
||||
}
|
||||
@ -129,6 +163,14 @@ public class PayPackage implements Serializable {
|
||||
this.totalFee = DateUtil.formaFee2Fen(totalFee);
|
||||
}
|
||||
|
||||
public String getNotifyUrl() {
|
||||
return notifyUrl;
|
||||
}
|
||||
|
||||
public void setNotifyUrl(String notifyUrl) {
|
||||
this.notifyUrl = notifyUrl;
|
||||
}
|
||||
|
||||
public String getCreateIp() {
|
||||
return createIp;
|
||||
}
|
||||
@ -137,6 +179,14 @@ public class PayPackage implements Serializable {
|
||||
this.createIp = createIp;
|
||||
}
|
||||
|
||||
public String getAttach() {
|
||||
return attach;
|
||||
}
|
||||
|
||||
public void setAttach(String attach) {
|
||||
this.attach = attach;
|
||||
}
|
||||
|
||||
public String getTimeStart() {
|
||||
return timeStart;
|
||||
}
|
||||
@ -171,62 +221,12 @@ public class PayPackage implements Serializable {
|
||||
this.goodsTag = goodsTag;
|
||||
}
|
||||
|
||||
public String getNotifyUrl() {
|
||||
return notifyUrl;
|
||||
}
|
||||
|
||||
public void setNotifyUrl(String notifyUrl) {
|
||||
this.notifyUrl = notifyUrl;
|
||||
}
|
||||
|
||||
protected PayPackage(){
|
||||
// jaxb required
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单对象
|
||||
*
|
||||
* @param body
|
||||
* 订单描述
|
||||
* @param attach
|
||||
* 附加数据
|
||||
* @param outTradeNo
|
||||
* 商户内部ID
|
||||
* @param totalFee
|
||||
* 订单总额 <font color="red">单位为元</font>
|
||||
* @param spbillCreateIp
|
||||
* 生成订单数据的机器IP
|
||||
* @param timeStart
|
||||
* 订单生成时间
|
||||
* @param timeExpire
|
||||
* 订单失效时间
|
||||
* @param goodsTag
|
||||
* 订单标记
|
||||
* @param notifyUrl
|
||||
* 回调地址
|
||||
*/
|
||||
public PayPackage(String body, String attach, String outTradeNo,
|
||||
double totalFee, String createIp, Date timeStart,
|
||||
Date timeExpire, String goodsTag, String notifyUrl) {
|
||||
this.body = body;
|
||||
this.attach = attach;
|
||||
this.outTradeNo = outTradeNo;
|
||||
this.totalFee = DateUtil.formaFee2Fen(totalFee);
|
||||
this.createIp = createIp;
|
||||
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 "PayPackage [body=" + body + ", detail=" + detail + ", attach="
|
||||
+ attach + ", outTradeNo=" + outTradeNo + ", totalFee="
|
||||
+ totalFee + ", createIp=" + createIp
|
||||
+ ", timeStart=" + timeStart + ", timeExpire=" + timeExpire
|
||||
+ ", goodsTag=" + goodsTag + ", notifyUrl=" + notifyUrl + "]";
|
||||
return "PayPackage [body=" + body + ", detail=" + detail
|
||||
+ ", outTradeNo=" + outTradeNo + ", totalFee=" + totalFee
|
||||
+ ", notifyUrl=" + notifyUrl + ", createIp=" + createIp
|
||||
+ ", attach=" + attach + ", timeStart=" + timeStart
|
||||
+ ", timeExpire=" + timeExpire + ", goodsTag=" + goodsTag + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
package com.foxinmy.weixin4j.payment;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.foxinmy.weixin4j.exception.PayException;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.exception.WeixinPayException;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinRequestExecutor;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
@ -64,24 +65,70 @@ public class PayUtil {
|
||||
* 用户ID
|
||||
* @param body
|
||||
* 订单描述
|
||||
* @param orderNo
|
||||
* @param outTradeNo
|
||||
* 订单号
|
||||
* @param orderFee
|
||||
* @param totalFee
|
||||
* 订单总额 按实际金额传入即可(元) 构造函数会转换为分
|
||||
* @param notifyUrl
|
||||
* 支付通知地址
|
||||
* @param ip
|
||||
* @param createIp
|
||||
* ip地址
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @return 支付json串
|
||||
* @throws PayException
|
||||
* @throws WeixinPayException
|
||||
*/
|
||||
public static String createPayJsRequestJson(String openId, String body,
|
||||
String orderNo, double orderFee, String notifyUrl, String ip,
|
||||
WeixinPayAccount weixinAccount) throws PayException {
|
||||
String outTradeNo, double totalFee, String notifyUrl,
|
||||
String createIp, WeixinPayAccount weixinAccount)
|
||||
throws WeixinPayException {
|
||||
return createPayJsRequestJson(weixinAccount, openId, body, outTradeNo,
|
||||
totalFee, notifyUrl, createIp, null, null, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成V3.x版本JSAPI支付字符串【完整参数】
|
||||
*
|
||||
* @param weixinAccount
|
||||
* 支付配置信息
|
||||
* @param openId
|
||||
* 用户ID
|
||||
* @param body
|
||||
* 商品描述
|
||||
* @param outTradeNo
|
||||
* 商户内部唯一订单号
|
||||
* @param totalFee
|
||||
* 商品总额 单位元
|
||||
* @param notifyUrl
|
||||
* 支付回调URL
|
||||
* @param createIp
|
||||
* 订单生成的机器 IP
|
||||
* @param attach
|
||||
* 附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
|
||||
* @param timeStart
|
||||
* 订单生成时间,格式为yyyyMMddHHmmss
|
||||
* @param timeExpire
|
||||
* 订单失效时间,格式为yyyyMMddHHmmss;注意:最短失效时间间隔必须大于5分钟
|
||||
* @param goodsTag
|
||||
* 商品标记,代金券或立减优惠功能的参数
|
||||
* @param limitPay
|
||||
* 指定支付方式:no_credit--指定不能使用信用卡支付
|
||||
* @return 支付json串
|
||||
* @throws WeixinPayException
|
||||
*/
|
||||
public static String createPayJsRequestJson(WeixinPayAccount weixinAccount,
|
||||
String openId, String body, String outTradeNo, double totalFee,
|
||||
String notifyUrl, String createIp, String attach, Date timeStart,
|
||||
Date timeExpire, String goodsTag, String limitPay)
|
||||
throws WeixinPayException {
|
||||
MchPayPackage payPackage = new MchPayPackage(weixinAccount, openId,
|
||||
body, orderNo, orderFee, notifyUrl, ip, TradeType.JSAPI);
|
||||
body, outTradeNo, totalFee, notifyUrl, createIp,
|
||||
TradeType.JSAPI);
|
||||
payPackage.setAttach(attach);
|
||||
payPackage.setTimeStart(timeStart);
|
||||
payPackage.setTimeExpire(timeExpire);
|
||||
payPackage.setGoodsTag(goodsTag);
|
||||
payPackage.setLimitPay(limitPay);
|
||||
String paySignKey = weixinAccount.getPaySignKey();
|
||||
payPackage.setSign(paysignMd5(payPackage, paySignKey));
|
||||
PrePay prePay = createPrePay(payPackage, paySignKey);
|
||||
@ -109,7 +156,7 @@ public class PayUtil {
|
||||
private final static WeixinRequestExecutor httpClient = new WeixinRequestExecutor();
|
||||
|
||||
public static PrePay createPrePay(MchPayPackage payPackage,
|
||||
String paySignKey) throws PayException {
|
||||
String paySignKey) throws WeixinPayException {
|
||||
if (StringUtil.isBlank(payPackage.getSign())) {
|
||||
payPackage.setSign(paysignMd5(payPackage, paySignKey));
|
||||
}
|
||||
@ -120,16 +167,16 @@ public class PayUtil {
|
||||
PrePay prePay = response.getAsObject(new TypeReference<PrePay>() {
|
||||
});
|
||||
if (!prePay.getReturnCode().equalsIgnoreCase(Consts.SUCCESS)) {
|
||||
throw new PayException(prePay.getReturnMsg(),
|
||||
throw new WeixinPayException(prePay.getReturnMsg(),
|
||||
prePay.getReturnCode());
|
||||
}
|
||||
if (!prePay.getResultCode().equalsIgnoreCase(Consts.SUCCESS)) {
|
||||
throw new PayException(prePay.getResultCode(),
|
||||
throw new WeixinPayException(prePay.getResultCode(),
|
||||
prePay.getErrCodeDes());
|
||||
}
|
||||
return prePay;
|
||||
} catch (WeixinException e) {
|
||||
throw new PayException(e.getErrorCode(), e.getErrorMsg());
|
||||
throw new WeixinPayException(e.getErrorCode(), e.getErrorMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,7 +247,7 @@ public class PayUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建V3.x NativePay支付(扫码支付)链接【模式二】
|
||||
* 创建V3.x NativePay支付(扫码支付)链接【模式二】【必填参数】
|
||||
*
|
||||
* @param weixinAccount
|
||||
* 支付配置信息
|
||||
@ -220,15 +267,63 @@ public class PayUtil {
|
||||
* @see <a href="http://pay.weixin.qq.com/wiki/doc/api/native.php">扫码支付</a>
|
||||
* @see <a
|
||||
* href="https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_5">模式二</a>
|
||||
* @throws PayException
|
||||
* @throws WeixinPayException
|
||||
*/
|
||||
public static String createNativePayRequestURL(
|
||||
WeixinPayAccount weixinAccount, String productId, String body,
|
||||
String outTradeNo, double totalFee, String notifyUrl,
|
||||
String createIp) throws PayException {
|
||||
String createIp) throws WeixinPayException {
|
||||
return createNativePayRequestURL(weixinAccount, productId, body,
|
||||
outTradeNo, totalFee, notifyUrl, createIp, null, null, null,
|
||||
null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建V3.x NativePay支付(扫码支付)链接【模式二】【完整参数】
|
||||
*
|
||||
* @param weixinAccount
|
||||
* 支付配置信息
|
||||
* @param productId
|
||||
* 商品ID
|
||||
* @param body
|
||||
* 商品描述
|
||||
* @param outTradeNo
|
||||
* 商户内部唯一订单号
|
||||
* @param totalFee
|
||||
* 商品总额 单位元
|
||||
* @param notifyUrl
|
||||
* 支付回调URL
|
||||
* @param createIp
|
||||
* 订单生成的机器 IP
|
||||
* @param attach
|
||||
* 附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
|
||||
* @param timeStart
|
||||
* 订单生成时间,格式为yyyyMMddHHmmss
|
||||
* @param timeExpire
|
||||
* 订单失效时间,格式为yyyyMMddHHmmss;注意:最短失效时间间隔必须大于5分钟
|
||||
* @param goodsTag
|
||||
* 商品标记,代金券或立减优惠功能的参数
|
||||
* @param limitPay
|
||||
* 指定支付方式:no_credit--指定不能使用信用卡支付
|
||||
* @return 支付链接
|
||||
* @see <a href="http://pay.weixin.qq.com/wiki/doc/api/native.php">扫码支付</a>
|
||||
* @see <a
|
||||
* href="https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_5">模式二</a>
|
||||
* @throws WeixinPayException
|
||||
*/
|
||||
public static String createNativePayRequestURL(
|
||||
WeixinPayAccount weixinAccount, String productId, String body,
|
||||
String outTradeNo, double totalFee, String notifyUrl,
|
||||
String createIp, String attach, Date timeStart, Date timeExpire,
|
||||
String goodsTag, String limitPay) throws WeixinPayException {
|
||||
MchPayPackage payPackage = new MchPayPackage(weixinAccount, null, body,
|
||||
outTradeNo, totalFee, notifyUrl, createIp, TradeType.NATIVE);
|
||||
payPackage.setProductId(productId);
|
||||
payPackage.setAttach(attach);
|
||||
payPackage.setTimeStart(timeStart);
|
||||
payPackage.setTimeExpire(timeExpire);
|
||||
payPackage.setGoodsTag(goodsTag);
|
||||
payPackage.setLimitPay(limitPay);
|
||||
String paySignKey = weixinAccount.getPaySignKey();
|
||||
payPackage.setSign(paysignMd5(payPackage, paySignKey));
|
||||
PrePay prePay = createPrePay(payPackage, paySignKey);
|
||||
@ -242,13 +337,11 @@ public class PayUtil {
|
||||
* 扫码支付授权码 ,设备读取用户微信中的条码或者二维码信息
|
||||
* @param body
|
||||
* 商品描述
|
||||
* @param attach
|
||||
* 附加数据
|
||||
* @param orderNo
|
||||
* 商户内部唯一订单号
|
||||
* @param orderFee
|
||||
* 商品总额 单位元
|
||||
* @param ip
|
||||
* @param createIp
|
||||
* 订单生成的机器 IP
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
@ -257,10 +350,10 @@ public class PayUtil {
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public static Order createMicroPay(String authCode, String body,
|
||||
String attach, String orderNo, double orderFee, String createIp,
|
||||
String orderNo, double orderFee, String createIp,
|
||||
WeixinPayAccount weixinAccount) throws WeixinException {
|
||||
MicroPayPackage payPackage = new MicroPayPackage(weixinAccount, body,
|
||||
attach, orderNo, orderFee, createIp, authCode);
|
||||
MicroPayPackage payPackage = new MicroPayPackage(weixinAccount,
|
||||
authCode, body, orderNo, orderFee, createIp);
|
||||
return createMicroPay(payPackage, weixinAccount);
|
||||
}
|
||||
|
||||
@ -289,7 +382,7 @@ public class PayUtil {
|
||||
});
|
||||
}
|
||||
|
||||
private static String JSAPI() throws PayException {
|
||||
private static String JSAPI() throws WeixinPayException {
|
||||
WeixinPayAccount weixinAccount = JSON.parseObject(
|
||||
Weixin4jConfigUtil.getValue("account"), WeixinPayAccount.class);
|
||||
return createPayJsRequestJson("oyFLst1bqtuTcxK-ojF8hOGtLQao", "支付测试",
|
||||
@ -303,7 +396,7 @@ public class PayUtil {
|
||||
return createNativePayRequestURL(weixinAccount, "P1");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws PayException {
|
||||
public static void main(String[] args) throws WeixinPayException {
|
||||
// V3版本下的JS支付
|
||||
System.out.println(JSAPI());
|
||||
// V3版本下的原生支付
|
||||
|
||||
@ -74,6 +74,12 @@ public class MchPayPackage extends PayPackage {
|
||||
@XmlElement(name = "product_id")
|
||||
@JSONField(name = "product_id")
|
||||
private String productId;
|
||||
/**
|
||||
* 指定支付方式:no_credit--指定不能使用信用卡支付
|
||||
*/
|
||||
@XmlElement(name = "limit_pay")
|
||||
@JSONField(name = "limit_pay")
|
||||
private String limitPay;
|
||||
|
||||
protected MchPayPackage() {
|
||||
// jaxb required
|
||||
@ -81,34 +87,35 @@ public class MchPayPackage extends PayPackage {
|
||||
|
||||
public MchPayPackage(WeixinPayAccount weixinAccount, String openId,
|
||||
String body, String outTradeNo, double totalFee, String notifyUrl,
|
||||
String spbillCreateIp, TradeType tradeType) {
|
||||
this(weixinAccount, openId, body, null, outTradeNo, totalFee,
|
||||
notifyUrl, spbillCreateIp, tradeType);
|
||||
String createIp, TradeType tradeType) {
|
||||
this(weixinAccount, openId, body, outTradeNo, totalFee, notifyUrl,
|
||||
createIp, tradeType, null);
|
||||
}
|
||||
|
||||
public MchPayPackage(WeixinPayAccount weixinAccount, String openId,
|
||||
String body, String attach, String outTradeNo, double totalFee,
|
||||
String notifyUrl, String spbillCreateIp, TradeType tradeType) {
|
||||
String body, String outTradeNo, double totalFee, String notifyUrl,
|
||||
String createIp, TradeType tradeType, String attach) {
|
||||
this(weixinAccount.getId(), weixinAccount.getMchId(), weixinAccount
|
||||
.getDeviceInfo(), RandomUtil.generateString(16), body, attach,
|
||||
outTradeNo, totalFee, spbillCreateIp, null, null, null,
|
||||
notifyUrl, tradeType, openId, null);
|
||||
.getDeviceInfo(), body, outTradeNo, totalFee, notifyUrl,
|
||||
createIp, tradeType, openId, attach, null, null, null, null,
|
||||
null);
|
||||
}
|
||||
|
||||
public MchPayPackage(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);
|
||||
String body, String outTradeNo, double totalFee, String notifyUrl,
|
||||
String createIp, TradeType tradeType, String openId, String attach,
|
||||
Date timeStart, Date timeExpire, String goodsTag, String productId,
|
||||
String limitPay) {
|
||||
super(body, outTradeNo, totalFee, notifyUrl, createIp, attach,
|
||||
timeStart, timeExpire, goodsTag);
|
||||
this.appId = appId;
|
||||
this.mchId = mchId;
|
||||
this.deviceInfo = deviceInfo;
|
||||
this.nonceStr = nonceStr;
|
||||
this.nonceStr = RandomUtil.generateString(16);
|
||||
this.tradeType = tradeType.name();
|
||||
this.openId = openId;
|
||||
this.productId = productId;
|
||||
this.limitPay = limitPay;
|
||||
}
|
||||
|
||||
public String getAppId() {
|
||||
@ -151,6 +158,14 @@ public class MchPayPackage extends PayPackage {
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public String getLimitPay() {
|
||||
return limitPay;
|
||||
}
|
||||
|
||||
public void setLimitPay(String limitPay) {
|
||||
this.limitPay = limitPay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MchPayPackage [appId=" + appId + ", mchId=" + mchId
|
||||
|
||||
@ -4,7 +4,7 @@ import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.PayException;
|
||||
import com.foxinmy.weixin4j.exception.WeixinPayException;
|
||||
import com.foxinmy.weixin4j.payment.PayRequest;
|
||||
|
||||
/**
|
||||
@ -34,7 +34,7 @@ public class MchPayRequest extends PayRequest {
|
||||
// jaxb required
|
||||
}
|
||||
|
||||
public MchPayRequest(PrePay prePay) throws PayException {
|
||||
public MchPayRequest(PrePay prePay) throws WeixinPayException {
|
||||
this.setAppId(prePay.getAppId());
|
||||
this.setPackageInfo("prepay_id=" + prePay.getPrepayId());
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.exception.PayException;
|
||||
import com.foxinmy.weixin4j.exception.WeixinPayException;
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
import com.foxinmy.weixin4j.payment.PayUtil;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
@ -44,7 +44,7 @@ public class NativePayResponse extends ApiResult {
|
||||
* 失败消息
|
||||
* @param resultMsg
|
||||
* 结果消息
|
||||
* @throws PayException
|
||||
* @throws WeixinPayException
|
||||
*/
|
||||
public NativePayResponse(String returnMsg, String resultMsg) {
|
||||
super.setReturnMsg(returnMsg);
|
||||
@ -58,10 +58,10 @@ public class NativePayResponse extends ApiResult {
|
||||
*
|
||||
* @param payPackage
|
||||
* 订单信息
|
||||
* @throws PayException
|
||||
* @throws WeixinPayException
|
||||
*/
|
||||
public NativePayResponse(MchPayPackage payPackage, String paysignKey)
|
||||
throws PayException {
|
||||
throws WeixinPayException {
|
||||
super.setReturnCode(Consts.SUCCESS);
|
||||
this.setResultCode(Consts.SUCCESS);
|
||||
this.setMchId(payPackage.getMchId());
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j</artifactId>
|
||||
<version>1.6.3</version>
|
||||
<version>1.6.4</version>
|
||||
</parent>
|
||||
<artifactId>weixin4j-mp</artifactId>
|
||||
<name>weixin4j-mp</name>
|
||||
|
||||
@ -65,33 +65,22 @@ public class PayPackageV2 extends PayPackage {
|
||||
// jaxb required
|
||||
}
|
||||
|
||||
public PayPackageV2(String outTradeNo, double totalFee,
|
||||
String spbillCreateIp) {
|
||||
this(null, null, null, outTradeNo, totalFee, null, spbillCreateIp,
|
||||
public PayPackageV2(String partner, String body, String outTradeNo,
|
||||
double totalFee, String notifyUrl, String createIp) {
|
||||
this(partner, body, outTradeNo, totalFee, notifyUrl, createIp, null,
|
||||
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 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 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);
|
||||
public PayPackageV2(String partner, String body, String outTradeNo,
|
||||
double totalFee, String notifyUrl, String createIp, String attach,
|
||||
Date timeStart, Date timeExpire, double transportFee,
|
||||
double productFee, String goodsTag) {
|
||||
super(body, outTradeNo, totalFee, notifyUrl, createIp, attach,
|
||||
timeStart, timeExpire, goodsTag);
|
||||
this.bankType = "WX";
|
||||
this.feeType = "1";
|
||||
this.inputCharset = "UTF-8";
|
||||
this.partner = partner;
|
||||
this.transportFee = transportFee > 0d ? DateUtil
|
||||
.formaFee2Fen(transportFee) : null;
|
||||
this.productFee = productFee > 0 ? DateUtil.formaFee2Fen(productFee)
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
package com.foxinmy.weixin4j.mp.payment.v2;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.foxinmy.weixin4j.exception.PayException;
|
||||
import com.foxinmy.weixin4j.exception.WeixinPayException;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
import com.foxinmy.weixin4j.type.SignType;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
import com.foxinmy.weixin4j.util.DigestUtil;
|
||||
import com.foxinmy.weixin4j.util.MapUtil;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
/**
|
||||
@ -25,49 +25,80 @@ import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
* @see
|
||||
*/
|
||||
public class PayUtil2 {
|
||||
/**
|
||||
* 生成V2.x版本JSAPI支付字符串
|
||||
*
|
||||
* @param payPackage
|
||||
* 订单信息
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @return 支付json串
|
||||
*/
|
||||
public static String createPayJsRequestJsonV2(PayPackageV2 payPackage,
|
||||
WeixinPayAccount weixinAccount) {
|
||||
if (StringUtil.isBlank(payPackage.getPartner())) {
|
||||
payPackage.setPartner(weixinAccount.getPartnerId());
|
||||
}
|
||||
JsPayRequestV2 jsPayRequest = new JsPayRequestV2(weixinAccount,
|
||||
payPackage);
|
||||
jsPayRequest.setPaySign(paysignSha(jsPayRequest,
|
||||
weixinAccount.getPaySignKey()));
|
||||
jsPayRequest.setSignType(SignType.SHA1);
|
||||
return JSON.toJSONString(jsPayRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成V2.x版本JSAPI支付字符串
|
||||
*
|
||||
* @param body
|
||||
* 支付详情
|
||||
* @param orderNo
|
||||
* @param outTradeNo
|
||||
* 订单号
|
||||
* @param orderFee
|
||||
* @param totalFee
|
||||
* 订单总额 按实际金额传入即可(元) 构造函数会转换为分
|
||||
* @param ip
|
||||
* @param notifyUrl
|
||||
* 支付回调URL
|
||||
* @param createIp
|
||||
* 订单生成的机器 IP
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @return 支付json串
|
||||
*/
|
||||
public static String createPayJsRequestJsonV2(String body, String orderNo,
|
||||
double orderFee, String notify_url, String ip,
|
||||
WeixinPayAccount weixinAccount) {
|
||||
PayPackageV2 payPackage = new PayPackageV2(body, orderNo, orderFee,
|
||||
notify_url, ip);
|
||||
payPackage.setPartner(weixinAccount.getPartnerId());
|
||||
return createPayJsRequestJsonV2(payPackage, weixinAccount);
|
||||
public static String createPayJsRequestJsonV2(String body,
|
||||
String outTradeNo, double totalFee, String notifyUrl,
|
||||
String createIp, WeixinPayAccount weixinAccount) {
|
||||
return createPayJsRequestJsonV2(weixinAccount, body, outTradeNo,
|
||||
totalFee, notifyUrl, createIp, null, null, null, 0d, 0d, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成V2.x版本JSAPI支付字符串
|
||||
*
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @param body
|
||||
* 支付详情
|
||||
* @param outTradeNo
|
||||
* 订单号
|
||||
* @param totalFee
|
||||
* 订单总额 按实际金额传入即可(元) 构造函数会转换为分
|
||||
* @param notifyUrl
|
||||
* 支付回调URL
|
||||
* @param createIp
|
||||
* 订单生成的机器 IP
|
||||
* @param attach
|
||||
* 附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
|
||||
* @param timeStart
|
||||
* 订单生成时间,格式为yyyyMMddHHmmss
|
||||
* @param timeExpire
|
||||
* 订单失效时间,格式为yyyyMMddHHmmss;注意:最短失效时间间隔必须大于5分钟
|
||||
* @param transportFee
|
||||
* 物流费用 如有值 必须保证 transportFee+productFee=totalFee
|
||||
* @param transportFee
|
||||
* 商品费用 如有值 必须保证 transportFee+productFee=totalFee
|
||||
* @param goodsTag
|
||||
* 商品标记,代金券或立减优惠功能的参数
|
||||
* @return 支付json串
|
||||
*/
|
||||
public static String createPayJsRequestJsonV2(
|
||||
WeixinPayAccount weixinAccount, String body, String outTradeNo,
|
||||
double totalFee, String notifyUrl, String createIp, String attach,
|
||||
Date timeStart, Date timeExpire, double transportFee,
|
||||
double productFee, String goodsTag) {
|
||||
PayPackageV2 payPackage = new PayPackageV2(
|
||||
weixinAccount.getPartnerId(), body, outTradeNo, totalFee,
|
||||
notifyUrl, createIp);
|
||||
payPackage.setAttach(attach);
|
||||
payPackage.setTimeStart(timeStart);
|
||||
payPackage.setTimeExpire(timeExpire);
|
||||
payPackage.setTransportFee(transportFee);
|
||||
payPackage.setProductFee(productFee);
|
||||
payPackage.setGoodsTag(goodsTag);
|
||||
JsPayRequestV2 jsPayRequest = new JsPayRequestV2(weixinAccount,
|
||||
payPackage);
|
||||
jsPayRequest.setPaySign(paysignSha(jsPayRequest,
|
||||
weixinAccount.getPaySignKey()));
|
||||
jsPayRequest.setSignType(SignType.SHA1);
|
||||
return JSON.toJSONString(jsPayRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,7 +194,7 @@ public class PayUtil2 {
|
||||
return createNativePayRequestURLV2(weixinAccount, "P1");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws PayException {
|
||||
public static void main(String[] args) throws WeixinPayException {
|
||||
// V2版本下的JS支付
|
||||
System.out.println(JSAPIV2());
|
||||
// V2版本下的原生支付
|
||||
|
||||
@ -9,7 +9,7 @@ import java.util.Date;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.PayException;
|
||||
import com.foxinmy.weixin4j.exception.WeixinPayException;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.XmlResult;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
@ -143,7 +143,7 @@ public class PayTest {
|
||||
try {
|
||||
prePay = PayUtil.createPrePay(payPackageV3,
|
||||
ACCOUNT3.getPaySignKey());
|
||||
} catch (PayException e) {
|
||||
} catch (WeixinPayException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.err.println(prePay);
|
||||
|
||||
@ -29,7 +29,7 @@ public class UserTest extends TokenTest {
|
||||
|
||||
@Test
|
||||
public void getUser() throws WeixinException {
|
||||
User user = userApi.getUser("owGBft_vbBbOaQOmpEUE4xDLeRSU");
|
||||
User user = userApi.getUser("o9Onds6fbeK0lDwD8lJt2PY1VRys");
|
||||
Assert.assertNotNull(user);
|
||||
System.out.println(user);
|
||||
// following();
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j</artifactId>
|
||||
<version>1.6.3</version>
|
||||
<version>1.6.4</version>
|
||||
</parent>
|
||||
<artifactId>weixin4j-qy</artifactId>
|
||||
<name>weixin4j-qy</name>
|
||||
|
||||
@ -31,13 +31,11 @@ public class AesToken implements Serializable {
|
||||
/**
|
||||
* 一般为明文模式
|
||||
*
|
||||
* @param weixinId
|
||||
* 微信号(原始ID/appid/corpid)
|
||||
* @param token
|
||||
* 开发者的Token
|
||||
*/
|
||||
public AesToken(String weixinId, String token) {
|
||||
this(weixinId, token, null);
|
||||
public AesToken(String token) {
|
||||
this(null, token, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user