Authored by TANLING

no message

... ... @@ -220,7 +220,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
bizJson.put("out_trade_no", orderCode);
params.put("biz_content", bizJson.toJSONString());
String preSignStr = getOpenApiSignString(params, false);
String preSignStr = StringConvertUtils.covertToStrIgnoreSign(params);
params.put("sign", helper().signWithRsa(preSignStr, StandardCharsets.UTF_8.name()));
return params;
}
... ... @@ -243,7 +243,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
bizJson.put("out_biz_no", orderCode);
params.put("biz_content", bizJson.toJSONString());
String preSignStr = getOpenApiSignString(params, false);
String preSignStr = StringConvertUtils.covertToStrIgnoreSign(params);
params.put("sign", helper().signWithRsa(preSignStr, StandardCharsets.UTF_8.name()));
return params;
}
... ... @@ -281,7 +281,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
params.put("biz_content", bizJson.toJSONString());
String preSignStr = getOpenApiSignString(params, false);
String preSignStr = StringConvertUtils.covertToStrIgnoreSign(params);
String sign = helper().signWithRsa(preSignStr, StandardCharsets.UTF_8.name());
params.put("sign", URLEncoder.encode(sign));
... ... @@ -353,8 +353,11 @@ public abstract class AbstractAlipayService extends AbstractPayService {
params.put("biz_content", bizJson.toJSONString());
String preSignStr = getOpenApiSignString(params, false);
String preSignStr = StringConvertUtils.covertToStrIgnoreSign(params);
String sign = helper().signWithRsa(preSignStr, StandardCharsets.UTF_8.name());
logger.debug("preSignStr {}, sign {}", preSignStr, sign);
params.put("sign", URLEncoder.encode(sign));
// 对biz_content进行encode
... ... @@ -396,35 +399,6 @@ public abstract class AbstractAlipayService extends AbstractPayService {
return json;
}
/**
* 获取openapi支付宝待签名字符串
*
* @param paramsMap
* @return
*/
public static String getOpenApiSignString(Map<String, String> paramsMap, boolean ignoreSignType) {
if (null == paramsMap) {
return "";
}
//使用SortedMap将参数按名称的字典序排队,且滤去签名字段、空值字段
SortedMap<String, String> sortMap = new TreeMap<String, String>();
for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
if ("sign".equalsIgnoreCase(entry.getKey())) {
continue;
}
if (ignoreSignType && "sign_type".equalsIgnoreCase(entry.getKey())) {
continue;
}
if (StringUtils.isEmpty(entry.getValue())) {
continue;
}
sortMap.put(entry.getKey(), entry.getValue());
}
return StringConvertUtils.covertToStr(sortMap);
}
public PaymentData getPaymentData(Map<String, String> params) {
... ... @@ -499,7 +473,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
}
public boolean notifyVerifyMApi(Map<String, String> params) {
String preSignStr = StringConvertUtils.covertToStr(params);
String preSignStr = StringConvertUtils.covertToStrIgnoreSignAndType(params);
return helper().verifyWithMapiRsa(preSignStr, StandardCharsets.UTF_8.name(), params.get("sign"));
}
... ... @@ -584,23 +558,13 @@ public abstract class AbstractAlipayService extends AbstractPayService {
bizJson.put("out_request_no", refundNo);
params.put("biz_content", bizJson.toJSONString());
String preSignStr = getOpenApiSignString(params, false);
String preSignStr = StringConvertUtils.covertToStrIgnoreSign(params);
params.put("sign", helper().signWithRsa(preSignStr, StandardCharsets.UTF_8.name()));
return params;
}
/**
* 生成RSA签名
*
* @param paramsMap
* @return
*/
public String rsaSign(Map<String, String> paramsMap) {
String preSignStr = StringConvertUtils.covertToStr(paramsMap);
return helper().signWithRsa(preSignStr, StandardCharsets.UTF_8.name());
}
/**
* 生成RSA签名
... ... @@ -645,7 +609,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
* @return
*/
public boolean verify(Map<String, String> paramsMap) {
String preSignStr = StringConvertUtils.covertToStr(paramsMap);
String preSignStr = StringConvertUtils.covertToStrIgnoreSignAndType(paramsMap);
return helper().verify(preSignStr, StandardCharsets.UTF_8.name(), paramsMap.get("sign"));
}
... ... @@ -720,11 +684,11 @@ public abstract class AbstractAlipayService extends AbstractPayService {
params.put("_input_charset", "utf-8");
params.put("batch_no", transferOrderCode);
params.put("email", abstractAlipayConfig().email());
String preSignStr = getOpenApiSignString(params, false);
String preSignStr = StringConvertUtils.covertToStrIgnoreSign(params);
String sign = helper().signWithMapiRsa(preSignStr, "utf-8");
params.put("sign", URLEncoder.encode(sign));
params.put("sign_type", "RSA");
return StringConvertUtils.covertToStr(params);
return StringConvertUtils.covertToStrIgnoreSignAndType(params);
}
}
... ...
package com.yohoufo.order.service.pay.alipay;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.security.transfer.utils.StringConvertUtils;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.common.utils.XMLUtil;
... ... @@ -17,7 +18,6 @@ import com.yohoufo.order.service.pay.alipay.config.CrossBorderAlipayPayConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.net.URLEncoder;
... ... @@ -139,7 +139,7 @@ public class AlipayCrossBorderService extends AbstractAlipayService {
params.put("gmt_return", DateUtil.formatDate(DateUtil.getCurrentTimeSecond(), DateUtil.yyyyMMddHHmmss));
params.put("product_code", "NEW_WAP_OVERSEAS_SELLER");
String preSignStr = getOpenApiSignString(params, true);
String preSignStr = StringConvertUtils.covertToStrIgnoreSignAndType(params);
params.put("sign", helper().sign(preSignStr, StandardCharsets.UTF_8.name()));
return params;
... ... @@ -174,7 +174,7 @@ public class AlipayCrossBorderService extends AbstractAlipayService {
params.put("buyer_name", certName);
params.put("buyer_id_no", certNo);
String preSignStr = getOpenApiSignString(params, true);
String preSignStr = StringConvertUtils.covertToStrIgnoreSignAndType(params);
params.put("sign", helper().sign(preSignStr,StandardCharsets.UTF_8.name()));
return params;
... ... @@ -197,7 +197,7 @@ public class AlipayCrossBorderService extends AbstractAlipayService {
params.put("out_request_nos", String.valueOf(orderCode));
String preSignStr = getOpenApiSignString(params, true);
String preSignStr = StringConvertUtils.covertToStrIgnoreSignAndType(params);
params.put("sign", helper().sign(preSignStr,StandardCharsets.UTF_8.name()));
return params;
... ... @@ -243,7 +243,7 @@ public class AlipayCrossBorderService extends AbstractAlipayService {
params.put("sign_type", abstractAlipayConfig().rsaType());
params.put("out_trade_no", orderCode);
String preSignStr = getOpenApiSignString(params, true);
String preSignStr = StringConvertUtils.covertToStrIgnoreSignAndType(params);
params.put("sign", helper().sign(preSignStr,StandardCharsets.UTF_8.name()));
return params;
}
... ... @@ -310,7 +310,7 @@ public class AlipayCrossBorderService extends AbstractAlipayService {
trade_information.put("total_quantity",1);
params.put("trade_information", trade_information.toJSONString());
String preSignStr = getOpenApiSignString(params, true);
String preSignStr = StringConvertUtils.covertToStrIgnoreSignAndType(params);
String sign = helper().sign(preSignStr,StandardCharsets.UTF_8.name());;
params.put("sign", URLEncoder.encode(sign));
... ...
... ... @@ -46,7 +46,6 @@ public class AlipaySignatureHelper {
public String signWithRsa(String content, String charset) {
String sign = StringUtils.EMPTY;
log.info("signWithRsa {},{},{},{}", config.appId(), config.rsaType(), content, charset);
try {
sign = alipayOpenapiHelper.sign(config.appId(), content, charset, config.rsaType());
} catch (AlipayException e) {
... ...