Authored by tanling

跨境支付 推送支付单

... ... @@ -44,6 +44,8 @@ public class DateUtil {
public static final String HH_mm = "HH:mm";
public final static String YYYY_MM_DD_DOT="yyyy.MM.dd";
public final static String YYYYMMDD = "yyyymmdd";
public static final String yyyyMM = "yyyyMM";
public static final String MM_dd_yyyy_HH_mm_ssEx = "yyyy.MM.dd HH:mm";
... ... @@ -91,6 +93,11 @@ public class DateUtil {
}
public static String getCurrentYYYYMMDD(){
return getDateFormatEx(getCurrentTimeSecond(), YYYYMMDD);
}
public static String formatYYMMddHHmmssPoint(Integer time)
{
if (time == null || time==0) {
... ...
... ... @@ -68,7 +68,7 @@
#{payLevel,jdbcType=INTEGER}, #{serialNo,jdbcType=VARCHAR}, #{createTime,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" parameterType="com.yohoufo.dal.order.model.OrdersPay" >
<insert id="insertSelective" parameterType="com.yohoufo.dal.order.model.OrdersPay" keyProperty="id" useGeneratedKeys="true" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
... ...
... ... @@ -8,8 +8,10 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.yohobuy.ufo.model.order.bo.PaymentData;
import com.yohoufo.order.service.pay.alipay.AlipayCrossBorderService;
import com.yohoufo.order.service.pay.alipay.AbstractAlipayService;
import com.yohoufo.order.service.pay.alipay.bean.AlipayCustomsResponse;
import com.yohoufo.order.service.pay.unionpay.JsUnionpayService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
... ... @@ -29,7 +31,6 @@ import com.yohoufo.common.utils.WXUtil;
import com.yohoufo.order.constants.RefundContant;
import com.yohoufo.order.model.NotifyResponse;
import com.yohoufo.order.model.PayRefundBo;
import com.yohoufo.order.model.PaymentData;
import com.yohoufo.order.model.TransferData;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.model.response.PaymentConfirmRsp;
... ... @@ -42,7 +43,6 @@ import com.yohoufo.order.service.pay.weixin.WeixinPayUFORealAppService;
@RequestMapping(value = "/payment")
public class PaymentController {
private final Logger logger = LoggerFactory.getLogger(getClass());
... ... @@ -120,6 +120,23 @@ public class PaymentController {
}
/**
* 跨境支付宝推送支付单
* @param orderCode
* @param outRequestNo
* @param tradeNo
* @param amount
* @return
*/
@RequestMapping(params = "method=ufo.order.customs")
public ApiResponse customs(@RequestParam(name = "orderCode") long orderCode,
@RequestParam(name = "outRequestNo") String outRequestNo,
@RequestParam(name = "tradeNo") String tradeNo,
@RequestParam(name = "amount") double amount){
AlipayCustomsResponse alipayCustomsResponse = paymentService.customs(orderCode, outRequestNo, tradeNo, amount);
return new ApiResponse.ApiResponseBuilder().code(PrepayResponse.SUCCESS).data(alipayCustomsResponse).message("推送支付单").build();
}
/**
* 退款结果确认
... ...
package com.yohoufo.order.model;
import com.yohobuy.ufo.model.order.bo.PaymentData;
public class NotifyResponse {
/**
* 支付回调处理结果
... ...
package com.yohoufo.order.model;
import lombok.Data;
import lombok.ToString;
@Data
@ToString
public class PaymentData {
/**
* 订单Code
*/
private String orderCode = "";
/**
* 支付阶段
*/
private int payLevel;
/**
* 支付平台ID
*/
private byte paymentID;
/**
* 支付的总金额
*/
private double totalFee;
/**
* 付款时间
*/
private String paymentTime = "";
/**
* 支付时的交易单号
*/
private String outTradeNo = "";
/**
* 回调时间
* @return
*/
private String callbackTime = "";
/**
* 银行名称,中文
*/
private String bankName = "";
/**
* 银行代码
*/
private String bankCode = "";
/**
* 支付平台流水号
*/
private String tradeNo = "";
/**
* 银行的流水号
*/
private String bankBillNo = "";
/**
* 用户id
*/
private int uid;
/**
* 订单类型
*/
private int orderType;
/**
* 商户号
*/
private String mchId;
//微信支付的appId
private String appId;
//消息id
private String messageId;
//买家
private String buyerId;
}
... ... @@ -3,9 +3,9 @@ package com.yohoufo.order.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.rholder.retry.*;
import com.google.common.base.Predicates;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.message.sdk.utils.DateUtils;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.common.*;
import com.yohobuy.ufo.model.order.constants.DepotType;
... ... @@ -31,6 +31,8 @@ import com.yohoufo.order.service.cache.CacheCleaner;
import com.yohoufo.order.service.impl.*;
import com.yohoufo.order.service.listener.BuyerOrderChangeEvent;
import com.yohoufo.order.service.listener.OrderChangeListenerContainer;
import com.yohoufo.order.service.pay.alipay.AlipayCrossBorderService;
import com.yohoufo.order.service.pay.alipay.bean.AlipayCustomsResponse;
import com.yohoufo.order.service.proxy.*;
import com.yohoufo.order.utils.BuyerOrderUtils;
import com.yohoufo.order.utils.SellerGoodsHelper;
... ... @@ -43,7 +45,6 @@ import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
... ... @@ -108,6 +109,9 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService {
@Autowired
FastDeliveryProxyService fastDeliveryProxyService;
@Autowired
private AlipayCrossBorderService crossBorderService;
private ExecutorService executors = Executors.newFixedThreadPool(1);
Retryer<Object> retryer = RetryerBuilder.<Object>newBuilder()
... ... @@ -438,6 +442,24 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService {
break;
case OVERSEAS_IN_STOCK:
processOverSeasOrder(buyerOrder, sellerOrderGoods);
// 跨境支付 推送支付单
if (buyerOrder.getPayment() == Payment.CROSS_BORDER_ALIPAY.getCode() && orderInfo.getPaymentData()!=null){
String outRequestNo = DateUtil.getCurrentYYYYMMDD()+orderInfo.getPaymentData().getId();
try{
AlipayCustomsResponse alipayCustomsResponse = crossBorderService.customsOpenApi(buyerOrder.getOrderCode(),
outRequestNo,
orderInfo.getPaymentData().getTradeNo(), buyerOrder.getAmount().doubleValue());
if (alipayCustomsResponse.getIs_success().equalsIgnoreCase("F")){
logger.warn("customs error. {},{},{},{}",buyerOrder.getOrderCode(), outRequestNo,
orderInfo.getPaymentData().getTradeNo(), buyerOrder.getAmount().doubleValue());
}
}catch (Exception e){
logger.warn("customs error. {},{},{},{},{}",buyerOrder.getOrderCode(), outRequestNo,
orderInfo.getPaymentData().getTradeNo(), buyerOrder.getAmount().doubleValue(),e);
}
}
break;
}
... ...
... ... @@ -2,18 +2,30 @@ package com.yohoufo.order.service;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.bo.PaymentData;
import com.yohobuy.ufo.model.order.req.ManualDealRequest;
import com.yohoufo.order.model.PayRefundBo;
import com.yohoufo.order.model.PaymentData;
import com.yohoufo.order.model.TransferData;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.model.response.PaymentConfirmRsp;
import com.yohoufo.order.model.response.PrepayResponse;
import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohoufo.order.service.pay.alipay.bean.AlipayCustomsResponse;
public interface IPaymentService {
/**
* 推送支付单
* @param orderCode
* @param outRequestNo
* @param tradeNo
* @param amount
* @return
*/
public AlipayCustomsResponse customs(long orderCode, String outRequestNo, String tradeNo, double amount);
/**
* 获取订单信息(买家订单|卖家订单|入驻充值)
* @param uid
... ...
... ... @@ -10,6 +10,7 @@ import com.yoho.tools.common.beans.ApiResponse;
import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.bo.OutTradeNoMeta;
import com.yohobuy.ufo.model.order.bo.PaymentData;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohobuy.ufo.model.order.common.Payment;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
... ... @@ -30,7 +31,6 @@ import com.yohoufo.order.common.TransferCase;
import com.yohoufo.order.constants.RefundContant;
import com.yohoufo.order.model.PayQueryBo;
import com.yohoufo.order.model.PayRefundBo;
import com.yohoufo.order.model.PaymentData;
import com.yohoufo.order.model.TransferData;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.model.request.TransferMoneyRequest;
... ... @@ -49,6 +49,7 @@ import com.yohoufo.order.service.handler.transfer.TransferChancelSelector;
import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohoufo.order.service.pay.alipay.AlipayCrossBorderService;
import com.yohoufo.order.service.pay.alipay.AlipayOuyinService;
import com.yohoufo.order.service.pay.alipay.bean.AlipayCustomsResponse;
import com.yohoufo.order.service.pay.unionpay.JsUnionpayService;
import com.yohoufo.order.service.pay.wallet.WalletPayService;
import com.yohoufo.order.service.pay.weixin.WeixinMiniappPayService;
... ... @@ -181,6 +182,30 @@ public class PaymentServiceImpl implements IPaymentService {
@Autowired
private RedisLockFactory redisLockFactory;
@Autowired
private AlipayCrossBorderService crossBorderService;
/**
* 推送支付单
* @param orderCode
* @param outRequestNo
* @param tradeNo
* @param amount
* @return
*/
public AlipayCustomsResponse customs(long orderCode, String outRequestNo, String tradeNo, double amount){
if (orderCode<0
|| StringUtils.isEmpty(outRequestNo)
|| StringUtils.isEmpty(tradeNo)
|| amount < 0){
logger.warn("payConfirm request empty");
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
return crossBorderService.customsOpenApi(orderCode, outRequestNo, tradeNo, amount);
}
/**
* 订单支付结果确认
... ... @@ -394,6 +419,8 @@ public class PaymentServiceImpl implements IPaymentService {
ordersPay.setAttach(attach.toJSONString());
ordersPayMapper.insertSelective(ordersPay);
orderInfo.setPaymentData(paymentData);
return ordersPay;
}
... ...
... ... @@ -7,6 +7,7 @@ import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.bo.OutTradeNoMeta;
import com.yohobuy.ufo.model.order.bo.PaymentData;
import com.yohobuy.ufo.model.order.common.Payment;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.common.utils.DateUtil;
... ... @@ -19,7 +20,6 @@ import com.yohoufo.order.config.AlipayConfig;
import com.yohoufo.order.constants.RefundContant;
import com.yohoufo.order.model.PayQueryBo;
import com.yohoufo.order.model.PayRefundBo;
import com.yohoufo.order.model.PaymentData;
import com.yohoufo.order.model.TransferData;
import com.yohoufo.order.service.PaymentSupportService;
import com.yohoufo.order.service.pay.AbstractPayService;
... ...
... ... @@ -9,6 +9,7 @@ import com.yohoufo.order.config.AlipayConfig;
import com.yohoufo.order.constants.RefundContant;
import com.yohoufo.order.model.PayQueryBo;
import com.yohoufo.order.model.PayRefundBo;
import com.yohoufo.order.service.pay.alipay.bean.AlipayCustomsResponse;
import com.yohoufo.order.service.pay.alipay.bean.AlipayQueryResponse;
import com.yohoufo.order.service.pay.alipay.bean.AlipayRefundResponse;
import org.slf4j.Logger;
... ... @@ -38,6 +39,27 @@ public class AlipayCrossBorderService extends AbstractAlipayService {
return "zfbgj@yoho.cn";
}
/**
* 商户在海关系统中的code
* @return
*/
private String getMerchantCustomsCode(){
return "3201962889";
}
private String getMerchantCustomsName(){
return "南京新与力文化传播有限公司";
}
/**
* 萝岗海关
* @return
*/
private String getCustomsPlace(){
return "5224";
}
/**
* OpenApi退款
* @param refundBo
... ... @@ -54,6 +76,22 @@ public class AlipayCrossBorderService extends AbstractAlipayService {
}
public AlipayCustomsResponse customsOpenApi(long orderCode, String outRequestNo, String tradeNo, double amount){
logger.info("enter customsOpenApi to {}, {}, {}, {}", orderCode, outRequestNo, tradeNo, amount);
Map<String, String> customsParam = buildOpenApiCustoms(outRequestNo, tradeNo, amount);
String respTxt = sendOpenApiRequest(String.valueOf(orderCode), customsParam, AlipayConfig.CROSS_BORDER_OPENAPI_URL);
AlipayCustomsResponse refundResponse = (AlipayCustomsResponse)XMLUtil.convertXmlStrToObject(AlipayRefundResponse.class, respTxt);
logger.info("exit customsOpenApi, result {}", refundResponse);
return refundResponse;
}
public PayRefundBo refundOpenApiConvert(String respText, PayRefundBo bo) {
AlipayRefundResponse refundResponse = (AlipayRefundResponse)XMLUtil.convertXmlStrToObject(AlipayRefundResponse.class, respText);
... ... @@ -98,6 +136,37 @@ public class AlipayCrossBorderService extends AbstractAlipayService {
return params;
}
/**
* 给海关推支付单
* @param outRequestNo
* @param tradeNo
* @param amount
* @return
*/
private Map<String, String> buildOpenApiCustoms(String outRequestNo, String tradeNo, double amount){
Map<String, String> params = new HashMap<>();
params.put("service","alipay.acquire.customs");
params.put("partner", getPartnerId());
params.put("_input_charset", AlipayConfig.input_charset);
params.put("sign_type", "RSA");
params.put("out_request_no", outRequestNo);
params.put("trade_no", tradeNo);
params.put("merchant_customs_code", getMerchantCustomsCode());
params.put("amount", String.valueOf(amount));
params.put("customs_place", getCustomsPlace());
params.put("merchant_customs_name", getMerchantCustomsName());
String preSignStr = getOpenApiSignString(params, true);
params.put("sign", helper().signWithRsa(preSignStr,AlipayConfig.input_charset));
return params;
}
/**
* 查询支付结果
* @param tradeNo
... ...
package com.yohoufo.order.service.pay.alipay.bean;
import lombok.ToString;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "alipay")
@ToString
public class AlipayCustomsResponse {
/**
* 是否成功
* T:成功, F:失败
*/
private String is_success;
private String error;
private String result_code;
private String detail_error_code;
private String detail_error_des;
public String getResult_code() {
return result_code;
}
public void setResult_code(String result_code) {
this.result_code = result_code;
}
public String getDetail_error_code() {
return detail_error_code;
}
public void setDetail_error_code(String detail_error_code) {
this.detail_error_code = detail_error_code;
}
public String getDetail_error_des() {
return detail_error_des;
}
public void setDetail_error_des(String detail_error_des) {
this.detail_error_des = detail_error_des;
}
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
public String getIs_success() {
return is_success;
}
public void setIs_success(String is_success) {
this.is_success = is_success;
}
}
... ...
... ... @@ -4,13 +4,13 @@ import com.alibaba.fastjson.JSONObject;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.bo.PaymentData;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.common.utils.TimeUtils;
import com.yohoufo.common.utils.YHMath;
import com.yohoufo.order.constants.RefundContant;
import com.yohoufo.order.model.PayQueryBo;
import com.yohoufo.order.model.PayRefundBo;
import com.yohoufo.order.model.PaymentData;
import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohoufo.order.service.pay.unionpay.utils.AcpService;
import com.yohoufo.order.service.pay.unionpay.utils.SDKConfig;
... ...
... ... @@ -6,6 +6,7 @@ import com.yoho.core.security.WechatException;
import com.yoho.core.security.WechatHelper;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.PaymentData;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.common.utils.HttpClient;
import com.yohoufo.common.utils.TimeUtils;
... ... @@ -15,7 +16,6 @@ import com.yohoufo.order.constants.RefundContant;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohoufo.order.model.PayQueryBo;
import com.yohoufo.order.model.PayRefundBo;
import com.yohoufo.order.model.PaymentData;
import com.yohoufo.order.service.PaymentSupportService;
import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohobuy.ufo.model.order.bo.OutTradeNoMeta;
... ...