Commit 26258731 authored by lc@weface.com.cn's avatar lc@weface.com.cn

'多配置'

parent 61360f89
...@@ -41,6 +41,13 @@ ...@@ -41,6 +41,13 @@
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
......
package com.weface.component; package com.weface.component;
import cn.hutool.core.util.StrUtil;
import com.gexin.rp.sdk.base.IBatch; import com.gexin.rp.sdk.base.IBatch;
import com.gexin.rp.sdk.base.IIGtPush; import com.gexin.rp.sdk.base.IIGtPush;
import com.gexin.rp.sdk.base.IPushResult; import com.gexin.rp.sdk.base.IPushResult;
...@@ -15,34 +14,35 @@ import com.gexin.rp.sdk.http.IGtPush; ...@@ -15,34 +14,35 @@ import com.gexin.rp.sdk.http.IGtPush;
import com.gexin.rp.sdk.template.NotificationTemplate; import com.gexin.rp.sdk.template.NotificationTemplate;
import com.gexin.rp.sdk.template.style.Style0; import com.gexin.rp.sdk.template.style.Style0;
import com.gexin.rp.sdk.template.style.Style6; import com.gexin.rp.sdk.template.style.Style6;
import com.weface.config.GeTuiApp;
import com.weface.config.GeTuiConfig;
import com.weface.dto.MsgDTO; import com.weface.dto.MsgDTO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List; import java.util.List;
@Component @Component
@Slf4j @Slf4j
public class GeTuiSDK { public class GeTuiSDK {
@Value("${config.getui.appkey}") @Resource
private String appKey; private GeTuiApp geTuiApp;
@Value("${config.getui.mastersecret}") private GeTuiConfig getConfig(String fromApp){
private String masterSecret; return geTuiApp.getApps().get(fromApp);
}
@Value("${config.getui.appId}")
private String appId;
@Value("${config.getui.baseUrl}")
private String host;
public IPushResult pushSingle(String alias, String title, String body) { public IPushResult pushSingle(String alias, String title, String body) {
// 设置后,根据别名推送,会返回每个cid的推送结果 // 设置后,根据别名推送,会返回每个cid的推送结果
System.setProperty(Constants.GEXIN_PUSH_SINGLE_ALIAS_DETAIL, "true"); System.setProperty(Constants.GEXIN_PUSH_SINGLE_ALIAS_DETAIL, "true");
IGtPush push = new IGtPush(host, appKey, masterSecret); String fromApp = alias.split("_")[0];
NotificationTemplate template = getNotificationTemplate(title, body); GeTuiConfig config = getConfig(fromApp);
String appId = config.getAppId();
String appKey = config.getAppkey();
IGtPush push = new IGtPush(config.getBaseUrl(), appKey, config.getMastersecret());
NotificationTemplate template = getNotificationTemplate(title, body,appId,appKey);
SingleMessage message = new SingleMessage(); SingleMessage message = new SingleMessage();
message.setOffline(true); message.setOffline(true);
// 离线有效时间,单位为毫秒 // 离线有效时间,单位为毫秒
...@@ -68,7 +68,7 @@ public class GeTuiSDK { ...@@ -68,7 +68,7 @@ public class GeTuiSDK {
return ret; return ret;
} }
public NotificationTemplate getNotificationTemplate(String title, String body) { public NotificationTemplate getNotificationTemplate(String title, String body,String appId,String appKey) {
NotificationTemplate template = new NotificationTemplate(); NotificationTemplate template = new NotificationTemplate();
// 设置APPID与APPKEY // 设置APPID与APPKEY
template.setAppId(appId); template.setAppId(appId);
...@@ -84,8 +84,7 @@ public class GeTuiSDK { ...@@ -84,8 +84,7 @@ public class GeTuiSDK {
style6.setRing(true); style6.setRing(true);
style6.setVibrate(true); style6.setVibrate(true);
style6.setClearable(true); style6.setClearable(true);
/* // 设置通知栏标题与内容
/* // 设置通知栏标题与内容
style.setTitle(title); style.setTitle(title);
style.setText(body); style.setText(body);
// 配置通知栏图标 // 配置通知栏图标
...@@ -138,18 +137,19 @@ public class GeTuiSDK { ...@@ -138,18 +137,19 @@ public class GeTuiSDK {
} }
public void batchPush(List<MsgDTO> objs) throws Exception { public void batchPush(List<MsgDTO> objs,String fromApp) throws Exception {
IIGtPush push = new IGtPush(host, appKey, masterSecret); GeTuiConfig config = getConfig(fromApp);
IIGtPush push = new IGtPush(config.getBaseUrl(), config.getAppkey(), config.getMastersecret());
IBatch batch = push.getBatch(); IBatch batch = push.getBatch();
for (MsgDTO msg : objs) { for (MsgDTO msg : objs) {
constructClientNotifyMsg(msg.getFromApp() + "_" + msg.getUserId(), msg.getTitle(), msg.getBody(), batch); constructClientNotifyMsg(msg.getFromApp() + "_" + msg.getUserId(), msg.getTitle(), msg.getBody(), batch,config.getAppId(),config.getAppkey());
} }
batch.submit(); batch.submit();
} }
public void constructClientNotifyMsg(String alia, String title, String body, IBatch batch) throws Exception { public void constructClientNotifyMsg(String alia, String title, String body, IBatch batch,String appId,String appKey) throws Exception {
SingleMessage message = new SingleMessage(); SingleMessage message = new SingleMessage();
ITemplate template = notificationTemplateDemo(title, body); ITemplate template = notificationTemplateDemo(title, body,appId,appKey);
//template.setAPNInfo(getAPNPayload()); //详见【推送模板说明】iOS通知样式设置 //template.setAPNInfo(getAPNPayload()); //详见【推送模板说明】iOS通知样式设置
...@@ -167,7 +167,7 @@ public class GeTuiSDK { ...@@ -167,7 +167,7 @@ public class GeTuiSDK {
} }
public NotificationTemplate notificationTemplateDemo(String title, String body) { public NotificationTemplate notificationTemplateDemo(String title, String body,String appId,String appKey) {
NotificationTemplate template = new NotificationTemplate(); NotificationTemplate template = new NotificationTemplate();
// 设置APPID与APPKEY // 设置APPID与APPKEY
template.setAppId(appId); template.setAppId(appId);
......
package com.weface.config;
public class APPConfig {
public static final String [] apps = {"kkwj","kkmz","kksb"};
}
package com.weface.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.util.Map;
@Configuration
@ConfigurationProperties(prefix = "getui")
public class GeTuiApp {
private Map<String,GeTuiConfig> apps;
public Map<String, GeTuiConfig> getApps() {
return apps;
}
public void setApps(Map<String, GeTuiConfig> apps) {
this.apps = apps;
}
}
package com.weface.config;
import lombok.Data;
@Data
public class GeTuiConfig {
private String appkey;
private String mastersecret;
private String appId;
private String baseUrl;
}
...@@ -6,4 +6,5 @@ import java.util.List; ...@@ -6,4 +6,5 @@ import java.util.List;
@Data @Data
public class PushDTO { public class PushDTO {
private List<MsgDTO> userList; private List<MsgDTO> userList;
private String fromApp;
} }
...@@ -6,7 +6,7 @@ import java.util.List; ...@@ -6,7 +6,7 @@ import java.util.List;
public interface AsyncService { public interface AsyncService {
void batchPush(List<MsgDTO> objs) throws Exception; void batchPush(List<MsgDTO> objs,String fromApp) throws Exception;
void pushSingle(MsgDTO param); void pushSingle(MsgDTO param);
} }
...@@ -19,8 +19,8 @@ public class AsyncServiceImpl implements AsyncService { ...@@ -19,8 +19,8 @@ public class AsyncServiceImpl implements AsyncService {
@Override @Override
@Async @Async
public void batchPush(List<MsgDTO> objs) throws Exception { public void batchPush(List<MsgDTO> objs,String fromApp) throws Exception {
geTuiSDK.batchPush(objs); geTuiSDK.batchPush(objs,fromApp);
} }
@Override @Override
......
package com.weface.serviceimpl; package com.weface.serviceimpl;
import com.weface.code.CommonResult; import com.weface.code.CommonResult;
import com.weface.component.GeTuiSDK;
import com.weface.dto.MsgDTO; import com.weface.dto.MsgDTO;
import com.weface.dto.PushDTO; import com.weface.dto.PushDTO;
import com.weface.service.AsyncService; import com.weface.service.AsyncService;
...@@ -17,7 +16,7 @@ public class PushServiceImpl implements PushService { ...@@ -17,7 +16,7 @@ public class PushServiceImpl implements PushService {
@Override @Override
public CommonResult pushList(PushDTO param) throws Exception { public CommonResult pushList(PushDTO param) throws Exception {
asyncService.batchPush(param.getUserList()); asyncService.batchPush(param.getUserList(),param.getFromApp());
return CommonResult.success(null); return CommonResult.success(null);
} }
......
...@@ -3,9 +3,11 @@ spring: ...@@ -3,9 +3,11 @@ spring:
name: service-web name: service-web
server: server:
port: 8080 port: 8080
config: getui:
getui: apps: {
appkey: "vIBAFNAEk88qekbfS3miE8" kkwj: {appkey: "vIBAFNAEk88qekbfS3miE8",mastersecret: "JojRk0duJd6oXiHIyFPqj",appId: "LhnWI1t7hc7ABsYbWokXD6",baseUrl: "http://api.getui.com/apiex.htm"},
mastersecret: "JojRk0duJd6oXiHIyFPqj" kkmz: {appkey: "ywXeatlN0k5vDkHDQCqb87",mastersecret: "Jt4Rj3b3YA6qJkOmkN8HG3",appId: "739bQ9FSze62zjgXsZtAF4",baseUrl: "http://api.getui.com/apiex.htm"},
appId: "LhnWI1t7hc7ABsYbWokXD6" kksh: {appkey: "rdLx5zumRK7oEme8MheAh8",mastersecret: "mekLZ4frLu7RHtKsN9mQn",appId: "CYol79N33N71BV6dcjrqj3",baseUrl: "http://api.getui.com/apiex.htm"}
baseUrl: "http://api.getui.com/apiex.htm" }
package com.weface; package com.weface;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest @SpringBootTest
...@@ -10,4 +11,9 @@ class PushMessageApplicationTests { ...@@ -10,4 +11,9 @@ class PushMessageApplicationTests {
void contextLoads() { void contextLoads() {
} }
@Test
public void test(){
}
} }
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