diff --git a/hai-order/src/main/java/com/web/config/AuthConfig.java b/hai-order/src/main/java/com/web/config/AuthConfig.java index ae57f712..0e222d7e 100644 --- a/hai-order/src/main/java/com/web/config/AuthConfig.java +++ b/hai-order/src/main/java/com/web/config/AuthConfig.java @@ -91,6 +91,7 @@ public class AuthConfig implements WebMvcConfigurer { .excludePathPatterns("/**/swagger-ui.html") .excludePathPatterns("/login/*") .excludePathPatterns("/payNotify/*") + .excludePathPatterns("/telChargeCallback/*") ; } diff --git a/hai-order/src/main/java/com/web/controller/business/OrderTelChargeCallbackController.java b/hai-order/src/main/java/com/web/controller/business/OrderTelChargeCallbackController.java new file mode 100644 index 00000000..c06f31a2 --- /dev/null +++ b/hai-order/src/main/java/com/web/controller/business/OrderTelChargeCallbackController.java @@ -0,0 +1,231 @@ +package com.web.controller.business; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hai.common.pay.WechatPayUtil; +import com.hai.common.security.UserCenter; +import com.hai.config.UnionPayConfig; +import com.hai.config.WxMsgConfig; +import com.hai.dao.HighGasOrderPushMapper; +import com.hai.entity.*; +import com.hai.enum_type.OrderPushType; +import com.hai.enum_type.RechargePayType; +import com.hai.service.*; +import com.hai.service.impl.OutRechargeOrderServiceImpl; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.PrintWriter; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +@Controller +@RequestMapping(value = "telChargeCallback") +@Api(value = "话费充值回调业务") +public class OrderTelChargeCallbackController { + + private static Logger log = LoggerFactory.getLogger(OutRechargeOrderServiceImpl.class); + + @Resource + private OutRechargeOrderService outRechargeOrderService; + + @Resource + private OutRechargeChildOrderService outRechargeChildOrderService; + + @Resource + private HighUserService highUserService; + + @Resource + private ApiOrderRecordService apiOrderRecordService; + + + @RequestMapping(value = "/rechargeCallbackByJj", method = RequestMethod.POST) + @ApiOperation(value = "尖椒充值回调") + @ResponseBody + public void rechargeCallbackByJj(@RequestBody String reqBodyStr, HttpServletRequest request, HttpServletResponse response) { + try { + + JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class); + + log.info("============回调任务Start============="); + log.info("尖椒订单充值-回调参数: " + dataObject); + log.info("============回调任务End============="); + + // 1 尖椒 2 龙阅 + dataObject.put("orderNo" , dataObject.getString("out_order_id")); + + // 查询充值记录订单 + OutRechargeChildOrder childOrder = outRechargeChildOrderService.findByOrderNo(dataObject.getString("out_order_id")); + + // 查询充值订单 + OutRechargeOrder rechargeOrder = outRechargeOrderService.findByOrderId(childOrder.getParentOrderId()); + + // 判断是否充值成功 并发送微信小程序服务通知 + if (dataObject.getInteger("status") == 3) { + if (rechargeOrder.getRechargeStatus() ==201) { + new Thread(() -> { + HighUser highUser = highUserService.findByUserId(rechargeOrder.getUserId()); + WxMsgConfig.rechargedSuccess( + rechargeOrder.getRechargeContent() + "充值成功", + String.valueOf(rechargeOrder.getPayRealPrice()), + rechargeOrder.getOrderNo(), + rechargeOrder.getFinishTime(), + RechargePayType.getNameByType(rechargeOrder.getPayType()), + highUser.getOpenId()); + }).start(); + } + + childOrder.setStatus(101); + rechargeOrder.setRechargeStatus(202); + rechargeOrder.setPayStatus(100); + + outRechargeOrderService.updateOrder(rechargeOrder); + outRechargeChildOrderService.updateOrder(childOrder); + + // api商户订单 + if (rechargeOrder.getPayType() == 6) { + apiOrderRecord(rechargeOrder); + } + + } else { + // 充值失败操作 + callbackResult(childOrder , rechargeOrder); + } + + response.setCharacterEncoding("UTF-8"); + response.setContentType("text/html;charset=utf-8"); + PrintWriter writer= response.getWriter(); + writer.write("SUCCESS"); + + + } catch (Exception e) { + log.error("WechatPayController --> wechatNotify() error!", e); + } + } + + + @RequestMapping(value = "/rechargeCallbackByLy", method = RequestMethod.POST) + @ApiOperation(value = "龙阅充值回调") + @ResponseBody + public void rechargeCallbackByLy( + @RequestParam(name = "out_trade_num", required = true) String out_trade_num, + @RequestParam(name = "userid", required = true) Long userid, + @RequestParam(name = "state", required = true) Long state, + @RequestBody String reqBodyStr , + HttpServletRequest request, HttpServletResponse response) { + try { + + log.info("============回调任务Start============="); + log.info("龙阅订单充值-回调参数: " + reqBodyStr); + log.info("============回调任务End============="); + + OutRechargeChildOrder childOrder = outRechargeChildOrderService.findByOrderNo(out_trade_num); + + OutRechargeOrder rechargeOrder = outRechargeOrderService.findByOrderId(childOrder.getParentOrderId()); + + // 判断是否充值成功 并发送微信小程序服务通知 + if (state == 1) { + if (rechargeOrder.getRechargeStatus() ==201) { + new Thread(() -> { + HighUser highUser = highUserService.findByUserId(rechargeOrder.getUserId()); + WxMsgConfig.rechargedSuccess( + rechargeOrder.getRechargeContent() + "充值成功", + String.valueOf(rechargeOrder.getPayRealPrice()), + rechargeOrder.getOrderNo(), + rechargeOrder.getFinishTime(), + RechargePayType.getNameByType(rechargeOrder.getPayType()), + highUser.getOpenId()); + }).start(); + } + childOrder.setStatus(101); + rechargeOrder.setRechargeStatus(202); + rechargeOrder.setPayStatus(100); + rechargeOrder.setFinishTime(new Date()); + + outRechargeOrderService.updateOrder(rechargeOrder); + outRechargeChildOrderService.updateOrder(childOrder); + if (rechargeOrder.getPayType() == 6) { + apiOrderRecord(rechargeOrder); + } + } else { + callbackResult(childOrder , rechargeOrder); + } + + response.setCharacterEncoding("UTF-8"); + response.setContentType("text/html;charset=utf-8"); + PrintWriter writer= response.getWriter(); + writer.write("SUCCESS"); + + + } catch (Exception e) { + log.error("WechatPayController --> wechatNotify() error!", e); + } + } + + // 充值回调结果处理 + private void callbackResult(OutRechargeChildOrder childOrder , OutRechargeOrder rechargeOrder) throws Exception { + + // 101:充值成功 102: 充值中 103:充值失败 104 未充值 + // 订单支付状态 : 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款 + if (childOrder.getStatus() == 102 && rechargeOrder.getPayStatus() == 102) { + + Date rechargeTime = rechargeOrder.getCreateTimed(); + Date currentTime = new Date(); +// 当前时间减去充值时间 + int hours = (int) ((currentTime.getTime() - rechargeTime.getTime()) / (1000 * 60 * 60)); + +// // 判断快充 并且 充值时间小于6 +// if (rechargeOrder.getRechargeType() == 1 && hours < 6) { +// outRechargeOrderService.pollRequest(rechargeOrder); +// return; +// } + // 判断慢充 并且 充值时间小于72 + if (hours < 72) { + outRechargeOrderService.pollRequest(rechargeOrder); + return; + } + + rechargeOrder.setRechargeStatus(203); + childOrder.setStatus(103); + outRechargeOrderService.updateOrder(rechargeOrder); + outRechargeChildOrderService.updateOrder(childOrder); + + outRechargeOrderService.rechargeOrderToRefund(rechargeOrder.getId()); + + + // 发送充值失败 微信小程序服务通知 + new Thread(() -> { + HighUser highUser = highUserService.findByUserId(rechargeOrder.getUserId()); + WxMsgConfig.rechargedFail( + rechargeOrder.getRechargeContent() + "充值失败", + String.valueOf(rechargeOrder.getPayRealPrice()), + highUser.getOpenId()); + }).start(); + + } + + } + + private void apiOrderRecord(OutRechargeOrder rechargeOrder) { + Map orderMap = new HashMap<>(); + orderMap.put("orderId" , rechargeOrder.getId()); + + // 查询是否用重复订单 + ApiOrderRecord apiOrderRecord = apiOrderRecordService.queryOrderResult(orderMap); + + apiOrderRecord.setStatus(100); + apiOrderRecord.setRequestTime(new Date()); + apiOrderRecordService.updateOrderRecord(apiOrderRecord); + + } + +} diff --git a/hai-service/src/main/java/com/hai/config/CommonSysConfig.java b/hai-service/src/main/java/com/hai/config/CommonSysConfig.java index 7b78bf88..97fd5ec7 100644 --- a/hai-service/src/main/java/com/hai/config/CommonSysConfig.java +++ b/hai-service/src/main/java/com/hai/config/CommonSysConfig.java @@ -107,6 +107,25 @@ public class CommonSysConfig { private String fileUrl; + private String wxAppId; + private String wxAppSecret; + + public String getWxAppId() { + return wxAppId; + } + + public void setWxAppId(String wxAppId) { + this.wxAppId = wxAppId; + } + + public String getWxAppSecret() { + return wxAppSecret; + } + + public void setWxAppSecret(String wxAppSecret) { + this.wxAppSecret = wxAppSecret; + } + public String getChongQingCnpcUrl() { return ChongQingCnpcUrl; } diff --git a/hai-service/src/main/java/com/hai/config/WxMaConfiguration.java b/hai-service/src/main/java/com/hai/config/WxMaConfiguration.java new file mode 100644 index 00000000..a5dfe8f5 --- /dev/null +++ b/hai-service/src/main/java/com/hai/config/WxMaConfiguration.java @@ -0,0 +1,33 @@ +package com.hai.config; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; +import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; +import org.springframework.context.annotation.Configuration; + +import javax.annotation.PostConstruct; + +@Configuration +public class WxMaConfiguration { + + private static WxMaService maService; + + public static WxMaService getMaService() { + if (maService == null) { + throw new IllegalArgumentException(String.format("未找到对应的配置,请核实!")); + } + + return maService; + } + + @PostConstruct + public void init() { + WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); + config.setAppid(CommonSysConst.getSysConfig().getWxAppId()); + config.setSecret(CommonSysConst.getSysConfig().getWxAppSecret()); + + maService = new WxMaServiceImpl(); + maService.setWxMaConfig(config); + } + +} diff --git a/hai-service/src/main/java/com/hai/config/WxMsgConfig.java b/hai-service/src/main/java/com/hai/config/WxMsgConfig.java new file mode 100644 index 00000000..abd6bf50 --- /dev/null +++ b/hai-service/src/main/java/com/hai/config/WxMsgConfig.java @@ -0,0 +1,121 @@ +package com.hai.config; + +import cn.binarywang.wx.miniapp.api.WxMaMsgService; +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage; +import com.hai.common.utils.DateUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Async; + +import java.util.*; + +public class WxMsgConfig { + + private static Logger log = LoggerFactory.getLogger(WxMsgConfig.class); + + public static void pushOneUser(String orderName , String price , String orderNo , Date payTime , String remark , Long orderId , String openId) { + + try { + List list = new ArrayList<>(); + + Map m = new HashMap<>(); + + m.put("thing1", orderName); + m.put("amount2", price + "元"); + m.put("character_string3", orderNo); + m.put("time4", DateUtil.date2String(payTime , "yyyy年MM月dd日 HH:mm:ss")); + m.put("thing6", remark); + + for (String key: m.keySet()) { + WxMaSubscribeMessage.Data msgElement = new WxMaSubscribeMessage.Data(); + msgElement.setName(key); + msgElement.setValue(m.get(key)); + list.add(msgElement); + } + + WxMaSubscribeMessage subscribeMessage = new WxMaSubscribeMessage(); + subscribeMessage.setToUser(openId); // 小程序openId + subscribeMessage.setTemplateId("oUvaCPeeOg4wH6HTvCcSabU6FnzXUXOBXsqBYAPOV-U"); + subscribeMessage.setData(list); + subscribeMessage.setPage("pages/user/order_details/order_details?id=" + orderId); + subscribeMessage.setMiniprogramState("developer"); + + final WxMaService wxService = WxMaConfiguration.getMaService(); + WxMaMsgService maMsgService = wxService.getMsgService(); + maMsgService.sendSubscribeMsg(subscribeMessage); + } catch (Exception e) { + log.error(String.valueOf(e)); + } + + } + + public static void rechargedSuccess(String orderName , String price , String orderNo , Date payTime , String payType , String openId) { + + try { + List list = new ArrayList<>(); + + Map m = new HashMap<>(); + + m.put("character_string1", orderNo); // 订单号 + m.put("thing11", orderName); // 充值项目 + m.put("thing10", payType); // 支付方式 + m.put("amount8", price); // 支付金额 + m.put("date5", DateUtil.date2String(payTime , "yyyy年MM月dd日 HH:mm:ss")); + + for (String key: m.keySet()) { + WxMaSubscribeMessage.Data msgElement = new WxMaSubscribeMessage.Data(); + msgElement.setName(key); + msgElement.setValue(m.get(key)); + list.add(msgElement); + } + + WxMaSubscribeMessage subscribeMessage = new WxMaSubscribeMessage(); + subscribeMessage.setToUser(openId); // 小程序openId + subscribeMessage.setTemplateId("ZO6kC3oJv0zj9QzL0htsF-mM9vAElcgPZEcUGglxsoU"); + subscribeMessage.setData(list); + + final WxMaService wxService = WxMaConfiguration.getMaService(); + WxMaMsgService maMsgService = wxService.getMsgService(); + maMsgService.sendSubscribeMsg(subscribeMessage); + } catch (Exception e) { + log.error(String.valueOf(e)); + } + + } + + public static void rechargedFail(String orderName , String price , String openId) { + + try { + List list = new ArrayList<>(); + + Map m = new HashMap<>(); + + m.put("thing1", orderName); // 订单内容 + m.put("thing2", "充值通道爆满!"); // 失败原因 + m.put("amount3", price); // 退款金额 + m.put("thing4", "退款将在1-3日内原路退回"); // 温馨提示 + + for (String key: m.keySet()) { + WxMaSubscribeMessage.Data msgElement = new WxMaSubscribeMessage.Data(); + msgElement.setName(key); + msgElement.setValue(m.get(key)); + list.add(msgElement); + } + + WxMaSubscribeMessage subscribeMessage = new WxMaSubscribeMessage(); + subscribeMessage.setToUser(openId); // 小程序openId + subscribeMessage.setTemplateId("xjacmzuWSRdiKGz4IJVeuvyGE0vOhoy0JVQPgOr-PuI"); + subscribeMessage.setData(list); + + final WxMaService wxService = WxMaConfiguration.getMaService(); + WxMaMsgService maMsgService = wxService.getMsgService(); + maMsgService.sendSubscribeMsg(subscribeMessage); + } catch (Exception e) { + log.error(String.valueOf(e)); + } + + } + + +} diff --git a/hai-service/src/main/resources/dev/commonConfig.properties b/hai-service/src/main/resources/dev/commonConfig.properties index f4d0140c..bfb1fe7c 100644 --- a/hai-service/src/main/resources/dev/commonConfig.properties +++ b/hai-service/src/main/resources/dev/commonConfig.properties @@ -79,13 +79,13 @@ TelApiSecret=d11ee9b41e014a039f030e53ae6f5295 TelMemberId=d13091df65d64aafbf0f35d2093157b7 # Jj -JjNotifyUrl = https://hsgcs.dctpay.com/crest/czOrder/rechargeCallbackByJj +JjNotifyUrl = https://hsgcs.dctpay.com/order/telChargeCallback/rechargeCallbackByJj JjAppKey = eaomqcbpdz7yjfih JjUrl = https://hfcs.dmjvip.com/index.php/third/mobile/ JjAppSecret = xkf9eoq2cjh6uvzp0mtrga134lnibdw8 #LY -LyNotifyUrl = https://hsgcs.dctpay.com/crest/czOrder/rechargeCallbackByLy +LyNotifyUrl = https://hsgcs.dctpay.com/order/telChargeCallback/rechargeCallbackByLy #LyApiKey=CMdyxh2gJ7tbXc6rS0KADqPIfVpaQLjU #LyMemberId=18665 #LyPostUrl=https://cz.31994.cn/yrapi.php/ @@ -106,3 +106,7 @@ unionRsaKey=891f6775fba7f12cc23df7c75e02b39b891f6775fba7f12c #url fileUrl=/home/project/hsg/filesystem/ #fileUrl=/Volumes/work/code/filesystem/ + +#wx +wxAppId=wx8d49e2f83025229d +wxAppSecret=d8d6dcaef77d3b659258a01b5ddba5df diff --git a/hai-service/src/main/resources/prod-9401/commonConfig.properties b/hai-service/src/main/resources/prod-9401/commonConfig.properties index 52af6340..f9923ae2 100644 --- a/hai-service/src/main/resources/prod-9401/commonConfig.properties +++ b/hai-service/src/main/resources/prod-9401/commonConfig.properties @@ -71,13 +71,13 @@ TelApiSecret=d11ee9b41e014a039f030e53ae6f5295 TelMemberId=d13091df65d64aafbf0f35d2093157b7 // Mobile -JjNotifyUrl = https://hsg.dctpay.com/crest/czOrder/rechargeCallbackByJj +JjNotifyUrl = https://hsg.dctpay.com/order/telChargeCallback/rechargeCallbackByJj JjAppKey = p429mlj3cvn5hb07 JjUrl = https://jj.dmjvip.com/index.php/third/mobile/ JjAppSecret = bf57pnqy8mkexr0v169c3g4odazwu2ij #LY -LyNotifyUrl = https://hsg.dctpay.com/crest/czOrder/rechargeCallbackByLy +LyNotifyUrl = https://hsg.dctpay.com/order/telChargeCallback/rechargeCallbackByLy #LyApiKey=CMdyxh2gJ7tbXc6rS0KADqPIfVpaQLjU #LyMemberId=18665 #LyPostUrl=https://cz.31994.cn/yrapi.php/ @@ -98,3 +98,5 @@ unionRsaKey=f2e6b6b95da445866194498c371a7c8af2e6b6b95da44586 #url fileUrl=/home/project/hsg/filesystem/ +wxAppId=wx8d49e2f83025229d +wxAppSecret=d8d6dcaef77d3b659258a01b5ddba5df diff --git a/hai-service/src/main/resources/prod/commonConfig.properties b/hai-service/src/main/resources/prod/commonConfig.properties index 6f7009f1..2260665d 100644 --- a/hai-service/src/main/resources/prod/commonConfig.properties +++ b/hai-service/src/main/resources/prod/commonConfig.properties @@ -69,13 +69,13 @@ TelApiSecret=d11ee9b41e014a039f030e53ae6f5295 TelMemberId=d13091df65d64aafbf0f35d2093157b7 // Mobile -JjNotifyUrl = https://hsg.dctpay.com/crest/czOrder/rechargeCallbackByJj +JjNotifyUrl = https://hsg.dctpay.com/order/telChargeCallback/rechargeCallbackByJj JjAppKey = p429mlj3cvn5hb07 JjUrl = https://jj.dmjvip.com/index.php/third/mobile/ JjAppSecret = bf57pnqy8mkexr0v169c3g4odazwu2ij #LY -LyNotifyUrl = https://hsg.dctpay.com/crest/czOrder/rechargeCallbackByLy +LyNotifyUrl = https://hsg.dctpay.com/order/telChargeCallback/rechargeCallbackByLy #LyApiKey=CMdyxh2gJ7tbXc6rS0KADqPIfVpaQLjU ##LyMemberId=18665 ##LyPostUrl=https://cz.31994.cn/yrapi.php/ @@ -96,3 +96,5 @@ unionRsaKey=f2e6b6b95da445866194498c371a7c8af2e6b6b95da44586 #url fileUrl=/home/project/hsg/filesystem/ +wxAppId=wx8d49e2f83025229d +wxAppSecret=d8d6dcaef77d3b659258a01b5ddba5df