mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-24 16:18:51 +08:00
添加构造支付参数的重载方法,准备替换原有方法
This commit is contained in:
parent
b7e8f2129d
commit
8619430ae5
@ -65,9 +65,18 @@ public interface WxMpPayService {
|
|||||||
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
|
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
|
||||||
*
|
*
|
||||||
* @param parameters the required or optional parameters
|
* @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;
|
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发起支付请求需要的参数
|
* 该接口调用“统一下单”接口,并拼装NATIVE发起支付请求需要的参数
|
||||||
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
|
* 详见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 body 商品描述
|
||||||
* @param ip 发起支付的客户端IP
|
* @param ip 发起支付的客户端IP
|
||||||
* @param notifyUrl 通知地址
|
* @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
|
@Deprecated
|
||||||
Map<String, String> getNativePayInfo(String productId, String outTradeNo, double amt, String body, String ip, String notifyUrl) throws WxErrorException;
|
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 body 商品描述
|
||||||
* @param ip 发起支付的客户端IP
|
* @param ip 发起支付的客户端IP
|
||||||
* @param notifyUrl 通知地址
|
* @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
|
@Deprecated
|
||||||
Map<String, String> getJsapiPayInfo(String openId, String outTradeNo, double amt, String body, String ip, String notifyUrl) throws WxErrorException;
|
Map<String, String> getJsapiPayInfo(String openId, String outTradeNo, double amt, String body, String ip, String notifyUrl) throws WxErrorException;
|
||||||
|
@ -9,6 +9,7 @@ import java.util.SortedMap;
|
|||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.joor.Reflect;
|
import org.joor.Reflect;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -168,6 +169,7 @@ public class WxMpPayServiceImpl implements WxMpPayService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public Map<String, String> getPayInfo(Map<String, String> parameters)
|
public Map<String, String> getPayInfo(Map<String, String> parameters)
|
||||||
throws WxErrorException {
|
throws WxErrorException {
|
||||||
WxMpPrepayIdResult wxMpPrepayIdResult = getPrepayId(parameters);
|
WxMpPrepayIdResult wxMpPrepayIdResult = getPrepayId(parameters);
|
||||||
@ -477,7 +479,7 @@ public class WxMpPayServiceImpl implements WxMpPayService {
|
|||||||
|
|
||||||
if (!TRADE_TYPES.contains(request.getTradeType())) {
|
if (!TRADE_TYPES.contains(request.getTradeType())) {
|
||||||
throw new IllegalArgumentException(
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user