|
@@ -0,0 +1,417 @@
|
|
|
+package com.emato.cuspay.biz.wx;
|
|
|
+
|
|
|
+import com.emato.cuspay.biz.CuspayBiz;
|
|
|
+import com.emato.cuspay.common.contant.MerchNoticeDict;
|
|
|
+import com.emato.cuspay.common.contant.TablePrimaryKeyPrefix;
|
|
|
+import com.emato.cuspay.common.core.db.IdWorkerAide;
|
|
|
+import com.emato.cuspay.entity.merch.MerchNoti;
|
|
|
+import com.emato.cuspay.entity.merch.MerchPayCfg;
|
|
|
+import com.emato.cuspay.service.MerchNotiService;
|
|
|
+import com.emato.cuspay.util.OkHttpUtils;
|
|
|
+import com.emato.cuspay.util.ReaderXmlForDOM4J;
|
|
|
+import com.emato.cuspay.util.XmlUtils;
|
|
|
+import com.emato.cuspay.wx.common.MerchNotiBuilder;
|
|
|
+import com.emato.cuspay.wx.common.WxContants;
|
|
|
+import com.emato.cuspay.wx.common.WxDict;
|
|
|
+import com.emato.cuspay.wx.dto.WxQueryResponseMsg;
|
|
|
+import com.emato.cuspay.wx.dto.WxResponseMsg;
|
|
|
+import com.emato.cuspay.wx.entity.WxCbPayDoc;
|
|
|
+import com.emato.cuspay.wx.entity.WxPayError;
|
|
|
+import com.emato.cuspay.wx.service.WxCbPayDocService;
|
|
|
+import com.emato.cuspay.wx.service.WxPayErrorService;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+import okhttp3.MediaType;
|
|
|
+import okhttp3.Request;
|
|
|
+import okhttp3.RequestBody;
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import javax.xml.bind.JAXB;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.StringReader;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.SortedMap;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 微信海关申报
|
|
|
+ * @author zx
|
|
|
+ * @version 1.0
|
|
|
+ * 2018-05-23 09:55
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class WxHeavyPushCusDeclareBiz extends AbstractCusDeclareBiz implements CuspayBiz {
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(WxHeavyPushCusDeclareBiz.class);
|
|
|
+
|
|
|
+ private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ @Value("${db.wx.declare.limit}")
|
|
|
+ private Integer limit;
|
|
|
+
|
|
|
+ @Value("${db.wx.declare.count}")
|
|
|
+ private Integer count;
|
|
|
+
|
|
|
+ @Value("${wx.payment.declare.deavyPushUrl}")
|
|
|
+ private String declareDeavyPushUrl;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WxCbPayDocService wxCbPayDocService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WxPayErrorService wxPayErrorService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MerchNotiService merchNotiService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 海关报关接口
|
|
|
+ */
|
|
|
+ public void biz() {
|
|
|
+ limit = (limit != null && limit > 0) ? limit : 20;
|
|
|
+ count = (count != null && count > 0) ? count : 10;
|
|
|
+
|
|
|
+ List<WxCbPayDoc> wxCbPayDocList = null;
|
|
|
+ try {
|
|
|
+ wxCbPayDocList = wxCbPayDocService.selectHeavyPushDeclaredData(limit);
|
|
|
+ if (wxCbPayDocList == null || wxCbPayDocList.isEmpty()) {
|
|
|
+ logger.info("未查到需重推的微信推海关的支付数据");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("查询需重推的微信推海关的支付数据异常", e);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新状态申报中
|
|
|
+ wxCbPayDocList.forEach(wxCbPayDoc -> {
|
|
|
+ wxCbPayDoc.setDocStatus(WxDict.PaymentDocStatus.i_01.getItem());
|
|
|
+ });
|
|
|
+
|
|
|
+ try {
|
|
|
+ int reslut = wxCbPayDocService.updateBatch(wxCbPayDocList);
|
|
|
+ if (reslut < 0) {
|
|
|
+ throw new Exception("批量更新失败影响行数为0");
|
|
|
+ }
|
|
|
+ } catch(Exception e) {
|
|
|
+ logger.error("微信报关数据批量更失败data:"+ wxCbPayDocList, e);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //记录异常数据
|
|
|
+ List<WxPayError> errors = Lists.newArrayList();
|
|
|
+ //待通知的用户
|
|
|
+ List<MerchNoti> merchNotis = Lists.newArrayList();
|
|
|
+
|
|
|
+ wxCbPayDocList.forEach(wxCbPayDoc -> {
|
|
|
+
|
|
|
+ //获取商户信息 从缓存中去 缓存不存在 从数据库重取
|
|
|
+ MerchPayCfg merchPayCfg = getMerchPayCfgCache(wxCbPayDoc.getAppid());
|
|
|
+
|
|
|
+ MerchNotiBuilder builder = new MerchNotiBuilder();
|
|
|
+
|
|
|
+ //设置支付信息
|
|
|
+ builder.wxCbPay(wxCbPayDoc);
|
|
|
+ //设置通知次数
|
|
|
+ builder.notiCount(count);
|
|
|
+
|
|
|
+ if (merchPayCfg == null) {
|
|
|
+ wxCbPayDoc.setReturnCode("FAIL");
|
|
|
+ wxCbPayDoc.setReturnMsg("appid为【"+wxCbPayDoc.getAppid()+"】的商户支付配置信息不存在");
|
|
|
+ wxCbPayDocService.updateWxCbPay(wxCbPayDoc);
|
|
|
+ logger.error("appid为【"+wxCbPayDoc.getAppid()+"】的商户支付配置信息不存在");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (merchPayCfg.getMerchWxApiKey() == null) {
|
|
|
+ wxCbPayDoc.setReturnCode(WxContants.ERROR_NO_INFOMATION);
|
|
|
+ wxCbPayDoc.setReturnMsg("appid为【"+wxCbPayDoc.getAppid()+"】的商户支付信息api密钥为空");
|
|
|
+ wxCbPayDocService.updateWxCbPay(wxCbPayDoc);
|
|
|
+ logger.error("appid为【"+wxCbPayDoc.getAppid()+"】的商户支付信息api密钥为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //设置商户配置信息
|
|
|
+ builder.merchPay(merchPayCfg);
|
|
|
+
|
|
|
+ //组装xml 格式数据
|
|
|
+ String xml = XmlUtils.map2Xml(assemblyDeclareXml(wxCbPayDoc, merchPayCfg.getMerchWxApiKey()));
|
|
|
+ logger.info("微信支付报关请求数xml据为:"+xml);
|
|
|
+
|
|
|
+ //通过http post请求 发送xml数据
|
|
|
+ Request request = OkHttpUtils.buildRequest(declareDeavyPushUrl,
|
|
|
+ RequestBody.create(MediaType.parse("application/xml; charset=utf-8"), xml));
|
|
|
+
|
|
|
+ WxResponseMsg wxResponseMsgDto = null;
|
|
|
+ try {
|
|
|
+ String result = OkHttpUtils.post(request);
|
|
|
+ StringReader reader = new StringReader(result);
|
|
|
+ wxResponseMsgDto = JAXB.unmarshal(reader, WxResponseMsg.class);
|
|
|
+ logger.info("result:"+result + "wx response message pojo:"+wxResponseMsgDto);
|
|
|
+ if (wxResponseMsgDto == null) {
|
|
|
+ throw new IOException("http请求["+declareDeavyPushUrl+"]响应结果为空" );
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("数据请求异常,支付单请求数据为xml{}", xml, e);
|
|
|
+ WxPayError wxPayError = createWxPayError(wxCbPayDoc);
|
|
|
+ errors.add(wxPayError);
|
|
|
+ }
|
|
|
+
|
|
|
+ MerchNoti merchNoti = new MerchNoti();
|
|
|
+ try {
|
|
|
+ wxCbPayDoc.setResultCode(wxResponseMsgDto.getResultCode());
|
|
|
+ wxCbPayDoc.setReturnCode(wxResponseMsgDto.getReturnCode());
|
|
|
+ wxCbPayDoc.setReturnMsg(wxResponseMsgDto.getReturnMsg());
|
|
|
+ //返回这状态码为成功 业务结果成功
|
|
|
+ if (WxContants.SUCCESS.equals(wxResponseMsgDto.getReturnCode())) {
|
|
|
+ if (WxContants.SUCCESS.equals(wxResponseMsgDto.getResultCode())) {
|
|
|
+ wxCbPayDoc.setSubOrderNo(wxResponseMsgDto.getSubOrderNo());
|
|
|
+ wxCbPayDoc.setSubOrderId(wxResponseMsgDto.getSubOrderId());
|
|
|
+
|
|
|
+ //订购人与支付人校验结果
|
|
|
+ if (!StringUtils.isEmpty(wxResponseMsgDto.getCertCheckResult())) {
|
|
|
+ if ("UNCHECKED".equals(wxResponseMsgDto.getCertCheckResult())) { //未知
|
|
|
+ builder.certCheckResult(MerchNoticeDict.BuyerPayerCheckStatus.i_0.getItem());
|
|
|
+ wxCbPayDoc.setBuyerPayerCheck(MerchNoticeDict.BuyerPayerCheckStatus.i_0.getItem());
|
|
|
+ }
|
|
|
+ if ("SAME".equals(wxResponseMsgDto.getCertCheckResult())) {//一致
|
|
|
+ builder.certCheckResult(MerchNoticeDict.BuyerPayerCheckStatus.i_1.getItem());
|
|
|
+ wxCbPayDoc.setBuyerPayerCheck(MerchNoticeDict.BuyerPayerCheckStatus.i_1.getItem());
|
|
|
+ }
|
|
|
+ if ("DIFFERENT".equals(wxResponseMsgDto.getCertCheckResult())) {//不一致
|
|
|
+ builder.certCheckResult(MerchNoticeDict.BuyerPayerCheckStatus.i_2.getItem());
|
|
|
+ wxCbPayDoc.setBuyerPayerCheck(MerchNoticeDict.BuyerPayerCheckStatus.i_2.getItem());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //返回状态未申报
|
|
|
+ if (WxDict.ResponseMsgState.UNDECLARED.getItem().equals(wxResponseMsgDto.getState())) {
|
|
|
+ wxCbPayDoc.setDocStatus(WxDict.PaymentDocStatus.i_10.getItem());
|
|
|
+ merchNoti = builder.code(wxResponseMsgDto.getErrCode())
|
|
|
+ .msg(WxDict.ResponseMsgState.UNDECLARED.getItemName())
|
|
|
+ .cusDeclStatus(WxDict.MerchNoticeStatus.i_10.getItem())
|
|
|
+ .build();
|
|
|
+ } else if (WxDict.ResponseMsgState.PROCESSING.getItem().equals(wxResponseMsgDto.getState())) {//申报中
|
|
|
+ wxCbPayDoc.setDocStatus(WxDict.PaymentDocStatus.i_11.getItem());
|
|
|
+ merchNoti = builder.code(wxResponseMsgDto.getErrCode())
|
|
|
+ .msg(WxDict.ResponseMsgState.PROCESSING.getItemName())
|
|
|
+ .cusDeclStatus(WxDict.MerchNoticeStatus.i_11.getItem())
|
|
|
+ .build();
|
|
|
+ } else if (WxDict.ResponseMsgState.SUBMITTED.getItem().equals(wxResponseMsgDto.getState())) {//申报已提交
|
|
|
+ wxCbPayDoc.setDocStatus(WxDict.PaymentDocStatus.i_10.getItem());
|
|
|
+ merchNoti = builder.code(wxResponseMsgDto.getErrCode())
|
|
|
+ .msg(WxDict.ResponseMsgState.SUBMITTED.getItemName())
|
|
|
+ .cusDeclStatus(WxDict.MerchNoticeStatus.i_11.getItem())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ } else if (WxDict.ResponseMsgState.SUCCESS.getItem().equals(wxResponseMsgDto.getState())) {//申报成功
|
|
|
+ wxCbPayDoc.setDocStatus(WxDict.PaymentDocStatus.i_12.getItem());
|
|
|
+ merchNoti = builder.code(wxResponseMsgDto.getErrCode())
|
|
|
+ .msg(wxResponseMsgDto.getErrCodeDes())
|
|
|
+ .cusDeclStatus(WxDict.MerchNoticeStatus.i_12.getItem())
|
|
|
+ .build();
|
|
|
+ } else if (WxDict.ResponseMsgState.FAIL.getItem().equals(wxResponseMsgDto.getState())) {//申报失败
|
|
|
+ wxCbPayDoc.setDocStatus(WxDict.PaymentDocStatus.i_03.getItem());
|
|
|
+ merchNoti = builder.code(wxResponseMsgDto.getErrCode())
|
|
|
+ .msg(WxDict.ResponseMsgState.FAIL.getItemName())
|
|
|
+ .cusDeclStatus(WxDict.MerchNoticeStatus.i_13.getItem())
|
|
|
+ .build();
|
|
|
+ } else if (WxDict.ResponseMsgState.EXCEPT.getItem().equals(wxResponseMsgDto.getState())) {//海关接口异常
|
|
|
+ wxCbPayDoc.setDocStatus(WxDict.PaymentDocStatus.i_03.getItem());
|
|
|
+ merchNoti = builder.code(wxResponseMsgDto.getErrCode())
|
|
|
+ .msg(WxDict.ResponseMsgState.EXCEPT.getItemName())
|
|
|
+ .cusDeclStatus(WxDict.MerchNoticeStatus.i_13.getItem())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //返回状态码为成功 业务结果失败
|
|
|
+ wxCbPayDoc.setErrCode(wxResponseMsgDto.getErrCode());
|
|
|
+ wxCbPayDoc.setErrCodeDes(wxResponseMsgDto.getErrCodeDes());
|
|
|
+ wxCbPayDoc.setDocStatus(WxDict.PaymentDocStatus.i_13.getItem());
|
|
|
+ wxCbPayDoc.setBuyerPayerCheck(MerchNoticeDict.BuyerPayerCheckStatus.i_3.getItem());
|
|
|
+ //[35324042]您的证件号码校验异常请联系财付通客服处理的情况,修改商户通知数据为“身份校验不一致”,“申报成功”
|
|
|
+ if("35324042".equalsIgnoreCase(wxResponseMsgDto.getErrCode())){
|
|
|
+ builder.certCheckResult(MerchNoticeDict.BuyerPayerCheckStatus.i_2.getItem());
|
|
|
+ merchNoti = builder.code(wxResponseMsgDto.getErrCode())
|
|
|
+ .msg(wxResponseMsgDto.getErrCodeDes())
|
|
|
+ .cusDeclStatus(WxDict.MerchNoticeStatus.i_12.getItem())
|
|
|
+ .build();
|
|
|
+ }else {
|
|
|
+ builder.certCheckResult(MerchNoticeDict.BuyerPayerCheckStatus.i_3.getItem());
|
|
|
+ merchNoti = builder.code(wxResponseMsgDto.getErrCode())
|
|
|
+ .msg(wxResponseMsgDto.getErrCodeDes())
|
|
|
+ .cusDeclStatus(WxDict.MerchNoticeStatus.i_13.getItem())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ///返回状态码为失败
|
|
|
+ if (WxContants.RETURN_CODE_FAIL.equals(wxResponseMsgDto.getReturnCode()) ||
|
|
|
+ WxContants.FAIL.equals(wxResponseMsgDto.getReturnCode())) {
|
|
|
+ wxCbPayDoc.setDocStatus(WxDict.PaymentDocStatus.i_03.getItem());
|
|
|
+
|
|
|
+ //通知商户
|
|
|
+ merchNoti = builder.code(WxContants.ERROR_FAIL)
|
|
|
+ .msg(wxResponseMsgDto.getReturnMsg())
|
|
|
+ .cusDeclStatus(WxDict.MerchNoticeStatus.i_13.getItem())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+ wxCbPayDocService.updateWxCbPay(wxCbPayDoc);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("重推更新支付单证入库信息状态异常", e);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ merchNotis.add(merchNoti);
|
|
|
+ });
|
|
|
+
|
|
|
+ //持久化商户通知数据
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ //存储异常记录
|
|
|
+ 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);
|
|
|
+ throw new RuntimeException("持久化支付申报异常信息数据失败data:",e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 记录异常的支付单证信息
|
|
|
+ * @param wxCbPayDoc
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private WxPayError createWxPayError(WxCbPayDoc wxCbPayDoc) {
|
|
|
+ WxPayError wxPayError = new WxPayError();
|
|
|
+ wxPayError.setErrorSn(TablePrimaryKeyPrefix.wx_pay_error_type + IdWorkerAide.nextId());
|
|
|
+ wxPayError.setWxPaySn(wxCbPayDoc.getTransactionId());
|
|
|
+ wxPayError.setMerchSn(wxCbPayDoc.getMerchSn());
|
|
|
+ wxPayError.setMerchName(wxCbPayDoc.getMerchName());
|
|
|
+ wxPayError.setAppid(wxCbPayDoc.getAppid());
|
|
|
+ wxPayError.setMchId(wxCbPayDoc.getMchId());
|
|
|
+ wxPayError.setOutTradeNo(wxCbPayDoc.getOutTradeNo());
|
|
|
+ wxPayError.setTransactionId(wxCbPayDoc.getTransactionId());
|
|
|
+ wxPayError.setSubOrderNo(wxCbPayDoc.getSubOrderNo());
|
|
|
+ wxPayError.setCustoms(wxCbPayDoc.getCustoms());
|
|
|
+ wxPayError.setErrCode(wxCbPayDoc.getErrCode());
|
|
|
+ wxPayError.setErrMsg(wxCbPayDoc.getReturnMsg());
|
|
|
+ wxPayError.getCreateTime(sdf.format(new Date()));
|
|
|
+ return wxPayError;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组装报关所需要的报关数据
|
|
|
+ * @param wxCbPayDoc 微信支付数据
|
|
|
+ * @param key 微信Api密钥
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ protected Map<String, String> assemblyDeclareXml(WxCbPayDoc wxCbPayDoc, String key) {
|
|
|
+ //1.选择报关数据,排序
|
|
|
+ SortedMap<String, String> sorted = Maps.newTreeMap();
|
|
|
+ sorted.put("appid", wxCbPayDoc.getAppid());
|
|
|
+ sorted.put("mch_id", wxCbPayDoc.getMchId());
|
|
|
+ sorted.put("out_trade_no", wxCbPayDoc.getOutTradeNo());
|
|
|
+ sorted.put("transaction_id", wxCbPayDoc.getTransactionId());
|
|
|
+ if (wxCbPayDoc.getSubOrderNo() != null && !wxCbPayDoc.getSubOrderNo().isEmpty()) {
|
|
|
+ sorted.put("sub_order_no", wxCbPayDoc.getSubOrderNo());
|
|
|
+ }
|
|
|
+ sorted.put("customs", wxCbPayDoc.getCustoms());
|
|
|
+ sorted.put("mch_customs_no", wxCbPayDoc.getMchCustomsNo());
|
|
|
+
|
|
|
+ //2.生成签名
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (Map.Entry<String,String> entry : sorted.entrySet()) {
|
|
|
+ sb.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
|
|
|
+ }
|
|
|
+ sb.append("key").append("=").append(key);
|
|
|
+ //签名MD5 加密
|
|
|
+ String sign = DigestUtils.md5Hex(sb.toString()).toUpperCase();
|
|
|
+
|
|
|
+ sorted.put("sign", sign);
|
|
|
+ return sorted;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+
|
|
|
+ String queryURL = "https://api.mch.weixin.qq.com/cgi-bin/mch/newcustoms/customdeclareredeclare";
|
|
|
+ WxCbPayDoc wxCbPayDoc = new WxCbPayDoc();
|
|
|
+ wxCbPayDoc.setAppid("wxb6b30b1b14ee502a");
|
|
|
+ wxCbPayDoc.setMchId("1501125641");
|
|
|
+ wxCbPayDoc.setOutTradeNo("EMATO84648344");
|
|
|
+ wxCbPayDoc.setTransactionId("4200000391201908044429129649");
|
|
|
+ wxCbPayDoc.setCustoms("SHENZHEN");
|
|
|
+ wxCbPayDoc.setSubOrderNo("ZWCG0010077179262");
|
|
|
+ wxCbPayDoc.setMchCustomsNo("4403160Z3Y");//中网科技(深圳)有限公司
|
|
|
+
|
|
|
+
|
|
|
+ SortedMap<String, String> sorted = Maps.newTreeMap();
|
|
|
+ sorted.put("appid", wxCbPayDoc.getAppid());
|
|
|
+ sorted.put("mch_id", wxCbPayDoc.getMchId());
|
|
|
+ sorted.put("out_trade_no", wxCbPayDoc.getOutTradeNo());
|
|
|
+ sorted.put("transaction_id", wxCbPayDoc.getTransactionId());
|
|
|
+ if (wxCbPayDoc.getSubOrderNo() != null && !wxCbPayDoc.getSubOrderNo().isEmpty()) {
|
|
|
+ sorted.put("sub_order_no", wxCbPayDoc.getSubOrderNo());
|
|
|
+ }
|
|
|
+ sorted.put("customs", wxCbPayDoc.getCustoms());
|
|
|
+ sorted.put("mch_customs_no", wxCbPayDoc.getMchCustomsNo());
|
|
|
+
|
|
|
+ //2.生成签名
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (Map.Entry<String,String> entry : sorted.entrySet()) {
|
|
|
+ sb.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
|
|
|
+ }
|
|
|
+ sb.append("key").append("=").append("Zx1245uytDLliom12345622222222222");
|
|
|
+ //签名MD5 加密
|
|
|
+ String sign = DigestUtils.md5Hex(sb.toString()).toUpperCase();
|
|
|
+
|
|
|
+ sorted.put("sign", sign);
|
|
|
+
|
|
|
+ String xml = XmlUtils.map2Xml(sorted);
|
|
|
+
|
|
|
+ System.out.println("xml:"+xml);
|
|
|
+
|
|
|
+ //通过http post请求 发送xml数据
|
|
|
+ Request request = OkHttpUtils.buildRequest(queryURL,
|
|
|
+ RequestBody.create(MediaType.parse("application/xml; charset=utf-8"), xml));
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ result = OkHttpUtils.post(request);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ System.out.println(result);
|
|
|
+ System.out.println(ReaderXmlForDOM4J.parse(result,1));
|
|
|
+
|
|
|
+ StringReader reader = new StringReader(result);
|
|
|
+ WxQueryResponseMsg wxResponseMsg = JAXB.unmarshal(reader, WxQueryResponseMsg.class);
|
|
|
+
|
|
|
+ System.out.println(wxResponseMsg);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|