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

'多配置'

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