Commit ae55e0ad authored by renandong's avatar renandong 🇨🇳

1,袤博推送集成看看社保,看看民政,看看卫健

parent 8ad52600
......@@ -12,6 +12,8 @@ import com.alibaba.fastjson.JSONObject;
import com.weface.code.CommonResult;
import com.weface.common.utils.Constant;
import com.weface.common.utils.Model;
import com.weface.config.GeTuiConfig;
import com.weface.config.MobApp;
import com.weface.dto.InformForm;
import com.weface.service.PushLogService;
import lombok.extern.slf4j.Slf4j;
......@@ -30,18 +32,17 @@ import java.util.*;
@Component
@Slf4j
public class MobPushService {
/**
* mob推送key
*/
private static final String APP_KEY = "3511c2579cad6";
/**
* mob推送密钥
*/
private static final String APP_SECRET = "f446a56b98aae09beb5721ebdbe0d2e8";
@Autowired
private MobApp mobApp;
@Autowired
private PushLogService pushLogService;
public GeTuiConfig getAppConfigByName(String appName) {
return mobApp.getApps().get(appName);
}
/**
* mob 推送
*
......@@ -50,6 +51,10 @@ public class MobPushService {
* @return 执行结果
*/
public CommonResult mobPush(InformForm informForm, Constant.PushTarget target) {
String equipmentType = informForm.getEquipmentType();
GeTuiConfig appConfig = getAppConfigByName(equipmentType);
String appKey = appConfig.getAppkey();
String appSecret = appConfig.getMastersecret();
String pushUrl = "http://api.push.mob.com/v3/push/createPush";
Map<String, Object> request = new HashMap<>();
//枚举值 webapi
......@@ -57,7 +62,7 @@ public class MobPushService {
//自定义任务id(用户自自定义生成且唯一、不能重复)
request.put("workno", IdUtil.fastUUID());
//appkey
request.put("appkey", APP_KEY);
request.put("appkey", appKey);
informForm.setUrl(HtmlUtil.unescape(informForm.getUrl()));
String[] split = new String[0];
if (target.getKey() != 1) {
......@@ -82,7 +87,7 @@ public class MobPushService {
request.put("pushFactoryExtra", pushFactoryExtra);
//groupId: AB分组测试ID
request.put("groupId", target.getValue());
String body = generalPost(request, pushUrl);
String body = generalPost(request, pushUrl, appKey, appSecret);
if (body != null) {
pushLogService.saveMobLog(JSONObject.parseObject(body), informForm);
return CommonResult.success();
......@@ -114,6 +119,10 @@ public class MobPushService {
* @return 执行结果
*/
public Model batchMobPush(InformForm informForm, Constant.PushTarget target) {
String equipmentType = informForm.getEquipmentType();
GeTuiConfig appConfig = getAppConfigByName(equipmentType);
String appKey = appConfig.getAppkey();
String appSecret = appConfig.getMastersecret();
String pushUrl = "http://api.push.mob.com/v3/push/createMulti";
Map<String, Object> request = new HashMap<>(2);
......@@ -121,7 +130,7 @@ public class MobPushService {
//枚举值 webapi
pushWork.put("source", "webapi");
//Mob-appkey
pushWork.put("appkey", APP_KEY);
pushWork.put("appkey", appKey);
//推送展示细节配置
Map<String, Object> pushNotify = getBatchPushNotify(informForm);
pushWork.put("pushNotify", pushNotify);
......@@ -145,7 +154,7 @@ public class MobPushService {
}
Map<String, Object> items = getItems(split, informForm.getTitle(), informForm.getBody(), target.getKey());
request.put("items", new Object[]{items});
String body = generalPost(request, pushUrl);
String body = generalPost(request, pushUrl, appKey, appSecret);
log.info("批量推送结果:{}", body);
if (body != null) {
return Model.ok();
......@@ -160,12 +169,15 @@ public class MobPushService {
* @return 是否收到
*/
public boolean getPushInfoById(String workId) {
GeTuiConfig appConfig = getAppConfigByName("kksh");
String appKey = appConfig.getAppkey();
String appSecret = appConfig.getMastersecret();
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", appKey);
request.put("workId", workId);
String body = generalPost(request, reqUrl);
String body = generalPost(request, reqUrl, appKey, appSecret);
log.error("查询回调结果:{}", body);
if (JSONUtil.isJson(body)) {
JSONObject json = JSONObject.parseObject(body);
......@@ -482,7 +494,7 @@ public class MobPushService {
* @param url 请求地址
* @return 执行结果
*/
private String generalPost(Map<String, Object> map, String url) {
private String generalPost(Map<String, Object> map, String url, String appKey, String appSecret) {
String request;
if (map == null) {
request = "";
......@@ -492,8 +504,8 @@ public class MobPushService {
log.error("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", appKey);
post.header("sign", getSign(request, appSecret));
String body = post.body(request).execute().body();
log.error("mob推送结果:{}", body);
if (JSONUtil.isJson(body)) {
......@@ -510,10 +522,10 @@ public class MobPushService {
* @param url 请求路径
* @return 执行结果
*/
private String generalGet(String url) {
private String generalGet(String url, String appKey, String appSecret) {
HttpRequest get = HttpUtil.createGet(url);
get.header("key", APP_KEY);
get.header("sign", getSign(""));
get.header("key", appKey);
get.header("sign", getSign("", appSecret));
String body = get.execute().body();
log.info("推送结果:{}", body);
if (JSONUtil.isJson(body)) {
......@@ -530,7 +542,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 appSecret) {
return SecureUtil.md5(body + appSecret);
}
}
package com.weface.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.util.Map;
@Configuration
@ConfigurationProperties(prefix = "maob")
public class MobApp {
private Map<String,GeTuiConfig> apps;
public Map<String, GeTuiConfig> getApps() {
return apps;
}
public void setApps(Map<String, GeTuiConfig> apps) {
this.apps = apps;
}
}
......@@ -36,6 +36,14 @@ getui:
kksb: { appkey: "2tLtJhcpij7lu3ksutgpU3",mastersecret: "b8MSgB7j8PAImc3eN0yuL9",appId: "Ued41NRq7j9Nh1qI81gQ54",baseUrl: "http://api.getui.com/apiex.htm" }
}
maob:
apps: {
kksh: { appkey: "3511c2579cad6",mastersecret: "f446a56b98aae09beb5721ebdbe0d2e8" },
kksb: { appkey: "35e36a9bc94bd",mastersecret: "0a097f62ac25e0cb7a750ab293b583d1" },
kkmz: { appkey: "35e377d8521b0",mastersecret: "a6350ece59dd756aaabf40f6d8c27a9c" },
kkwj: { appkey: "35e37131417e3",mastersecret: "27955f2bc52c8fc0d053375d422ced0e" }
}
#mybatis
mybatis-plus:
mapper-locations: classpath*:/mapper/**/*.xml
......
......@@ -7,10 +7,11 @@ import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.weface.code.CommonResult;
import com.weface.common.utils.CommonUtil;
import com.weface.common.utils.Constant;
import com.weface.common.utils.RedisUtil;
import com.weface.common.utils.SnowIdUtil;
import com.weface.component.GeTuiService;
import com.weface.component.MenuService;
import com.weface.component.MobPushService;
import com.weface.config.SignValidateFilter;
import com.weface.dto.InformForm;
import com.weface.entity.MenuTagsEntity;
......@@ -118,7 +119,7 @@ class PushMessageApplicationTests {
}
@Test
void testPushResult(){
void testPushResult() {
String taskId = "RASA_0726_e51c93e787d103e072e4cd2cd43e8500";
String equipmentType = "kksh";
String s = geTuiService.getReportByTaskId(taskId, equipmentType);
......@@ -386,4 +387,23 @@ class PushMessageApplicationTests {
String s = CommonUtil.apiParamSign(map, SignValidateFilter.SECRET_KEY);
System.out.println(s);
}
@Autowired
private MobPushService mobPushService;
@Test
public void testSinglePush() {
InformForm informForm = new InformForm();
informForm.setTitle("缴电费充值通知");
informForm.setBody("尊敬的用户您好,您的户号充值已到账");
informForm.setUrl("mineEarnGold");
informForm.setPushType(1);
informForm.setClassName("mineEarnGold");
informForm.setClassTitle("我的金币");
informForm.setNeedLogin("1");
informForm.setEquipmentType("kksb");
informForm.setCid("kksb_12339934");
CommonResult commonResult = mobPushService.mobPush(informForm, Constant.PushTarget.ALIAS);
System.out.println(commonResult);
}
}
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