Authored by tanling

海关

@@ -12,6 +12,7 @@ import com.yohobuy.ufo.model.order.bo.PaymentData; @@ -12,6 +12,7 @@ import com.yohobuy.ufo.model.order.bo.PaymentData;
12 import com.yohoufo.order.service.pay.alipay.AlipayCrossBorderService; 12 import com.yohoufo.order.service.pay.alipay.AlipayCrossBorderService;
13 import com.yohoufo.order.service.pay.alipay.AbstractAlipayService; 13 import com.yohoufo.order.service.pay.alipay.AbstractAlipayService;
14 import com.yohoufo.order.service.pay.alipay.bean.AlipayCustomsResponse; 14 import com.yohoufo.order.service.pay.alipay.bean.AlipayCustomsResponse;
  15 +import com.yohoufo.order.service.pay.alipay.bean.AlipayQueryCustomsResponse;
15 import com.yohoufo.order.service.pay.unionpay.JsUnionpayService; 16 import com.yohoufo.order.service.pay.unionpay.JsUnionpayService;
16 import org.apache.commons.lang.StringUtils; 17 import org.apache.commons.lang.StringUtils;
17 import org.slf4j.Logger; 18 import org.slf4j.Logger;
@@ -121,19 +122,16 @@ public class PaymentController { @@ -121,19 +122,16 @@ public class PaymentController {
121 } 122 }
122 123
123 /** 124 /**
124 - * 跨境支付宝推送支付单 125 + * 查询海关清关情况
125 * @param orderCode 126 * @param orderCode
126 - * @param outRequestNo  
127 * @param tradeNo 127 * @param tradeNo
128 * @param amount 128 * @param amount
129 * @return 129 * @return
130 */ 130 */
131 - @RequestMapping(params = "/erp/order/customes")  
132 - public ApiResponse customs(@RequestParam(name = "orderCode") long orderCode,  
133 - @RequestParam(name = "tradeNo") String tradeNo,  
134 - @RequestParam(name = "amount") double amount){  
135 - AlipayCustomsResponse alipayCustomsResponse = paymentService.customs(orderCode, tradeNo, amount);  
136 - return new ApiResponse.ApiResponseBuilder().code(PrepayResponse.SUCCESS).data(alipayCustomsResponse).message("推送支付单").build(); 131 + @RequestMapping(params = "/erp/order/queryCustoms")
  132 + public ApiResponse queryCustoms(@RequestParam(name = "orderCode") long orderCode){
  133 + AlipayQueryCustomsResponse alipayCustomsResponse = paymentService.queryCustoms(orderCode);
  134 + return new ApiResponse.ApiResponseBuilder().code(PrepayResponse.SUCCESS).data(alipayCustomsResponse).message("查询海关清关情况").build();
137 } 135 }
138 136
139 137
@@ -13,6 +13,7 @@ import com.yohobuy.ufo.model.order.constants.OrderConstant; @@ -13,6 +13,7 @@ import com.yohobuy.ufo.model.order.constants.OrderConstant;
13 import com.yohobuy.ufo.model.order.constants.SkupType; 13 import com.yohobuy.ufo.model.order.constants.SkupType;
14 import com.yohobuy.ufo.model.order.req.SellerDeliverToDepotReq; 14 import com.yohobuy.ufo.model.order.req.SellerDeliverToDepotReq;
15 import com.yohoufo.common.alarm.EventBusPublisher; 15 import com.yohoufo.common.alarm.EventBusPublisher;
  16 +import com.yohoufo.common.exception.UfoServiceException;
