Commit 7ea41b61 authored by menghongtao's avatar menghongtao

新闻群推IOS无法收到的问题1929

parent 496d95f7
......@@ -12,10 +12,10 @@ import com.alibaba.fastjson.JSONObject;
import com.weface.code.CommonResult;
import com.weface.common.utils.CommonUtil;
import com.weface.common.utils.Constant;
import com.weface.common.utils.Model;
import com.weface.dto.InformForm;
import com.weface.dto.MultiInformForm;
import com.weface.dto.MultiMsgDTO;
import com.weface.enums.AppKeyEnum;
import com.weface.service.PushLogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
......@@ -27,7 +27,6 @@ import org.springframework.util.ObjectUtils;
import java.lang.reflect.Type;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author : Administrator
......@@ -37,14 +36,6 @@ import java.util.stream.Collectors;
@Component
@Slf4j
public class MobPushService {
/**
* mob推送key
*/
private static final String APP_KEY = "3511c2579cad6";
/**
* mob推送密钥
*/
private static final String APP_SECRET = "f446a56b98aae09beb5721ebdbe0d2e8";
@Autowired
private PushLogService pushLogService;
......@@ -58,6 +49,89 @@ public class MobPushService {
* 批量推送的消息体内最大推送设备数
*/
private static final int MAX_ALIAS = 200;
public CommonResult mobPushForAndroid(InformForm informForm, Constant.PushTarget target) {
log.info("开始安卓新闻消息群推......");
informForm.setAppKey(AppKeyEnum.ANDROID.getKey());
CommonResult result = mobPushByAppKey(informForm, target);
log.info("安卓新闻消息群推结束,result = {}", JSONUtil.toJsonStr(result));
return result;
}
public CommonResult mobPushForIOS(InformForm informForm, Constant.PushTarget target) {
log.info("开始IOS新闻消息群推......");
informForm.setAppKey(AppKeyEnum.IOS.getKey());
CommonResult result = mobPushByAppKey(informForm, target);
log.info("IOS新闻消息群推结束,result = {}", JSONUtil.toJsonStr(result));
return result;
}
public CommonResult mobPushForHarmony(InformForm informForm, Constant.PushTarget target) {
log.info("开始鸿蒙新闻消息群推......");
informForm.setAppKey(AppKeyEnum.HARMONY.getKey());
CommonResult result = mobPushByAppKey(informForm, target);
log.info("鸿蒙新闻消息群推结束,result = {}", JSONUtil.toJsonStr(result));
return result;
}
/**
* mob 推送
*
* @param informForm 推送信息
* @param target 推送目标类型
* @return 执行结果
*/
public CommonResult mobPushByAppKey(InformForm informForm, Constant.PushTarget target) {
String pushUrl = "http://api.push.mob.com/v3/push/createPush";
Map<String, Object> request = new HashMap<>();
//枚举值 webapi
request.put("source", "webapi");
//自定义任务id(用户自自定义生成且唯一、不能重复)
request.put("workno", IdUtil.fastUUID());
//appkey
request.put("appkey", informForm.getAppKey());
informForm.setUrl(HtmlUtil.unescape(informForm.getUrl()));
Map<String, Object> pushTarget = new HashMap<>();
if (Constant.PushTarget.CITY.getKey() != target.getKey()) {
String[] split = new String[0];
if (target.getKey() != 1) {
//推送目标
String cid = informForm.getCid();
if (cid.contains(",")) {
split = cid.split(",");
} else {
split = new String[]{cid};
}
}
pushTarget = getPushTarget(target.getKey(), split);
} else {
Map<String, String> regionMap = new HashMap<>();
regionMap.put("city", informForm.getCity());
regionMap.put("province", informForm.getProvince());
regionMap.put("country", informForm.getCountry());
pushTarget = getPushTarget(target.getKey(), regionMap);
}
request.put("pushTarget", pushTarget);
//推送展示细节配置
Map<String, Object> pushNotify = getPushNotify(informForm);
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);
if (body != null) {
pushLogService.saveMobLog(JSONObject.parseObject(body), informForm, false);
return CommonResult.success();
}
return null;
}
/**
* mob 推送
*
......@@ -73,7 +147,7 @@ public class MobPushService {
//自定义任务id(用户自自定义生成且唯一、不能重复)
request.put("workno", IdUtil.fastUUID());
//appkey
request.put("appkey", APP_KEY);
request.put("appkey", AppKeyEnum.ANDROID.getKey());
informForm.setUrl(HtmlUtil.unescape(informForm.getUrl()));
Map<String, Object> pushTarget = new HashMap<>();
if (Constant.PushTarget.CITY.getKey() != target.getKey()) {
......@@ -135,6 +209,7 @@ public class MobPushService {
/**
* mob别名批量推送
* 与袤博技术人员确认:建议一个推送任务设置20 items,一个items可以设置200个推送设备
*
* @param multiInformForm 推送内容
* @return 执行结果
*/
......@@ -179,6 +254,7 @@ public class MobPushService {
/**
* 执行批量推送
*
* @param multiInformFormList 推送任务集合
*/
public void batchMobPushExecute(List<MultiInformForm> multiInformFormList) {
......@@ -191,7 +267,7 @@ public class MobPushService {
//枚举值 webapi
pushWork.put("source", "webapi");
//Mob-appkey
pushWork.put("appkey", APP_KEY);
pushWork.put("appkey", AppKeyEnum.ANDROID.getKey());
//推送展示细节配置
InformForm informForm = new InformForm();
BeanUtils.copyProperties(form, informForm);
......@@ -232,6 +308,7 @@ public class MobPushService {
/**
* 将超出 最大推送设备数的消息体进行分割
*
* @param msg 消息体
* @return 分割后的消息体的集合
*/
......@@ -269,6 +346,7 @@ public class MobPushService {
/**
* 将超出 最大推送消息体数量的任务进行分割
*
* @param form 推送任务
* @return 分割后的推送任务的集合
*/
......@@ -322,7 +400,7 @@ public class MobPushService {
String reqUrl = "http://api.push.mob.com/v3/stats/getByWorkId";
Map<String, Object> request = new HashMap<>();
//appkey
request.put("appkey", APP_KEY);
request.put("appkey", AppKeyEnum.ANDROID.getKey());
request.put("workId", workId);
String body = generalPost(request, reqUrl);
log.error("查询回调结果:{}", body);
......@@ -635,8 +713,8 @@ public class MobPushService {
log.info("mob推送内容:{}", request);
HttpRequest post = HttpUtil.createPost(url);
post.header("Content-Type", "application/json");
post.header("key", APP_KEY);
post.header("sign", getSign(request));
post.header("key", map.get("appkey").toString());
post.header("sign", getSign(request, map.get("appkey").toString()));
String body = post.body(request).execute().body();
log.info("mob推送结果:{}", body);
if (JSONUtil.isJson(body)) {
......@@ -664,14 +742,15 @@ public class MobPushService {
*/
private String generalGet(String url) {
HttpRequest get = HttpUtil.createGet(url);
get.header("key", APP_KEY);
get.header("sign", getSign(""));
get.header("key", AppKeyEnum.ANDROID.getKey());
get.header("sign", getSign("", AppKeyEnum.ANDROID.getKey()));
String body = get.execute().body();
log.info("推送结果:{}", body);
if (JSONUtil.isJson(body)) {
JSONObject json = JSONObject.parseObject(body);
if (json.containsKey("status") && json.getInteger("status").equals(200))
if (json.containsKey("status") && json.getInteger("status").equals(200)) {
return body;
}
}
return null;
}
......@@ -682,7 +761,7 @@ public class MobPushService {
* @param body 请求体
* @return sign
*/
private String getSign(String body) {
return SecureUtil.md5(body + APP_SECRET);
private String getSign(String body, String appKey) {
return SecureUtil.md5(body + AppKeyEnum.getSecretByKey(appKey));
}
}
......@@ -58,7 +58,12 @@ public class PushController {
return result;
}
if (informForm.getEquipmentType().equals("kksh")) {
mobPushService.mobPush(informForm, Constant.PushTarget.RADIO);
//安卓群推
mobPushService.mobPushForAndroid(informForm, Constant.PushTarget.RADIO);
//IOS群推
mobPushService.mobPushForIOS(informForm, Constant.PushTarget.RADIO);
//鸿蒙群推
mobPushService.mobPushForHarmony(informForm, Constant.PushTarget.RADIO);
}
return geTuiService.listPush(informForm);
}
......
......@@ -10,13 +10,13 @@ import javax.validation.constraints.NotBlank;
@Data
public class InformForm {
//标题
@NotBlank(message = "标题不能为空",groups = {PushValid.class})
@NotBlank(message = "标题不能为空", groups = {PushValid.class})
private String title;
//内容
@NotBlank(message = "内容不能为空",groups = {PushValid.class})
@NotBlank(message = "内容不能为空", groups = {PushValid.class})
private String body;
//跳转url
@NotBlank(message = "url不能为空",groups = {PushValid.class})
@NotBlank(message = "url不能为空", groups = {PushValid.class})
private String url;
//推送类型 0:h5 1:原生
private Integer pushType;
......@@ -27,7 +27,7 @@ public class InformForm {
//是否需要登录
private String needLogin;
//请求应用名称首字母小写 例:看看生活->kksh
@NotBlank(message = "应用名称不能为空",groups = {PushValid.class})
@NotBlank(message = "应用名称不能为空", groups = {PushValid.class})
private String equipmentType;
//推送设备 4 android 1: ios
private Integer device;
......@@ -62,7 +62,12 @@ public class InformForm {
*/
private String country;
public interface PushValid{
/**
* 新闻群推APP_KEY(安卓,IOS,鸿蒙)
*/
private String appKey;
public interface PushValid {
}
}
package com.weface.enums;
import java.math.BigDecimal;
/**
* 新闻消息推送APP_KEY ENUMS
*
* @author mht
* @date 2024/12/17
*/
public enum AppKeyEnum {
/**
* 安卓
*/
ANDROID("3511c2579cad6", "f446a56b98aae09beb5721ebdbe0d2e8"),
/**
* IOS
*/
IOS("38b797dbbf6ec", "05883c7b9185edb99a6ded653cfe3e39"),
/**
* 鸿蒙
*/
HARMONY("3a69c3c5f3cc7", "78f9a9f474086eee124b2be762e356ca"),
;
private String key;
private String secret;
AppKeyEnum(String key, String secret) {
this.key = key;
this.secret = secret;
}
public String getKey() {
return key;
}
public String getSecret() {
return secret;
}
/**
* 根据freezeAmt获取medicareAmt
*
* @param key appKey
* @return {@link String }
*/
public static String getSecretByKey(String key) {
AppKeyEnum[] enums = AppKeyEnum.values();
for (int i = 0; i < enums.length; i++) {
if (enums[i].getKey().equals(key)) {
return enums[i].getSecret();
}
}
return null;
}
}
......@@ -13,9 +13,9 @@
<!-- 生产环境 -->
<springProfile name="prod">
<logger name="org.springframework.web" level="ERROR"/>
<logger name="org.springboot.sample" level="ERROR" />
<logger name="com.weface" level="ERROR" />
<logger name="org.springframework.web" level="INFO"/>
<logger name="org.springboot.sample" level="INFO" />
<logger name="com.weface" level="INFO" />
</springProfile>
</configuration>
\ No newline at end of file
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