|
@@ -81,6 +81,16 @@ public class StandardWechatPaymentProcessor implements WechatPaymentProcessor {
|
|
this.callback = properties.getCallback();
|
|
this.callback = properties.getCallback();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 参数签名
|
|
|
|
+ *
|
|
|
|
+ * @param parameters 签名参数
|
|
|
|
+ * @return 签名信息
|
|
|
|
+ */
|
|
|
|
+ private String sign(@NonNull Map<String, String> parameters) {
|
|
|
|
+ return WechatContextHolder.sign(this.mchkey, parameters);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 执行接口调用
|
|
* 执行接口调用
|
|
*
|
|
*
|
|
@@ -98,11 +108,6 @@ public class StandardWechatPaymentProcessor implements WechatPaymentProcessor {
|
|
return WechatContextHolder.xml2map(Objects.requireNonNull(response.getBody()));
|
|
return WechatContextHolder.xml2map(Objects.requireNonNull(response.getBody()));
|
|
}
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
|
- public String sign(@NonNull Map<String, String> parameters) {
|
|
|
|
- return WechatContextHolder.sign(this.mchkey, parameters);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
public WechatPaymentCallback callback(@NonNull String content) {
|
|
public WechatPaymentCallback callback(@NonNull String content) {
|
|
Map<String, String> payment;
|
|
Map<String, String> payment;
|
|
@@ -115,7 +120,7 @@ public class StandardWechatPaymentProcessor implements WechatPaymentProcessor {
|
|
if (log.isDebugEnabled()) {
|
|
if (log.isDebugEnabled()) {
|
|
log.debug("Wechat payment callback: {}", payment);
|
|
log.debug("Wechat payment callback: {}", payment);
|
|
}
|
|
}
|
|
- if (Objects.isNull(payment) || !Objects.equals(payment.get("mch_id"), this.getMchid())) {
|
|
|
|
|
|
+ if (Objects.isNull(payment) || !Objects.equals(payment.get("mch_id"), this.mchid)) {
|
|
return null;
|
|
return null;
|
|
} else if (!Objects.equals(payment.get("return_code"), "SUCCESS")
|
|
} else if (!Objects.equals(payment.get("return_code"), "SUCCESS")
|
|
|| !Objects.equals(payment.get("result_code"), "SUCCESS")
|
|
|| !Objects.equals(payment.get("result_code"), "SUCCESS")
|
|
@@ -129,8 +134,8 @@ public class StandardWechatPaymentProcessor implements WechatPaymentProcessor {
|
|
public WechatOrderResponse unifiedorder(@NonNull WechatPayRequest request) {
|
|
public WechatOrderResponse unifiedorder(@NonNull WechatPayRequest request) {
|
|
// 调用微信接口
|
|
// 调用微信接口
|
|
Map<String, String> parameters = Maps.newHashMap();
|
|
Map<String, String> parameters = Maps.newHashMap();
|
|
- parameters.put("appid", this.getAppid());
|
|
|
|
- parameters.put("mch_id", this.getMchid());
|
|
|
|
|
|
+ parameters.put("appid", this.appid);
|
|
|
|
+ parameters.put("mch_id", this.mchid);
|
|
parameters.put("body", request.getComment());
|
|
parameters.put("body", request.getComment());
|
|
parameters.put("out_trade_no", request.getOrder());
|
|
parameters.put("out_trade_no", request.getOrder());
|
|
if (StringUtils.notEmpty(request.getContext())) {
|
|
if (StringUtils.notEmpty(request.getContext())) {
|
|
@@ -139,13 +144,13 @@ public class StandardWechatPaymentProcessor implements WechatPaymentProcessor {
|
|
parameters.put("fee_type", "CNY");
|
|
parameters.put("fee_type", "CNY");
|
|
parameters.put("total_fee", WechatContextHolder.amount2string(request.getAmount()));
|
|
parameters.put("total_fee", WechatContextHolder.amount2string(request.getAmount()));
|
|
parameters.put("spbill_create_ip", HostUtils.LOCAL_ADDRESS);
|
|
parameters.put("spbill_create_ip", HostUtils.LOCAL_ADDRESS);
|
|
- parameters.put("notify_url", this.getCallback());
|
|
|
|
- parameters.put("trade_type", StringUtils.toString(this.getMode()));
|
|
|
|
|
|
+ parameters.put("notify_url", this.callback);
|
|
|
|
+ parameters.put("trade_type", StringUtils.toString(this.mode));
|
|
parameters.put("nonce_str", WXPayUtil.generateNonceStr());
|
|
parameters.put("nonce_str", WXPayUtil.generateNonceStr());
|
|
- if (this.getMode() == PayMode.MWEB) {
|
|
|
|
|
|
+ if (this.mode == PayMode.MWEB) {
|
|
// 如果是H5支付则需要指定scene_info,场景信息
|
|
// 如果是H5支付则需要指定scene_info,场景信息
|
|
parameters.put("scene_info", request.getScene());
|
|
parameters.put("scene_info", request.getScene());
|
|
- } else if (this.getMode() == PayMode.JSAPI) {
|
|
|
|
|
|
+ } else if (this.mode == PayMode.JSAPI) {
|
|
// 如果是小程序支付则需要指定openid
|
|
// 如果是小程序支付则需要指定openid
|
|
parameters.put("openid", request.getOpenid());
|
|
parameters.put("openid", request.getOpenid());
|
|
}
|
|
}
|
|
@@ -170,14 +175,33 @@ public class StandardWechatPaymentProcessor implements WechatPaymentProcessor {
|
|
// 构建响应结果
|
|
// 构建响应结果
|
|
String nonce = WXPayUtil.generateNonceStr();
|
|
String nonce = WXPayUtil.generateNonceStr();
|
|
String timestamp = String.valueOf(System.currentTimeMillis() / 1000).substring(0, 10);
|
|
String timestamp = String.valueOf(System.currentTimeMillis() / 1000).substring(0, 10);
|
|
- WechatOrderResponse order = WechatOrderResponse.builder().mode(this.getMode()).appid(this.getAppid())
|
|
|
|
- .mchid(this.getMchid()).nonce(nonce).prepayid(result.get("prepay_id")).qrcode(result.get("code_url"))
|
|
|
|
- .redirect(result.get("mweb_url")).channel(this.getChannel()).timestamp(timestamp).build();
|
|
|
|
- if (this.getMode() == PayMode.MWEB || this.getMode() == PayMode.JSAPI) {
|
|
|
|
|
|
+ WechatOrderResponse order = WechatOrderResponse.builder().mode(this.mode).appid(this.appid)
|
|
|
|
+ .mchid(this.mchid).nonce(nonce).prepayid(result.get("prepay_id")).qrcode(result.get("code_url"))
|
|
|
|
+ .redirect(result.get("mweb_url")).channel(this.channel).timestamp(timestamp).build();
|
|
|
|
+ if (this.mode == PayMode.MWEB || this.mode == PayMode.JSAPI) {
|
|
order.setAlgorithm(MessageDigestAlgorithms.MD5);
|
|
order.setAlgorithm(MessageDigestAlgorithms.MD5);
|
|
order.setPack("prepay_id=" + order.getPrepayid());
|
|
order.setPack("prepay_id=" + order.getPrepayid());
|
|
|
|
+
|
|
|
|
+ // 设置数字签名
|
|
|
|
+ Map<String, String> signature = Maps.newHashMapWithExpectedSize(5);
|
|
|
|
+ signature.put("appId", order.getAppid());
|
|
|
|
+ signature.put("nonceStr", order.getNonce());
|
|
|
|
+ signature.put("package", order.getPack());
|
|
|
|
+ signature.put("signType", order.getAlgorithm());
|
|
|
|
+ signature.put("timeStamp", order.getTimestamp());
|
|
|
|
+ order.setSign(this.sign(signature));
|
|
} else {
|
|
} else {
|
|
order.setPack("Sign=WXPay");
|
|
order.setPack("Sign=WXPay");
|
|
|
|
+
|
|
|
|
+ // 设置数字签名
|
|
|
|
+ Map<String, String> signature = Maps.newHashMapWithExpectedSize(6);
|
|
|
|
+ signature.put("appid", order.getAppid());
|
|
|
|
+ signature.put("partnerid", order.getMchid());
|
|
|
|
+ signature.put("prepayid", order.getPrepayid());
|
|
|
|
+ signature.put("noncestr", order.getNonce());
|
|
|
|
+ signature.put("package", order.getPack());
|
|
|
|
+ signature.put("timestamp", order.getTimestamp());
|
|
|
|
+ order.setSign(this.sign(signature));
|
|
}
|
|
}
|
|
return order;
|
|
return order;
|
|
}
|
|
}
|
|
@@ -185,8 +209,8 @@ public class StandardWechatPaymentProcessor implements WechatPaymentProcessor {
|
|
@Override
|
|
@Override
|
|
public WechatOrder getOrder(@NonNull String identity) {
|
|
public WechatOrder getOrder(@NonNull String identity) {
|
|
Map<String, String> parameters = Maps.newHashMapWithExpectedSize(5);
|
|
Map<String, String> parameters = Maps.newHashMapWithExpectedSize(5);
|
|
- parameters.put("appid", this.getAppid());
|
|
|
|
- parameters.put("mch_id", this.getMchid());
|
|
|
|
|
|
+ parameters.put("appid", this.appid);
|
|
|
|
+ parameters.put("mch_id", this.mchid);
|
|
parameters.put("nonce_str", WXPayUtil.generateNonceStr());
|
|
parameters.put("nonce_str", WXPayUtil.generateNonceStr());
|
|
if (WechatContextHolder.isOrderIdentity(identity)) {
|
|
if (WechatContextHolder.isOrderIdentity(identity)) {
|
|
parameters.put("transaction_id", identity);
|
|
parameters.put("transaction_id", identity);
|
|
@@ -229,8 +253,8 @@ public class StandardWechatPaymentProcessor implements WechatPaymentProcessor {
|
|
|
|
|
|
// 调用微信关单接口
|
|
// 调用微信关单接口
|
|
Map<String, String> parameters = Maps.newHashMapWithExpectedSize(5);
|
|
Map<String, String> parameters = Maps.newHashMapWithExpectedSize(5);
|
|
- parameters.put("appid", this.getAppid());
|
|
|
|
- parameters.put("mch_id", this.getMchid());
|
|
|
|
|
|
+ parameters.put("appid", this.appid);
|
|
|
|
+ parameters.put("mch_id", this.mchid);
|
|
parameters.put("nonce_str", WXPayUtil.generateNonceStr());
|
|
parameters.put("nonce_str", WXPayUtil.generateNonceStr());
|
|
parameters.put("out_trade_no", identity);
|
|
parameters.put("out_trade_no", identity);
|
|
parameters.put("sign", this.sign(parameters));
|
|
parameters.put("sign", this.sign(parameters));
|