From 6f82e4bfdeb6395d986fdb4ac63a409ab37443b3 Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Sat, 8 Dec 2018 16:01:06 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=88=86=E8=B4=A6=E5=AE=8C=E7=BB=93][?= =?UTF-8?q?=E6=96=B0=E5=A2=9E]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iformall/pay/WxProfitSharingFinishP.java | 114 ++++++++++++++++++ .../com/iformall/pay/WxProfitSharingP.java | 2 +- .../impl/WxProfitSharingOrderServiceImpl.java | 52 +++++++- 3 files changed, 162 insertions(+), 6 deletions(-) create mode 100644 mallinkService/src/main/java/com/iformall/pay/WxProfitSharingFinishP.java diff --git a/mallinkService/src/main/java/com/iformall/pay/WxProfitSharingFinishP.java b/mallinkService/src/main/java/com/iformall/pay/WxProfitSharingFinishP.java new file mode 100644 index 000000000..0943c2df5 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/pay/WxProfitSharingFinishP.java @@ -0,0 +1,114 @@ +package com.iformall.pay; + +import java.io.Serializable; + +/** + * Created by Peng on 2018/8/10. + */ +public class WxProfitSharingFinishP implements Serializable { + private static final long serialVersionUID = 1L; + + private String mch_id; // 商户号 + private String sub_mch_id; // 子商户号 + private String appid; // 公众账号ID + private String nonce_str; // 随机字符串 + private String sign; // 签名 + private String sign_type; // 签名方法 + private String transaction_id ; // 支付订单号 + private String out_order_no; // 商户订单号 + private Integer amount; // 商户分账金额 + private String description; // 分账完结的原因描述 + + public String getMch_id() { + return mch_id; + } + + public void setMch_id(String mch_id) { + this.mch_id = mch_id; + } + + public String getSub_mch_id() { return sub_mch_id; } + + public void setSub_mch_id(String sub_mch_id) { + this.sub_mch_id = sub_mch_id; + } + + public String getAppid() { + return appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getNonce_str() { + return nonce_str; + } + + public void setNonce_str(String nonce_str) { + this.nonce_str = nonce_str; + } + + public String getSign() { + return sign; + } + + public void setSign(String sign) { + this.sign = sign; + } + + public String getSign_type() { + return sign_type; + } + + public void setSign_type(String sign_type) { + this.sign_type = sign_type; + } + public String getTransaction_id() { + return transaction_id; + } + + public void setTransaction_id(String transaction_id) { + this.transaction_id = transaction_id; + } + + public String getOut_order_no() { return out_order_no; } + + public void setOut_order_no(String out_order_no) { + this.out_order_no = out_order_no; + } + + public Integer getAmount() { + return amount; + } + + public void setAmount(Integer amount) { + this.amount = amount; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("WxProfitSharingFinishP{"); + sb.append("mch_id='").append(mch_id).append('\''); + sb.append(", sub_mch_id='").append(sub_mch_id).append('\''); + sb.append(", appid='").append(appid).append('\''); + sb.append(", nonce_str='").append(nonce_str).append('\''); + sb.append(", sign='").append(sign).append('\''); + sb.append(", sign_type='").append(sign_type).append('\''); + sb.append(", transaction_id='").append(transaction_id).append('\''); + sb.append(", out_order_no='").append(out_order_no).append('\''); + sb.append(", amount='").append(amount).append('\''); + sb.append(", description='").append(description).append('\''); + sb.append('}'); + return sb.toString(); + } + +} diff --git a/mallinkService/src/main/java/com/iformall/pay/WxProfitSharingP.java b/mallinkService/src/main/java/com/iformall/pay/WxProfitSharingP.java index 69fc26362..6e3f5d63f 100644 --- a/mallinkService/src/main/java/com/iformall/pay/WxProfitSharingP.java +++ b/mallinkService/src/main/java/com/iformall/pay/WxProfitSharingP.java @@ -96,7 +96,7 @@ public class WxProfitSharingP implements Serializable { @Override public String toString() { - final StringBuilder sb = new StringBuilder("WxPayOrderSQ{"); + final StringBuilder sb = new StringBuilder("WxProfitSharingP{"); sb.append("appid='").append(appid).append('\''); sb.append(", sub_appid='").append(sub_appid).append('\''); sb.append(", mch_id='").append(mch_id).append('\''); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java index 3ec0d0d11..97377d92d 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java @@ -13,10 +13,7 @@ import com.iformall.domain.po.*; import com.iformall.enums.*; import com.iformall.exception.MallinkException; import com.iformall.mapper.*; -import com.iformall.pay.WxPayment; -import com.iformall.pay.WxProfitSharing; -import com.iformall.pay.WxProfitSharingP; -import com.iformall.pay.WxProfitSharingQueryP; +import com.iformall.pay.*; import com.iformall.service.WxProfitSharingOrderService; import com.iformall.utils.BeanUtils; import com.iformall.utils.Utility; @@ -137,6 +134,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ } @Override + @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) public ResultData createSharingOrder(WxPayOrder wxPayOrder, Long merchantId) { //添加分账接受方 WxProfitSharingReceiver psReceiverQ = new WxProfitSharingReceiver(); @@ -152,7 +150,6 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ return createPSOrder(wxPayOrder, merchantId, psReceiverList, false); } - @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) private ResultData createPSOrder(WxPayOrder wxPayOrder, Long merchantId, List psReceiverList, boolean multiCmd) { final IdWorker idworker = IdWorker.get(); @@ -416,4 +413,49 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ } return new ResultData(returnMap); } + + // 分账完结 + private ResultData finishPSOrder(WxPayOrder wxPayOrder) { + WxAppinfo appInfo = getAppinfo(wxPayOrder); + WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appInfo.getPayId()); + + WxOrder wxOrder = wxOrderMapper.selectByPrimaryKey(wxPayOrder.getOrderId()); + + //分账提交 + WxProfitSharingFinishP psFCmd = new WxProfitSharingFinishP(); + psFCmd.setMch_id(payAccount.getMchId()); + psFCmd.setSub_mch_id(payAccount.getSubMchId()); + psFCmd.setAppid(appInfo.getParentAppId()); + psFCmd.setNonce_str(Utility.generate32UUID()); + psFCmd.setTransaction_id(wxPayOrder.getTransactionId()); + psFCmd.setOut_order_no(wxPayOrder.getId().toString()); + psFCmd.setSign_type("HMAC-SHA256"); + + String response; + try { + psFCmd.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(psFCmd), payAccount.getApiKey())); + response = WxProfitSharing.finishOrder(BeanUtils.toStringMap(psFCmd), payAccount.getCertPath(), payAccount.getMchId()); + } catch (Exception e) { + return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED); + } + + logger.info("response: " + response); + Map returnMap = WxPayment.xmlToMap(response); + String return_code = returnMap.get("return_code"); + + if (!"SUCCESS".equals(return_code)) { + return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(), returnMap.get("return_msg")); + } + + if (!WxPayment.verifyNotifyHMAC(returnMap,payAccount.getApiKey())){ + return new ResultData(ErrorCode.PROFIT_SHARING_RETURN_INVALID.getCode()); + } + + String result_code = returnMap.get("result_code"); + if (!"SUCCESS".equals(result_code)) { + return new ResultData(ErrorCode.PROFIT_SHARING_APPLY_FAILED.getCode(), returnMap.get("err_code_des")); + } + + return new ResultData(returnMap); + } }