|
@@ -31,6 +31,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.util.UriComponentsBuilder;
|
|
|
+import reactor.util.function.Tuple2;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
@@ -103,6 +104,9 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
|
@Autowired
|
|
|
private RedisUtil<String> redisUtil;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private KfWxApiService wxApiService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private IDistributedLockComponent distributedLockComponent;
|
|
|
|
|
@@ -211,8 +215,14 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
|
//玩家符合条件
|
|
|
if (CollectionUtils.isNotEmpty(orderList) && orderList.stream().map(Order::getAmount)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add).intValue() >= kfSystemReply.getRechargeReplyAmount()) {
|
|
|
- //发送消息
|
|
|
- this.sysMsgSend(gameId, openId, kfSystemReply.getRechargeReplyContent(), kfRoom);
|
|
|
+ //发送文字消息
|
|
|
+ if (Strings.isNotBlank(kfSystemReply.getRechargeReplyContent())) {
|
|
|
+ this.sysMsgSend(gameId, openId, kfSystemReply.getRechargeReplyContent(), kfRoom);
|
|
|
+ }
|
|
|
+ //发送图片消息
|
|
|
+ if (Strings.isNotBlank(kfSystemReply.getRechargeReplyPicture())) {
|
|
|
+ this.sysImgMsgSend(gameId, openId, kfSystemReply.getRechargeReplyPicture(), kfRoom);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
//判断玩家是否已接入状态, 非带接入状态, 不发送
|
|
@@ -238,13 +248,45 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
|
msgParamMap.put("touser", openId);
|
|
|
msgParamMap.put("msgtype", KfRoomMsgTypeEnum.KF_MSG_TYPE_TEXT.getValue());
|
|
|
msgParamMap.put("text", textMap);
|
|
|
- kfWxApiService.sendCustomMessageApi(gameId, msgParamMap);
|
|
|
+ //调腾讯接口发送消息
|
|
|
+ Tuple2<Long, String> tuple2 = kfWxApiService.sendCustomMessageApi(gameId, msgParamMap);
|
|
|
+ //发送失败
|
|
|
+ if (!Objects.equals(tuple2.getT1(), 0L)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
//保存消息
|
|
|
Map<String, Object> kfRoomMsgMap = new HashMap<>(1);
|
|
|
kfRoomMsgMap.put("text", msgContent);
|
|
|
kfRoomMsgService.save(this.transform(openId, gameId, kfRoom, KfRoomMsgTypeEnum.KF_MSG_TYPE_TEXT, JsonUtil.toString(kfRoomMsgMap)));
|
|
|
}
|
|
|
|
|
|
+ private void sysImgMsgSend(Long gameId, String openId, String imageUrl, KfRoom kfRoom) {
|
|
|
+ //发送消息
|
|
|
+ Map<String, Object> imageMap = new HashMap<>(1);
|
|
|
+ //图片上传到腾讯, 转成 media_id
|
|
|
+ Tuple2<Long, String> uploadTuple2 = wxApiService.mediaUpload(gameId, FileUtil.urlToMultipartFile(imageUrl));
|
|
|
+ //素材上传失败
|
|
|
+ if (uploadTuple2.getT1() != 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ imageMap.put("media_id", uploadTuple2.getT2());
|
|
|
+ //构造消息发送参数
|
|
|
+ Map<String, Object> msgParamMap = new HashMap<>(3);
|
|
|
+ msgParamMap.put("touser", openId);
|
|
|
+ msgParamMap.put("msgtype", KfRoomMsgTypeEnum.KF_MSG_TYPE_IMAGE.getValue());
|
|
|
+ msgParamMap.put(KfRoomMsgTypeEnum.KF_MSG_TYPE_IMAGE.getValue(), imageMap);
|
|
|
+ //调腾讯接口发送消息
|
|
|
+ Tuple2<Long, String> tuple2 = wxApiService.sendCustomMessageApi(gameId, msgParamMap);
|
|
|
+ //发送失败
|
|
|
+ if (!Objects.equals(tuple2.getT1(), 0L)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //保存消息
|
|
|
+ Map<String, Object> kfRoomMsgMap = new HashMap<>(1);
|
|
|
+ kfRoomMsgMap.put("image", imageUrl);
|
|
|
+ kfRoomMsgService.save(this.transform(openId, gameId, kfRoom, KfRoomMsgTypeEnum.KF_MSG_TYPE_IMAGE, JsonUtil.toString(kfRoomMsgMap)));
|
|
|
+ }
|
|
|
+
|
|
|
private boolean orderHandle(String orderId, Long gameId, KfAppletMsgDTO kfAppletMsgDTO, KfRoom kfRoom, KfRoomMsg kfRoomMsg) {
|
|
|
//判断收到的消息是否为充值消息或者小程序消息
|
|
|
if (!KfAppletMsgDTO.MSG_CONTENT_PAY.contains(kfAppletMsgDTO.getContent())
|
|
@@ -475,7 +517,11 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
|
msgParamMap.put("touser", openId);
|
|
|
msgParamMap.put("msgtype", KfRoomMsgTypeEnum.KF_MSG_TYPE_LINK.getValue());
|
|
|
msgParamMap.put(KfRoomMsgTypeEnum.KF_MSG_TYPE_LINK.getValue(), linkMap);
|
|
|
- kfWxApiService.sendCustomMessageApi(gameId, msgParamMap);
|
|
|
+ Tuple2<Long, String> tuple2 = kfWxApiService.sendCustomMessageApi(gameId, msgParamMap);
|
|
|
+ //发送失败
|
|
|
+ if (!Objects.equals(tuple2.getT1(), 0L)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
//保存发送的支付链接消息
|
|
|
kfRoomMsgService.save(this.transform(openId, gameId, kfRoom, KfRoomMsgTypeEnum.KF_MSG_TYPE_LINK, JsonUtil.toString(msgParamMap)));
|
|
|
//删除待支付订单标记
|