|
@@ -3,9 +3,14 @@ package com.yonge.toolset.thirdparty.message.provider;
|
|
|
import java.io.IOException;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.yonge.toolset.base.exception.BizException;
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.InitializingBean;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -222,7 +227,94 @@ public class JiguangPushPlugin implements MessageSenderPlugin, InitializingBean
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- public void setStudentAppKey(String studentAppKey) {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除设备的别名
|
|
|
+ *
|
|
|
+ * @param alias 用户别名
|
|
|
+ * @param registerIds 设备注册ID
|
|
|
+ * @param pushType 极光应用类型
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void deviceRemoveAlias(String alias, List<String> registerIds, String pushType) {
|
|
|
+ //MessageSenderService.super.deviceRemoveAlias(alias, registerId);
|
|
|
+
|
|
|
+ // 接口访问基础
|
|
|
+ String baseUrl = "https://device.jpush.cn";
|
|
|
+
|
|
|
+ String base64_auth_string;
|
|
|
+
|
|
|
+ switch (pushType){
|
|
|
+ case "TENANT_STUDENT":
|
|
|
+ case "STUDENT":
|
|
|
+ base64_auth_string = encryptBASE64(this.studentAppKey + ":" + this.studentMasterSecret);
|
|
|
+ break;
|
|
|
+ case "TEACHER":
|
|
|
+ base64_auth_string = encryptBASE64(this.teacherAppKey + ":" + this.teacherMasterSecret);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ base64_auth_string = encryptBASE64(this.systemAppKey + ":" + this.systemMasterSecret);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String authorization = "Basic " + base64_auth_string;
|
|
|
+
|
|
|
+ List<String> removeIds = Lists.newArrayList();
|
|
|
+ // 查询别名绑定设备
|
|
|
+ {
|
|
|
+
|
|
|
+ // 请求头授权参数
|
|
|
+ HashMap<String, String> HeaderMap = new HashMap<String, String>(){{
|
|
|
+ put("Authorization", authorization.trim());
|
|
|
+ }};
|
|
|
+
|
|
|
+ // 请求参数
|
|
|
+ HashMap<String, Object> data = new HashMap<String, Object>(){{
|
|
|
+ put("new_format", "false"); // 返回结果是否使用新格式
|
|
|
+ }};
|
|
|
+
|
|
|
+ // 发起请求
|
|
|
+ try {
|
|
|
+ String ret = HttpUtil.get(baseUrl + "/v3/aliases/" + alias, data, HeaderMap);
|
|
|
+ if (StringUtils.isNotBlank(ret)) {
|
|
|
+ JSONObject json = JSONObject.parseObject(ret);
|
|
|
+
|
|
|
+ json.getJSONArray("registration_ids").forEach(item -> removeIds.add(item.toString()));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BizException("deviceRemoveAlias 查询别名绑定设备", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 排除当前设备
|
|
|
+ if (CollectionUtils.isNotEmpty(removeIds) && CollectionUtils.isNotEmpty(registerIds)) {
|
|
|
+ removeIds.removeAll(registerIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除别名绑定设备
|
|
|
+ if (CollectionUtils.isNotEmpty(removeIds)) {
|
|
|
+ // 请求头授权参数
|
|
|
+ HashMap<String, String> HeaderMap = new HashMap<String, String>(){{
|
|
|
+ put("Authorization", authorization.trim());
|
|
|
+ }};
|
|
|
+
|
|
|
+ // 请求参数
|
|
|
+ HashMap<String, Object> data = new HashMap<String, Object>(){{
|
|
|
+ put("registration_ids", new HashMap<String, Object>(){{
|
|
|
+ put("remove", removeIds);
|
|
|
+ }});
|
|
|
+ }};
|
|
|
+
|
|
|
+ // 发起请求
|
|
|
+ try {
|
|
|
+ HttpUtil.postForHttps(baseUrl + "/v3/aliases/" + alias, JSON.toJSONString(data), HeaderMap);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BizException("deviceRemoveAlias 删除别名绑定设备", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void setStudentAppKey(String studentAppKey) {
|
|
|
this.studentAppKey = studentAppKey;
|
|
|
}
|
|
|
|