Commit 7d2c1770 authored by renandong's avatar renandong 🇨🇳

1,设置毛博厂商特殊配置

2,增加查询毛博推送是否到达
3,短信推送定时任务增加毛博
parent 36a8d9ce
......@@ -19,10 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* @author : Administrator
......@@ -79,6 +76,9 @@ public class MobPushService {
request.put("pushNotify", pushNotify);
Map<String, Object> pushForward = getPushForward();
request.put("pushForward", pushForward);
//厂商特殊配置
Map<String, Object> pushFactoryExtra = getPushFactoryExtra();
request.put("pushFactoryExtra", pushFactoryExtra);
//groupId: AB分组测试ID
request.put("groupId", target.getValue());
String body = generalPost(request, pushUrl);
......@@ -89,6 +89,22 @@ public class MobPushService {
return null;
}
/**
* 厂商特殊渠道配置
*
* @return map
*/
private Map<String, Object> getPushFactoryExtra() {
Map<String, Object> pushFactoryExtra = new HashMap<>();
Map<String, Object> huaweiExtra = new HashMap<>();
huaweiExtra.put("importance", "NORMAL");
pushFactoryExtra.put("huaweiExtra", huaweiExtra);
Map<String, Object> vivoExtra = new HashMap<>();
vivoExtra.put("classification", "1");
pushFactoryExtra.put("vivoExtra", vivoExtra);
return pushFactoryExtra;
}
/**
* mob批量推送
*
......@@ -136,6 +152,45 @@ public class MobPushService {
return Model.error();
}
public boolean getPushInfoById(String workId) {
String reqUrl = "http://api.push.mob.com/v3/stats/getByWorkId";
Map<String, Object> request = new HashMap<>();
//appkey
request.put("appkey", APP_KEY);
request.put("workId", workId);
String body = generalPost(request, reqUrl);
log.error("查询回调结果:{}", body);
if (JSONUtil.isJson(body)) {
JSONObject json = JSONObject.parseObject(body);
if (json.containsKey("status") && json.getInteger("status").equals(200)) {
if (json.containsKey("res")) {
JSONObject res = json.getJSONObject("res");
if (Objects.nonNull(res)) {
if (res.containsKey("android")) {
JSONObject android = res.getJSONObject("android");
if (Objects.nonNull(android)) {
if (android.containsKey("deliverFailNum")) {
Integer deliverFailNum = android.getInteger("deliverFailNum");
return deliverFailNum <= 0;
}
}
} else if (res.containsKey("ios")) {
JSONObject ios = res.getJSONObject("ios");
if (Objects.nonNull(ios)) {
if (ios.containsKey("deliverFailNum")) {
Integer deliverFailNum = ios.getInteger("deliverFailNum");
return deliverFailNum <= 0;
}
}
}
}
}
}
}
return false;
}
private Map<String, Object> getItems(String[] target, String title, String content, Integer pushType) {
Map<String, Object> items = new HashMap<>();
items.put("itemId", IdUtil.fastUUID());
......
......@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.json.JSONUtil;
import com.weface.common.utils.*;
import com.weface.component.MenuService;
import com.weface.component.MobPushService;
import com.weface.config.RedisExpireData;
import com.weface.entity.MenuTagsEntity;
import com.weface.entity.PushLogEntity;
......@@ -58,35 +59,55 @@ public class UserTagsTask {
@Autowired
private PushLogService pushLogService;
@Autowired
private MobPushService mobPushService;
/**
* 查询推送日志时间
*/
private static final Integer TIME = 1;
private static final Integer TIME = 2;
/**
* 查询未推送消息成功记录,发送短信通知
*/
@Scheduled(cron = "0 0 0/1 * * ? ")
// @Scheduled(cron = "0 0 0/1 * * ?")
@Scheduled(cron = "0 0/2 * * * ?")
public void sendMessage() {
try {
log.error("开始执行短信送任务");
log.error("开始执行短信送任务");
List<PushLogEntity> list = pushLogService.getPushLogByTime(TIME);
if (!CollectionUtils.isEmpty(list)) {
DES des = DES.getInstanceDes();
for (PushLogEntity pushLogEntity : list) {
String phone = pushLogEntity.getPhone();
if (StringUtils.isNotEmpty(phone)){
if (StringUtils.isEmpty(phone)) {
continue;
}
if (CommonUtil.isBase64(phone)) {
phone = des.decrypt(phone);
}
Integer arriveStatus = pushLogEntity.getArriveStatus();
if (arriveStatus.equals(1001)) {
Integer pushType = pushLogEntity.getPushType();
if (Objects.nonNull(pushType)) {
String pushContent = pushLogEntity.getPushContent();
Integer messageTemplate = pushLogEntity.getMessageTemplate();
Integer arriveStatus = pushLogEntity.getArriveStatus();
if (1001 == arriveStatus) {
boolean push = false;
//毛博推送
if (pushType.equals(2)) {
//查询推送记录是否送到
push = mobPushService.getPushInfoById(pushLogEntity.getTaskId());
//推送已到达
if (push) {
pushLogEntity.setArriveStatus(1002);
pushLogEntity.setUpdateTime(new Date());
pushLogService.updateById(pushLogEntity);
}
}
if (!push) {
boolean b = ShortMsgSend.sendMobileByRegister(pushContent, phone, messageTemplate);
if (b) {
log.error("执行短信发送成功");
log.error("执行短信发送成功:{}", phone);
pushLogEntity.setArriveStatus(1003);
pushLogEntity.setUpdateTime(new Date());
pushLogService.updateById(pushLogEntity);
......@@ -95,6 +116,7 @@ public class UserTagsTask {
}
}
}
}
} catch (IOException e) {
log.error("执行短信发送失败:{}", e.getMessage());
e.printStackTrace();
......
......@@ -24,7 +24,7 @@
<select id="getPushLogByTime" resultMap="pushLogMap">
SELECT *
FROM tb_push_log
WHERE is_valid = 1
WHERE is_valid = 1 AND phone IS NOT NULL
AND arrive_status = 1001
AND create_time > DATE_SUB(
NOW(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment