浏览代码

添加构造支付参数的重载方法,准备替换原有方法

master
Binary Wang 8 年前
父节点
当前提交
8619430ae5
共有 2 个文件被更改,包括 49 次插入3 次删除
  1. +11
    -2
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java
  2. +38
    -1
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java

+ 11
- 2
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java 查看文件

@@ -65,9 +65,18 @@ public interface WxMpPayService {
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
*
* @param parameters the required or optional parameters
* @deprecated use me.chanjar.weixin.mp.api.WxMpPayService.getPayInfo(WxUnifiedOrderRequest) instead.
*/
@Deprecated
Map<String, String> getPayInfo(Map<String, String> parameters) throws WxErrorException;

/**
* 该接口调用“统一下单”接口,并拼装发起支付请求需要的参数
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
*
*/
Map<String, String> getPayInfo(WxUnifiedOrderRequest request) throws WxErrorException;

/**
* 该接口调用“统一下单”接口,并拼装NATIVE发起支付请求需要的参数
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
@@ -79,7 +88,7 @@ public interface WxMpPayService {
* @param body 商品描述
* @param ip 发起支付的客户端IP
* @param notifyUrl 通知地址
* @deprecated Use me.chanjar.weixin.mp.api.WxMpPayService.getPayInfo(Map<String, String>) instead
* @deprecated Use me.chanjar.weixin.mp.api.WxMpPayService.getPayInfo(WxUnifiedOrderRequest) instead
*/
@Deprecated
Map<String, String> getNativePayInfo(String productId, String outTradeNo, double amt, String body, String ip, String notifyUrl) throws WxErrorException;
@@ -95,7 +104,7 @@ public interface WxMpPayService {
* @param body 商品描述
* @param ip 发起支付的客户端IP
* @param notifyUrl 通知地址
* @deprecated Use me.chanjar.weixin.mp.api.WxMpPayService.getPayInfo(Map<String, String>) instead
* @deprecated Use me.chanjar.weixin.mp.api.WxMpPayService.getPayInfo(WxUnifiedOrderRequest) instead
*/
@Deprecated
Map<String, String> getJsapiPayInfo(String openId, String outTradeNo, double amt, String body, String ip, String notifyUrl) throws WxErrorException;


+ 38
- 1
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java 查看文件

@@ -9,6 +9,7 @@ import java.util.SortedMap;
import java.util.TreeMap;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.joor.Reflect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -168,6 +169,7 @@ public class WxMpPayServiceImpl implements WxMpPayService {
}

@Override
@Deprecated
public Map<String, String> getPayInfo(Map<String, String> parameters)
throws WxErrorException {
WxMpPrepayIdResult wxMpPrepayIdResult = getPrepayId(parameters);
@@ -477,7 +479,7 @@ public class WxMpPayServiceImpl implements WxMpPayService {

if (!TRADE_TYPES.contains(request.getTradeType())) {
throw new IllegalArgumentException(
"trade_type目前必须为" + TRADE_TYPES + "其中之一");
"trade_type目前必须为" + TRADE_TYPES + "其中之一");

}

@@ -491,4 +493,39 @@ public class WxMpPayServiceImpl implements WxMpPayService {
}
}

@Override
public Map<String, String> getPayInfo(WxUnifiedOrderRequest request) throws WxErrorException {
WxUnifiedOrderResult unifiedOrderResult = this.unifiedOrder(request);

if (!"SUCCESS".equalsIgnoreCase(unifiedOrderResult.getReturnCode())
|| !"SUCCESS".equalsIgnoreCase(unifiedOrderResult.getResultCode())) {
throw new WxErrorException(WxError.newBuilder().setErrorCode(-1)
.setErrorMsg("return_code:" + unifiedOrderResult.getReturnCode() + ";return_msg:"
+ unifiedOrderResult.getReturnMsg() + ";result_code:" + unifiedOrderResult.getResultCode() + ";err_code"
+ unifiedOrderResult.getErrCode() + ";err_code_des" + unifiedOrderResult.getErrCodeDes())
.build());
}

String prepayId = unifiedOrderResult.getPrepayId();
if (StringUtils.isBlank(prepayId)) {
throw new RuntimeException(String.format("Failed to get prepay id due to error code '%s'(%s).",
unifiedOrderResult.getErrCode(), unifiedOrderResult.getErrCodeDes()));
}

Map<String, String> payInfo = new HashMap<>();
payInfo.put("appId", this.wxMpService.getWxMpConfigStorage().getAppId());
// 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
payInfo.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000));
payInfo.put("nonceStr", System.currentTimeMillis() + "");
payInfo.put("package", "prepay_id=" + prepayId);
payInfo.put("signType", "MD5");
if ("NATIVE".equals(request.getTradeType())) {
payInfo.put("codeUrl", unifiedOrderResult.getCodeURL());
}

String finalSign = this.createSign(payInfo, this.wxMpService.getWxMpConfigStorage().getPartnerKey());
payInfo.put("paySign", finalSign);
return payInfo;
}

}

正在加载...
取消
保存