Authored by LUOXC

使用沙箱配置

package com.yohoufo.order.config;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.Getter;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
@Getter
@Accessors(fluent = true)
public class AlipayConfig {
// 字符编码格式 目前支持 gbk 或 utf-8
... ... @@ -13,27 +16,25 @@ public class AlipayConfig {
// 签名方式 不需修改
public static final String sign_type = "RSA";
/**
* 支付宝ATN验证地址
*/
public static final String NOTIFY_VERIFY_URL = "https://mapi.alipay.com/gateway.do?service=notify_verify";
//查询、退款地址
public static final String MAPI_URL = "https://mapi.alipay.com/gateway.do";
//openapi
public static final String OPENAPI_URL = "https://openapi.alipay.com/gateway.do";
// 跨境openapi
public static final String CROSS_BORDER_OPENAPI_URL = "https://intlmapi.alipay.com/gateway.do";
public static final String OPENAPI_BIZ_SUCCESS = "10000";
/********************/ //OUYIN
public static final String OUYIN_PARTNER = "2088421850636193";
public static final String OUYIN_APPID = "2016091401906455";
public static final String OUYIN_EMAIL = "ouyin@yoho.cn";
public static final String OUYIN_USER_NAME = "欧印南京贸易有限公司";
private String mapiUrl = "https://mapi.alipay.com/gateway.do";
@Value("${alipay.openapi.url:https://openapi.alipay.com/gateway.do}")
private String openapiUrl;
@Value("${alipay.ouyin.appid:2016091401906455}")
private String ouyinAppid;
@Value("${alipay.ouyin.partner:2088421850636193}")
private String ouyinPartner;
@Value("${alipay.ouyin.email:ouyin@yoho.cn}")
private String ouyinEmail;
@Value("${alipay.ouyin.user_name:欧印南京贸易有限公司}")
private String ouyinUserName;
}
... ...
... ... @@ -11,7 +11,6 @@ import com.yohobuy.ufo.model.order.common.Payment;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.common.utils.HttpClient;
import com.yohoufo.common.utils.RSAUtils;
import com.yohoufo.common.utils.WXUtil;
import com.yohoufo.dal.order.OrdersPayHbfqMapper;
import com.yohoufo.dal.order.model.OrdersPayHbfq;
... ... @@ -28,6 +27,9 @@ import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.transfer.TransferChannel;
import com.yohoufo.order.service.transfer.TransferResult;
import com.yohoufo.order.utils.AlipayExceedMillionTransferErrors;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -90,7 +92,10 @@ public abstract class AbstractAlipayService extends AbstractPayService {
@Autowired
private OrdersPayHbfqMapper ordersPayHbfqDao;
@Autowired
@Getter(AccessLevel.PROTECTED)
@Accessors(fluent = true)
private AlipayConfig alipayConfig;
@Value("${alipay.notifyurl}")
private String notifyURL;
... ... @@ -105,7 +110,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
public PayQueryBo payQuery(String tradeNo, int orderCreateTime) {
Map<String, String> queryParams = buildOpenApiQueryParams(tradeNo);
String respTxt = sendOpenApiRequest(tradeNo, queryParams, AlipayConfig.OPENAPI_URL);
String respTxt = sendOpenApiRequest(tradeNo, queryParams, alipayConfig.openapiUrl());
QueryBo queryBo = JSON.parseObject(JSONObject.toJSONString(JSON.parseObject(respTxt).getJSONObject("alipay_trade_query_response")), QueryBo.class);
// 查询结果转换成 共通的对象
... ... @@ -430,7 +435,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
public JSONObject transferQueryAsOriginalResult(String buyerOrderCode) {
String tradeNo = buyerOrderCode;
Map<String, String> queryParams = buildAlipayTransferQueryParams(tradeNo);
String respTxt = sendOpenApiRequest(tradeNo, queryParams, AlipayConfig.OPENAPI_URL);
String respTxt = sendOpenApiRequest(tradeNo, queryParams, alipayConfig.openapiUrl());
JSONObject result = JSON.parseObject(respTxt).getJSONObject("alipay_fund_trans_order_query_response");
logger.info("查询转账{}结果为:{}", tradeNo, result);
return result;
... ... @@ -458,7 +463,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
private String sendOpenApiRequestWithException(String orderCode, Map<String, String> paramMap) throws Exception {
logger.info("[{}] send openapi request: {}", orderCode, paramMap);
String response = httpClient.postFormData(AlipayConfig.OPENAPI_URL, paramMap);
String response = httpClient.postFormData(alipayConfig.openapiUrl(), paramMap);
logger.info("[{}] trade openapi resp: {}", orderCode, response);
return response;
}
... ... @@ -469,7 +474,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
for(Map.Entry<String, String> entry : paramMap.entrySet()) {
paramStr.append("&").append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue(),AlipayConfig.input_charset));
}
String url = AlipayConfig.MAPI_URL +"?"+paramStr.substring(1);
String url = alipayConfig.mapiUrl() +"?"+paramStr.substring(1);
logger.info("[{}] send openapi requestUrl is: {}", orderCode, url);
String response = httpClient.get(url);
logger.info("[{}] trade openapi resp: {}", orderCode, response);
... ... @@ -810,7 +815,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
public PayRefundBo refundOpenApi(PayRefundBo refundBo) {
logger.info("enter AliPayRefunder to refund tradeNo {}, amount {}", refundBo.getRefundOrderCode(), refundBo.getAmount());
Map<String, String> refundParams = buildOpenApiRefundParams(refundBo.getPayOrderCode(), refundBo.getRefundOrderCode(), refundBo.getAmount());
String respTxt = sendOpenApiRequest(String.valueOf(refundBo.getPayOrderCode()), refundParams, AlipayConfig.OPENAPI_URL);
String respTxt = sendOpenApiRequest(String.valueOf(refundBo.getPayOrderCode()), refundParams, alipayConfig.openapiUrl());
//logger.info("refund response for alipay: {}", responseText);
PayRefundBo bo = refundOpenApiConvert(respTxt, refundBo);
logger.info("exit AliPayRefunder refund, refundStatus: {}, refundMsg", bo.getRefundStatus(), bo.getRefundMsg());
... ... @@ -1025,7 +1030,7 @@ public abstract class AbstractAlipayService extends AbstractPayService {
* @return
*/
private String obtainAtn(String outTradeNo, String notifyId) {
String verify_url = AlipayConfig.NOTIFY_VERIFY_URL + "&partner=" + getPartnerId() + "&notify_id=" + notifyId;
String verify_url = alipayConfig.mapiUrl() + "?service=notify_verify&partner=" + getPartnerId() + "&notify_id=" + notifyId;
String response = "";
logger.info("[{}] obtain atn begin, check url: {}", outTradeNo, verify_url);
... ...
package com.yohoufo.order.service.pay.alipay;
import com.yohoufo.order.config.AlipayConfig;
import org.springframework.stereotype.Service;
@Service
... ... @@ -10,8 +8,8 @@ public class AlipayOuyinService extends AbstractAlipayService {
@Override
protected AlipaySignatureSetting getAlipaySignatureSetting() {
return new AlipaySignatureSetting(
AlipayConfig.OUYIN_APPID,
AlipayConfig.OUYIN_PARTNER,
alipayConfig().ouyinAppid(),
alipayConfig().ouyinPartner(),
false,
"RSA"
);
... ... @@ -19,12 +17,12 @@ public class AlipayOuyinService extends AbstractAlipayService {
@Override
protected String getAccountUserName() {
return AlipayConfig.OUYIN_USER_NAME;
return alipayConfig().ouyinUserName();
}
@Override
protected String getAccountEmail() {
return AlipayConfig.OUYIN_EMAIL;
return alipayConfig().ouyinEmail();
}
}
... ...
... ... @@ -13,11 +13,12 @@ import java.util.Map;
@Service
public class AlipayOuyinWapService extends AbstractAlipayService {
@Override
protected AlipaySignatureSetting getAlipaySignatureSetting() {
return new AlipaySignatureSetting(
AlipayConfig.OUYIN_APPID,
AlipayConfig.OUYIN_PARTNER,
alipayConfig().ouyinAppid(),
alipayConfig().ouyinPartner(),
false,
"RSA"
);
... ... @@ -25,12 +26,12 @@ public class AlipayOuyinWapService extends AbstractAlipayService {
@Override
protected String getAccountUserName() {
return AlipayConfig.OUYIN_USER_NAME;
return alipayConfig().ouyinUserName();
}
@Override
protected String getAccountEmail() {
return AlipayConfig.OUYIN_EMAIL;
return alipayConfig().ouyinEmail();
}
@Override
... ...
... ... @@ -122,4 +122,11 @@ ufo.product.addSizeSortId=40
ufo.certification.timesLimit=3
unionpay.env=00
unionpay.notifyurl=${unionpay.notifyurl}
\ No newline at end of file
unionpay.notifyurl=${unionpay.notifyurl}
alipay.mapi.url=${alipay.mapi.url}
alipay.openapi.url=${alipay.openapi.url}
alipay.ouyin.appid=${alipay.ouyin.appid}
alipay.ouyin.partner=${alipay.ouyin.partner}
alipay.ouyin.email=${alipay.ouyin.email}
alipay.ouyin.user_name=${alipay.ouyin.user_name}
\ No newline at end of file
... ...