| @@ -115,6 +115,21 @@ public class WxPayController extends BaseController { | |||
| // } | |||
| } | |||
| /** | |||
| * 微信支付3.0版本 | |||
| * @return 接收微信异步通知 | |||
| * @throws Exception 可能产生的任何异常 | |||
| */ | |||
| @RequestMapping(value = "/pay/v3", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | |||
| @ResponseBody | |||
| public String _payV3Notify(HttpServletRequest request) throws IOException, JDOMException { | |||
| logger.info("[" +getIpAddr() + "]微信支付回调"); | |||
| SortedMap resultMap = new TreeMap(); | |||
| resultMap.put("return_code", "SUCCESS"); | |||
| resultMap.put("return_msg", "OK"); | |||
| return XmlUtil.getRequestXml(resultMap); | |||
| } | |||
| /** | |||
| * | |||
| @@ -165,6 +180,56 @@ public class WxPayController extends BaseController { | |||
| return XmlUtil.getRequestXml(resultMap); | |||
| } | |||
| } | |||
| /** | |||
| *微信支付3.0版本 | |||
| * @return 接收微信退款异步通知 | |||
| * @throws Exception 可能产生的任何异常 | |||
| */ | |||
| @RequestMapping(value = "/refund/v3") | |||
| public String __refundV3Notify(HttpServletRequest request) throws Exception { | |||
| logger.info("[" +getIpAddr() + "]微信退款回调"); | |||
| Map<String, String> paramMap = null; | |||
| String response = ""; | |||
| String xml = ""; | |||
| try { | |||
| xml = IOUtils.toString(request.getInputStream(), Charset.forName("UTF-8")); | |||
| logger.info(xml); | |||
| paramMap = WxPayment.xmlToMap(xml); | |||
| String jsonMsg = JSON.toJSONString(paramMap); | |||
| FmInsideNotifyRefundSuccessMsg refundSuccessMsg = new FmInsideNotifyRefundSuccessMsg(); | |||
| refundSuccessMsg.setMsgType(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode()); | |||
| refundSuccessMsg.setDelayTimeLevel(3); | |||
| refundSuccessMsg.setPayWay(EnumPayWay.PAY_WAY_WECHAT.getCode()); | |||
| refundSuccessMsg.setPayVersion(EnumPayVersion.WX_PAY_V2.getCode()); | |||
| refundSuccessMsg.setJsonMsg(jsonMsg); | |||
| // response = wxRefundOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | |||
| mqBaseProducer.sendMessage(refundSuccessMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| logger.info("refund wxpay, notify success, req : " + xml + ", resp: " + response.toString()); | |||
| return response; | |||
| } catch (BizMessageException e) { | |||
| logger.error("refund wxpay, notify error, req: " + xml + ", e:" + e.getLocalizedMessage()); | |||
| SortedMap resultMap = new TreeMap(); | |||
| resultMap.put("return_code", "FAIL"); | |||
| resultMap.put("return_msg", e.getMessage()); | |||
| return XmlUtil.getRequestXml(resultMap); | |||
| } catch (MallinkException e) { | |||
| logger.error("refund wxpay, notify error, req: " + xml + ", e:" +e.getLocalizedMessage()); | |||
| SortedMap resultMap = new TreeMap(); | |||
| resultMap.put("return_code", "FAIL"); | |||
| resultMap.put("return_msg", e.getMessage()); | |||
| return XmlUtil.getRequestXml(resultMap); | |||
| } catch (Exception e) { | |||
| logger.error("refund wxpay, order create error, req: " + xml + ", e: " + e.getMessage()); | |||
| SortedMap resultMap = new TreeMap(); | |||
| resultMap.put("return_code", "FAIL"); | |||
| resultMap.put("return_msg", e.getMessage()); | |||
| return XmlUtil.getRequestXml(resultMap); | |||
| } | |||
| } | |||
| /** | |||
| * | |||
| @@ -204,6 +269,45 @@ public class WxPayController extends BaseController { | |||
| return XmlUtil.getRequestXml(resultMap); | |||
| } | |||
| } | |||
| /** | |||
| * | |||
| * @return 接收微信分账异步通知 | |||
| * @throws Exception 可能产生的任何异常 | |||
| */ | |||
| @RequestMapping(value = "/sharing/v3") | |||
| public String __shareV3Notify(HttpServletRequest request) throws Exception { | |||
| logger.info("[" +getIpAddr() + "]微信分账回调"); | |||
| Map<String, String> paramMap = null; | |||
| String response = ""; | |||
| String xml = ""; | |||
| try { | |||
| xml = IOUtils.toString(request.getInputStream(), Charset.forName("UTF-8")); | |||
| paramMap = WxPayment.xmlToMap(xml); | |||
| logger.info("share wxpay, notify, param: " + xml ); | |||
| response = wxPayOrderService.shareNotify(paramMap, EnumPayWay.PAY_WAY_WECHAT,EnumPayVersion.WX_PAY_V2); | |||
| logger.info("share wxpay, notify success, req : " + xml + ", resp: " + response.toString()); | |||
| return response; | |||
| } catch (BizMessageException e) { | |||
| logger.error("share wxpay, notify error, req: " + xml + ", e:" + e.getLocalizedMessage()); | |||
| SortedMap resultMap = new TreeMap(); | |||
| resultMap.put("return_code", "FAIL"); | |||
| resultMap.put("return_msg", e.getMessage()); | |||
| return XmlUtil.getRequestXml(resultMap); | |||
| } catch (MallinkException e) { | |||
| logger.error("refund wxpay, notify error, req: " + xml + ", e:" +e.getLocalizedMessage()); | |||
| SortedMap resultMap = new TreeMap(); | |||
| resultMap.put("return_code", "FAIL"); | |||
| resultMap.put("return_msg", e.getMessage()); | |||
| return XmlUtil.getRequestXml(resultMap); | |||
| } catch (Exception e) { | |||
| logger.error("refund wxpay, order create error, req: " + xml + ", e: " + e.getMessage()); | |||
| SortedMap resultMap = new TreeMap(); | |||
| resultMap.put("return_code", "FAIL"); | |||
| resultMap.put("return_msg", e.getMessage()); | |||
| return XmlUtil.getRequestXml(resultMap); | |||
| } | |||
| } | |||
| /** | |||
| * | |||
| @@ -58,12 +58,21 @@ public class WxPayAccount extends TenantEntity { | |||
| private Integer realRate; | |||
| public String getPayNotifyV3Url() { | |||
| return notifyUrl + "/pay/v3"; | |||
| } | |||
| public String getPayNotifyUrl() { | |||
| return notifyUrl + "/pay"; | |||
| } | |||
| public String getRefundNotifyV3Url() { | |||
| return notifyUrl + "/refund/v3"; | |||
| } | |||
| public String getRefundNotifyUrl() { | |||
| return notifyUrl + "/refund"; | |||
| } | |||
| public String getSubsidyNotifyV3Url() { | |||
| return notifyUrl + "/subsidyPay/v3"; | |||
| } | |||
| public String getSubsidyNotifyUrl() { | |||
| return notifyUrl + "/subsidyPay"; | |||
| } | |||
| @@ -34,6 +34,7 @@ import com.iformall.service.order.entity.WxComposeOrder; | |||
| import com.iformall.service.pay.entity.PayExtraParam; | |||
| import com.iformall.service.pay.service.cashout.wx.v3.entity.CombineItemOrder; | |||
| import com.iformall.service.pay.service.cashout.wx.v3.entity.CombinePayCommonMiniAppReq; | |||
| import com.iformall.service.pay.service.cashout.wx.v3.entity.CombinePayerReq; | |||
| import com.iformall.service.pay.service.cashout.wx.v3.entity.PayAmountReq; | |||
| import com.iformall.service.pay.service.cashout.wx.v3.entity.PayCommonMiniAppReq; | |||
| import com.iformall.service.pay.service.cashout.wx.v3.entity.PaySettleReq; | |||
| @@ -60,11 +61,10 @@ public class WxMiniAppPayV3AdapterService implements CDrivingPayService{ | |||
| PayCommonMiniAppReq req = new PayCommonMiniAppReq(); | |||
| req.setSp_appid(String.valueOf(appInfo.getId())); | |||
| req.setSp_mchid(payAccount.getMchId()); | |||
| WxComposeChildOrderShare share = record.getChildOrderShare(composeOrder.getSingleOrder().getId()); | |||
| req.setSub_mchid(share.getMerchantUid()); | |||
| req.setSub_mchid(getMerchantUid(record,composeOrder.getSingleOrder())); | |||
| req.setDescription(appInfo.getName()+"-"+productName); | |||
| req.setOut_trade_no(String.valueOf(composeOrder.getMainOrderId())); | |||
| req.setNotify_url(payAccount.getPayNotifyUrl()); | |||
| req.setNotify_url(payAccount.getPayNotifyV3Url()); | |||
| PaySettleReq settle = new PaySettleReq(); | |||
| settle.setProfit_sharing(true); | |||
| @@ -81,6 +81,11 @@ public class WxMiniAppPayV3AdapterService implements CDrivingPayService{ | |||
| return req; | |||
| } | |||
| private String getMerchantUid(WxPayOrder payOrder,WxOrder order) { | |||
| WxComposeChildOrderShare share = payOrder.getChildOrderShare(order.getId()); | |||
| return share.getMerchantUid(); | |||
| } | |||
| private CombinePayCommonMiniAppReq generateCombinePayReqeust(WxPayAccount payAccount,WxComposeOrder composeOrder,List<WxOrder> childOrders,String productName, | |||
| WxPayOrder record,WxAppinfo appInfo,String openId,String appId,Date currentDate,EnumPayShare isShare) throws Exception { | |||
| @@ -89,44 +94,21 @@ public class WxMiniAppPayV3AdapterService implements CDrivingPayService{ | |||
| req.setCombine_mchid(payAccount.getMchId()); | |||
| req.setCombine_out_trade_no(String.valueOf(composeOrder.getMainOrderId())); | |||
| List<CombineItemOrder> suborders = new ArrayList<CombineItemOrder>(); | |||
| for (WxOrder order : childOrders) { | |||
| CombineItemOrder so = new CombineItemOrder(); | |||
| String subMchId = getMerchantUid(record,order); | |||
| so.initByWxOrder(payAccount, order, subMchId, appInfo, productName, String.valueOf(record.getId())); | |||
| suborders.add(so); | |||
| } | |||
| req.setSub_orders(suborders); | |||
| //composeOrder. | |||
| CombinePayerReq payer = new CombinePayerReq(); | |||
| payer.setOpenid(openId); | |||
| req.setCombine_payer_info(payer); | |||
| String noncestr = Utility.generate32UUID(); | |||
| WxPayOrderSP wxPayOrderSP = new WxPayOrderSP(); | |||
| wxPayOrderSP.setSub_openid(openId); | |||
| wxPayOrderSP.setAppid(appInfo.getParentAppId()); | |||
| wxPayOrderSP.setMch_id(payAccount.getMchId()); | |||
| wxPayOrderSP.setSub_appid(appId); | |||
| wxPayOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||
| wxPayOrderSP.setNonce_str(noncestr); | |||
| wxPayOrderSP.setBody(productName); | |||
| wxPayOrderSP.setOut_trade_no(record.getPayOrderNo()); | |||
| wxPayOrderSP.setTotal_fee(composeOrder.getPayment().toString()); | |||
| wxPayOrderSP.setSpbill_create_ip(record.getIp()); // 终端IP | |||
| wxPayOrderSP.setGoods_tag(productName); // 券ID | |||
| wxPayOrderSP.setNotify_url(payAccount.getPayNotifyUrl()); | |||
| wxPayOrderSP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 | |||
| wxPayOrderSP.setProduct_id(String.valueOf(composeOrder.getMainOrderId())); // | |||
| wxPayOrderSP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||
| Date futureDate = new Date(); | |||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||
| wxPayOrderSP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||
| wxPayOrderSP.setSign_type("HMAC-SHA256"); | |||
| wxPayOrderSP.setProfit_sharing(null); | |||
| if (isShare == EnumPayShare.YES) { | |||
| wxPayOrderSP.setProfit_sharing("Y"); | |||
| } | |||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderSP); | |||
| wxPayOrderSP.setSign(WxPayment.createSignHMAC(payOrderMap, payAccount.getApiKey())); | |||
| return null; | |||
| req.setNotify_url(payAccount.getPayNotifyV3Url()); | |||
| return req; | |||
| } | |||
| private PayAdapterResult getOrderPResult(String response) { | |||