Authored by LUOXC

使用沙箱配置

1 package com.yohoufo.order.config; 1 package com.yohoufo.order.config;
2 2
3 3
4 -import java.util.Arrays;  
5 -import java.util.HashMap;  
6 -import java.util.List;  
7 -import java.util.Map;  
8 - 4 +import lombok.Getter;
  5 +import lombok.experimental.Accessors;
  6 +import org.springframework.beans.factory.annotation.Value;
  7 +import org.springframework.stereotype.Component;
  8 +
  9 +@Component
  10 +@Getter
  11 +@Accessors(fluent = true)
9 public class AlipayConfig { 12 public class AlipayConfig {
10 13
11 // 字符编码格式 目前支持 gbk 或 utf-8 14 // 字符编码格式 目前支持 gbk 或 utf-8
@@ -13,27 +16,25 @@ public class AlipayConfig { @@ -13,27 +16,25 @@ public class AlipayConfig {
13 16
14 // 签名方式 不需修改 17 // 签名方式 不需修改
15 public static final String sign_type = "RSA"; 18 public static final String sign_type = "RSA";
16 - /**  
17 - * 支付宝ATN验证地址  
18 - */  
19 - public static final String NOTIFY_VERIFY_URL = "https://mapi.alipay.com/gateway.do?service=notify_verify";  
20 -  
21 - //查询、退款地址  
22 - public static final String MAPI_URL = "https://mapi.alipay.com/gateway.do";  
23 -  
24 - //openapi  
25 - public static final String OPENAPI_URL = "https://openapi.alipay.com/gateway.do";  
26 19
27 // 跨境openapi 20 // 跨境openapi
28 public static final String CROSS_BORDER_OPENAPI_URL = "https://intlmapi.alipay.com/gateway.do"; 21 public static final String CROSS_BORDER_OPENAPI_URL = "https://intlmapi.alipay.com/gateway.do";
29 22
30 public static final String OPENAPI_BIZ_SUCCESS = "10000"; 23 public static final String OPENAPI_BIZ_SUCCESS = "10000";
31 24
32 - /********************/ //OUYIN  
33 - public static final String OUYIN_PARTNER = "2088421850636193";  
34 - public static final String OUYIN_APPID = "2016091401906455";  
35 - public static final String OUYIN_EMAIL = "ouyin@yoho.cn";  
36 - public static final String OUYIN_USER_NAME = "欧印南京贸易有限公司"; 25 + private String mapiUrl = "https://mapi.alipay.com/gateway.do";
  26 +
  27 + @Value("${alipay.openapi.url:https://openapi.alipay.com/gateway.do}")
  28 + private String openapiUrl;
  29 +
  30 + @Value("${alipay.ouyin.appid:2016091401906455}")
  31 + private String ouyinAppid;
  32 + @Value("${alipay.ouyin.partner:2088421850636193}")
  33 + private String ouyinPartner;
  34 + @Value("${alipay.ouyin.email:ouyin@yoho.cn}")
  35 + private String ouyinEmail;
  36 + @Value("${alipay.ouyin.user_name:欧印南京贸易有限公司}")
  37 + private String ouyinUserName;
37 38
38 39
39 } 40 }
@@ -11,7 +11,6 @@ import com.yohobuy.ufo.model.order.common.Payment; @@ -11,7 +11,6 @@ import com.yohobuy.ufo.model.order.common.Payment;
11 import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO; 11 import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
12 import com.yohoufo.common.utils.DateUtil; 12 import com.yohoufo.common.utils.DateUtil;
13 import com.yohoufo.common.utils.HttpClient; 13 import com.yohoufo.common.utils.HttpClient;
14 -import com.yohoufo.common.utils.RSAUtils;  
15 import com.yohoufo.common.utils.WXUtil; 14 import com.yohoufo.common.utils.WXUtil;
16 import com.yohoufo.dal.order.OrdersPayHbfqMapper; 15 import com.yohoufo.dal.order.OrdersPayHbfqMapper;
17 import com.yohoufo.dal.order.model.OrdersPayHbfq; 16 import com.yohoufo.dal.order.model.OrdersPayHbfq;
@@ -28,6 +27,9 @@ import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; @@ -28,6 +27,9 @@ import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
28 import com.yohoufo.order.service.transfer.TransferChannel; 27 import com.yohoufo.order.service.transfer.TransferChannel;
29 import com.yohoufo.order.service.transfer.TransferResult; 28 import com.yohoufo.order.service.transfer.TransferResult;
30 import com.yohoufo.order.utils.AlipayExceedMillionTransferErrors; 29 import com.yohoufo.order.utils.AlipayExceedMillionTransferErrors;
  30 +import lombok.AccessLevel;
  31 +import lombok.Getter;
  32 +import lombok.experimental.Accessors;
31 import org.apache.commons.lang3.StringUtils; 33 import org.apache.commons.lang3.StringUtils;
32 import org.slf4j.Logger; 34 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory; 35 import org.slf4j.LoggerFactory;
@@ -90,7 +92,10 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -90,7 +92,10 @@ public abstract class AbstractAlipayService extends AbstractPayService {
90 @Autowired 92 @Autowired
91 private OrdersPayHbfqMapper ordersPayHbfqDao; 93 private OrdersPayHbfqMapper ordersPayHbfqDao;
92 94
93 - 95 + @Autowired
  96 + @Getter(AccessLevel.PROTECTED)
  97 + @Accessors(fluent = true)
  98 + private AlipayConfig alipayConfig;
94 99
95 @Value("${alipay.notifyurl}") 100 @Value("${alipay.notifyurl}")
96 private String notifyURL; 101 private String notifyURL;
@@ -105,7 +110,7 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -105,7 +110,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
105 110
106 public PayQueryBo payQuery(String tradeNo, int orderCreateTime) { 111 public PayQueryBo payQuery(String tradeNo, int orderCreateTime) {
107 Map<String, String> queryParams = buildOpenApiQueryParams(tradeNo); 112 Map<String, String> queryParams = buildOpenApiQueryParams(tradeNo);
108 - String respTxt = sendOpenApiRequest(tradeNo, queryParams, AlipayConfig.OPENAPI_URL); 113 + String respTxt = sendOpenApiRequest(tradeNo, queryParams, alipayConfig.openapiUrl());
109 QueryBo queryBo = JSON.parseObject(JSONObject.toJSONString(JSON.parseObject(respTxt).getJSONObject("alipay_trade_query_response")), QueryBo.class); 114 QueryBo queryBo = JSON.parseObject(JSONObject.toJSONString(JSON.parseObject(respTxt).getJSONObject("alipay_trade_query_response")), QueryBo.class);
110 115
111 // 查询结果转换成 共通的对象 116 // 查询结果转换成 共通的对象
@@ -430,7 +435,7 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -430,7 +435,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
430 public JSONObject transferQueryAsOriginalResult(String buyerOrderCode) { 435 public JSONObject transferQueryAsOriginalResult(String buyerOrderCode) {
431 String tradeNo = buyerOrderCode; 436 String tradeNo = buyerOrderCode;
432 Map<String, String> queryParams = buildAlipayTransferQueryParams(tradeNo); 437 Map<String, String> queryParams = buildAlipayTransferQueryParams(tradeNo);
433 - String respTxt = sendOpenApiRequest(tradeNo, queryParams, AlipayConfig.OPENAPI_URL); 438 + String respTxt = sendOpenApiRequest(tradeNo, queryParams, alipayConfig.openapiUrl());
434 JSONObject result = JSON.parseObject(respTxt).getJSONObject("alipay_fund_trans_order_query_response"); 439 JSONObject result = JSON.parseObject(respTxt).getJSONObject("alipay_fund_trans_order_query_response");
435 logger.info("查询转账{}结果为:{}", tradeNo, result); 440 logger.info("查询转账{}结果为:{}", tradeNo, result);
436 return result; 441 return result;
@@ -458,7 +463,7 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -458,7 +463,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
458 463
459 private String sendOpenApiRequestWithException(String orderCode, Map<String, String> paramMap) throws Exception { 464 private String sendOpenApiRequestWithException(String orderCode, Map<String, String> paramMap) throws Exception {
460 logger.info("[{}] send openapi request: {}", orderCode, paramMap); 465 logger.info("[{}] send openapi request: {}", orderCode, paramMap);
461 - String response = httpClient.postFormData(AlipayConfig.OPENAPI_URL, paramMap); 466 + String response = httpClient.postFormData(alipayConfig.openapiUrl(), paramMap);
462 logger.info("[{}] trade openapi resp: {}", orderCode, response); 467 logger.info("[{}] trade openapi resp: {}", orderCode, response);
463 return response; 468 return response;
464 } 469 }
@@ -469,7 +474,7 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -469,7 +474,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
469 for(Map.Entry<String, String> entry : paramMap.entrySet()) { 474 for(Map.Entry<String, String> entry : paramMap.entrySet()) {
470 paramStr.append("&").append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue(),AlipayConfig.input_charset)); 475 paramStr.append("&").append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue(),AlipayConfig.input_charset));
471 } 476 }
472 - String url = AlipayConfig.MAPI_URL +"?"+paramStr.substring(1); 477 + String url = alipayConfig.mapiUrl() +"?"+paramStr.substring(1);
473 logger.info("[{}] send openapi requestUrl is: {}", orderCode, url); 478 logger.info("[{}] send openapi requestUrl is: {}", orderCode, url);
474 String response = httpClient.get(url); 479 String response = httpClient.get(url);
475 logger.info("[{}] trade openapi resp: {}", orderCode, response); 480 logger.info("[{}] trade openapi resp: {}", orderCode, response);
@@ -810,7 +815,7 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -810,7 +815,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
810 public PayRefundBo refundOpenApi(PayRefundBo refundBo) { 815 public PayRefundBo refundOpenApi(PayRefundBo refundBo) {
811 logger.info("enter AliPayRefunder to refund tradeNo {}, amount {}", refundBo.getRefundOrderCode(), refundBo.getAmount()); 816 logger.info("enter AliPayRefunder to refund tradeNo {}, amount {}", refundBo.getRefundOrderCode(), refundBo.getAmount());
812 Map<String, String> refundParams = buildOpenApiRefundParams(refundBo.getPayOrderCode(), refundBo.getRefundOrderCode(), refundBo.getAmount()); 817 Map<String, String> refundParams = buildOpenApiRefundParams(refundBo.getPayOrderCode(), refundBo.getRefundOrderCode(), refundBo.getAmount());
813 - String respTxt = sendOpenApiRequest(String.valueOf(refundBo.getPayOrderCode()), refundParams, AlipayConfig.OPENAPI_URL); 818 + String respTxt = sendOpenApiRequest(String.valueOf(refundBo.getPayOrderCode()), refundParams, alipayConfig.openapiUrl());
814 //logger.info("refund response for alipay: {}", responseText); 819 //logger.info("refund response for alipay: {}", responseText);
815 PayRefundBo bo = refundOpenApiConvert(respTxt, refundBo); 820 PayRefundBo bo = refundOpenApiConvert(respTxt, refundBo);
816 logger.info("exit AliPayRefunder refund, refundStatus: {}, refundMsg", bo.getRefundStatus(), bo.getRefundMsg()); 821 logger.info("exit AliPayRefunder refund, refundStatus: {}, refundMsg", bo.getRefundStatus(), bo.getRefundMsg());
@@ -1025,7 +1030,7 @@ public abstract class AbstractAlipayService extends AbstractPayService { @@ -1025,7 +1030,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
1025 * @return 1030 * @return
1026 */ 1031 */
1027 private String obtainAtn(String outTradeNo, String notifyId) { 1032 private String obtainAtn(String outTradeNo, String notifyId) {
1028 - String verify_url = AlipayConfig.NOTIFY_VERIFY_URL + "&partner=" + getPartnerId() + "&notify_id=" + notifyId; 1033 + String verify_url = alipayConfig.mapiUrl() + "?service=notify_verify&partner=" + getPartnerId() + "&notify_id=" + notifyId;
1029 String response = ""; 1034 String response = "";
1030 logger.info("[{}] obtain atn begin, check url: {}", outTradeNo, verify_url); 1035 logger.info("[{}] obtain atn begin, check url: {}", outTradeNo, verify_url);
1031 1036
1 package com.yohoufo.order.service.pay.alipay; 1 package com.yohoufo.order.service.pay.alipay;
2 2
3 -import com.yohoufo.order.config.AlipayConfig;  
4 -  
5 import org.springframework.stereotype.Service; 3 import org.springframework.stereotype.Service;
6 4
7 @Service 5 @Service
@@ -10,8 +8,8 @@ public class AlipayOuyinService extends AbstractAlipayService { @@ -10,8 +8,8 @@ public class AlipayOuyinService extends AbstractAlipayService {
10 @Override 8 @Override
11 protected AlipaySignatureSetting getAlipaySignatureSetting() { 9 protected AlipaySignatureSetting getAlipaySignatureSetting() {
12 return new AlipaySignatureSetting( 10 return new AlipaySignatureSetting(
13 - AlipayConfig.OUYIN_APPID,  
14 - AlipayConfig.OUYIN_PARTNER, 11 + alipayConfig().ouyinAppid(),
  12 + alipayConfig().ouyinPartner(),
15 false, 13 false,
16 "RSA" 14 "RSA"
17 ); 15 );
@@ -19,12 +17,12 @@ public class AlipayOuyinService extends AbstractAlipayService { @@ -19,12 +17,12 @@ public class AlipayOuyinService extends AbstractAlipayService {
19 17
20 @Override 18 @Override
21 protected String getAccountUserName() { 19 protected String getAccountUserName() {
22 - return AlipayConfig.OUYIN_USER_NAME; 20 + return alipayConfig().ouyinUserName();
23 } 21 }
24 22
25 @Override 23 @Override
26 protected String getAccountEmail() { 24 protected String getAccountEmail() {
27 - return AlipayConfig.OUYIN_EMAIL; 25 + return alipayConfig().ouyinEmail();
28 } 26 }
29 27
30 } 28 }
@@ -13,11 +13,12 @@ import java.util.Map; @@ -13,11 +13,12 @@ import java.util.Map;
13 13
14 @Service 14 @Service
15 public class AlipayOuyinWapService extends AbstractAlipayService { 15 public class AlipayOuyinWapService extends AbstractAlipayService {
  16 +
16 @Override 17 @Override
17 protected AlipaySignatureSetting getAlipaySignatureSetting() { 18 protected AlipaySignatureSetting getAlipaySignatureSetting() {
18 return new AlipaySignatureSetting( 19 return new AlipaySignatureSetting(
19 - AlipayConfig.OUYIN_APPID,  
20 - AlipayConfig.OUYIN_PARTNER, 20 + alipayConfig().ouyinAppid(),
  21 + alipayConfig().ouyinPartner(),
21 false, 22 false,
22 "RSA" 23 "RSA"
23 ); 24 );
@@ -25,12 +26,12 @@ public class AlipayOuyinWapService extends AbstractAlipayService { @@ -25,12 +26,12 @@ public class AlipayOuyinWapService extends AbstractAlipayService {
25 26
26 @Override 27 @Override
27 protected String getAccountUserName() { 28 protected String getAccountUserName() {
28 - return AlipayConfig.OUYIN_USER_NAME; 29 + return alipayConfig().ouyinUserName();
29 } 30 }
30 31
31 @Override 32 @Override
32 protected String getAccountEmail() { 33 protected String getAccountEmail() {
33 - return AlipayConfig.OUYIN_EMAIL; 34 + return alipayConfig().ouyinEmail();
34 } 35 }
35 36
36 @Override 37 @Override
@@ -122,4 +122,11 @@ ufo.product.addSizeSortId=40 @@ -122,4 +122,11 @@ ufo.product.addSizeSortId=40
122 ufo.certification.timesLimit=3 122 ufo.certification.timesLimit=3
123 123
124 unionpay.env=00 124 unionpay.env=00
125 -unionpay.notifyurl=${unionpay.notifyurl}  
  125 +unionpay.notifyurl=${unionpay.notifyurl}
  126 +
  127 +alipay.mapi.url=${alipay.mapi.url}
  128 +alipay.openapi.url=${alipay.openapi.url}
  129 +alipay.ouyin.appid=${alipay.ouyin.appid}
  130 +alipay.ouyin.partner=${alipay.ouyin.partner}
  131 +alipay.ouyin.email=${alipay.ouyin.email}
  132 +alipay.ouyin.user_name=${alipay.ouyin.user_name}