|
@@ -2,18 +2,21 @@ package com.zanxiang.sdk.service.Impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.zanxiang.common.enums.OrderStateEnum;
|
|
|
import com.zanxiang.common.exception.BaseException;
|
|
|
import com.zanxiang.module.util.JsonUtil;
|
|
|
import com.zanxiang.module.util.bean.BeanUtil;
|
|
|
import com.zanxiang.mybatis.entity.GameApplet;
|
|
|
import com.zanxiang.mybatis.entity.Order;
|
|
|
-import com.zanxiang.mybatis.entity.User;
|
|
|
import com.zanxiang.mybatis.mapper.GameAppletMapper;
|
|
|
import com.zanxiang.sdk.domain.dto.AppletMsgDTO;
|
|
|
import com.zanxiang.sdk.domain.dto.GameAppletDTO;
|
|
|
+import com.zanxiang.sdk.domain.dto.GamePayWayDTO;
|
|
|
+import com.zanxiang.sdk.domain.dto.UserDTO;
|
|
|
import com.zanxiang.sdk.domain.params.UserData;
|
|
|
import com.zanxiang.sdk.domain.vo.GameAppletVO;
|
|
|
import com.zanxiang.sdk.service.GameAppletService;
|
|
|
+import com.zanxiang.sdk.service.GamePayWayService;
|
|
|
import com.zanxiang.sdk.service.OrderService;
|
|
|
import com.zanxiang.sdk.service.UserService;
|
|
|
import com.zanxiang.sdk.service.api.WxApiService;
|
|
@@ -25,6 +28,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
import org.springframework.web.util.UriComponentsBuilder;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.net.URI;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
@@ -51,6 +55,9 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
|
|
|
@Autowired
|
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private GamePayWayService gamePayWayService;
|
|
|
+
|
|
|
@Override
|
|
|
public String appletMsgCheck(String appId, String signature, String timestamp, String nonce, String echoStr) throws Exception {
|
|
|
log.error("验证参数, appId : {}, signature : {}, timestamp : {}, nonce : {}, echoStr : {}", appId, signature, timestamp, nonce, echoStr);
|
|
@@ -62,7 +69,7 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
|
|
|
String mySignature = SignUtil.SHA1(gameApplet.getMsgPushToken(), timestamp, nonce);
|
|
|
log.error("计算出来的签名, signature : {}, mySignature : {}", signature, mySignature);
|
|
|
if (!Objects.equals(mySignature, signature)) {
|
|
|
- throw new BaseException("签名不匹配");
|
|
|
+ throw new BaseException("验证签名不匹配");
|
|
|
}
|
|
|
return echoStr;
|
|
|
}
|
|
@@ -71,73 +78,73 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
|
|
|
public String appletMsg(String appId, String signature, String timestamp, String nonce, String postData) throws Exception {
|
|
|
log.error("接收到事件消息, appId : {}, signature : {}, timestamp : {}, nonce : {}, postData : {}",
|
|
|
appId, signature, timestamp, nonce, postData);
|
|
|
+ String result = "success";
|
|
|
if (Strings.isBlank(postData)) {
|
|
|
- return "success";
|
|
|
+ return result;
|
|
|
}
|
|
|
GameApplet gameApplet = super.getOne(new LambdaQueryWrapper<GameApplet>()
|
|
|
.eq(GameApplet::getAppId, appId));
|
|
|
if (gameApplet == null) {
|
|
|
- return "success";
|
|
|
+ return result;
|
|
|
}
|
|
|
String mySignature = SignUtil.SHA1(gameApplet.getMsgPushToken(), timestamp, nonce);
|
|
|
- log.error("计算出来的签名, signature : {}, mySignature : {}", signature, mySignature);
|
|
|
if (!Objects.equals(mySignature, signature)) {
|
|
|
- return "success";
|
|
|
+ log.error("计算出来的签名不匹配, signature : {}, mySignature : {}", signature, mySignature);
|
|
|
+ return result;
|
|
|
}
|
|
|
AppletMsgDTO appletMsgDTO = JsonUtil.toObj(postData, AppletMsgDTO.class);
|
|
|
//消息内容判断, 值回复文本消息为2的内容
|
|
|
if (!Objects.equals(appletMsgDTO.getMsgType(), "text") || !Objects.equals(appletMsgDTO.getContent(), "2")) {
|
|
|
- return "success";
|
|
|
- }
|
|
|
- //查询用户信息
|
|
|
- User user = userService.getOne(new LambdaQueryWrapper<User>()
|
|
|
- .eq(User::getGameId, gameApplet.getGameId())
|
|
|
- .eq(User::getOpenId, appletMsgDTO.getFromUserName()));
|
|
|
- if (user == null) {
|
|
|
- return "success";
|
|
|
+ return result;
|
|
|
}
|
|
|
+ //用户信息
|
|
|
+ UserDTO userDTO = userService.getUserByOpenId(gameApplet.getGameId(), appletMsgDTO.getFromUserName());
|
|
|
//查询用户最新订单
|
|
|
Order order = orderService.getOne(new LambdaQueryWrapper<Order>()
|
|
|
- .eq(Order::getUserId, user.getId())
|
|
|
+ .eq(Order::getUserId, userDTO.getId())
|
|
|
+ .eq(Order::getStatus, OrderStateEnum.NO_PAY.getCode())
|
|
|
.orderByDesc(Order::getCreateTime)
|
|
|
.last("limit 1"));
|
|
|
if (order == null) {
|
|
|
- return "success";
|
|
|
+ return result;
|
|
|
}
|
|
|
- this.sendCustomMessage(gameApplet, user, order);
|
|
|
- return "success";
|
|
|
+ //发送客服消息
|
|
|
+ return this.sendCustomMessage(gameApplet, userDTO.getOpenId(), order);
|
|
|
}
|
|
|
|
|
|
- private void sendCustomMessage(GameApplet gameApplet, User user, Order order) {
|
|
|
- //获取接口token
|
|
|
- String accessToken = wxApiService.getAccessToken(gameApplet.getAppId(), gameApplet.getAppSecret());
|
|
|
- URI uri = UriComponentsBuilder.fromHttpUrl("https://api.weixin.qq.com/cgi-bin/message/custom/send")
|
|
|
- .queryParam("access_token", accessToken)
|
|
|
- .build().toUri();
|
|
|
- log.error("发送客服消息url, uri : {}", uri);
|
|
|
-
|
|
|
- Map<String, Object> paramMap = new HashMap<>(4);
|
|
|
- paramMap.put("touser", user.getOpenId());
|
|
|
- paramMap.put("msgtype", "link");
|
|
|
- //link参数
|
|
|
- Map<String, Object> linkMap = new HashMap<>(4);
|
|
|
- linkMap.put("title", "点我充值");
|
|
|
- linkMap.put("description", "点我充值" + order.getAmount() + "元,用于购买" + order.getAmount() + "元档充值");
|
|
|
- //构造url
|
|
|
+ private String sendCustomMessage(GameApplet gameApplet, String openId, Order order) {
|
|
|
+ //查询订单支付方式
|
|
|
+ GamePayWayDTO gamePayWayDTO = gamePayWayService.getById(order.getGamePayWayId());
|
|
|
+ //订单金额
|
|
|
+ BigDecimal amount = order.getAmount();
|
|
|
+ //构造跳转链接url
|
|
|
URI url = UriComponentsBuilder.fromHttpUrl("http://corp.complaint.zanxiangnet.com/html/wechatPay/index.html")
|
|
|
- .queryParam("appId", "wx91208c6c8651a97d")
|
|
|
+ .queryParam("appId", gamePayWayDTO.getAppId())
|
|
|
.queryParam("orderId", order.getOrderId())
|
|
|
- .queryParam("amount", order.getAmount())
|
|
|
- .queryParam("description", "购买" + order.getAmount() + "元档充值")
|
|
|
+ .queryParam("amount", amount)
|
|
|
+ .queryParam("description", "购买" + amount + "元档充值")
|
|
|
.build().toUri();
|
|
|
- //添加参数
|
|
|
+ //link参数构造
|
|
|
+ Map<String, Object> linkMap = new HashMap<>(4);
|
|
|
+ linkMap.put("title", "点我充值");
|
|
|
+ linkMap.put("description", "点我充值" + amount + "元,用于购买" + amount + "元档充值");
|
|
|
linkMap.put("url", url);
|
|
|
linkMap.put("thumb_url", "https://book.zanxiangnet.com/qc-tip/1.jpg");
|
|
|
+ //客服消息参数构造
|
|
|
+ Map<String, Object> paramMap = new HashMap<>(3);
|
|
|
+ paramMap.put("touser", openId);
|
|
|
+ paramMap.put("msgtype", "link");
|
|
|
paramMap.put("link", linkMap);
|
|
|
log.error("客服消息发送参数, paramMap : {}", JsonUtil.toString(paramMap));
|
|
|
+ //获取接口token
|
|
|
+ String accessToken = wxApiService.getAccessToken(gameApplet.getAppId(), gameApplet.getAppSecret());
|
|
|
+ URI uri = UriComponentsBuilder.fromHttpUrl("https://api.weixin.qq.com/cgi-bin/message/custom/send")
|
|
|
+ .queryParam("access_token", accessToken)
|
|
|
+ .build().toUri();
|
|
|
// 发送请求
|
|
|
String result = restTemplate.postForObject(uri, paramMap, String.class);
|
|
|
log.error("客服消息发送结果, result : {}", result);
|
|
|
+ return "success";
|
|
|
}
|
|
|
|
|
|
@Override
|