|
@@ -17,6 +17,7 @@ import com.zanxiang.game.module.sdk.pojo.param.UserData;
|
|
import com.zanxiang.game.module.sdk.pojo.vo.GameInitVO;
|
|
import com.zanxiang.game.module.sdk.pojo.vo.GameInitVO;
|
|
import com.zanxiang.game.module.sdk.service.*;
|
|
import com.zanxiang.game.module.sdk.service.*;
|
|
import com.zanxiang.game.module.sdk.service.api.WxApiService;
|
|
import com.zanxiang.game.module.sdk.service.api.WxApiService;
|
|
|
|
+import com.zanxiang.game.module.sdk.service.pay.MiPayService;
|
|
import com.zanxiang.game.module.sdk.util.SignUtil;
|
|
import com.zanxiang.game.module.sdk.util.SignUtil;
|
|
import com.zanxiang.module.util.JsonUtil;
|
|
import com.zanxiang.module.util.JsonUtil;
|
|
import com.zanxiang.module.util.bean.BeanUtil;
|
|
import com.zanxiang.module.util.bean.BeanUtil;
|
|
@@ -28,9 +29,11 @@ import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.util.UriComponentsBuilder;
|
|
import org.springframework.web.util.UriComponentsBuilder;
|
|
|
|
+import reactor.util.function.Tuples;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.net.URI;
|
|
import java.net.URI;
|
|
|
|
+import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
@@ -68,6 +71,9 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
|
|
@Autowired
|
|
@Autowired
|
|
private IGameExtService gameExtService;
|
|
private IGameExtService gameExtService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private MiPayService miPayService;
|
|
|
|
+
|
|
@Value("${payConfig.wxPay.customH5Url}")
|
|
@Value("${payConfig.wxPay.customH5Url}")
|
|
private String customH5Url;
|
|
private String customH5Url;
|
|
|
|
|
|
@@ -108,32 +114,77 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
|
|
}
|
|
}
|
|
//消息内容
|
|
//消息内容
|
|
AppletMsgDTO appletMsgDTO = JsonUtil.toObj(postData, AppletMsgDTO.class);
|
|
AppletMsgDTO appletMsgDTO = JsonUtil.toObj(postData, AppletMsgDTO.class);
|
|
|
|
+ //用户客服支付会话
|
|
|
|
+ if (Objects.equals(appletMsgDTO.getMsgType(), AppletMsgDTO.MSG_TYPE_TEXT)
|
|
|
|
+ && Objects.equals(appletMsgDTO.getContent(), AppletMsgDTO.MSG_CONTENT_PAY)) {
|
|
|
|
+ return this.customPayMessage(gameAppletDTO, appletMsgDTO);
|
|
|
|
+ }
|
|
|
|
+ //米大师支付回调事件
|
|
|
|
+ if (Objects.equals(appletMsgDTO.getMsgType(), AppletMsgDTO.MSG_TYPE_EVENT)
|
|
|
|
+ && Objects.equals(appletMsgDTO.getEvent(), AppletMsgDTO.EVENT_MI_PAY_CALL_BACK)) {
|
|
|
|
+ return this.miPayMessage(appletMsgDTO, gameAppletDTO);
|
|
|
|
+ }
|
|
|
|
+ //其他消息不处理, 直接返回成功
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String miPayMessage(AppletMsgDTO appletMsgDTO, GameAppletDTO gameAppletDTO) {
|
|
|
|
+ log.error("米大师支付回调 appletMsgDTO : {}", JsonUtil.toString(appletMsgDTO));
|
|
|
|
+ String failResult = JsonUtil.toString(Collections.singletonMap(99999L, "internal error"));
|
|
|
|
+ String successResult = JsonUtil.toString(Collections.singletonMap(0L, "Success"));
|
|
|
|
+ //通知内容
|
|
|
|
+ AppletMsgDTO.MiniGameBean miniGame = appletMsgDTO.getMiniGame();
|
|
|
|
+ //判断是否为模拟数据, 模拟数据直接返回, 不进行业务处理
|
|
|
|
+ if (Objects.equals(miniGame.getIsMock(), Boolean.TRUE)) {
|
|
|
|
+ return successResult;
|
|
|
|
+ }
|
|
|
|
+ //支付内容
|
|
|
|
+ AppletMsgDTO.PayloadBean payload = miniGame.getPayload();
|
|
|
|
+ if (payload == null) {
|
|
|
|
+ log.error("米大师支付回调参数错误, 没有支付信息 appletMsgDTO : {}", JsonUtil.toString(appletMsgDTO));
|
|
|
|
+ return failResult;
|
|
|
|
+ }
|
|
|
|
+ //商户订单号和交易订单号判断
|
|
|
|
+ AppletMsgDTO.WeChatPayInfoBean weChatPayInfo = payload.getWeChatPayInfo();
|
|
|
|
+ if (weChatPayInfo == null || Strings.isBlank(weChatPayInfo.getMchOrderNo())
|
|
|
|
+ || Strings.isBlank(weChatPayInfo.getTransactionId())) {
|
|
|
|
+ log.error("米大师支付回调参数错误, 没有支付信息 appletMsgDTO : {}", JsonUtil.toString(appletMsgDTO));
|
|
|
|
+ return failResult;
|
|
|
|
+ }
|
|
|
|
+ //查询游戏小程序信息
|
|
|
|
+ String appKey = gameAppletDTO.getMiPayConfigBean().getAppKey();
|
|
|
|
+ //计算签名
|
|
|
|
+ String mySign = miPayService.calcSignature(appletMsgDTO.getEvent() + "&" + miniGame.getPayload(), appKey);
|
|
|
|
+ //签名不匹配
|
|
|
|
+ if (Objects.equals(mySign, miniGame.getPayEventSig())) {
|
|
|
|
+ log.error("米大师支付回调签名不匹配, mySign : {}, PayEventSig : {}, appKey : {}",
|
|
|
|
+ mySign, miniGame.getPayEventSig(), appKey);
|
|
|
|
+ return failResult;
|
|
|
|
+ }
|
|
|
|
+ log.error("米大师支付回调签名匹配成功, 开始计算业务数据--------------->");
|
|
|
|
+ //更新订单信息
|
|
|
|
+ Boolean miPayNotifyResult = miPayService.miPayNotify(payload.getOutTradeNo(),
|
|
|
|
+ Tuples.of(weChatPayInfo.getMchOrderNo(), weChatPayInfo.getTransactionId()));
|
|
|
|
+ //放业务更新结果
|
|
|
|
+ return Objects.equals(miPayNotifyResult, Boolean.TRUE) ? successResult : failResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String customPayMessage(GameAppletDTO gameAppletDTO, AppletMsgDTO appletMsgDTO) {
|
|
//用户信息
|
|
//用户信息
|
|
UserDTO userDTO = userService.getUserByOpenId(gameAppletDTO.getGameId(), appletMsgDTO.getFromUserName());
|
|
UserDTO userDTO = userService.getUserByOpenId(gameAppletDTO.getGameId(), appletMsgDTO.getFromUserName());
|
|
- //客服支付
|
|
|
|
- if (Objects.equals(appletMsgDTO.getMsgType(), "text") && Objects.equals(appletMsgDTO.getContent(), "2")) {
|
|
|
|
- //查询用户最新客服支付订单
|
|
|
|
- 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);
|
|
|
|
- }
|
|
|
|
|
|
+ //查询用户最新客服支付订单
|
|
|
|
+ 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 result;
|
|
|
|
-// //非客服支付, 回复通用消息
|
|
|
|
-// GameExt gameExt = gameExtService.getByGameId(userDTO.getGameId());
|
|
|
|
-// String text = "尊敬的玩家您好,请您用QQ添加:" + gameExt.getCustomerQq()
|
|
|
|
-// + ",联系官方客服哦,客服目前排队比较多,请您耐心等待,请您备注好区服角色,方便客服第一时间为您处理问题";
|
|
|
|
-// //客服消息参数构造
|
|
|
|
-// Map<String, Object> textMap = new HashMap<>(1);
|
|
|
|
-// textMap.put("content", text);
|
|
|
|
-// return this.sendCustomMessageApi(gameAppletDTO, userDTO.getOpenId(), "text", textMap);
|
|
|
|
|
|
+ return HttpStatusEnum.SUCCESS.getMsg();
|
|
}
|
|
}
|
|
|
|
|
|
private String sendCustomMessage(GameAppletDTO gameAppletDTO, String openId, Order order) {
|
|
private String sendCustomMessage(GameAppletDTO gameAppletDTO, String openId, Order order) {
|