Authored by TANLING

no message

@@ -220,7 +220,7 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -220,7 +220,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
220 bizJson.put("out_trade_no", orderCode); 220 bizJson.put("out_trade_no", orderCode);
221 params.put("biz_content", bizJson.toJSONString()); 221 params.put("biz_content", bizJson.toJSONString());
222 222
223 - String preSignStr = getOpenApiSignString(params, false); 223 + String preSignStr = StringConvertUtils.covertToStrIgnoreSign(params);
224 params.put("sign", helper().signWithRsa(preSignStr, StandardCharsets.UTF_8.name())); 224 params.put("sign", helper().signWithRsa(preSignStr, StandardCharsets.UTF_8.name()));
225 return params; 225 return params;
226 } 226 }
@@ -243,7 +243,7 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -243,7 +243,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
243 bizJson.put("out_biz_no", orderCode); 243 bizJson.put("out_biz_no", orderCode);
244 params.put("biz_content", bizJson.toJSONString()); 244 params.put("biz_content", bizJson.toJSONString());
245 245
246 - String preSignStr = getOpenApiSignString(params, false); 246 + String preSignStr = StringConvertUtils.covertToStrIgnoreSign(params);
247 params.put("sign", helper().signWithRsa(preSignStr, StandardCharsets.UTF_8.name())); 247 params.put("sign", helper().signWithRsa(preSignStr, StandardCharsets.UTF_8.name()));
248 return params; 248 return params;
249 } 249 }
@@ -281,7 +281,7 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -281,7 +281,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
281 281
282 params.put("biz_content", bizJson.toJSONString()); 282 params.put("biz_content", bizJson.toJSONString());
283 283
284 - String preSignStr = getOpenApiSignString(params, false); 284 + String preSignStr = StringConvertUtils.covertToStrIgnoreSign(params);
285 String sign = helper().signWithRsa(preSignStr, StandardCharsets.UTF_8.name()); 285 String sign = helper().signWithRsa(preSignStr, StandardCharsets.UTF_8.name());
286 params.put("sign", URLEncoder.encode(sign)); 286 params.put("sign", URLEncoder.encode(sign));
287 287
@@ -353,8 +353,11 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -353,8 +353,11 @@ public abstract class AbstractAlipayService extends AbstractPayService {
353 353
354 params.put("biz_content", bizJson.toJSONString()); 354 params.put("biz_content", bizJson.toJSONString());
355 355
356 - String preSignStr = getOpenApiSignString(params, false); 356 + String preSignStr = StringConvertUtils.covertToStrIgnoreSign(params);
  357 +
357 String sign = helper().signWithRsa(preSignStr, StandardCharsets.UTF_8.name()); 358 String sign = helper().signWithRsa(preSignStr, StandardCharsets.UTF_8.name());
  359 +
  360 + logger.debug("preSignStr {}, sign {}", preSignStr, sign);
358 params.put("sign", URLEncoder.encode(sign)); 361 params.put("sign", URLEncoder.encode(sign));
359 362
360 // 对biz_content进行encode 363 // 对biz_content进行encode
@@ -396,35 +399,6 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -396,35 +399,6 @@ public abstract class AbstractAlipayService extends AbstractPayService {
396 return json; 399 return json;
397 } 400 }
398 401
399 - /**  
400 - * 获取openapi支付宝待签名字符串  
401 - *  
402 - * @param paramsMap  
403 - * @return  
404 - */  
405 - public static String getOpenApiSignString(Map<String, String> paramsMap, boolean ignoreSignType) {  
406 - if (null == paramsMap) {  
407 - return "";  
408 - }  
409 - //使用SortedMap将参数按名称的字典序排队,且滤去签名字段、空值字段  
410 - SortedMap<String, String> sortMap = new TreeMap<String, String>();  
411 - for (Map.Entry<String, String> entry : paramsMap.entrySet()) {  
412 - if ("sign".equalsIgnoreCase(entry.getKey())) {  
413 - continue;  
414 - }  
415 -  
416 - if (ignoreSignType && "sign_type".equalsIgnoreCase(entry.getKey())) {  
417 - continue;  
418 - }  
419 -  
420 - if (StringUtils.isEmpty(entry.getValue())) {  
421 - continue;  
422 - }  
423 - sortMap.put(entry.getKey(), entry.getValue());  
424 - }  
425 -  
426 - return StringConvertUtils.covertToStr(sortMap);  
427 - }  
428 402
429 403
430 public PaymentData getPaymentData(Map<String, String> params) { 404 public PaymentData getPaymentData(Map<String, String> params) {
@@ -499,7 +473,7 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -499,7 +473,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
499 } 473 }
500 474
501 public boolean notifyVerifyMApi(Map<String, String> params) { 475 public boolean notifyVerifyMApi(Map<String, String> params) {
502 - String preSignStr = StringConvertUtils.covertToStr(params); 476 + String preSignStr = StringConvertUtils.covertToStrIgnoreSignAndType(params);
503 return helper().verifyWithMapiRsa(preSignStr, StandardCharsets.UTF_8.name(), params.get("sign")); 477 return helper().verifyWithMapiRsa(preSignStr, StandardCharsets.UTF_8.name(), params.get("sign"));
504 } 478 }
505 479
@@ -584,23 +558,13 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -584,23 +558,13 @@ public abstract class AbstractAlipayService extends AbstractPayService {
584 bizJson.put("out_request_no", refundNo); 558 bizJson.put("out_request_no", refundNo);
585 params.put("biz_content", bizJson.toJSONString()); 559 params.put("biz_content", bizJson.toJSONString());
586 560
587 - String preSignStr = getOpenApiSignString(params, false); 561 + String preSignStr = StringConvertUtils.covertToStrIgnoreSign(params);
588 params.put("sign", helper().signWithRsa(preSignStr, StandardCharsets.UTF_8.name())); 562 params.put("sign", helper().signWithRsa(preSignStr, StandardCharsets.UTF_8.name()));
589 563
590 return params; 564 return params;
591 } 565 }
592 566
593 567
594 - /**  
595 - * 生成RSA签名  
596 - *  
597 - * @param paramsMap  
598 - * @return  
599 - */  
600 - public String rsaSign(Map<String, String> paramsMap) {  
601 - String preSignStr = StringConvertUtils.covertToStr(paramsMap);  
602 - return helper().signWithRsa(preSignStr, StandardCharsets.UTF_8.name());  
603 - }  
604 568
605 /** 569 /**
606 * 生成RSA签名 570 * 生成RSA签名
@@ -645,7 +609,7 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -645,7 +609,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
645 * @return 609 * @return
646 */ 610 */
647 public boolean verify(Map<String, String> paramsMap) { 611 public boolean verify(Map<String, String> paramsMap) {
648 - String preSignStr = StringConvertUtils.covertToStr(paramsMap); 612 + String preSignStr = StringConvertUtils.covertToStrIgnoreSignAndType(paramsMap);
649 return helper().verify(preSignStr, StandardCharsets.UTF_8.name(), paramsMap.get("sign")); 613 return helper().verify(preSignStr, StandardCharsets.UTF_8.name(), paramsMap.get("sign"));
650 } 614 }
651 615
@@ -720,11 +684,11 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -720,11 +684,11 @@ public abstract class AbstractAlipayService extends AbstractPayService {
720 params.put("_input_charset", "utf-8"); 684 params.put("_input_charset", "utf-8");
721 params.put("batch_no", transferOrderCode); 685 params.put("batch_no", transferOrderCode);
722 params.put("email", abstractAlipayConfig().email()); 686 params.put("email", abstractAlipayConfig().email());
723 - String preSignStr = getOpenApiSignString(params, false); 687 + String preSignStr = StringConvertUtils.covertToStrIgnoreSign(params);
724 String sign = helper().signWithMapiRsa(preSignStr, "utf-8"); 688 String sign = helper().signWithMapiRsa(preSignStr, "utf-8");
725 params.put("sign", URLEncoder.encode(sign)); 689 params.put("sign", URLEncoder.encode(sign));
726 params.put("sign_type", "RSA"); 690 params.put("sign_type", "RSA");
727 - return StringConvertUtils.covertToStr(params); 691 + return StringConvertUtils.covertToStrIgnoreSignAndType(params);
728 } 692 }
729 693
730 } 694 }
1 package com.yohoufo.order.service.pay.alipay; 1 package com.yohoufo.order.service.pay.alipay;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
  4 +import com.yoho.core.security.transfer.utils.StringConvertUtils;
