|
@@ -2,6 +2,7 @@ package com.emato.cuspay.wx.declare;
|
|
|
|
|
|
import com.emato.cuspay.base.merch.MerchCusService;
|
|
|
import com.emato.cuspay.base.merch.MerchNotiService;
|
|
|
+import com.emato.cuspay.common.contant.MerchNoticeDict;
|
|
|
import com.emato.cuspay.dto.merch.MerchCusCfg;
|
|
|
import com.emato.cuspay.wx.common.MerchNotiBuilder;
|
|
|
import com.emato.cuspay.wx.common.WxContants;
|
|
@@ -50,10 +51,10 @@ public class WxCusDeclare extends AbstractCusDeclare implements CusDeclare{
|
|
|
private static final Logger logger = LoggerFactory.getLogger(WxCusDeclare.class);
|
|
|
|
|
|
|
|
|
- @Value("${db.wx.notify.limit}")
|
|
|
+ @Value("${db.wx.declare.limit}")
|
|
|
private Integer limit;
|
|
|
|
|
|
- @Value("${wx.notice.count}")
|
|
|
+ @Value("${db.merch.notice.count}")
|
|
|
private Integer count;
|
|
|
|
|
|
@Value("${wx.payment.declare.url}")
|
|
@@ -90,9 +91,15 @@ public class WxCusDeclare extends AbstractCusDeclare implements CusDeclare{
|
|
|
wxCbPayDocs.forEach(wxCbPayDoc -> {
|
|
|
wxCbPayDoc.setDocStatus(WxDict.PaymentDocStatus.i_01.getItem());
|
|
|
});
|
|
|
- int wxResult = wxCbPayDocService.updateBatch(wxCbPayDocs);
|
|
|
- if (wxResult < 0) {
|
|
|
- logger.error("批量更新待申报的微信推海关支付数据失败size:"+wxCbPayDocs.size()+" data:"+wxCbPayDocs);
|
|
|
+
|
|
|
+ try {
|
|
|
+ int reslut = wxCbPayDocService.updateBatch(wxCbPayDocs);
|
|
|
+ if (reslut < 0) {
|
|
|
+ throw new Exception("批量更新失败影响行数为0");
|
|
|
+ }
|
|
|
+ } catch(Exception e) {
|
|
|
+ logger.error("微信报关数据批量更失败data:"+wxCbPayDocs, e);
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -188,7 +195,18 @@ public class WxCusDeclare extends AbstractCusDeclare implements CusDeclare{
|
|
|
wxCbPayDoc.setResultCode(wxResponseMsgDto.getResultCode());
|
|
|
|
|
|
//订购人与支付人校验结果
|
|
|
- builder.certCheckResult(wxResponseMsgDto.getCertCheckResult());
|
|
|
+ if (wxResponseMsgDto.getCertCheckResult() != null) {
|
|
|
+ if ("UNCHECKED".equals(wxResponseMsgDto.getCertCheckResult())) { //未知
|
|
|
+ builder.certCheckResult(MerchNoticeDict.BuyerPayerCheckStatus.i_0.getItem());
|
|
|
+ }
|
|
|
+ if ("SAME".equals(wxResponseMsgDto.getCertCheckResult())) {//一致
|
|
|
+ builder.certCheckResult(MerchNoticeDict.BuyerPayerCheckStatus.i_1.getItem());
|
|
|
+ }
|
|
|
+ if ("DIFFERENT".equals(wxResponseMsgDto.getCertCheckResult())) {//不一致
|
|
|
+ builder.certCheckResult(MerchNoticeDict.BuyerPayerCheckStatus.i_2.getItem());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
//返回状态未申报
|
|
|
if (WxDict.ResponseMsgState.UNDECLARED.getItem().equals(wxResponseMsgDto.getState())) {
|
|
@@ -281,23 +299,35 @@ public class WxCusDeclare extends AbstractCusDeclare implements CusDeclare{
|
|
|
}
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
+ logger.error("数据请求异常的支付单请求数据为xml:"+xml, e);
|
|
|
WxPayError wxPayError = createWxPayError(wxCbPayDoc);
|
|
|
errors.add(wxPayError);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
//持久化商户通知数据
|
|
|
- int result = merchNotiService.insertBatch(merchNotis);
|
|
|
- if (result < 0) {
|
|
|
- logger.error("持久化"+result+"条商户通知数据失败data:"+merchNotis);
|
|
|
+ try {
|
|
|
+ int result = merchNotiService.insertBatch(merchNotis);
|
|
|
+ if (result < 0) {
|
|
|
+ logger.error("持久化" + result + "条商户通知数据失败data:" + merchNotis);
|
|
|
+ throw new Exception("持久化" + result + "条商户通知数据失败data:" + merchNotis);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("持久化商户通知数据异常", e);
|
|
|
+ return;
|
|
|
}
|
|
|
-
|
|
|
//存储异常记录
|
|
|
- if (errors != null && !errors.isEmpty()) {
|
|
|
- int errResult = wxPayErrorService.insertWxPayErrorBatch(errors);
|
|
|
- if (errResult < 0) {
|
|
|
- logger.error("持久化支付申报异常信息数据失败data:"+errors);
|
|
|
+ try {
|
|
|
+ if (errors != null && !errors.isEmpty()) {
|
|
|
+ int errResult = wxPayErrorService.insertWxPayErrorBatch(errors);
|
|
|
+ if (errResult < 0) {
|
|
|
+ logger.error("持久化支付申报异常信息数据失败data:" + errors);
|
|
|
+ throw new Exception("持久化支付申报异常信息数据失败data:" + errors);
|
|
|
+ }
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("持久化支付申报异常信息数据失败data:" + errors, e);
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -320,6 +350,8 @@ public class WxCusDeclare extends AbstractCusDeclare implements CusDeclare{
|
|
|
wxPayError.setCustoms(wxCbPayDoc.getCustoms());
|
|
|
wxPayError.setErrCode(wxCbPayDoc.getErrCode());
|
|
|
wxPayError.setErrMsg(wxCbPayDoc.getReturnMsg());
|
|
|
+ //TODO:
|
|
|
+ wxPayError.getCreateTime();
|
|
|
return wxPayError;
|
|
|
}
|
|
|
|
|
@@ -345,13 +377,13 @@ public class WxCusDeclare extends AbstractCusDeclare implements CusDeclare{
|
|
|
if (wxCbPayDoc.getDuty() != null) {
|
|
|
sorted.put("duty", String.valueOf(wxCbPayDoc.getDuty()));
|
|
|
}
|
|
|
- if (wxCbPayDoc.getActionType() != null) {
|
|
|
+ if (wxCbPayDoc.getActionType() != null && !wxCbPayDoc.getActionType().isEmpty()) {
|
|
|
sorted.put("action_type", wxCbPayDoc.getActionType());
|
|
|
}
|
|
|
- if (wxCbPayDoc.getSubOrderNo() != null) {
|
|
|
+ if (wxCbPayDoc.getSubOrderNo() != null && !wxCbPayDoc.getSubOrderNo().isEmpty()) {
|
|
|
sorted.put("sub_order_no", wxCbPayDoc.getActionType());
|
|
|
}
|
|
|
- if (wxCbPayDoc.getFeeType() != null) {
|
|
|
+ if (wxCbPayDoc.getFeeType() != null && !wxCbPayDoc.getFeeType().isEmpty()) {
|
|
|
sorted.put("fee_type", wxCbPayDoc.getFeeType());
|
|
|
}
|
|
|
if (wxCbPayDoc.getOrderFee() != null) {
|
|
@@ -363,13 +395,13 @@ public class WxCusDeclare extends AbstractCusDeclare implements CusDeclare{
|
|
|
if (wxCbPayDoc.getProductFee() != null) {
|
|
|
sorted.put("product_fee", String.valueOf(wxCbPayDoc.getProductFee()));
|
|
|
}
|
|
|
- if (wxCbPayDoc.getCertType() != null ) {
|
|
|
+ if (wxCbPayDoc.getCertType() != null && !wxCbPayDoc.getCertType().isEmpty()) {
|
|
|
sorted.put("cert_type", wxCbPayDoc.getCertType());
|
|
|
}
|
|
|
- if (wxCbPayDoc.getCertId() != null) {
|
|
|
+ if (wxCbPayDoc.getCertId() != null && !wxCbPayDoc.getCertId().isEmpty()) {
|
|
|
sorted.put("cert_id", wxCbPayDoc.getCertId());
|
|
|
}
|
|
|
- if (wxCbPayDoc.getName() != null) {
|
|
|
+ if (wxCbPayDoc.getName() != null && !wxCbPayDoc.getName().isEmpty()) {
|
|
|
sorted.put("name", wxCbPayDoc.getName());
|
|
|
}
|
|
|
|
|
@@ -388,10 +420,10 @@ public class WxCusDeclare extends AbstractCusDeclare implements CusDeclare{
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
WxCbPayDoc wxCbPayDoc = new WxCbPayDoc();
|
|
|
- wxCbPayDoc.setAppid("wxd678efh567hg6787");
|
|
|
+ wxCbPayDoc.setAppid("wx24013b34e349db3c");
|
|
|
wxCbPayDoc.setMchId("1501125641");
|
|
|
- wxCbPayDoc.setOutTradeNo("205598019850");
|
|
|
- wxCbPayDoc.setTransactionId("401020180502000000011943");
|
|
|
+ wxCbPayDoc.setOutTradeNo("669918012250");
|
|
|
+ wxCbPayDoc.setTransactionId("4200000120201805021020091366");
|
|
|
wxCbPayDoc.setCustoms("SHENZHEN");
|
|
|
wxCbPayDoc.setMchCustomsNo("4403160Z3Y");//中网科技(深圳)有限公司
|
|
|
|
|
@@ -417,6 +449,8 @@ public class WxCusDeclare extends AbstractCusDeclare implements CusDeclare{
|
|
|
|
|
|
String xml = XmlUtils.map2Xml(sorted);
|
|
|
|
|
|
+ System.out.println("xml:"+xml);
|
|
|
+
|
|
|
//通过http post请求 发送xml数据
|
|
|
Request request = OkHttpUtils.buildRequest("https://api.mch.weixin.qq.com/cgi-bin/mch/customs/customdeclareorder",
|
|
|
RequestBody.create(MediaType.parse("application/xml; charset=utf-8"), xml));
|