Commit ded133fc authored by renandong's avatar renandong 🇨🇳

1,处理冲突

parent 30d0f9bb
...@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil; ...@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions; import cn.hutool.core.bean.copier.CopyOptions;
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;
...@@ -19,6 +20,8 @@ import lombok.extern.slf4j.Slf4j; ...@@ -19,6 +20,8 @@ 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;
...@@ -250,20 +253,35 @@ public class GeTuiUtils { ...@@ -250,20 +253,35 @@ public class GeTuiUtils {
/** /**
* 【toSingle】执行别名单推 * 【toSingle】执行别名单推
* *
* @param alias 用户别名 * @param messageTemplate 应用id
* @param appId 应用id * @param appId 消息模板
* @param messageTemplate 消息模板
* @param token 接口访问凭据 * @param token 接口访问凭据
* @return 消息推送结果 * @return 消息推送结果
*/ */
public static String singlePushAlias(String[] alias, String appId, 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 + appId + "/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
* *
...@@ -271,10 +289,10 @@ public class GeTuiUtils { ...@@ -271,10 +289,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;
...@@ -338,45 +356,57 @@ public class GeTuiUtils { ...@@ -338,45 +356,57 @@ public class GeTuiUtils {
*/ */
public static CommonResult listPush(InformForm informForm) { public static CommonResult listPush(InformForm informForm) {
MessageTemplate messageTemplate = new MessageTemplate(); MessageTemplate messageTemplate = new MessageTemplate();
try {
messageTemplate.setAudience(new MessageTemplate.Audience(informForm.getAlias())); // String[] alias = {"kksh_59354"};
MessageTemplate.Settings settings = new MessageTemplate.Settings(); // String[] alias = {"kksh_10131492"};
settings.setTtl(3600000); Integer device = informForm.getDevice();
messageTemplate.setSettings(settings); if (device == null) {
device = 4;
MessageTemplate.PushMessage pushMessage = new MessageTemplate.PushMessage(); }
MessageTemplate.PushMessage.Notification notification = new MessageTemplate.PushMessage.Notification(); Integer speed = informForm.getSpeed();
BeanUtil.copyProperties(informForm, notification, CopyOptions.create().ignoreNullValue()); // messageTemplate.setAudience(new MessageTemplate.Audience(alias));
notification.setChannel_level(4); messageTemplate.setSettings(new MessageTemplate.Settings(3600000, speed == null ? 0 : speed));
pushMessage.setNotification(notification);
MessageTemplate.PushMessage pushMessage = new MessageTemplate.PushMessage();
messageTemplate.setPush_message(pushMessage); MessageTemplate.PushMessage.Transmission transmission = new MessageTemplate.PushMessage.Transmission();
String result = null; transmission.setTitle(informForm.getTitle());
switch (informForm.getEquipmentType()) { transmission.setContent(informForm.getBody());
//看看生活 transmission.setUrl(HtmlUtil.unescape(informForm.getUrl()));
case "kksh": pushMessage.setTransmission(transmission);
String kk_sh_token_ge_tui = getAuthToken("kk_sh_token_ge_tui");
result = GeTuiUtils.listPushToApp(messageTemplate, KK_SH_APP_ID, kk_sh_token_ge_tui); messageTemplate.setPush_message(pushMessage);
break; String result = null;
//看看社保 switch (informForm.getEquipmentType()) {
case "kksb": //看看生活
String kk_sb_token_ge_tui = getAuthToken("kk_sb_token_ge_tui"); case "kksh":
result = GeTuiUtils.listPushToApp(messageTemplate, KK_SB_APP_ID, kk_sb_token_ge_tui); String kk_sh_token_ge_tui = getAuthToken("kk_sh_token_ge_tui");
break; // result = GeTuiUtils.singlePushAlias(device, messageTemplate, KK_SH_APP_ID, kk_sh_token_ge_tui);
case "kkwj": result = GeTuiUtils.listPushToApp(device, messageTemplate, KK_SH_APP_ID, kk_sh_token_ge_tui);
String kk_wj_token_ge_tui = getAuthToken("kk_wj_token_ge_tui"); break;
result = GeTuiUtils.listPushToApp(messageTemplate, KK_WJ_APP_ID, kk_wj_token_ge_tui); //看看社保
break; case "kksb":
default: String kk_sb_token_ge_tui = getAuthToken("kk_sb_token_ge_tui");
break; // result = GeTuiUtils.singlePushAlias(device, messageTemplate, KK_SB_APP_ID, kk_sb_token_ge_tui);
} result = GeTuiUtils.listPushToApp(device, messageTemplate, KK_SB_APP_ID, kk_sb_token_ge_tui);
if (result == null) { break;
return CommonResult.failed(); case "kkwj":
} String kk_wj_token_ge_tui = getAuthToken("kk_wj_token_ge_tui");
JSONObject jsonObject = JSONObject.parseObject(result); // result = GeTuiUtils.singlePushAlias(device, messageTemplate, KK_WJ_APP_ID, kk_wj_token_ge_tui);
if ((jsonObject.containsKey("code") && jsonObject.getInteger("code") == 0)) { result = GeTuiUtils.listPushToApp(device, messageTemplate, KK_WJ_APP_ID, kk_wj_token_ge_tui);
JSONObject data = jsonObject.getJSONObject("data"); break;
return CommonResult.success(data); 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(); return CommonResult.failed();
} }
...@@ -388,8 +418,8 @@ public class GeTuiUtils { ...@@ -388,8 +418,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("执行群推");
...@@ -399,17 +429,13 @@ public class GeTuiUtils { ...@@ -399,17 +429,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()));
...@@ -420,118 +446,129 @@ public class GeTuiUtils { ...@@ -420,118 +446,129 @@ 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 intent = null;
//设置消息 // if (device == 4) {
Map<String, Object> notifications = BeanUtil.beanToMap(notification, false, true); // String pack = "com.weface.kksocialsecurity";
push_messages.put("notification", notifications); // 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";
// intent = String.format(str, URLEncoder.encode(transmission.getUrl(), "UTF-8"), pack, component, transmission.getContent(), transmission.getTitle(), URLEncoder.encode(transmission.getUrl(), "UTF-8"));
// } else if (device == 1) {
// }
String str = "{\"content\": \"%s\", \"push_type\": \"0\", \"title\": \"%s\", \"url\": \"%s\"}";
String intent = String.format(str, transmission.getContent(), transmission.getTitle(), transmission.getUrl());
push_messages.put("transmission", intent);
//撤回消息时使用(仅撤回厂商通道消息,支持的厂商有小米、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");
switch (notification.getClick_type()) { String pack = "com.weface.kksocialsecurity";
case "url": String component = pack + "/com.weface.kksocialsecurity.activity.WellcomeActivity";
informAndroid.put("url", notification.getUrl()); 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";
break; String intent = String.format(str, URLEncoder.encode(transmission.getUrl(), "UTF-8"), pack, component, transmission.getContent(), transmission.getTitle(), URLEncoder.encode(transmission.getUrl(), "UTF-8"));
case "intent": notification.put("intent", intent);
informAndroid.put("intent", notification.getIntent()); ups.put("notification", notification);
}
ups.put("notification", informAndroid);
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;
} }
...@@ -186,9 +187,11 @@ public class MenuService { ...@@ -186,9 +187,11 @@ public class MenuService {
//如果调用的是看看生活的用户标签失败时,尝试调取看看社保用户标签 //如果调用的是看看生活的用户标签失败时,尝试调取看看社保用户标签
if (type == 1) { if (type == 1) {
List<Map<String, Object>> sbTags = getSBTags(gidList, tags); if (CollUtil.isNotEmpty(gidList)) {
if (sbTags != null && sbTags.size() > 0) { List<Map<String, Object>> sbTags = getSBTags(gidList, tags);
userTags.addAll(sbTags); if (sbTags != null && sbTags.size() > 0) {
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;
......
...@@ -36,7 +36,7 @@ public class PushController { ...@@ -36,7 +36,7 @@ public class PushController {
} }
@PostMapping("/all") @PostMapping("/all")
public CommonResult pushAll(@RequestBody @Validated({Default.class}) InformForm informForm) { public CommonResult pushAll(@Validated({Default.class}) InformForm informForm) {
return GeTuiUtils.listPush(informForm); return GeTuiUtils.listPush(informForm);
} }
} }
...@@ -9,14 +9,28 @@ import javax.validation.constraints.NotBlank; ...@@ -9,14 +9,28 @@ import javax.validation.constraints.NotBlank;
*/ */
@Data @Data
public class InformForm { public class InformForm {
//标题
@NotBlank @NotBlank
private String title; private String title;
//内容
@NotBlank @NotBlank
private String body; private String body;
@NotBlank //跳转url
private String click_type;
private String url; private String url;
private String[] alias; //推送类型 0:h5 1:原生
private String push_type;
//跳转功能名称
private String className;
//功能标题
private String classTitle;
//是否需要登录
private String needLogin;
//请求应用名称首字母小写 例:看看生活->kksh
@NotBlank @NotBlank
private String equipmentType; private String equipmentType;
//推送设备 4 android 1: ios
private Integer device;
//定速推送,例如100,个推控制下发速度在100条/秒左右,0表示不限速
private Integer speed;
} }
...@@ -2,9 +2,12 @@ package com.weface; ...@@ -2,9 +2,12 @@ package com.weface;
import cn.hutool.core.util.IdUtil; 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;
...@@ -90,33 +93,49 @@ class PushMessageApplicationTests { ...@@ -90,33 +93,49 @@ class PushMessageApplicationTests {
} }
} }
@Test
void testListPush() {
InformForm informForm = new InformForm();
informForm.setTitle("河南一名小学生确诊阳性!");
informForm.setBody("1月23日新增一例本土确诊病例!为11岁小学生");
informForm.setUrl("https://kk.weface.com.cn/news/page/?id=c0933d0e2fc85f7333b6202dff0e611c&type=hot&from=101");
informForm.setPush_type("0");
informForm.setEquipmentType("kksh");
CommonResult commonResult = GeTuiUtils.listPush(informForm);
System.out.println(commonResult);
}
@Test @Test
void testConventTemplate() throws UnsupportedEncodingException { 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("1月23日新增一例本土确诊病例!为11岁小学生"); transmission.setTitle(informForm.getTitle());
notification.setClick_type("intent"); transmission.setContent(informForm.getBody());
String pack = "com.weface.kksocialsecurity/com.weface.kksocialsecurity.activity.WellcomeActivity"; transmission.setUrl(informForm.getUrl());
String str = "intent:#Intent;component=%s;S.kkparam={\"content\": \"%s\", \"ispush\": \"1\", \"preload\": \"2\", \"push_type\": \"0\", \"pushlabel\": \"\", \"pushts\": \"1561619033\", \"title\": \"%s\", \"url\": \"%s\"};end";
String url = "https://kk.weface.com.cn/news/page/?id=c0933d0e2fc85f7333b6202dff0e611c&type=hot&from=101"; pushMessage.setTransmission(transmission);
String intent = String.format(str, pack, notification.getBody(), notification.getTitle(), URLEncoder.encode(url, "UTF-8"));
// String intent = "intent:#Intent;component=com.weface.kksocialsecurity/com.weface.kksocialsecurity.activity.WellcomeActivity;S.kkparam={\"content\": \"1月23日新增一例本土确诊病例!为11岁小学生\", \"ispush\": \"1\", \"preload\": \"2\", \"push_type\": \"0\", \"pushlabel\": \"\", \"pushts\": \"1561619033\", \"title\": \"河南一名小学生确诊阳性!\", \"url\": \"https://kk.weface.com.cn/news/page/?id=c0933d0e2fc85f7333b6202dff0e611c&type=hot&from=101\"};end";
notification.setIntent(intent);
notification.setChannel_level(4);
pushMessage.setNotification(notification);
messageTemplate.setPush_message(pushMessage); messageTemplate.setPush_message(pushMessage);
String s = GeTuiUtils.singlePushAlias(alias, GeTuiUtils.KK_SH_APP_ID, 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);
} }
...@@ -129,7 +148,7 @@ class PushMessageApplicationTests { ...@@ -129,7 +148,7 @@ class PushMessageApplicationTests {
Map<String, Object> push_message = new HashMap<>(); Map<String, Object> push_message = new HashMap<>();
HashMap<String, Object> revoke = new HashMap<>(); HashMap<String, Object> revoke = new HashMap<>();
revoke.put("old_task_id", "RASA_0124_1679436c706dc2ea869c7c43eed0fb7d"); revoke.put("old_task_id", "RASA_0127_011f801354c5236738787cdda86cf232");
revoke.put("force", false); revoke.put("force", false);
push_message.put("revoke", revoke); push_message.put("revoke", revoke);
map.put("push_message", push_message); map.put("push_message", push_message);
...@@ -140,4 +159,11 @@ class PushMessageApplicationTests { ...@@ -140,4 +159,11 @@ class PushMessageApplicationTests {
} }
@Test
void testBase() {
String url = "https://kk.weface.com.cn/news/page/?id=8def012d3485ca0e87455b6c5aeeea18&amp;type=hot&amp;from=101";
String unescape = HtmlUtil.unescape(url);
System.out.println(unescape);
}
} }
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