4 import com.yohobuy.ufo.model.order.bo.OrderInfo; 5 import com.yohobuy.ufo.model.order.bo.OrderInfo;
5 import com.yohoufo.common.utils.DateUtil; 6 import com.yohoufo.common.utils.DateUtil;
6 import com.yohoufo.common.utils.XMLUtil; 7 import com.yohoufo.common.utils.XMLUtil;
@@ -17,7 +18,6 @@ import com.yohoufo.order.service.pay.alipay.config.CrossBorderAlipayPayConfig; @@ -17,7 +18,6 @@ import com.yohoufo.order.service.pay.alipay.config.CrossBorderAlipayPayConfig;
17 import org.slf4j.Logger; 18 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory; 19 import org.slf4j.LoggerFactory;
19 import org.springframework.beans.factory.annotation.Autowired; 20 import org.springframework.beans.factory.annotation.Autowired;
20 -import org.springframework.beans.factory.annotation.Value;  
21 import org.springframework.stereotype.Service; 21 import org.springframework.stereotype.Service;
22 import java.math.BigDecimal; 22 import java.math.BigDecimal;
23 import java.net.URLEncoder; 23 import java.net.URLEncoder;
@@ -139,7 +139,7 @@ public class AlipayCrossBorderService extends AbstractAlipayService { @@ -139,7 +139,7 @@ public class AlipayCrossBorderService extends AbstractAlipayService {
139 params.put("gmt_return", DateUtil.formatDate(DateUtil.getCurrentTimeSecond(), DateUtil.yyyyMMddHHmmss)); 139 params.put("gmt_return", DateUtil.formatDate(DateUtil.getCurrentTimeSecond(), DateUtil.yyyyMMddHHmmss));
140 params.put("product_code", "NEW_WAP_OVERSEAS_SELLER"); 140 params.put("product_code", "NEW_WAP_OVERSEAS_SELLER");
141 141
142 - String preSignStr = getOpenApiSignString(params, true); 142 + String preSignStr = StringConvertUtils.covertToStrIgnoreSignAndType(params);
143 params.put("sign", helper().sign(preSignStr, StandardCharsets.UTF_8.name())); 143 params.put("sign", helper().sign(preSignStr, StandardCharsets.UTF_8.name()));
144 144
145 return params; 145 return params;
@@ -174,7 +174,7 @@ public class AlipayCrossBorderService extends AbstractAlipayService { @@ -174,7 +174,7 @@ public class AlipayCrossBorderService extends AbstractAlipayService {
174 params.put("buyer_name", certName); 174 params.put("buyer_name", certName);
175 params.put("buyer_id_no", certNo); 175 params.put("buyer_id_no", certNo);
176 176
177 - String preSignStr = getOpenApiSignString(params, true); 177 + String preSignStr = StringConvertUtils.covertToStrIgnoreSignAndType(params);
178 params.put("sign", helper().sign(preSignStr,StandardCharsets.UTF_8.name())); 178 params.put("sign", helper().sign(preSignStr,StandardCharsets.UTF_8.name()));
179 179
180 return params; 180 return params;
@@ -197,7 +197,7 @@ public class AlipayCrossBorderService extends AbstractAlipayService { @@ -197,7 +197,7 @@ public class AlipayCrossBorderService extends AbstractAlipayService {
197 197
198 params.put("out_request_nos", String.valueOf(orderCode)); 198 params.put("out_request_nos", String.valueOf(orderCode));
199 199
200 - String preSignStr = getOpenApiSignString(params, true); 200 + String preSignStr = StringConvertUtils.covertToStrIgnoreSignAndType(params);
201 params.put("sign", helper().sign(preSignStr,StandardCharsets.UTF_8.name())); 201 params.put("sign", helper().sign(preSignStr,StandardCharsets.UTF_8.name()));
202 202
203 return params; 203 return params;
@@ -243,7 +243,7 @@ public class AlipayCrossBorderService extends AbstractAlipayService { @@ -243,7 +243,7 @@ public class AlipayCrossBorderService extends AbstractAlipayService {
243 params.put("sign_type", abstractAlipayConfig().rsaType()); 243 params.put("sign_type", abstractAlipayConfig().rsaType());
244 params.put("out_trade_no", orderCode); 244 params.put("out_trade_no", orderCode);
245 245
246 - String preSignStr = getOpenApiSignString(params, true); 246 + String preSignStr = StringConvertUtils.covertToStrIgnoreSignAndType(params);
247 params.put("sign", helper().sign(preSignStr,StandardCharsets.UTF_8.name())); 247 params.put("sign", helper().sign(preSignStr,StandardCharsets.UTF_8.name()));
248 return params; 248 return params;
249 } 249 }
@@ -310,7 +310,7 @@ public class AlipayCrossBorderService extends AbstractAlipayService { @@ -310,7 +310,7 @@ public class AlipayCrossBorderService extends AbstractAlipayService {
310 trade_information.put("total_quantity",1); 310 trade_information.put("total_quantity",1);
311 params.put("trade_information", trade_information.toJSONString()); 311 params.put("trade_information", trade_information.toJSONString());
312 312
313 - String preSignStr = getOpenApiSignString(params, true); 313 + String preSignStr = StringConvertUtils.covertToStrIgnoreSignAndType(params);
314 String sign = helper().sign(preSignStr,StandardCharsets.UTF_8.name());; 314 String sign = helper().sign(preSignStr,StandardCharsets.UTF_8.name());;
315 315
316 params.put("sign", URLEncoder.encode(sign)); 316 params.put("sign", URLEncoder.encode(sign));
@@ -46,7 +46,6 @@ public class AlipaySignatureHelper { @@ -46,7 +46,6 @@ public class AlipaySignatureHelper {
46 public String signWithRsa(String content, String charset) { 46 public String signWithRsa(String content, String charset) {
47 String sign = StringUtils.EMPTY; 47 String sign = StringUtils.EMPTY;
48 48
49 - log.info("signWithRsa {},{},{},{}", config.appId(), config.rsaType(), content, charset);  
50 try { 49 try {
51 sign = alipayOpenapiHelper.sign(config.appId(), content, charset, config.rsaType()); 50 sign = alipayOpenapiHelper.sign(config.appId(), content, charset, config.rsaType());
52 } catch (AlipayException e) { 51 } catch (AlipayException e) {