16 import com.yohoufo.common.utils.DateUtil; 17 import com.yohoufo.common.utils.DateUtil;
17 import com.yohoufo.common.utils.StringUtil; 18 import com.yohoufo.common.utils.StringUtil;
18 import com.yohoufo.dal.order.BuyerOrderGoodsMapper; 19 import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
@@ -20,7 +21,9 @@ import com.yohoufo.dal.order.BuyerOrderMapper; @@ -20,7 +21,9 @@ import com.yohoufo.dal.order.BuyerOrderMapper;
20 import com.yohoufo.dal.order.BuyerOrderMetaMapper; 21 import com.yohoufo.dal.order.BuyerOrderMetaMapper;
21 import com.yohoufo.dal.order.SellerOrderGoodsMapper; 22 import com.yohoufo.dal.order.SellerOrderGoodsMapper;
22 import com.yohoufo.dal.order.model.*; 23 import com.yohoufo.dal.order.model.*;
  24 +import com.yohoufo.dal.user.model.ZhiMaCert;
23 import com.yohoufo.order.constants.ClearanceFailType; 25 import com.yohoufo.order.constants.ClearanceFailType;
  26 +import com.yohoufo.order.constants.ClientSpecialSemanticCode;
24 import com.yohoufo.order.constants.MetaKey; 27 import com.yohoufo.order.constants.MetaKey;
25 import com.yohoufo.order.event.DeliverNoticeEvent; 28 import com.yohoufo.order.event.DeliverNoticeEvent;
26 import com.yohoufo.order.event.ErpBuyerOrderEvent; 29 import com.yohoufo.order.event.ErpBuyerOrderEvent;
@@ -38,6 +41,7 @@ import com.yohoufo.order.service.pay.alipay.AlipayCrossBorderService; @@ -38,6 +41,7 @@ import com.yohoufo.order.service.pay.alipay.AlipayCrossBorderService;
38 import com.yohoufo.order.service.pay.alipay.bean.AlipayCustomsResponse; 41 import com.yohoufo.order.service.pay.alipay.bean.AlipayCustomsResponse;
39 import com.yohoufo.order.service.pay.alipay.bean.CustomsErrorMsg; 42 import com.yohoufo.order.service.pay.alipay.bean.CustomsErrorMsg;
40 import com.yohoufo.order.service.proxy.*; 43 import com.yohoufo.order.service.proxy.*;
  44 +import com.yohoufo.order.service.support.CustomsSupportService;
