优化扫码支付(Native)
This commit is contained in:
@@ -34,6 +34,7 @@ import com.foxinmy.weixin4j.payment.mch.JSAPIPayRequest;
|
||||
import com.foxinmy.weixin4j.payment.mch.MchPayPackage;
|
||||
import com.foxinmy.weixin4j.payment.mch.MchPayRequest;
|
||||
import com.foxinmy.weixin4j.payment.mch.NATIVEPayRequest;
|
||||
import com.foxinmy.weixin4j.payment.mch.NativePayResponse;
|
||||
import com.foxinmy.weixin4j.payment.mch.Order;
|
||||
import com.foxinmy.weixin4j.payment.mch.PrePay;
|
||||
import com.foxinmy.weixin4j.payment.mch.RefundRecord;
|
||||
@@ -290,6 +291,38 @@ public class Pay3Api {
|
||||
timestamp, noncestr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建Native支付(扫码支付)回调对象【模式一】
|
||||
*
|
||||
* @param productId
|
||||
* 商品ID
|
||||
* @param body
|
||||
* 商品描述
|
||||
* @param outTradeNo
|
||||
* 商户内部唯一订单号
|
||||
* @param totalFee
|
||||
* 商品总额 单位元
|
||||
* @param notifyUrl
|
||||
* 支付回调URL
|
||||
* @param createIp
|
||||
* 订单生成的机器 IP
|
||||
* @return Native回调对象
|
||||
* @see com.foxinmy.weixin4j.payment.mch.NativePayResponse
|
||||
* @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>
|
||||
* @throws WeixinPayException
|
||||
*/
|
||||
public NativePayResponse createNativePayResponse(String productId,
|
||||
String body, String outTradeNo, double totalFee, String notifyUrl,
|
||||
String createIp) throws WeixinPayException {
|
||||
MchPayPackage payPackage = new MchPayPackage(weixinAccount, null, body,
|
||||
outTradeNo, totalFee, notifyUrl, createIp, TradeType.NATIVE);
|
||||
payPackage.setProductId(productId);
|
||||
PrePay prePay = createPrePay(payPackage);
|
||||
return new NativePayResponse(weixinAccount, prePay.getPrepayId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建Native支付(扫码支付)链接【模式二】
|
||||
*
|
||||
|
||||
@@ -6,6 +6,7 @@ import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.type.SignType;
|
||||
@@ -92,6 +93,7 @@ public class PayBaseInfo implements Serializable {
|
||||
return signType;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
@JSONField(serialize = false)
|
||||
public SignType getFormatSignType() {
|
||||
return signType != null ? SignType.valueOf(signType.toUpperCase())
|
||||
|
||||
@@ -36,8 +36,8 @@ public class PayRequest extends PayBaseInfo {
|
||||
@JSONField(serialize = false)
|
||||
private String partnerId;
|
||||
|
||||
public PayRequest() {
|
||||
super(null, DateUtil.timestamp2string(), RandomUtil.generateString(16));
|
||||
protected PayRequest() {
|
||||
// jaxb required
|
||||
}
|
||||
|
||||
public PayRequest(String appId, String packageInfo) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.foxinmy.weixin4j.payment.mch.MPPaymentRecord;
|
||||
import com.foxinmy.weixin4j.payment.mch.MPPaymentResult;
|
||||
import com.foxinmy.weixin4j.payment.mch.MchPayPackage;
|
||||
import com.foxinmy.weixin4j.payment.mch.MchPayRequest;
|
||||
import com.foxinmy.weixin4j.payment.mch.NativePayResponse;
|
||||
import com.foxinmy.weixin4j.payment.mch.Order;
|
||||
import com.foxinmy.weixin4j.payment.mch.PrePay;
|
||||
import com.foxinmy.weixin4j.payment.mch.Redpacket;
|
||||
@@ -237,6 +238,36 @@ public class WeixinPayProxy {
|
||||
return pay3Api.createNativePayRequestURL(productId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建Native支付(扫码支付)回调对象【模式一】
|
||||
*
|
||||
* @param productId
|
||||
* 商品ID
|
||||
* @param body
|
||||
* 商品描述
|
||||
* @param outTradeNo
|
||||
* 商户内部唯一订单号
|
||||
* @param totalFee
|
||||
* 商品总额 单位元
|
||||
* @param notifyUrl
|
||||
* 支付回调URL
|
||||
* @param createIp
|
||||
* 订单生成的机器 IP
|
||||
* @return Native回调对象
|
||||
* @see com.foxinmy.weixin4j.api.Pay3Api
|
||||
* @see com.foxinmy.weixin4j.payment.mch.NativePayResponse
|
||||
* @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>
|
||||
* @throws WeixinPayException
|
||||
*/
|
||||
public NativePayResponse createNativePayResponse(String productId,
|
||||
String body, String outTradeNo, double totalFee, String notifyUrl,
|
||||
String createIp) throws WeixinPayException {
|
||||
return pay3Api.createNativePayResponse(productId, body, outTradeNo,
|
||||
totalFee, notifyUrl, createIp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建Native支付(扫码支付)链接【模式二】
|
||||
*
|
||||
|
||||
+2
-26
@@ -4,7 +4,6 @@ import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.exception.WeixinPayException;
|
||||
@@ -12,7 +11,6 @@ import com.foxinmy.weixin4j.model.Consts;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
import com.foxinmy.weixin4j.util.DigestUtil;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
/**
|
||||
* Native支付时的回调响应
|
||||
@@ -33,10 +31,6 @@ public class NativePayResponse extends ApiResult {
|
||||
@JSONField(name = "prepay_id")
|
||||
private String prepayId;
|
||||
|
||||
@XmlTransient
|
||||
@JSONField(serialize = false)
|
||||
private WeixinPayAccount weixinAccount;
|
||||
|
||||
protected NativePayResponse() {
|
||||
// jaxb required
|
||||
}
|
||||
@@ -44,21 +38,17 @@ public class NativePayResponse extends ApiResult {
|
||||
/**
|
||||
* 作为return_code 为 FAIL 的时候返回
|
||||
*
|
||||
* @param weixinAccount
|
||||
* 商户信息
|
||||
* @param returnMsg
|
||||
* 失败消息
|
||||
* @param resultMsg
|
||||
* 结果消息
|
||||
* @throws WeixinPayException
|
||||
*/
|
||||
public NativePayResponse(WeixinPayAccount weixinAccount, String returnMsg,
|
||||
String resultMsg) {
|
||||
public NativePayResponse(String returnMsg, String resultMsg) {
|
||||
super.setReturnMsg(returnMsg);
|
||||
super.setReturnCode(Consts.FAIL);
|
||||
super.setErrCodeDes(resultMsg);
|
||||
super.setResultCode(Consts.FAIL);
|
||||
this.weixinAccount = weixinAccount;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,27 +67,13 @@ public class NativePayResponse extends ApiResult {
|
||||
this.setAppId(weixinAccount.getId());
|
||||
this.setNonceStr(RandomUtil.generateString(16));
|
||||
this.prepayId = prepayId;
|
||||
this.weixinAccount = weixinAccount;
|
||||
this.setSign(DigestUtil.paysignMd5(this, weixinAccount.getPaySignKey()));
|
||||
}
|
||||
|
||||
public String getPrepayId() {
|
||||
return prepayId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成 回调字符串
|
||||
*
|
||||
* @param paySignKey
|
||||
* 支付签名密钥
|
||||
* @return native回调字符串
|
||||
*/
|
||||
@XmlTransient
|
||||
@JSONField(serialize = false)
|
||||
public String asRequestXml() {
|
||||
this.setSign(DigestUtil.paysignMd5(this, weixinAccount.getPaySignKey()));
|
||||
return XmlStream.toXML(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NativePayResponse [prepayId=" + prepayId + ", "
|
||||
|
||||
Reference in New Issue
Block a user