diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/PayPackage.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/PayPackage.java
index 67285bb8..a7584a78 100644
--- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/PayPackage.java
+++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/PayPackage.java
@@ -55,7 +55,7 @@ public class PayPackage implements Serializable {
*/
@XmlElement(name = "spbill_create_ip")
@JSONField(name = "spbill_create_ip")
- private String spbillCreateIp;
+ private String createIp;
/**
* 订单生成时间,格式为 yyyyMMddHHmmss,如 2009 年 12月25日9点10分10秒表示为 20091225091010。时区 为
* GMT+8 beijing。该时间取 自商户服务器 非必须
@@ -129,12 +129,12 @@ public class PayPackage implements Serializable {
this.totalFee = DateUtil.formaFee2Fen(totalFee);
}
- public String getSpbillCreateIp() {
- return spbillCreateIp;
+ public String getCreateIp() {
+ return createIp;
}
- public void setSpbillCreateIp(String spbillCreateIp) {
- this.spbillCreateIp = spbillCreateIp;
+ public void setCreateIp(String createIp) {
+ this.createIp = createIp;
}
public String getTimeStart() {
@@ -206,13 +206,13 @@ public class PayPackage implements Serializable {
* 回调地址
*/
public PayPackage(String body, String attach, String outTradeNo,
- double totalFee, String spbillCreateIp, Date timeStart,
+ 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.spbillCreateIp = spbillCreateIp;
+ this.createIp = createIp;
this.timeStart = timeStart != null ? DateUtil
.fortmat2yyyyMMddHHmmss(timeStart) : null;
this.timeExpire = timeExpire != null ? DateUtil
@@ -225,7 +225,7 @@ public class PayPackage implements Serializable {
public String toString() {
return "PayPackage [body=" + body + ", detail=" + detail + ", attach="
+ attach + ", outTradeNo=" + outTradeNo + ", totalFee="
- + totalFee + ", spbillCreateIp=" + spbillCreateIp
+ + totalFee + ", createIp=" + createIp
+ ", timeStart=" + timeStart + ", timeExpire=" + timeExpire
+ ", goodsTag=" + goodsTag + ", notifyUrl=" + notifyUrl + "]";
}
diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/PayURLConsts.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/PayURLConsts.java
index 05660fda..ffdc2817 100644
--- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/PayURLConsts.java
+++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/PayURLConsts.java
@@ -99,7 +99,12 @@ public final class PayURLConsts {
public static final String MCH_SHORTURL_URL = MCH_BASE_URL
+ "/tools/shorturl";
/**
- * 商户平台下native支付的url
+ * 商户平台下native支付的url-模式1
*/
- public static final String MCH_NATIVE_URL = "weixin://wxpay/bizpayurl?sign=%s&appid=%s&mch_id=%s&product_id=%s&time_stamp=%s&nonce_str=%s";
+ public static final String MCH_NATIVE_URL1 = "weixin://wxpay/bizpayurl?sign=%s&appid=%s&mch_id=%s&product_id=%s&time_stamp=%s&nonce_str=%s";
+
+ /**
+ * 商户平台下native支付的url-模式2
+ */
+ public static final String MCH_NATIVE_URL2 = "weixin://wxpay/bizpayurl?sr=%s";
}
diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/PayUtil.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/PayUtil.java
index eac89851..c8a09e6f 100644
--- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/PayUtil.java
+++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/PayUtil.java
@@ -188,7 +188,7 @@ public class PayUtil {
}
/**
- * 创建V3.x NativePay支付(扫码支付)链接
+ * 创建V3.x NativePay支付(扫码支付)链接【模式一】
*
* @param weixinAccount
* 支付配置信息
@@ -196,6 +196,8 @@ public class PayUtil {
* 与订单ID等价
* @return 支付链接
* @see 扫码支付
+ * @see 模式一
*/
public static String createNativePayRequestURL(
WeixinPayAccount weixinAccount, String productId) {
@@ -208,11 +210,41 @@ public class PayUtil {
map.put("nonce_str", noncestr);
map.put("product_id", productId);
String sign = paysignMd5(map, weixinAccount.getPaySignKey());
- return String.format(PayURLConsts.MCH_NATIVE_URL, sign,
+ return String.format(PayURLConsts.MCH_NATIVE_URL1, sign,
weixinAccount.getId(), weixinAccount.getMchId(), productId,
timestamp, noncestr);
}
+ /**
+ * 创建V3.x NativePay支付(扫码支付)链接【模式二】
+ *
+ * @param weixinAccount
+ * 支付配置信息
+ * @param body
+ * 商品描述
+ * @param outTradeNo
+ * 商户内部唯一订单号
+ * @param totalFee
+ * 商品总额 单位元
+ * @param createIp
+ * 订单生成的机器 IP
+ * @return 支付链接
+ * @see 扫码支付
+ * @see 模式二
+ * @throws PayException
+ */
+ public static String createNativePayRequestURL(
+ WeixinPayAccount weixinAccount, String body, String outTradeNo,
+ double totalFee, String createIp) throws PayException {
+ MchPayPackage payPackage = new MchPayPackage(weixinAccount, null, body,
+ outTradeNo, totalFee, createIp, TradeType.NATIVE);
+ String paySignKey = weixinAccount.getPaySignKey();
+ payPackage.setSign(paysignMd5(payPackage, paySignKey));
+ PrePay prePay = createPrePay(payPackage, paySignKey);
+ return String.format(PayURLConsts.MCH_NATIVE_URL2, prePay.getCodeUrl());
+ }
+
/**
* 提交被扫支付
*
@@ -235,10 +267,10 @@ public class PayUtil {
* @throws WeixinException
*/
public static Order createMicroPay(String authCode, String body,
- String attach, String orderNo, double orderFee, String ip,
+ String attach, String orderNo, double orderFee, String createIp,
WeixinPayAccount weixinAccount) throws WeixinException {
MicroPayPackage payPackage = new MicroPayPackage(weixinAccount, body,
- attach, orderNo, orderFee, ip, authCode);
+ attach, orderNo, orderFee, createIp, authCode);
return createMicroPay(payPackage, weixinAccount);
}