* master: 修改配置星巴克 肯德基 会员充值 话费 微信商户号 修改配置星巴克 肯德基 会员充值 话费 微信商户号 # Conflicts: # hai-cweb/src/main/java/com/cweb/controller/pay/CzOrderController.java # hai-cweb/src/main/java/com/cweb/controller/pay/ThirdOrderController.javadev-discount
parent
ff608b4070
commit
db3341f13a
@ -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<String, Object> orderMap = new HashMap<>(); |
||||||
|
orderMap.put("orderId" , rechargeOrder.getId()); |
||||||
|
|
||||||
|
// 查询是否用重复订单
|
||||||
|
ApiOrderRecord apiOrderRecord = apiOrderRecordService.queryOrderResult(orderMap); |
||||||
|
|
||||||
|
apiOrderRecord.setStatus(100); |
||||||
|
apiOrderRecord.setRequestTime(new Date()); |
||||||
|
apiOrderRecordService.updateOrderRecord(apiOrderRecord); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -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); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -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<WxMaSubscribeMessage.Data> list = new ArrayList<>(); |
||||||
|
|
||||||
|
Map<String, String> 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<WxMaSubscribeMessage.Data> list = new ArrayList<>(); |
||||||
|
|
||||||
|
Map<String, String> 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<WxMaSubscribeMessage.Data> list = new ArrayList<>(); |
||||||
|
|
||||||
|
Map<String, String> 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)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue