Authored by LUOXC

重构人工打款

Showing 18 changed files with 441 additions and 105 deletions
... ... @@ -3,6 +3,9 @@ package com.yohoufo.dal.order.model;
import java.math.BigDecimal;
public class OrdersPayTransfer {
public static final Integer INTERFACE_TYPE_TRANSFER_WHEN_EXCEED_MILLION = 2;
private Integer id;
private Long buyerOrderCode;
... ...
... ... @@ -40,13 +40,16 @@ import com.yohoufo.order.service.handler.BuyerCancelCompensateComputeHandler;
import com.yohoufo.order.service.handler.BuyerOrderPayDiffTimeHandler;
import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohoufo.order.service.pay.alipay.AlipayOuyinService;
import com.yohoufo.order.service.pay.alipay.AlipayServiceAbstract;
import com.yohoufo.order.service.pay.wallet.WalletPayService;
import com.yohoufo.order.service.pay.weixin.WeixinMiniappPayService;
import com.yohoufo.order.service.pay.weixin.WeixinPayUFORealAppService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import com.yohoufo.order.service.transfer.TransferResult;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.PaymentHelper;
import com.yohoufo.order.utils.ServiceExceptions;
import lombok.val;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
... ... @@ -1001,6 +1004,8 @@ public class PaymentServiceImpl implements IPaymentService {
if (tradeBillsMapper.selectByDealRelateId(tradeBillsId) != null) {
throw new ServiceException(400, "manualDeal:该流水已经处理过");
}
long orderCode = tradeBills.getOrderCode();
String logTag = "manualDeal orderCode is " + orderCode + "tradeBillId is " + tradeBillsId;
AuthorizeResultRespVO account = getAlipayAccount(tradeBills.getUid());
if (account == null ||
(StringUtils.isBlank(account.getAlipayAccount()) && StringUtils.isBlank(account.getAlipayId()))) {
... ... @@ -1015,7 +1020,7 @@ public class PaymentServiceImpl implements IPaymentService {
logger.info("manualDeal uid {} 支付宝账号uid无值使用账号{}", tradeBills.getUid(), account.getAlipayAccount());
alipayAccount = account.getAlipayAccount();
}
long orderCode = tradeBills.getOrderCode();
BigDecimal amount = null;
try {
... ... @@ -1098,104 +1103,112 @@ public class PaymentServiceImpl implements IPaymentService {
throw new ServiceException(500, "退款失败id=" + tradeBillsId);
}
}
JSONObject jsonObject = null;
Integer interfaceType = null;
try {
OrdersPayTransfer transfer = ordersPayTransferMapper.selectByBuyerOrderCode(orderCode);
if (transfer == null) {
throw new ServiceException(400, "转账记录不存在,流水id=" + tradeBillsId);
}
if (transfer == null || transfer.getStatus() == 1) {
throw new ServiceException(400, "转账记录已成功转账,流水id=" + tradeBillsId);
}
interfaceType = transfer.getInterfaceType();
logger.info("manualDeal orderCode={}, tradeBillId={}, 转账接口类型为 {}", orderCode, tradeBillsId, interfaceType);
if (interfaceType != null && interfaceType == 2) {
logger.info("manualDeal orderCode={}, tradeBillId={}, 转账接口类型为 超过100万的接口", orderCode, tradeBillsId);
Map<String, String> mapResult = transferWhenExceedMillion(transfer.getId(), preSuccess, orderCode, account, amount, now);
String resultStr = JSON.toJSONString(mapResult);
jsonObject = JSON.parseObject(resultStr);
if(!StringUtils.equals("T", mapResult.get("is_success"))) {
throw new ServiceException(500, "转账失败:返回={}" + resultStr);
} else {
return;
}
}
logger.info("manualDeal orderCode={}, tradeBillId={}, 转账接口类型为 小于100万的接口", orderCode, tradeBillsId);
jsonObject = alipayService.transferMoney(Long.toString(orderCode), account.getAlipayId(), account.getAlipayAccount(), amount);
if (jsonObject == null) {
logger.warn("manualDeal 转账失败 , req is {}", req);
throw new ServiceException(500, "转账失败:阿里接口返回null");
}
logger.info("manualDeal 转账阿里接口返回 {}", jsonObject.toJSONString());
// 成功
Integer code = null;
String orderId = null;
if (jsonObject.containsKey("code")
&& (code = jsonObject.getInteger("code")) == 10000
&& jsonObject.containsKey("order_id")
&& StringUtils.isNotBlank(orderId = jsonObject.getString("order_id"))) {
logger.info("manualDeal转账成功,targeAccount is {}, amount is {}", alipayAccount, amount);
// 加新流水
tradeBills.setDealRelateId(tradeBills.getId());
tradeBills.setId(null);
tradeBills.setTradeStatus(100);
tradeBills.setCreateTime(now);
addTradeBills(tradeBills);
OrdersPayTransfer transferSuccess = new OrdersPayTransfer();
transferSuccess.setId(transfer.getId());
transferSuccess.setAlipayTradeId(orderId);
transferSuccess.setStatus(1);
transferSuccess.setUpdateTime(now);
ordersPayTransferMapper.updateByPrimaryKeySelective(transferSuccess);
} else {
logger.warn("manualDealErr 返回code或者order_id不是成功状态,code={}, orderId={}", code, orderId);
// 上报
throw new ServiceException(500, "转账失败:返回code="+code+",order_id="+orderId);
}
} catch (Exception e) {
/*if (interfaceType != null && interfaceType == 2) {
return;
}*/
logger.warn("manualDealErr 转账失败 , orderCode is {}, msg is {}", orderCode, e.getMessage());
String alarmMsg = "订单号:" + orderCode + ",操作类型(转账),流水id=" + tradeBillsId + ",msg=" + e.getMessage();
if (jsonObject != null) {
alarmMsg += ",阿里返回DETAIL=" + jsonObject.toJSONString();
}
logger.info("manualDealErr 转账失败 , alarmMsg is {}", alarmMsg);
alarm("人工处理转账失败", "ufo.order.manualDeal", alarmMsg);
preSuccess.setDealStatus(0);
tradeBillsMapper.updateToFailByPrimaryKey(preSuccess);
if (e instanceof ServiceException) {
throw new ServiceException(((ServiceException) e).getCode(), "转账失败id=" + tradeBillsId + "," + e.getMessage());
} else {
throw new ServiceException(500, "转账失败id=" + tradeBillsId);
}
} finally {
logger.info("manualDeal转账结束, tradeBillsId is {}!", tradeBillsId);
}
try {
OrdersPayTransfer transfer = ordersPayTransferMapper.selectByBuyerOrderCode(orderCode);
ServiceExceptions.throwServiceExceptionIf(() -> Objects.isNull(transfer),
400, "转账记录不存在[" + tradeBillsId + "]");
ServiceExceptions.throwServiceExceptionIf(() -> transfer.getStatus() == 1,
400, "转账记录已成功转账,请不要重复操作。");
Integer interfaceType = transfer.getInterfaceType();
logger.info("{}, transfer channel router {}", logTag, interfaceType);
if (OrdersPayTransfer.INTERFACE_TYPE_TRANSFER_WHEN_EXCEED_MILLION.equals(interfaceType)) {
transferWithAlipayExceedMillionTransfer(tradeBills, orderCode, logTag, account, amount, transfer);
} else {
transferWithAlipayTransfer(logTag, tradeBills, orderCode, account, amount, now, transfer);
}
} catch (Exception e) {
logger.warn("{}, transfer fail", logTag, e);
alarm("人工处理转账失败",
"ufo.order.manualDeal",
"订单号:" + orderCode + ",操作类型(转账),流水id=" + tradeBillsId + ",msg=" + e.getMessage());
logger.info("{}, rollback lock", logTag);
preSuccess.setDealStatus(0);
tradeBillsMapper.updateToFailByPrimaryKey(preSuccess);
logger.info("{}, rollback lock success", logTag);
if (e instanceof ServiceException) {
throw e;
} else {
ServiceExceptions.throwServiceException(500, "转账失败id=" + tradeBillsId);
}
} finally {
logger.info("{}, complete", logTag);
}
}
private void transferWithAlipayTransfer(String logTag, TradeBills tradeBills, long orderCode, AuthorizeResultRespVO account, BigDecimal amount, int now, OrdersPayTransfer transfer) {
TransferResult transferResult = alipayService.newAlipayTransfer()
.transferOrderCode(Long.toString(orderCode))
.alipayUid(account.getAlipayId())
.alipayAccount(account.getAlipayAccount())
.transferAmount(amount)
.transfer();
if (transferResult.getCode() == 200) {
logger.info("{}, transfer success and out trade no is {}", logTag, orderCode);
// 加新流水
tradeBills.setDealRelateId(tradeBills.getId());
tradeBills.setId(null);
tradeBills.setTradeStatus(100);
tradeBills.setCreateTime(now);
addTradeBills(tradeBills);
// ?
OrdersPayTransfer transferSuccess = new OrdersPayTransfer();
transferSuccess.setId(transfer.getId());
transferSuccess.setAlipayTradeId(transferResult.getTradeNo());
transferSuccess.setStatus(1);
transferSuccess.setUpdateTime(now);
ordersPayTransferMapper.updateByPrimaryKeySelective(transferSuccess);
}else {
logger.warn("{}, transfer fail {}", logTag,transferResult);
throw new ServiceException(transferResult.getCode(), transferResult.getMsg());
}
}
private void transferWithAlipayExceedMillionTransfer(TradeBills tradeBills, long orderCode, String logTag, AuthorizeResultRespVO account, BigDecimal amount, OrdersPayTransfer transfer) {
String businessId = transfer.getId() + "_" + tradeBills.getId();
TransferResult transferResult = alipayService.newAlipayExceedMillionTransfer()
.transferOrderCode( Long.toString(orderCode))
.alipayUid(account.getAlipayId())
.alipayAccount(account.getAlipayAccount())
.transferAmount(amount)
.businessId(businessId)
.userName(account.getCertName())
.transfer();
// success to wait
if (transferResult.getCode() == 200) {
logger.info("{}, transfer success and out trade no is {}", logTag, businessId);
// 更新流水状态为转账中
tradeBills.setDealStatus(0);
tradeBills.setTradeStatus(TradeBills.Status.TRANSFER_WAITING.getCode());
tradeBillsMapper.updateSelectiveByPrimaryKeyNoCondition(tradeBills);
logger.info("{}, the trade bill has updated to transfer waiting", logTag);
} else {
logger.warn("{}, transfer fail {}", logTag,transferResult);
throw new ServiceException(transferResult.getCode(), transferResult.getMsg());
}
}
private Map<String, String> transferWhenExceedMillion(Integer transferId, TradeBills tradeBills, long orderCode, AuthorizeResultRespVO account,
BigDecimal amount, int now) throws Exception {
Map<String, String> mapResult = alipayService.transferMoneyWhenExceedMillion(Long.toString(orderCode),
transferId + "_" + tradeBills.getId(), account.getAlipayId(), account.getAlipayAccount(),
account.getCertName(), amount);
private Map<String, String> transferWhenExceedMillion(Integer transferId, TradeBills tradeBills, long orderCode, AuthorizeResultRespVO account,
BigDecimal amount, int now) throws Exception {
Map<String, String> mapResult = alipayService.transferMoneyWhenExceedMillion(
Long.toString(orderCode),
transferId + "_" + tradeBills.getId(),
account.getAlipayId(),
account.getAlipayAccount(),
account.getCertName(),
amount);
logger.info("transferWhenExceedMillion 转账阿里接口(总金额超过100万)返回 {}, orderCode is {}, transferId is {}, tradeBillsId is {}, alibillId is {}", mapResult, orderCode, transferId, tradeBills.getId(), transferId + "_" + tradeBills.getId());
// success to wait
if (StringUtils.equals("T", mapResult.get("is_success"))) {
tradeBills.setDealStatus(0);
tradeBills.setTradeStatus(TradeBills.Status.TRANSFER_WAITING.getCode());
// wait
tradeBillsMapper.updateSelectiveByPrimaryKeyNoCondition(tradeBills);
if (StringUtils.equals("T", mapResult.get("is_success"))) {
tradeBills.setDealStatus(0);
tradeBills.setTradeStatus(TradeBills.Status.TRANSFER_WAITING.getCode());
// wait
tradeBillsMapper.updateSelectiveByPrimaryKeyNoCondition(tradeBills);
logger.info("transferWhenExceedMillion 转账阿里接口(总金额超过100万)更新之后的tradeBill: {}", tradeBillsMapper.selectByPrimaryKey(tradeBills.getId()));
}
return mapResult;
}
return mapResult;
}
private boolean exceedMillion(JSONObject jsonObject) {
// {"msg":"Business Failed","code":"40004","sub_msg":"单日最多可转100万元","sub_code":"EXCEED_LIMIT_DM_MAX_AMOUNT"}
... ...
... ... @@ -14,11 +14,16 @@ 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;
import com.yohoufo.dal.order.model.TradeBills;
import com.yohoufo.order.common.HbfqEnum;
import com.yohoufo.order.config.AlipayConfig;
import com.yohoufo.order.constants.RefundContant;
import com.yohoufo.order.model.*;
import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohoufo.order.service.transfer.TransferChannel;
import com.yohoufo.order.service.transfer.TransferResult;
import lombok.Builder;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -49,7 +54,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
protected abstract String getAppId();
protected abstract String getPartnerId();
protected String getAccountUserName() {
return "";
}
... ... @@ -57,7 +62,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
protected String getAccountEmail() {
return "";
}
protected String getRsaAliMApipubKey() {
return "";
}
... ... @@ -70,7 +75,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
@Value("${alipay.notifyurl}")
private String notifyURL;
@Value("${alipay.transfer.notifyurl}")
private String transferNotifyURL;
... ... @@ -168,7 +173,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
* @param alipayAccount
* @param transferAmount
* @return
* @throws Exception
* @throws Exception
*/
public JSONObject transferMoney(String transferOrderCode, String alipayUid, String alipayAccount, BigDecimal transferAmount) throws Exception{
... ... @@ -184,14 +189,192 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
}
return result;
}
public class AlipayTransfer implements TransferChannel {
String transferOrderCode;
String alipayUid;
String alipayAccount;
BigDecimal transferAmount;
private AlipayTransfer(){
}
public AlipayTransfer transferOrderCode(String transferOrderCode){
this.transferOrderCode = transferOrderCode;
return this;
}
public AlipayTransfer alipayUid(String alipayUid){
this.alipayUid = alipayUid;
return this;
}
public AlipayTransfer alipayAccount(String alipayAccount){
this.alipayAccount = alipayAccount;
return this;
}
public AlipayTransfer transferAmount(BigDecimal transferAmount){
this.transferAmount = transferAmount;
return this;
}
@Override
public TransferResult transfer() {
Map<String, String> queryParams = buildTransferParams(transferOrderCode, alipayUid, alipayAccount, transferAmount);
String respTxt;
try {
respTxt = sendOpenApiRequestWithException(transferOrderCode, queryParams);
} catch (Exception e) {
logger.warn("transfer fail transferOrderCode is {} alipayUid is {} alipayAccount is {} transferAmount is {}",
transferOrderCode, alipayUid, alipayAccount, transferAmount, e);
return TransferResult.builder()
.code(599)
.msg("未知异常:" + e.getMessage())
.build();
}
if (StringUtils.isNotBlank(respTxt)){
JSONObject json = JSON.parseObject(respTxt);
JSONObject result = json.getJSONObject("alipay_fund_trans_toaccount_transfer_response");
String code = result.getString("code");
String msg = result.getString("msg");
String out_biz_no = result.getString("out_biz_no");
String order_id = result.getString("order_id");
String pay_date = result.getString("pay_date");
if (StringUtils.equals("10000", code)) {
if(StringUtils.isNoneBlank(order_id)){
return TransferResult.builder()
.code(200)
.msg(msg)
.transferOrderCode(out_biz_no)
.tradeNo(order_id)
.payDate(pay_date)
.build();
}else {
return TransferResult.builder()
.code(599)
.msg("未知异常:code is 10000 but order_id is blank")
.build();
}
} else {
return transformError(result.getString("sub_code"), result.getString("sub_msg"));
}
} else {
return TransferResult.builder()
.code(500)
.msg("Response data is blank")
.build();
}
}
}
public AlipayTransfer newAlipayTransfer(){
return new AlipayTransfer();
}
public AlipayExceedMillionTransferChannel newAlipayExceedMillionTransfer(){
return new AlipayExceedMillionTransferChannel();
}
private TransferResult transformError(String sub_code, String sub_msg) {
/*
* 错误描述:系统繁忙
* 解决方案:可能发生了网络或者系统异常,导致无法判定准确的转账结果。
* 此时,商户不能直接当做转账成功或者失败处理,可以考虑采用相同的out_biz_no重发请求,
* 或者通过调用“(alipay.fund.trans.order.query)”来查询该笔转账订单的最终状态。
*/
if (StringUtils.equals("SYSTEM_ERROR", sub_code)) {
return TransferResult.builder()
.code(501)
.msg("可能发生了网络或者系统异常,请重试。")
.build();
} else if (StringUtils.equals("EXCEED_LIMIT_PERSONAL_SM_AMOUNT", sub_code)) {
return TransferResult.builder()
.code(502)
.msg("转账给个人支付宝账户单笔最多5万元。")
.build();
} else if (StringUtils.equals("EXCEED_LIMIT_ENT_SM_AMOUNT", sub_code)) {
return TransferResult.builder()
.code(503)
.msg("转账给企业支付宝账户单笔最多10万元。")
.build();
} else if (StringUtils.equals("EXCEED_LIMIT_SM_MIN_AMOUNT", sub_code)) {
return TransferResult.builder()
.code(504)
.msg("单笔最低转账金额0.1元。")
.build();
} else if (StringUtils.equals("EXCEED_LIMIT_DM_MAX_AMOUNT", sub_code)) {
return TransferResult.builder()
.code(505)
.msg("单日最多可转100万元,请明天重试。")
.build();
} else if (StringUtils.equals("EXCEED_LIMIT_UNRN_DM_AMOUNT", sub_code)) {
return TransferResult.builder()
.code(506)
.msg("收款账户未实名,单日最多可收款1000元,请明天重试。")
.build();
} else if (StringUtils.equals("PAYER_PAYEE_CANNOT_SAME", sub_code)) {
return TransferResult.builder()
.code(507)
.msg("请检查一下收款方信息填写是否为付款方本人。")
.build();
}
/*
错误描述:根据监管部门的要求,对方未完善身份信息或未开立余额账户,无法收款
解决方案:可能发生了网络或者系统异常,导致无法判定准确的转账结果。
*/
else if (StringUtils.equals("PERMIT_NON_BANK_LIMIT_PAYEE", sub_code)) {
return TransferResult.builder()
.code(508)
.msg("请联系收款方登录支付宝站内或手机客户端更新身份信息后重试。")
.build();
}
/*
错误描述:根据监管部门的要求,需要付款用户更新身份信息才能继续操作
解决方案:根据监管部门的要求,需要付款用户登录支付宝站内或手机客户端更新身份信息才能继续操作。
*/
else if (StringUtils.equals("PAYER_CERT_EXPIRED", sub_code)) {
return TransferResult.builder()
.code(509)
.msg("请联系收款方登录支付宝站内或手机客户端完善身份信息后重试。")
.build();
}/*
错误描述:根据监管部门的要求,需要付款用户更新身份信息才能继续操作
解决方案:根据监管部门的要求,需要付款用户登录支付宝站内或手机客户端更新身份信息才能继续操作。
*/ else if (StringUtils.equals("PAYER_CERT_EXPIRED", sub_code)) {
return TransferResult.builder()
.code(510)
.msg("请联系收款方登录支付宝站内或手机客户端补全身份信息后重试。")
.build();
} else if (StringUtils.equals("REMARK_HAS_SENSITIVE_WORD", sub_code)) {
return TransferResult.builder()
.code(511)
.msg("转账备注包含敏感词,请修改备注文案后重试。")
.build();
} else if (StringUtils.equals("PAYER_BALANCE_NOT_ENOUGH", sub_code)) {
return TransferResult.builder()
.code(512)
.msg("付款账户余额不足,请联系财务保持付款账户余额充足。")
.build();
} else {
return TransferResult.builder()
.code(599)
.msg("未知异常:sub_code is " + sub_code + ",sub_msg is " + sub_msg)
.build();
}
}
/**
* 转账功能
* @param transferOrderCode
* @param alipayAccount
* @param transferAmount
* @return
* @throws Exception
* @throws Exception
*/
public Map<String, String> transferMoneyWhenExceedMillion(String transferOrderCode, String businessId, String alipayUid, String alipayAccount, String userName, BigDecimal transferAmount) throws Exception{
... ... @@ -207,7 +390,90 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
}
return result;
}
public class AlipayExceedMillionTransferChannel implements TransferChannel{
String transferOrderCode;
String alipayUid;
String alipayAccount;
BigDecimal transferAmount;
String businessId;
String userName;
private AlipayExceedMillionTransferChannel(){
}
public AlipayExceedMillionTransferChannel transferOrderCode(String transferOrderCode){
this.transferOrderCode = transferOrderCode;
return this;
}
public AlipayExceedMillionTransferChannel alipayUid(String alipayUid){
this.alipayUid = alipayUid;
return this;
}
public AlipayExceedMillionTransferChannel alipayAccount(String alipayAccount){
this.alipayAccount = alipayAccount;
return this;
}
public AlipayExceedMillionTransferChannel transferAmount(BigDecimal transferAmount){
this.transferAmount = transferAmount;
return this;
}
public AlipayExceedMillionTransferChannel businessId(String businessId){
this.businessId = businessId;
return this;
}
public AlipayExceedMillionTransferChannel userName(String userName){
this.userName = userName;
return this;
}
@Override
public TransferResult transfer() {
Map<String, String> queryParams = buildTransferParamsWhenExceedMillion(transferOrderCode, businessId, alipayUid, alipayAccount, userName, transferAmount);
String respTxt;
try {
respTxt = sendMApiRequestWithException(transferOrderCode, queryParams);
} catch (Exception e) {
logger.warn("transfer fail transferOrderCode is {} alipayUid is {} alipayAccount is {} transferAmount is {}",
transferOrderCode, alipayUid, alipayAccount, transferAmount, e);
return TransferResult.builder()
.code(599)
.msg("未知异常:" + e.getMessage())
.build();
}
Map<String, String> result;
if (StringUtils.isNotBlank(respTxt)){
result = WXUtil.parseWXPayXml(respTxt);
if (StringUtils.equals("T", result.get("is_success"))) {
return TransferResult.builder()
.code(200)
.msg("ok")
.build();
} else {
String error = result.get("error");
return TransferResult.builder()
.code(599)
.msg("未知异常:error is " + error)
.build();
}
} else {
return TransferResult.builder()
.code(500)
.msg("Response data is blank")
.build();
}
}
}
public PayQueryBo transferQuery(String buyerOrderCode) {
String tradeNo = buyerOrderCode;
Map<String, String> queryParams = buildAlipayTransferQueryParams(tradeNo);
... ... @@ -245,14 +511,14 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
logger.info("[{}] trade openapi resp: {}", orderCode, response);
return response;
}
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);
logger.info("[{}] trade openapi resp: {}", orderCode, response);
return response;
}
private String sendMApiRequestWithException(String orderCode, Map<String, String> paramMap) throws Exception {
logger.info("[{}] send openapi request: {}", orderCode, paramMap);
StringBuilder paramStr = new StringBuilder();
... ... @@ -291,7 +557,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
params.put("sign", RSAUtils.sign(preSignStr, getRsaPrivateKey(), AlipayConfig.input_charset));
return params;
}
/**
* openapi支付查询
* @param orderData
... ... @@ -349,7 +615,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
params.put("sign", RSAUtils.sign(preSignStr, getRsaPrivateKey(), AlipayConfig.input_charset));
return params;
}
/**
* 单笔转账
* @param orderData
... ... @@ -367,7 +633,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
params.put("batch_num", "1");
params.put("batch_fee", transferAmount.toString());
params.put("email", getAccountEmail());
StringBuilder detailAppender = new StringBuilder();
detailAppender.append(businessId).append("^");
if (StringUtils.isNotBlank(alipayUid)) {
... ... @@ -536,7 +802,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
}
return payData;
}
public TransferData getTransferData(String data) {
if (StringUtils.isBlank(data)) {
return null;
... ...
package com.yohoufo.order.service.transfer;
public interface TransferChannel {
TransferResult transfer();
}
... ...
package com.yohoufo.order.service.transfer;
import com.yohoufo.order.service.pay.alipay.AlipayOuyinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
public interface TransferChannelRouter {
}
... ...
package com.yohoufo.order.service.transfer;
import lombok.Builder;
@Builder
@lombok.Value
public class TransferResult {
private int code;
private String msg;
private String transferOrderCode;
private String tradeNo;
private String payDate;
}
... ...
... ... @@ -3,18 +3,36 @@ package com.yohoufo.order.utils;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import java.util.function.Function;
import java.util.function.Predicate;
/**
* @author LUOXC
* @date 2019/1/9 11:14
*/
public class ServiceExceptions {
@FunctionalInterface
public interface Condition {
boolean test();
}
public static void throwServiceException(String message) {
ServiceException serviceException = new ServiceException(ServiceError.ORDER_SERVICE_ERROR);
serviceException.setParams(message);
throw serviceException;
}
public static void throwServiceExceptionIf(Condition condition, int code, String message) {
if (condition.test()) {
throw new ServiceException(code, message);
}
}
public static void throwServiceException(int code, String message) {
throw new ServiceException(code, message);
}
public static void throwServiceException(ServiceError serviceError) {
throw new ServiceException(serviceError);
}
... ...