41 import com.yohoufo.order.utils.BuyerOrderUtils; 45 import com.yohoufo.order.utils.BuyerOrderUtils;
42 import com.yohoufo.order.utils.SellerGoodsHelper; 46 import com.yohoufo.order.utils.SellerGoodsHelper;
43 import com.yohoufo.order.utils.TimeUtils; 47 import com.yohoufo.order.utils.TimeUtils;
@@ -122,6 +126,13 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService { @@ -122,6 +126,13 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService {
122 BuyerOrderCancelService buyerOrderCancelService; 126 BuyerOrderCancelService buyerOrderCancelService;
123 127
124 128
  129 + @Autowired
  130 + private UserProxyService userProxyService;
  131 +
  132 + @Autowired
  133 + CustomsSupportService customsSupportService;
  134 +
  135 +
125 136
126 private ExecutorService executors = Executors.newFixedThreadPool(1); 137 private ExecutorService executors = Executors.newFixedThreadPool(1);
127 138
@@ -460,25 +471,8 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService { @@ -460,25 +471,8 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService {
460 case OVERSEAS_IN_STOCK: 471 case OVERSEAS_IN_STOCK:
461 processOverSeasOrder(buyerOrder, sellerOrderGoods); 472 processOverSeasOrder(buyerOrder, sellerOrderGoods);
462 473
463 - // 跨境支付 推送支付单  
464 - if (buyerOrder.getPayment() == Payment.CROSS_BORDER_ALIPAY.getCode() && orderInfo.getPaymentData()!=null){  
465 - String tradeNo = orderInfo.getPaymentData().getTradeNo();  
466 - try{  
467 - AlipayCustomsResponse alipayCustomsResponse = crossBorderService.customsOpenApi(buyerOrder.getOrderCode(),  
468 - tradeNo, buyerOrder.getAmount().doubleValue());  
469 - if ("F".equalsIgnoreCase(alipayCustomsResponse.getIs_success())){  
470 -  
471 - String error = StringUtils.isEmpty(alipayCustomsResponse.getResult_code()) ? alipayCustomsResponse.getError() : alipayCustomsResponse.getResult_code();  
472 - buyerOrderCancelService.clearanceFail(buyerOrder.getOrderCode(),  
473 - CustomsErrorMsg.getCustomsError(error),  
474 - ClearanceFailType.BUYER);  
475 -  
476 - logger.warn("customs error. {},{},{}",buyerOrder.getOrderCode(), tradeNo, buyerOrder.getAmount().doubleValue());  
477 - }  
478 - }catch (Exception e){  
479 - logger.warn("customs error. {},{},{},{},{}",buyerOrder.getOrderCode(), tradeNo, buyerOrder.getAmount().doubleValue(),e);  
480 - }  
481 - } 474 + // 推送支付单到海关
  475 + customsSupportService.sendPaymentInfoToCustoms(orderCode, uid);
482 476
483 break; 477 break;
484 478
@@ -12,18 +12,18 @@ import com.yohoufo.order.model.response.PaymentConfirmRsp; @@ -12,18 +12,18 @@ import com.yohoufo.order.model.response.PaymentConfirmRsp;
12 import com.yohoufo.order.model.response.PrepayResponse; 12 import com.yohoufo.order.model.response.PrepayResponse;
13 import com.yohoufo.order.service.pay.AbstractPayService; 13 import com.yohoufo.order.service.pay.AbstractPayService;
14 import com.yohoufo.order.service.pay.alipay.bean.AlipayCustomsResponse; 14 import com.yohoufo.order.service.pay.alipay.bean.AlipayCustomsResponse;
  15 +import com.yohoufo.order.service.pay.alipay.bean.AlipayQueryCustomsResponse;
15 16
16 public interface IPaymentService { 17 public interface IPaymentService {
17 18
18 19
19 /** 20 /**
20 - * 推送支付单 21 + * 海关清关状态查询
21 * @param orderCode 22 * @param orderCode
22 - * @param tradeNo  
23 - * @param amount  
24 * @return 23 * @return
25 */ 24 */
26 - public AlipayCustomsResponse customs(long orderCode, String tradeNo, double amount); 25 + public AlipayQueryCustomsResponse queryCustoms(long orderCode);
  26 +
27 27
28 /** 28 /**
29 * 获取订单信息(买家订单|卖家订单|入驻充值) 29 * 获取订单信息(买家订单|卖家订单|入驻充值)
@@ -51,12 +51,14 @@ import com.yohoufo.order.service.pay.AbstractPayService; @@ -51,12 +51,14 @@ import com.yohoufo.order.service.pay.AbstractPayService;
51 import com.yohoufo.order.service.pay.alipay.AlipayCrossBorderService; 51 import com.yohoufo.order.service.pay.alipay.AlipayCrossBorderService;
52 import com.yohoufo.order.service.pay.alipay.AlipayOuyinService; 52 import com.yohoufo.order.service.pay.alipay.AlipayOuyinService;
53 import com.yohoufo.order.service.pay.alipay.bean.AlipayCustomsResponse; 53 import com.yohoufo.order.service.pay.alipay.bean.AlipayCustomsResponse;
  54 +import com.yohoufo.order.service.pay.alipay.bean.AlipayQueryCustomsResponse;
54 import com.yohoufo.order.service.pay.alipay.bean.CustomsErrorMsg; 55 import com.yohoufo.order.service.pay.alipay.bean.CustomsErrorMsg;
55 import com.yohoufo.order.service.pay.unionpay.JsUnionpayService; 56 import com.yohoufo.order.service.pay.unionpay.JsUnionpayService;
56 import com.yohoufo.order.service.pay.wallet.WalletPayService; 57 import com.yohoufo.order.service.pay.wallet.WalletPayService;
57 import com.yohoufo.order.service.pay.weixin.WeixinMiniappPayService; 58 import com.yohoufo.order.service.pay.weixin.WeixinMiniappPayService;
58 import com.yohoufo.order.service.pay.weixin.WeixinPayUFORealAppService; 59 import com.yohoufo.order.service.pay.weixin.WeixinPayUFORealAppService;
59 import com.yohoufo.order.service.proxy.WalletTransferService; 60 import com.yohoufo.order.service.proxy.WalletTransferService;
  61 +import com.yohoufo.order.service.support.CustomsSupportService;
60 import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; 62 import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
61 import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta; 63 import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
62 import com.yohoufo.order.service.transfer.TransferResult; 64 import com.yohoufo.order.service.transfer.TransferResult;
@@ -187,29 +189,24 @@ public class PaymentServiceImpl implements IPaymentService { @@ -187,29 +189,24 @@ public class PaymentServiceImpl implements IPaymentService {
187 @Autowired 189 @Autowired
188 private AlipayCrossBorderService crossBorderService; 190 private AlipayCrossBorderService crossBorderService;
189 191
190 - @Autowired  
191 - BuyerOrderCancelService buyerOrderCancelService;  
192 -  
193 /** 192 /**
194 - * 推送支付单 193 + * 海关清关状态查询
195 * @param orderCode 194 * @param orderCode
196 - * @param tradeNo  
197 - * @param amount  
198 * @return 195 * @return
199 */ 196 */
200 - public AlipayCustomsResponse customs(long orderCode, String tradeNo, double amount){ 197 + public AlipayQueryCustomsResponse queryCustoms(long orderCode){
201 198
202 - if (orderCode<0  
203 - || StringUtils.isEmpty(tradeNo)  
204 - || amount < 0){  
205 - logger.warn("payConfirm request empty"); 199 + if (orderCode<0){
  200 + logger.warn("queryCustoms request empty");
206 throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY); 201 throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
207 } 202 }
208 203
209 - return crossBorderService.customsOpenApi(orderCode,tradeNo, amount); 204 + return crossBorderService.customsOpenQueryApi(orderCode);
210 205
211 } 206 }
212 207
  208 +
  209 +
213 /** 210 /**
214 * 订单支付结果确认 211 * 订单支付结果确认
215 * 212 *
@@ -3,13 +3,13 @@ package com.yohoufo.order.service.pay.alipay; @@ -3,13 +3,13 @@ package com.yohoufo.order.service.pay.alipay;
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import com.yohobuy.ufo.model.order.bo.OrderInfo; 4 import com.yohobuy.ufo.model.order.bo.OrderInfo;
5 import com.yohoufo.common.utils.DateUtil; 5 import com.yohoufo.common.utils.DateUtil;
6 -import com.yohoufo.common.utils.RSAUtils;  
7 import com.yohoufo.common.utils.XMLUtil; 6 import com.yohoufo.common.utils.XMLUtil;
8 import com.yohoufo.order.config.AlipayConfig; 7 import com.yohoufo.order.config.AlipayConfig;
9 import com.yohoufo.order.constants.RefundContant; 8 import com.yohoufo.order.constants.RefundContant;
10 import com.yohoufo.order.model.PayQueryBo; 9 import com.yohoufo.order.model.PayQueryBo;
11 import com.yohoufo.order.model.PayRefundBo; 10 import com.yohoufo.order.model.PayRefundBo;
12 import com.yohoufo.order.service.pay.alipay.bean.AlipayCustomsResponse; 11 import com.yohoufo.order.service.pay.alipay.bean.AlipayCustomsResponse;
  12 +import com.yohoufo.order.service.pay.alipay.bean.AlipayQueryCustomsResponse;
13 import com.yohoufo.order.service.pay.alipay.bean.AlipayQueryResponse; 13 import com.yohoufo.order.service.pay.alipay.bean.AlipayQueryResponse;
14 import com.yohoufo.order.service.pay.alipay.bean.AlipayRefundResponse; 14 import com.yohoufo.order.service.pay.alipay.bean.AlipayRefundResponse;
15 import lombok.AccessLevel; 15 import lombok.AccessLevel;
@@ -85,11 +85,11 @@ public class AlipayCrossBorderService extends AbstractAlipayService { @@ -85,11 +85,11 @@ public class AlipayCrossBorderService extends AbstractAlipayService {
85 } 85 }
86 86
87 87
88 - public AlipayCustomsResponse customsOpenApi(long orderCode, String tradeNo, double amount){ 88 + public AlipayCustomsResponse customsOpenApi(long orderCode, String tradeNo, double amount, String certName, String certNo){
89 89
90 - logger.info("enter customsOpenApi to {}, {}, {}", orderCode, tradeNo, amount); 90 + logger.info("enter customsOpenApi to {}, {}, {}, {}, {}", orderCode, tradeNo, amount, certName, certNo);
91 91
92 - Map<String, String> customsParam = buildOpenApiCustoms(orderCode, tradeNo, amount); 92 + Map<String, String> customsParam = buildOpenApiCustoms(orderCode, tradeNo, amount,certName, certNo);
93 String respTxt = sendOpenApiRequest(String.valueOf(orderCode), customsParam, alipayConfig.crossBorderMapiUrl()); 93 String respTxt = sendOpenApiRequest(String.valueOf(orderCode), customsParam, alipayConfig.crossBorderMapiUrl());
94 94
95 AlipayCustomsResponse customsResponse = (AlipayCustomsResponse)XMLUtil.convertXmlStrToObject(AlipayCustomsResponse.class, respTxt); 95 AlipayCustomsResponse customsResponse = (AlipayCustomsResponse)XMLUtil.convertXmlStrToObject(AlipayCustomsResponse.class, respTxt);
@@ -101,14 +101,14 @@ public class AlipayCrossBorderService extends AbstractAlipayService { @@ -101,14 +101,14 @@ public class AlipayCrossBorderService extends AbstractAlipayService {
101 } 101 }
102 102
103 103
104 - public AlipayCustomsResponse customsOpenQueryApi(long orderCode){ 104 + public AlipayQueryCustomsResponse customsOpenQueryApi(long orderCode){
105 105
106 logger.info("enter customsOpenQueryApi to {}", orderCode); 106 logger.info("enter customsOpenQueryApi to {}", orderCode);
107 107
108 Map<String, String> customsParam = buildOpenApiQueryCustoms(orderCode); 108 Map<String, String> customsParam = buildOpenApiQueryCustoms(orderCode);
109 String respTxt = sendOpenApiRequest(String.valueOf(orderCode), customsParam, alipayConfig.crossBorderMapiUrl()); 109 String respTxt = sendOpenApiRequest(String.valueOf(orderCode), customsParam, alipayConfig.crossBorderMapiUrl());
110 110
111 - AlipayCustomsResponse customsResponse = (AlipayCustomsResponse)XMLUtil.convertXmlStrToObject(AlipayCustomsResponse.class, respTxt); 111 + AlipayQueryCustomsResponse customsResponse = (AlipayQueryCustomsResponse)XMLUtil.convertXmlStrToObject(AlipayQueryCustomsResponse.class, respTxt);
112 112
113 logger.info("exit customsOpenApi, result {}", customsResponse); 113 logger.info("exit customsOpenApi, result {}", customsResponse);
114 114
@@ -166,9 +166,11 @@ public class AlipayCrossBorderService extends AbstractAlipayService { @@ -166,9 +166,11 @@ public class AlipayCrossBorderService extends AbstractAlipayService {
166 * @param orderCode 166 * @param orderCode
167 * @param tradeNo 167 * @param tradeNo
168 * @param amount 168 * @param amount
  169 + * @param certName
  170 + * @param certNo
169 * @return 171 * @return
170 */ 172 */
171 - private Map<String, String> buildOpenApiCustoms(long orderCode, String tradeNo, double amount){ 173 + private Map<String, String> buildOpenApiCustoms(long orderCode, String tradeNo, double amount, String certName, String certNo){
172 174
173 Map<String, String> params = new HashMap<>(); 175 Map<String, String> params = new HashMap<>();
174 176
@@ -184,6 +186,8 @@ public class AlipayCrossBorderService extends AbstractAlipayService { @@ -184,6 +186,8 @@ public class AlipayCrossBorderService extends AbstractAlipayService {
184 params.put("amount", String.valueOf(amount)); 186 params.put("amount", String.valueOf(amount));
185 params.put("customs_place", getCustomsPlace()); 187 params.put("customs_place", getCustomsPlace());
186 params.put("merchant_customs_name", getMerchantCustomsName()); 188 params.put("merchant_customs_name", getMerchantCustomsName());
  189 + params.put("buyer_name", certName);
  190 + params.put("buyer_id_no", certNo);
187 191
188 String preSignStr = getOpenApiSignString(params, true); 192 String preSignStr = getOpenApiSignString(params, true);
189 params.put("sign", helper().sign(preSignStr,AlipayConfig.input_charset)); 193 params.put("sign", helper().sign(preSignStr,AlipayConfig.input_charset));
1 package com.yohoufo.order.service.pay.alipay.bean; 1 package com.yohoufo.order.service.pay.alipay.bean;
2 2
3 -import lombok.Data;  
4 -import lombok.ToString;  
5 -  
6 -import javax.xml.bind.annotation.XmlAccessType;  
7 -import javax.xml.bind.annotation.XmlAccessorType; 3 +import javax.xml.bind.annotation.XmlElement;
8 import javax.xml.bind.annotation.XmlRootElement; 4 import javax.xml.bind.annotation.XmlRootElement;
9 import java.util.List; 5 import java.util.List;
10 6
11 -@XmlAccessorType(XmlAccessType.FIELD)  
12 @XmlRootElement(name = "alipay") 7 @XmlRootElement(name = "alipay")
13 -@ToString  
14 -@Data  
15 public class AlipayQueryCustomsResponse { 8 public class AlipayQueryCustomsResponse {
16 9
  10 + private Response response;
  11 +
17 private String is_success; 12 private String is_success;
18 13
  14 + private String error;
  15 +
  16 + @XmlElement(name = "error")
  17 + public String getError() {
  18 + return error;
  19 + }
19 20
  21 + @XmlElement(name="is_success")
  22 + public String getIs_success() {
  23 + return is_success;
  24 + }
20 25
21 - public static class Records{  
22 - List<CustomsDeclare> customs_declare; 26 + @XmlElement(name = "response")
  27 + public Response getResponse() {
  28 + return response;
23 } 29 }
24 30
25 - public static class CustomsDeclare{  
26 - private String out_request_no;  
27 - private String status; 31 + public void setResponse(Response response) {
  32 + this.response = response;
28 } 33 }
29 34
  35 + public void setIs_success(String is_success) {
  36 + this.is_success = is_success;
  37 + }
  38 +
  39 + public static class Response {
  40 +
  41 + private Alipay alipay;
  42 +
  43 + @XmlElement(name = "alipay")
  44 + public Alipay getAlipay() {
  45 + return alipay;
  46 + }
  47 +
  48 + public void setAlipay(Alipay alipay) {
  49 + this.alipay = alipay;
  50 + }
  51 +
  52 +
  53 + public static class Alipay {
  54 + private Records records;
  55 +
  56 + private String result_code;
  57 +
  58 + private String detail_error_code;
  59 +
  60 + private String detail_error_des;
  61 +
  62 + @XmlElement(name = "detail_error_des")
  63 + public String getDetail_error_des() {
  64 + return detail_error_des;
  65 + }
  66 +
  67 + @XmlElement(name = "detail_error_code")
  68 + public String getDetail_error_code() {
  69 + return detail_error_code;
  70 + }
  71 +
  72 + @XmlElement(name = "records")
  73 + public Records getRecords() {
  74 + return records;
  75 + }
  76 +
  77 + public void setRecords(Records records) {
  78 + this.records = records;
  79 + }
  80 +
  81 + @XmlElement(name = "result_code")
  82 + public String getResult_code() {
  83 + return result_code;
  84 + }
  85 +
  86 + public void setResult_code(String result_code) {
  87 + this.result_code = result_code;
  88 + }
  89 +
  90 + public void setDetail_error_code(String detail_error_code) {
  91 + this.detail_error_code = detail_error_code;
  92 + }
  93 +
  94 + public void setDetail_error_des(String detail_error_des) {
  95 + this.detail_error_des = detail_error_des;
  96 + }
  97 + }
  98 +
  99 + public static class Records {
  100 +
  101 + private List<CustomsDeclare> records;
  102 +
  103 +
  104 +
  105 + @XmlElement(name="customs_declare")
  106 + public List<CustomsDeclare> getRecords() {
  107 + return records;
  108 + }
  109 +
  110 +
  111 +
  112 + public void setRecords(List<CustomsDeclare> records) {
  113 + this.records = records;
  114 + }
  115 +
  116 +
  117 + }
  118 +
  119 + public static class CustomsDeclare {
  120 +
  121 + private String out_request_no;
  122 + private String status;
  123 +
  124 +
  125 + @XmlElement(name = "out_request_no")
  126 + public String getOut_request_no() {
  127 + return out_request_no;
  128 + }
  129 +
  130 + @XmlElement(name = "status")
  131 + public String getStatus() {
  132 + return status;
  133 + }
  134 +
  135 +
  136 + public void setOut_request_no(String out_request_no) {
  137 + this.out_request_no = out_request_no;
  138 + }
  139 +
  140 + public void setStatus(String status) {
  141 + this.status = status;
  142 + }
  143 + }
  144 + }
30 } 145 }
@@ -9,7 +9,8 @@ public enum CustomsErrorMsg { @@ -9,7 +9,8 @@ public enum CustomsErrorMsg {
9 CONTEXT_INCONSISTENT("不能发送多次,且参数不一致"), 9 CONTEXT_INCONSISTENT("不能发送多次,且参数不一致"),
10 SAME_CUSTOMS_DECLARE_ONCE("同一笔交易,只能在海关处申报一次"), 10 SAME_CUSTOMS_DECLARE_ONCE("同一笔交易,只能在海关处申报一次"),
11 REQUEST_AMOUNT_EXCEED("申报的总金额超过了交易金额"), 11 REQUEST_AMOUNT_EXCEED("申报的总金额超过了交易金额"),
12 - PAYER_ENABLE_STATUS_FORBID("声明的交易中付款人的身份无法通过验证"); 12 + PAYER_ENABLE_STATUS_FORBID("支付宝账户失效"),
  13 + IDENTITY_CHECK_F("订购人与实名认证信息不一致");
13 14
14 15
15 private String msg; 16 private String msg;
  1 +package com.yohoufo.order.service.support;
  2 +
  3 +import com.yohobuy.ufo.model.order.common.OrderAttributes;
  4 +import com.yohobuy.ufo.model.order.common.Payment;
  5 +import com.yohoufo.dal.order.BuyerOrderMapper;
  6 +import com.yohoufo.dal.order.OrdersPayMapper;
  7 +import com.yohoufo.dal.order.model.BuyerOrder;
  8 +import com.yohoufo.dal.order.model.OrdersPay;
  9 +import com.yohoufo.dal.user.model.ZhiMaCert;
  10 +import com.yohoufo.order.constants.ClearanceFailType;
  11 +import com.yohoufo.order.service.impl.BuyerOrderCancelService;
  12 +import com.yohoufo.order.service.pay.alipay.AlipayCrossBorderService;
  13 +import com.yohoufo.order.service.pay.alipay.bean.AlipayCustomsResponse;
  14 +import com.yohoufo.order.service.pay.alipay.bean.CustomsErrorMsg;
  15 +import com.yohoufo.order.service.proxy.UserProxyService;
  16 +import org.apache.commons.lang3.StringUtils;
  17 +import org.slf4j.Logger;
  18 +import org.slf4j.LoggerFactory;
  19 +import org.springframework.beans.factory.annotation.Autowired;
  20 +import org.springframework.stereotype.Service;
  21 +
  22 +@Service
  23 +public class CustomsSupportService {
  24 +
  25 + private final Logger logger = LoggerFactory.getLogger(CustomsSupportService.class);
  26 +
  27 + @Autowired
  28 + OrdersPayMapper ordersPayMapper;
  29 +
  30 + @Autowired
  31 + BuyerOrderMapper buyerOrderMapper;
  32 +
  33 + @Autowired
  34 + private UserProxyService userProxyService;
  35 +
  36 + @Autowired
  37 + private AlipayCrossBorderService crossBorderService;
  38 +
  39 + @Autowired
  40 + BuyerOrderCancelService buyerOrderCancelService;
  41 +
  42 +
  43 + /**
  44 + * 推送支付单到海关
  45 + * @param orderCode
  46 + * @param uid
  47 + */
  48 + public void sendPaymentInfoToCustoms(long orderCode, int uid){
  49 +
  50 + BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
  51 + if (buyerOrder == null){
  52 + logger.warn("sendPaymentInfoToCustoms orderCode info not exist {},{}", orderCode, uid);
  53 + return;
  54 + }
  55 +
  56 + OrdersPay ordersPay = ordersPayMapper.selectOrdersPay(orderCode, uid);
  57 +
  58 + if (ordersPay == null){
  59 + logger.warn("sendPaymentInfoToCustoms orderCode has not paid {},{}", orderCode, uid);
  60 + return;
  61 + }
  62 +
  63 + // 海外+跨境支付
  64 + if (ordersPay.getPayment() == Payment.CROSS_BORDER_ALIPAY.getCode() && buyerOrder.getAttributes() == OrderAttributes.OVERSEAS_IN_STOCK.getCode()){
  65 +
  66 + // 校验是否实名认证
  67 + ZhiMaCert zhimaCert = userProxyService.getRealNameInfo(uid);
  68 + if (zhimaCert == null){
  69 + logger.warn("sendPaymentInfoToCustoms: need realName cert, uid is {}", uid);
  70 + return;
  71 + }
  72 +
  73 + try{
  74 + AlipayCustomsResponse alipayCustomsResponse = crossBorderService.customsOpenApi(buyerOrder.getOrderCode(),
  75 + ordersPay.getSerialNo(), ordersPay.getAmount().doubleValue(), zhimaCert.getCertName(), zhimaCert.getCertNo());
  76 +
  77 + // 推送失败 || 下单人和支付人不一致
  78 + if ("F".equalsIgnoreCase(alipayCustomsResponse.getIs_success()) || "F".equalsIgnoreCase(alipayCustomsResponse.getIdentity_check())){
  79 +
  80 + String error = StringUtils.isEmpty(alipayCustomsResponse.getResult_code()) ? alipayCustomsResponse.getError() : alipayCustomsResponse.getResult_code();
  81 +
  82 + if ("F".equalsIgnoreCase(alipayCustomsResponse.getIdentity_check())){
  83 + error = CustomsErrorMsg.IDENTITY_CHECK_F.name();
  84 + }
  85 +
  86 + // 支付单推送失败
  87 + buyerOrderCancelService.clearanceFail(buyerOrder.getOrderCode(),
  88 + CustomsErrorMsg.getCustomsError(error),
  89 + ClearanceFailType.BUYER);
  90 +
  91 + logger.warn("sendPaymentInfoToCustoms error.{}, {}",orderCode, uid);
  92 + }
  93 + }catch (Exception e){
  94 + logger.warn("sendPaymentInfoToCustoms error. {}, {}, {}", orderCode, uid, e);
  95 + }
  96 + }
  97 + }
  98 +}