Commit 69c70dfb authored by zuoadmin's avatar zuoadmin

Merge branch 'dev' into 'master'

Dev

See merge request !12
parents 83787df1 17f7a014
...@@ -3,19 +3,24 @@ package com.weface.component; ...@@ -3,19 +3,24 @@ package com.weface.component;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HtmlUtil;
import cn.hutool.http.HttpException; import cn.hutool.http.HttpException;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.weface.code.CommonResult;
import com.weface.common.exception.RRException; import com.weface.common.exception.RRException;
import com.weface.common.utils.Base64Util; import com.weface.common.utils.Base64Util;
import com.weface.common.utils.HttpUtil; import com.weface.common.utils.HttpUtil;
import com.weface.common.utils.RedisUtil; import com.weface.common.utils.RedisUtil;
import com.weface.dto.InformForm;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -35,6 +40,10 @@ public class GeTuiUtils { ...@@ -35,6 +40,10 @@ public class GeTuiUtils {
public static final String KK_SB_MASTER_SECRET = "b8MSgB7j8PAImc3eN0yuL9"; public static final String KK_SB_MASTER_SECRET = "b8MSgB7j8PAImc3eN0yuL9";
public static final String KK_SB_APP_KEY = "2tLtJhcpij7lu3ksutgpU3"; public static final String KK_SB_APP_KEY = "2tLtJhcpij7lu3ksutgpU3";
public static final String KK_WJ_APP_ID = "LhnWI1t7hc7ABsYbWokXD6";
public static final String KK_WJ_MASTER_SECRET = "JojRk0duJd6oXiHIyFPqj";
public static final String KK_WJ_APP_KEY = "vIBAFNAEk88qekbfS3miE8";
public static final String GE_TUI_BASE_URL = "https://restapi.getui.com/v2/"; public static final String GE_TUI_BASE_URL = "https://restapi.getui.com/v2/";
public static final String BASEURL = "https://openapi-gi.getui.com/v2/"; public static final String BASEURL = "https://openapi-gi.getui.com/v2/";
public static final String ENCODING = "UTF-8"; public static final String ENCODING = "UTF-8";
...@@ -93,6 +102,13 @@ public class GeTuiUtils { ...@@ -93,6 +102,13 @@ public class GeTuiUtils {
} }
geTui = key; geTui = key;
break; break;
case "kk_wj_token_ge_tui":
authToken = getGeTuiAuth(KK_WJ_APP_ID, KK_WJ_APP_KEY, KK_WJ_MASTER_SECRET);
if (ObjectUtil.isNull(authToken)) {
throw new RRException("获取看看卫建个推token失败");
}
geTui = key;
break;
default: default:
break; break;
} }
...@@ -236,19 +252,35 @@ public class GeTuiUtils { ...@@ -236,19 +252,35 @@ public class GeTuiUtils {
/** /**
* 【toSingle】执行别名单推 * 【toSingle】执行别名单推
* *
* @param alias 用户别名 * @param messageTemplate 应用id
* @param messageTemplate 消息模板 * @param appId 消息模板
* @param token 接口访问凭据 * @param token 接口访问凭据
* @return 消息推送结果 * @return 消息推送结果
*/ */
public static String singlePushAlias(String[] alias, MessageTemplate messageTemplate, String token) { public static String singlePushAlias(Integer device, MessageTemplate messageTemplate, String appId, String token) throws UnsupportedEncodingException {
Map<String, Object> map = convertBeanToMap(alias, messageTemplate); Map<String, Object> map = convertBeanToMap(device, false, 1, messageTemplate);
//请求url //请求url
String url = GE_TUI_BASE_URL + KK_SH_APP_ID + "/push/single/alias"; String url = GE_TUI_BASE_URL + appId + "/push/single/alias";
log.info("执行别名单推"); log.info("执行别名单推");
return generalPost(url, token, map); return generalPost(url, token, map);
} }
/**
* 【toSingle】执行cid单推
*
* @param appId appId
* @param messageTemplate 消息
* @param token 鉴权
* @return 执行结果
*/
public static String singlePushCid(Integer device, String appId, MessageTemplate messageTemplate, String token) throws UnsupportedEncodingException {
Map<String, Object> map = convertBeanToMap(device, false, 0, messageTemplate);
//请求url
String url = GE_TUI_BASE_URL + appId + "/push/single/cid";
log.info("执行cid单推");
return generalPost(url, token, map);
}
/** /**
* 创建消息拿到任务id * 创建消息拿到任务id
* *
...@@ -256,10 +288,10 @@ public class GeTuiUtils { ...@@ -256,10 +288,10 @@ public class GeTuiUtils {
* @param token token * @param token token
* @return 任务id * @return 任务id
*/ */
public static String getTaskId(MessageTemplate messageTemplate, String token) { public static String getTaskId(Integer device, String appId, MessageTemplate messageTemplate, String token) throws UnsupportedEncodingException {
Map<String, Object> map = convertBeanToMap(null, messageTemplate); Map<String, Object> map = convertBeanToMap(device, true, 1, messageTemplate);
//请求url //请求url
String url = GE_TUI_BASE_URL + KK_SH_APP_ID + "/push/list/message"; String url = GE_TUI_BASE_URL + appId + "/push/list/message";
String body = generalPost(url, token, map); String body = generalPost(url, token, map);
JSONObject jsonObject = JSONObject.parseObject(body); JSONObject jsonObject = JSONObject.parseObject(body);
return (jsonObject.containsKey("code") && jsonObject.getInteger("code") == 0) ? jsonObject.getJSONObject("data").getString("taskid") : body; return (jsonObject.containsKey("code") && jsonObject.getInteger("code") == 0) ? jsonObject.getJSONObject("data").getString("taskid") : body;
...@@ -315,6 +347,63 @@ public class GeTuiUtils { ...@@ -315,6 +347,63 @@ public class GeTuiUtils {
return generalPost(url, token, map); return generalPost(url, token, map);
} }
/**
* 群推
*
* @param informForm 消息
* @return 执行状态
*/
public static CommonResult listPush(InformForm informForm) {
MessageTemplate messageTemplate = new MessageTemplate();
try {
Integer device = informForm.getDevice();
if (device == null) {
device = 4;
}
Integer speed = informForm.getSpeed();
messageTemplate.setSettings(new MessageTemplate.Settings(3600000, speed == null ? 0 : speed));
MessageTemplate.PushMessage pushMessage = new MessageTemplate.PushMessage();
MessageTemplate.PushMessage.Transmission transmission = new MessageTemplate.PushMessage.Transmission();
transmission.setTitle(informForm.getTitle());
transmission.setContent(informForm.getBody());
transmission.setUrl(HtmlUtil.unescape(informForm.getUrl()));
pushMessage.setTransmission(transmission);
messageTemplate.setPush_message(pushMessage);
String result = null;
switch (informForm.getEquipmentType()) {
//看看生活
case "kksh":
String kk_sh_token_ge_tui = getAuthToken("kk_sh_token_ge_tui");
result = GeTuiUtils.listPushToApp(device, messageTemplate, KK_SH_APP_ID, kk_sh_token_ge_tui);
break;
//看看社保
case "kksb":
String kk_sb_token_ge_tui = getAuthToken("kk_sb_token_ge_tui");
result = GeTuiUtils.listPushToApp(device, messageTemplate, KK_SB_APP_ID, kk_sb_token_ge_tui);
break;
case "kkwj":
String kk_wj_token_ge_tui = getAuthToken("kk_wj_token_ge_tui");
result = GeTuiUtils.listPushToApp(device, messageTemplate, KK_WJ_APP_ID, kk_wj_token_ge_tui);
break;
default:
break;
}
if (result == null) {
return CommonResult.failed();
}
JSONObject jsonObject = JSONObject.parseObject(result);
if ((jsonObject.containsKey("code") && jsonObject.getInteger("code") == 0)) {
JSONObject data = jsonObject.getJSONObject("data");
return CommonResult.success(data);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return CommonResult.failed();
}
/** /**
* 【toApp】执行群推 * 【toApp】执行群推
* *
...@@ -322,8 +411,8 @@ public class GeTuiUtils { ...@@ -322,8 +411,8 @@ public class GeTuiUtils {
* @param token token * @param token token
* @return 执行结果 * @return 执行结果
*/ */
public static String listPushToApp(MessageTemplate messageTemplate, String appId, String token) { public static String listPushToApp(Integer device, MessageTemplate messageTemplate, String appId, String token) throws UnsupportedEncodingException {
Map<String, Object> map = convertBeanToMap(null, messageTemplate); Map<String, Object> map = convertBeanToMap(device, false, 1, messageTemplate);
//请求url //请求url
String url = GE_TUI_BASE_URL + appId + "/push/all"; String url = GE_TUI_BASE_URL + appId + "/push/all";
log.info("执行群推"); log.info("执行群推");
...@@ -333,17 +422,13 @@ public class GeTuiUtils { ...@@ -333,17 +422,13 @@ public class GeTuiUtils {
/** /**
* 实体类封装为map * 实体类封装为map
* *
* @param alias 别名
* @param messageTemplate 消息模板 * @param messageTemplate 消息模板
* @return map对象 * @return map对象
*/ */
public static Map<String, Object> convertBeanToMap(String[] alias, MessageTemplate messageTemplate) { public static Map<String, Object> convertBeanToMap(Integer device, boolean flag, int type, MessageTemplate messageTemplate) throws UnsupportedEncodingException {
if (messageTemplate == null) { if (messageTemplate == null) {
return null; return null;
} }
//设置推送目标
messageTemplate.setAudience(new MessageTemplate.Audience(alias));
//设置请求唯一标识号,10-32位之间;如果request_id重复,会导致消息丢失 //设置请求唯一标识号,10-32位之间;如果request_id重复,会导致消息丢失
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("request_id", String.valueOf(IdUtil.getSnowflake(1, 1).nextId())); map.put("request_id", String.valueOf(IdUtil.getSnowflake(1, 1).nextId()));
...@@ -354,112 +439,120 @@ public class GeTuiUtils { ...@@ -354,112 +439,120 @@ public class GeTuiUtils {
} }
//推送条件设置 //推送条件设置
MessageTemplate.Settings settings = messageTemplate.getSettings(); Map<String, Object> setting = BeanUtil.beanToMap(messageTemplate.getSettings(), false, true);
if (settings != null) { Map<String, Object> strategy = new HashMap<>();
Map<String, Object> setting = BeanUtil.beanToMap(settings, false, true); strategy.put("default", 4);
Map<String, Object> strategy = new HashMap<>(); strategy.put("ios", 1);
strategy.put("default", 4); strategy.put("st", 4);
strategy.put("ios", 4); strategy.put("hw", 4);
strategy.put("st", 4); strategy.put("xm", 4);
strategy.put("hw", 4); strategy.put("vv", 4);
strategy.put("xm", 4); strategy.put("mz", 4);
strategy.put("vv", 4); strategy.put("op", 4);
strategy.put("mz", 4); setting.put("strategy", strategy);
strategy.put("op", 4); map.put("settings", setting);
setting.put("strategy", strategy); //获取推送目标
map.put("settings", setting); if (!flag) {
} //推送目标用户该接口audience 对应值为all,表示推送所有用户
MessageTemplate.Audience audience1 = messageTemplate.getAudience();
//推送目标用户该接口audience 对应值为all,表示推送所有用户 if (audience1 == null) {
if (alias == null || alias.length == 0) { map.put("audience", "all");
map.put("audience", "all"); } else {
} else { if (type == 1) {
Map<String, Object> audience = BeanUtil.beanToMap(messageTemplate.getAudience(), false, true); Map<String, Object> audience = BeanUtil.beanToMap(audience1, false, true);
map.put("audience", audience); map.put("audience", audience);
} else {
Map<String, Object> cid = new HashMap<>();
cid.put("cid", audience1.getAlias());
map.put("audience", cid);
}
}
} }
//获取推送消息转为map 不转为下划线,忽略空值 //获取推送消息转为map 不转为下划线,忽略空值
MessageTemplate.PushMessage push_message = messageTemplate.getPush_message(); MessageTemplate.PushMessage push_message = messageTemplate.getPush_message();
Map<String, Object> push_messages = BeanUtil.beanToMap(push_message, false, true); Map<String, Object> push_messages = BeanUtil.beanToMap(push_message, false, true);
//转换消息忽略空值 //透传消息内容,与notification、revoke 三选一,都填写时报错,长度 ≤ 3072
MessageTemplate.PushMessage.Notification notification = push_message.getNotification(); MessageTemplate.PushMessage.Transmission transmission = push_message.getTransmission();
if (notification != null) { String str = "{\"content\": \"%s\", \"push_type\": \"0\", \"title\": \"%s\", \"url\": \"%s\"}";
//设置消息 String intent = String.format(str, transmission.getContent(), transmission.getTitle(), transmission.getUrl());
Map<String, Object> notifications = BeanUtil.beanToMap(notification, false, true); push_messages.put("transmission", intent);
push_messages.put("notification", notifications);
}
//撤回消息时使用(仅撤回厂商通道消息,支持的厂商有小米、VIVO),与notification、transmission三选一,都填写时报错(消息撤回请勿填写策略参数)
MessageTemplate.PushMessage.Revoke revoke = push_message.getRevoke(); MessageTemplate.PushMessage.Revoke revoke = push_message.getRevoke();
if (revoke != null) { if (revoke != null) {
//设置撤回消息 //设置撤回消息
Map<String, Object> revokes = BeanUtil.beanToMap(revoke, false, true); Map<String, Object> revokes = BeanUtil.beanToMap(revoke, false, true);
push_messages.put("revoke", revokes); push_messages.put("revoke", revokes);
} }
//设置ios厂商通道 //设置推送消息
map.put("push_channel", setChannel(notification));
//设置android厂商通道
map.put("push_message", push_messages); map.put("push_message", push_messages);
//设置厂商通道
map.put("push_channel", setChannel(push_message));
return map; return map;
} }
/** /**
* 设置推送渠道 * 设置推送渠道
* *
* @param notification 消息 * @param push_message 消息
* @return json * @return json
*/ */
public static cn.hutool.json.JSONObject setChannel(MessageTemplate.PushMessage.Notification notification) { public static cn.hutool.json.JSONObject setChannel(MessageTemplate.PushMessage push_message) throws UnsupportedEncodingException {
Map<String, Object> channel = new HashMap<>(); Map<String, Object> channel = new HashMap<>();
//获取ios配置 //获取ios配置
channel.put("ios", getIosChannel(notification)); channel.put("ios", getIosChannel(push_message));
//获取android配置 //获取android配置
channel.put("android", getAndroidChannel(notification)); channel.put("android", getAndroidChannel(push_message));
return JSONUtil.parseFromMap(channel); return JSONUtil.parseFromMap(channel);
} }
/** /**
* ios厂商通道消息配置 * ios厂商通道消息配置
* *
* @param notification 消息 * @param push_message 消息
* @return ios配置 * @return ios配置
*/ */
private static Map<String, Object> getIosChannel(MessageTemplate.PushMessage.Notification notification) { private static Map<String, Object> getIosChannel(MessageTemplate.PushMessage push_message) throws UnsupportedEncodingException {
Map<String, Object> ios = new HashMap<>(); Map<String, Object> ios = new HashMap<>();
ios.put("type", "notify"); ios.put("type", "notify");
// ios.put("auto_badge", "+1");
//推送通知消息内容 //推送通知消息内容
Map<String, Object> aps = new HashMap<>(); Map<String, Object> aps = new HashMap<>();
aps.put("content-available", 0); aps.put("content-available", 0);
//通知消息 //通知消息
MessageTemplate.PushMessage.Transmission transmission = push_message.getTransmission();
Map<String, Object> alert = new HashMap<>(); Map<String, Object> alert = new HashMap<>();
alert.put("title", notification.getTitle()); alert.put("title", transmission.getTitle());
alert.put("body", notification.getBody()); alert.put("body", transmission.getContent());
aps.put("alert", alert); aps.put("alert", alert);
ios.put("aps", aps); ios.put("aps", aps);
String str = "{\"content\": \"%s\", \"push_type\": \"0\", \"title\": \"%s\", \"url\": \"%s\"}";
String intent = String.format(str, transmission.getContent(), transmission.getTitle(), transmission.getUrl());
ios.put("payload", intent);
return ios; return ios;
} }
/** /**
* 安卓厂商通道消息配置 * 安卓厂商通道消息配置
* *
* @param notification 消息 * @param push_message 消息
* @return android配置 * @return android配置
*/ */
private static Map<String, Object> getAndroidChannel(MessageTemplate.PushMessage.Notification notification) { private static Map<String, Object> getAndroidChannel(MessageTemplate.PushMessage push_message) throws UnsupportedEncodingException {
Map<String, Object> android = new HashMap<>(); Map<String, Object> android = new HashMap<>();
//android厂商通道推送消息内容
Map<String, Object> ups = new HashMap<>(); Map<String, Object> ups = new HashMap<>();
//通知消息内容,与transmission、revoke三选一,都填写时报错。若希望客户端离线时,直接在系统通知栏中展示通知栏消息,推荐使用此参数。 MessageTemplate.PushMessage.Transmission transmission = push_message.getTransmission();
Map<String, Object> informAndroid = new HashMap<>(); HashMap<String, Object> notification = new HashMap<>();
informAndroid.put("title", notification.getTitle()); notification.put("title", transmission.getTitle());
informAndroid.put("body", notification.getBody()); notification.put("body", transmission.getContent());
informAndroid.put("click_type", notification.getClick_type()); notification.put("click_type", "intent");
informAndroid.put("url", notification.getUrl()); String pack = "com.weface.kksocialsecurity";
ups.put("notification", informAndroid); String component = pack + "/com.weface.kksocialsecurity.activity.WellcomeActivity";
String str = "intent://com.weface.kksocialsecurity/localopen?push_type=0&url=%s#Intent;scheme=kankan;package=%s;component=%s;S.kkparam={\"content\": \"%s\", \"push_type\": \"0\", \"title\": \"%s\", \"url\": \"%s\"};end";
String intent = String.format(str, URLEncoder.encode(transmission.getUrl(), "UTF-8"), pack, component, transmission.getContent(), transmission.getTitle(), URLEncoder.encode(transmission.getUrl(), "UTF-8"));
notification.put("intent", intent);
ups.put("notification", notification);
android.put("ups", ups); android.put("ups", ups);
return android; return android;
} }
......
package com.weface.component; package com.weface.component;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.convert.ConvertException; import cn.hutool.core.convert.ConvertException;
import cn.hutool.core.lang.Snowflake; import cn.hutool.core.lang.Snowflake;
...@@ -104,7 +105,7 @@ public class MenuService { ...@@ -104,7 +105,7 @@ public class MenuService {
} }
return all; return all;
} else { } else {
log.error("返回值内不包含需要解析的数据" + jsonObject.toJSONString()); log.error("看看生活:返回值内不包含需要解析的数据{}", jsonObject.toJSONString());
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -133,7 +134,7 @@ public class MenuService { ...@@ -133,7 +134,7 @@ public class MenuService {
JSONArray userTag = jsonObject.getJSONArray("userTag"); JSONArray userTag = jsonObject.getJSONArray("userTag");
return getUserTagByTag(userTag, 2, tags); return getUserTagByTag(userTag, 2, tags);
} else { } else {
log.error("返回值内不包含需要解析的数据" + jsonObject.toJSONString()); log.error("看看社保:返回值内不包含需要解析的数据{}", jsonObject.toJSONString());
} }
return null; return null;
} }
...@@ -185,7 +186,7 @@ public class MenuService { ...@@ -185,7 +186,7 @@ public class MenuService {
} }
//如果调用的是看看生活的用户标签失败时,尝试调取看看社保用户标签 //如果调用的是看看生活的用户标签失败时,尝试调取看看社保用户标签
if (type == 1) { if (type == 1 && CollUtil.isNotEmpty(gidList)) {
List<Map<String, Object>> sbTags = getSBTags(gidList, tags); List<Map<String, Object>> sbTags = getSBTags(gidList, tags);
if (sbTags != null && sbTags.size() > 0) { if (sbTags != null && sbTags.size() > 0) {
userTags.addAll(sbTags); userTags.addAll(sbTags);
......
...@@ -75,11 +75,10 @@ public class MessageTemplate implements Serializable { ...@@ -75,11 +75,10 @@ public class MessageTemplate implements Serializable {
@AllArgsConstructor @AllArgsConstructor
public static class PushMessage implements Serializable { public static class PushMessage implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
//手机端通知展示时间段,格式为毫秒时间戳段,两个时间的时间差必须大于10分钟,例如:"1590547347000-1590633747000" //手机端通知展示时间段,格式为毫秒时间戳段,两个时间的时间差必须大于10分钟,例如:"1590547347000-1590633747000"
private String duration; private String duration;
//纯透传消息内容,安卓和iOS均支持,与notification、revoke 三选一,都填写时报错,长度 ≤ 3072 //纯透传消息内容,安卓和iOS均支持,与notification、revoke 三选一,都填写时报错,长度 ≤ 3072
private String transmission; private Transmission transmission;
//消息模板 //消息模板
private Notification notification; private Notification notification;
//撤回消息时使用(仅撤回个推通道消息),与notification、transmission三选一,都填写时报错(消息撤回请勿填写策略参数) //撤回消息时使用(仅撤回个推通道消息),与notification、transmission三选一,都填写时报错(消息撤回请勿填写策略参数)
...@@ -109,6 +108,23 @@ public class MessageTemplate implements Serializable { ...@@ -109,6 +108,23 @@ public class MessageTemplate implements Serializable {
private String thread_id; private String thread_id;
} }
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class Transmission {
private String title;
private String content;
private String url;
//0:h5 1:app原生
private String push_type;
//跳转功能名称
private String className;
//功能标题
private String classTitle;
//是否需要登录
private String needLogin;
}
@Data @Data
public static class Revoke { public static class Revoke {
private String old_task_id; private String old_task_id;
......
package com.weface.controller; package com.weface.controller;
import com.weface.code.CommonResult; import com.weface.code.CommonResult;
import com.weface.component.GeTuiUtils;
import com.weface.dto.InformForm;
import com.weface.dto.MsgDTO; import com.weface.dto.MsgDTO;
import com.weface.dto.PushDTO; import com.weface.dto.PushDTO;
import com.weface.service.PushService; import com.weface.service.PushService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.validation.groups.Default;
/** /**
* @author Administrator * @author Administrator
*/ */
...@@ -29,4 +34,9 @@ public class PushController { ...@@ -29,4 +34,9 @@ public class PushController {
public CommonResult pushSingle(@RequestBody MsgDTO param) { public CommonResult pushSingle(@RequestBody MsgDTO param) {
return pushService.pushSingle(param); return pushService.pushSingle(param);
} }
@PostMapping("/all")
public CommonResult pushAll(@Validated({Default.class}) InformForm informForm) {
return GeTuiUtils.listPush(informForm);
}
} }
package com.weface.dto;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* @author : Administrator
*/
@Data
public class InformForm {
//标题
@NotBlank
private String title;
//内容
@NotBlank
private String body;
//跳转url
private String url;
//推送类型 0:h5 1:原生
private String push_type;
//跳转功能名称
private String className;
//功能标题
private String classTitle;
//是否需要登录
private String needLogin;
//请求应用名称首字母小写 例:看看生活->kksh
@NotBlank
private String equipmentType;
//推送设备 4 android 1: ios
private Integer device;
//定速推送,例如100,个推控制下发速度在100条/秒左右,0表示不限速
private Integer speed;
}
...@@ -64,4 +64,4 @@ gexiang: ...@@ -64,4 +64,4 @@ gexiang:
maxIdle: 50 maxIdle: 50
minIdle: 10 minIdle: 10
user_tag_id: 251696 user_tag_id: 251696
push_max_size: 10000 push_max_size: 80000
package com.weface; package com.weface;
import cn.hutool.core.util.IdUtil;
import cn.hutool.http.HtmlUtil;
import com.weface.code.CommonResult;
import com.weface.component.GeTuiUtils; import com.weface.component.GeTuiUtils;
import com.weface.component.MenuService; import com.weface.component.MenuService;
import com.weface.component.MessageTemplate; import com.weface.component.MessageTemplate;
import com.weface.dto.InformForm;
import com.weface.entity.MenuTagsEntity; import com.weface.entity.MenuTagsEntity;
import com.weface.entity.UserTagEntity; import com.weface.entity.UserTagEntity;
import com.weface.entity.UserMenusEntity; import com.weface.entity.UserMenusEntity;
...@@ -15,7 +19,9 @@ import org.junit.jupiter.api.Test; ...@@ -15,7 +19,9 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
...@@ -87,30 +93,56 @@ class PushMessageApplicationTests { ...@@ -87,30 +93,56 @@ class PushMessageApplicationTests {
} }
@Test @Test
void testConventTemplate() { void testConventTemplate() throws UnsupportedEncodingException {
//String[] alias = {"kksh_10255318"}; InformForm informForm = new InformForm();
//String[] alias = {"kksh_10131492"};
String[] alias = {"kksh_59354"}; String[] alias = {"kksh_10131492"};
String token = GeTuiUtils.getAuthToken("kk_sh_token_ge_tui"); // String[] alias = {"kksh_59354"};
// String token = GeTuiUtils.getAuthToken("kk_sh_token_ge_tui");
String token = GeTuiUtils.getAuthToken("kk_sb_token_ge_tui");
informForm.setTitle("河南一名小学生确诊阳性!");
informForm.setBody("1月23日新增一例本土确诊病例!为11岁小学生");
informForm.setUrl("https://kk.weface.com.cn/news/page/?id=c0933d0e2fc85f7333b6202dff0e611c&type=hot&from=101");
MessageTemplate messageTemplate = new MessageTemplate(); MessageTemplate messageTemplate = new MessageTemplate();
messageTemplate.setAudience(new MessageTemplate.Audience(alias));
MessageTemplate.Settings settings = new MessageTemplate.Settings(); messageTemplate.setSettings(new MessageTemplate.Settings(3600000, 0));
settings.setTtl(3600000);
messageTemplate.setSettings(settings);
MessageTemplate.PushMessage pushMessage = new MessageTemplate.PushMessage(); MessageTemplate.PushMessage pushMessage = new MessageTemplate.PushMessage();
MessageTemplate.PushMessage.Notification notification = new MessageTemplate.PushMessage.Notification();
notification.setTitle("看看生活提醒"); MessageTemplate.PushMessage.Transmission transmission = new MessageTemplate.PushMessage.Transmission();
notification.setBody("看看生活->让领钱更简单"); transmission.setTitle(informForm.getTitle());
notification.setClick_type("url"); transmission.setContent(informForm.getBody());
notification.setUrl("https://www.baidu.com/"); transmission.setUrl(informForm.getUrl());
notification.setChannel_level(4);
pushMessage.setNotification(notification); pushMessage.setTransmission(transmission);
messageTemplate.setPush_message(pushMessage); messageTemplate.setPush_message(pushMessage);
String s = GeTuiUtils.singlePushAlias(alias, messageTemplate, token); // String s = GeTuiUtils.singlePushAlias(4, messageTemplate, GeTuiUtils.KK_SH_APP_ID, token);
String s = GeTuiUtils.singlePushAlias(1, messageTemplate, GeTuiUtils.KK_SB_APP_ID, token);
System.out.println(s); System.out.println(s);
}
@Test
void testRevoke() {
Map<String, Object> map = new HashMap<>();
map.put("request_id", String.valueOf(IdUtil.getSnowflake(1, 1).nextId()));
map.put("audience", "all");
Map<String, Object> push_message = new HashMap<>();
HashMap<String, Object> revoke = new HashMap<>();
revoke.put("old_task_id", "RASA_0127_011f801354c5236738787cdda86cf232");
revoke.put("force", false);
push_message.put("revoke", revoke);
map.put("push_message", push_message);
String url = GeTuiUtils.GE_TUI_BASE_URL + GeTuiUtils.KK_SH_APP_ID + "/push/all";
String kk_sh_token_ge_tui = GeTuiUtils.getAuthToken("kk_sh_token_ge_tui");
String s = GeTuiUtils.generalPost(url, kk_sh_token_ge_tui, map);
System.out.println(s);
} }
} }
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