PayUtil新增扫码支付(模式二)方法

This commit is contained in:
jinyu 2015-07-06 11:19:48 +08:00
parent 3872daa9a2
commit f56f0b1848
3 changed files with 51 additions and 14 deletions

View File

@ -55,7 +55,7 @@ public class PayPackage implements Serializable {
*/ */
@XmlElement(name = "spbill_create_ip") @XmlElement(name = "spbill_create_ip")
@JSONField(name = "spbill_create_ip") @JSONField(name = "spbill_create_ip")
private String spbillCreateIp; private String createIp;
/** /**
* 订单生成时间,格式为 yyyyMMddHHmmss, 2009 12月25日9点10分10秒表示为 20091225091010时区 * 订单生成时间,格式为 yyyyMMddHHmmss, 2009 12月25日9点10分10秒表示为 20091225091010时区
* GMT+8 beijing该时间取 自商户服务器 非必须 * GMT+8 beijing该时间取 自商户服务器 非必须
@ -129,12 +129,12 @@ public class PayPackage implements Serializable {
this.totalFee = DateUtil.formaFee2Fen(totalFee); this.totalFee = DateUtil.formaFee2Fen(totalFee);
} }
public String getSpbillCreateIp() { public String getCreateIp() {
return spbillCreateIp; return createIp;
} }
public void setSpbillCreateIp(String spbillCreateIp) { public void setCreateIp(String createIp) {
this.spbillCreateIp = spbillCreateIp; this.createIp = createIp;
} }
public String getTimeStart() { public String getTimeStart() {
@ -206,13 +206,13 @@ public class PayPackage implements Serializable {
* 回调地址 * 回调地址
*/ */
public PayPackage(String body, String attach, String outTradeNo, 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) { Date timeExpire, String goodsTag, String notifyUrl) {
this.body = body; this.body = body;
this.attach = attach; this.attach = attach;
this.outTradeNo = outTradeNo; this.outTradeNo = outTradeNo;
this.totalFee = DateUtil.formaFee2Fen(totalFee); this.totalFee = DateUtil.formaFee2Fen(totalFee);
this.spbillCreateIp = spbillCreateIp; this.createIp = createIp;
this.timeStart = timeStart != null ? DateUtil this.timeStart = timeStart != null ? DateUtil
.fortmat2yyyyMMddHHmmss(timeStart) : null; .fortmat2yyyyMMddHHmmss(timeStart) : null;
this.timeExpire = timeExpire != null ? DateUtil this.timeExpire = timeExpire != null ? DateUtil
@ -225,7 +225,7 @@ public class PayPackage implements Serializable {
public String toString() { public String toString() {
return "PayPackage [body=" + body + ", detail=" + detail + ", attach=" return "PayPackage [body=" + body + ", detail=" + detail + ", attach="
+ attach + ", outTradeNo=" + outTradeNo + ", totalFee=" + attach + ", outTradeNo=" + outTradeNo + ", totalFee="
+ totalFee + ", spbillCreateIp=" + spbillCreateIp + totalFee + ", createIp=" + createIp
+ ", timeStart=" + timeStart + ", timeExpire=" + timeExpire + ", timeStart=" + timeStart + ", timeExpire=" + timeExpire
+ ", goodsTag=" + goodsTag + ", notifyUrl=" + notifyUrl + "]"; + ", goodsTag=" + goodsTag + ", notifyUrl=" + notifyUrl + "]";
} }

View File

@ -99,7 +99,12 @@ public final class PayURLConsts {
public static final String MCH_SHORTURL_URL = MCH_BASE_URL public static final String MCH_SHORTURL_URL = MCH_BASE_URL
+ "/tools/shorturl"; + "/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";
} }

View File

@ -188,7 +188,7 @@ public class PayUtil {
} }
/** /**
* 创建V3.x NativePay支付(扫码支付)链接 * 创建V3.x NativePay支付(扫码支付)链接模式一
* *
* @param weixinAccount * @param weixinAccount
* 支付配置信息 * 支付配置信息
@ -196,6 +196,8 @@ public class PayUtil {
* 与订单ID等价 * 与订单ID等价
* @return 支付链接 * @return 支付链接
* @see <a href="http://pay.weixin.qq.com/wiki/doc/api/native.php">扫码支付</a> * @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_4">模式一</a>
*/ */
public static String createNativePayRequestURL( public static String createNativePayRequestURL(
WeixinPayAccount weixinAccount, String productId) { WeixinPayAccount weixinAccount, String productId) {
@ -208,11 +210,41 @@ public class PayUtil {
map.put("nonce_str", noncestr); map.put("nonce_str", noncestr);
map.put("product_id", productId); map.put("product_id", productId);
String sign = paysignMd5(map, weixinAccount.getPaySignKey()); 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, weixinAccount.getId(), weixinAccount.getMchId(), productId,
timestamp, noncestr); timestamp, noncestr);
} }
/**
* 创建V3.x NativePay支付(扫码支付)链接模式二
*
* @param weixinAccount
* 支付配置信息
* @param body
* 商品描述
* @param outTradeNo
* 商户内部唯一订单号
* @param totalFee
* 商品总额 单位元
* @param createIp
* 订单生成的机器 IP
* @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 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 * @throws WeixinException
*/ */
public static Order createMicroPay(String authCode, String body, 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 { WeixinPayAccount weixinAccount) throws WeixinException {
MicroPayPackage payPackage = new MicroPayPackage(weixinAccount, body, MicroPayPackage payPackage = new MicroPayPackage(weixinAccount, body,
attach, orderNo, orderFee, ip, authCode); attach, orderNo, orderFee, createIp, authCode);
return createMicroPay(payPackage, weixinAccount); return createMicroPay(payPackage, weixinAccount);
} }