|
@@ -5,18 +5,18 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.zanxiang.game.module.base.ServerInfo;
|
|
|
import com.zanxiang.game.module.base.pojo.dto.H5GameConfigDTO;
|
|
|
import com.zanxiang.game.module.base.pojo.enums.HttpStatusEnum;
|
|
|
-import com.zanxiang.game.module.base.pojo.enums.PayDeviceEnum;
|
|
|
-import com.zanxiang.game.module.base.pojo.enums.PayWayEnum;
|
|
|
-import com.zanxiang.game.module.base.rpc.IAgentRpc;
|
|
|
import com.zanxiang.game.module.base.rpc.IKfMsgRpc;
|
|
|
-import com.zanxiang.game.module.mybatis.entity.*;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.Game;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.GameApplet;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.GameExt;
|
|
|
import com.zanxiang.game.module.mybatis.mapper.GameAppletMapper;
|
|
|
-import com.zanxiang.game.module.sdk.enums.OrderStateEnum;
|
|
|
-import com.zanxiang.game.module.sdk.pojo.dto.*;
|
|
|
+import com.zanxiang.game.module.sdk.pojo.dto.AppletMsgDTO;
|
|
|
+import com.zanxiang.game.module.sdk.pojo.dto.GameAppletDTO;
|
|
|
import com.zanxiang.game.module.sdk.pojo.param.UserData;
|
|
|
import com.zanxiang.game.module.sdk.pojo.vo.GameInitVO;
|
|
|
-import com.zanxiang.game.module.sdk.service.*;
|
|
|
-import com.zanxiang.game.module.sdk.service.api.WxApiService;
|
|
|
+import com.zanxiang.game.module.sdk.service.IGameAppletService;
|
|
|
+import com.zanxiang.game.module.sdk.service.IGameExtService;
|
|
|
+import com.zanxiang.game.module.sdk.service.IGameService;
|
|
|
import com.zanxiang.game.module.sdk.service.pay.MiPayService;
|
|
|
import com.zanxiang.game.module.sdk.util.SignUtil;
|
|
|
import com.zanxiang.module.util.JsonUtil;
|
|
@@ -28,12 +28,8 @@ import org.apache.logging.log4j.util.Strings;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.web.client.RestTemplate;
|
|
|
-import org.springframework.web.util.UriComponentsBuilder;
|
|
|
import reactor.util.function.Tuples;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.net.URI;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
@@ -47,20 +43,11 @@ import java.util.Objects;
|
|
|
@Service
|
|
|
public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApplet> implements IGameAppletService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private IOrderService orderService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private WxApiService wxApiService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private RestTemplate restTemplate;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IGamePayWayService gamePayWayService;
|
|
|
+ @DubboReference(providedBy = ServerInfo.SERVER_DUBBO_NAME)
|
|
|
+ private IKfMsgRpc kfMsgRpc;
|
|
|
|
|
|
- @Autowired
|
|
|
- private IPayApplicationService payApplicationService;
|
|
|
+ @Value("${payConfig.wxPay.customH5Url}")
|
|
|
+ private String customH5Url;
|
|
|
|
|
|
@Autowired
|
|
|
private IGameService gameService;
|
|
@@ -71,15 +58,6 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
|
|
|
@Autowired
|
|
|
private MiPayService miPayService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private IKfLinkService kfLinkService;
|
|
|
-
|
|
|
- @DubboReference(providedBy = ServerInfo.SERVER_DUBBO_NAME)
|
|
|
- private IKfMsgRpc kfMsgRpc;
|
|
|
-
|
|
|
- @Value("${payConfig.wxPay.customH5Url}")
|
|
|
- private String customH5Url;
|
|
|
-
|
|
|
@Override
|
|
|
public String appletMsgCheck(String appId, String signature, String timestamp, String nonce, String echoStr) throws Exception {
|
|
|
GameAppletDTO gameAppletDTO = this.getByAppId(appId);
|
|
@@ -111,33 +89,18 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
|
|
|
signature, mySignature);
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
- log.error("收到腾讯监听服务器内容, postData : {}", JsonUtil.toString(postData));
|
|
|
-
|
|
|
//消息内容
|
|
|
AppletMsgDTO appletMsgDTO = JsonUtil.toObj(postData, AppletMsgDTO.class);
|
|
|
-
|
|
|
- log.error("收到腾讯监听服务器内容, appletMsgDTO : {}", JsonUtil.toString(appletMsgDTO));
|
|
|
-
|
|
|
-// //文本消息
|
|
|
-// if (Objects.equals(appletMsgDTO.getMsgType(), AppletMsgDTO.MSG_TYPE_TEXT)) {
|
|
|
-// //用户信息
|
|
|
-// UserDTO userDTO = userService.getUserByOpenId(gameAppletDTO.getGameId(), appletMsgDTO.getFromUserName());
|
|
|
-// //用户客服支付会话
|
|
|
-// if (Objects.equals(appletMsgDTO.getContent(), AppletMsgDTO.MSG_CONTENT_PAY)) {
|
|
|
-// return this.customPayMessage(gameAppletDTO, userDTO);
|
|
|
-// }
|
|
|
-// //非客服会话, 返回指定的客服链接
|
|
|
-// return this.customLinkMessage(gameAppletDTO, userDTO);
|
|
|
-// }
|
|
|
//米大师支付回调事件
|
|
|
if (Objects.equals(appletMsgDTO.getMsgType(), AppletMsgDTO.MSG_TYPE_EVENT)
|
|
|
&& Objects.equals(appletMsgDTO.getEvent(), AppletMsgDTO.EVENT_MI_PAY_CALL_BACK)) {
|
|
|
return this.miPayMessage(appletMsgDTO, gameAppletDTO);
|
|
|
}
|
|
|
-
|
|
|
- kfMsgRpc.appletMsg(postData);
|
|
|
-
|
|
|
+ //消息转发到后台客服系统处理
|
|
|
+ try {
|
|
|
+ kfMsgRpc.appletMsg(postData);
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ }
|
|
|
//其他消息不处理, 直接返回成功
|
|
|
return result;
|
|
|
}
|
|
@@ -189,84 +152,6 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
|
|
|
return Objects.equals(miPayNotifyResult, Boolean.TRUE) ? successResult : failResult;
|
|
|
}
|
|
|
|
|
|
- private String customPayMessage(GameAppletDTO gameAppletDTO, UserDTO userDTO) {
|
|
|
- //查询用户最新客服支付订单
|
|
|
- Order order = orderService.getOne(new LambdaQueryWrapper<Order>()
|
|
|
- .eq(Order::getUserId, userDTO.getId())
|
|
|
- .eq(Order::getStatus, OrderStateEnum.READY_PAY.getCode())
|
|
|
- .eq(Order::getPayWayId, PayWayEnum.WX_PAY.getPayWayId())
|
|
|
- .eq(Order::getPayDeviceId, PayDeviceEnum.CUSTOM_PAY.getPayDeviceId())
|
|
|
- .orderByDesc(Order::getCreateTime)
|
|
|
- .last("limit 1"));
|
|
|
- if (order != null) {
|
|
|
- //发送客服消息
|
|
|
- return this.sendCustomMessage(gameAppletDTO, userDTO.getOpenId(), order);
|
|
|
- }
|
|
|
- return HttpStatusEnum.SUCCESS.getMsg();
|
|
|
- }
|
|
|
-
|
|
|
- private String customLinkMessage(GameAppletDTO gameAppletDTO, UserDTO userDTO) {
|
|
|
- //判断是否配置了第三方客服链接
|
|
|
- KfLink kfLink = kfLinkService.getOne(new LambdaQueryWrapper<KfLink>()
|
|
|
- .eq(KfLink::getAppId, gameAppletDTO.getAppId()));
|
|
|
- if (kfLink == null || Strings.isBlank(kfLink.getCustomLink())) {
|
|
|
- return HttpStatusEnum.SUCCESS.getMsg();
|
|
|
- }
|
|
|
- //其他消息对象
|
|
|
- Map<String, Object> textMap = new HashMap<>(1);
|
|
|
- textMap.put("content", kfLink.getCustomLink());
|
|
|
- return this.sendCustomMessageApi(gameAppletDTO, userDTO.getOpenId(), "text", textMap);
|
|
|
- }
|
|
|
-
|
|
|
- private String sendCustomMessage(GameAppletDTO gameAppletDTO, String openId, Order order) {
|
|
|
- //查询订单支付方式
|
|
|
- GamePayWayDTO gamePayWayDTO = gamePayWayService.getById(order.getGamePayWayId());
|
|
|
- //查询支付应用信息
|
|
|
- PayApplicationDTO payApplicationDTO = payApplicationService.getPayApplicationByPayBoxId(gamePayWayDTO.getPayBoxId());
|
|
|
- //客服支付链接显示图片地址
|
|
|
- String thumbUrl = gamePayWayDTO.getThumbUrl();
|
|
|
- //支付配置参数判断
|
|
|
- if (Strings.isBlank(thumbUrl)) {
|
|
|
- log.error("客服消息卡片图片地址不存在, gamePayWayDTO : {}", JsonUtil.toString(gamePayWayDTO));
|
|
|
- return HttpStatusEnum.SUCCESS.getMsg();
|
|
|
- }
|
|
|
- //订单金额
|
|
|
- BigDecimal amount = order.getAmount();
|
|
|
- //构造跳转链接url
|
|
|
- URI url = UriComponentsBuilder.fromHttpUrl(this.customH5Url)
|
|
|
- .queryParam("appId", payApplicationDTO.getAppId())
|
|
|
- .queryParam("orderId", order.getOrderId())
|
|
|
- .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", thumbUrl);
|
|
|
- //发送客服消息
|
|
|
- return this.sendCustomMessageApi(gameAppletDTO, openId, "link", linkMap);
|
|
|
- }
|
|
|
-
|
|
|
- private String sendCustomMessageApi(GameAppletDTO gameAppletDTO, String openId, String msgType, Map<String, Object> msgMap) {
|
|
|
- //客服消息参数构造
|
|
|
- Map<String, Object> paramMap = new HashMap<>(3);
|
|
|
- paramMap.put("touser", openId);
|
|
|
- paramMap.put("msgtype", msgType);
|
|
|
- paramMap.put(msgType, msgMap);
|
|
|
- log.error("客服消息发送参数, paramMap : {}", JsonUtil.toString(paramMap));
|
|
|
- //获取接口token
|
|
|
- String accessToken = wxApiService.getAccessToken(gameAppletDTO.getAppId(), gameAppletDTO.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 HttpStatusEnum.SUCCESS.getMsg();
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public GameAppletDTO getByGameId(Long gameId) {
|
|
|
GameApplet gameApplet = super.getOne(new LambdaQueryWrapper<GameApplet>()
|