微调
This commit is contained in:
@@ -20,12 +20,12 @@ public class AliyunProviderFactory implements MessageProviderFactory {
|
||||
@Override
|
||||
public SmsSender createSmsSender(ChannelProviderConfigDO config, Sender sender) {
|
||||
// 配置缺失时返回固定结果 sender,由主流程统一落库为配置异常。
|
||||
if (ProviderFactorySupport.hasBlank(config.getAppKey(), config.getAppSecret())) {
|
||||
if (ProviderFactorySupport.hasBlank(config.getAppKey(), config.getSecret())) {
|
||||
return new FixedResultSmsSender(SendOutcome.CONFIG_INVALID, "当前服务商短信渠道配置不完整");
|
||||
}
|
||||
AliYunMailSetting aliYunSmsSetting = AliYunMailSetting.builder()
|
||||
.accessKeyId(config.getAppKey())
|
||||
.accessKeySecret(config.getAppSecret())
|
||||
.accessKeySecret(config.getSecret())
|
||||
.regionId("cn-hangzhou")
|
||||
.endpoint("dysmsapi.aliyuncs.com")
|
||||
.build();
|
||||
@@ -35,12 +35,12 @@ public class AliyunProviderFactory implements MessageProviderFactory {
|
||||
@Override
|
||||
public EmailSender createEmailSender(ChannelProviderConfigDO config, Sender sender) {
|
||||
// 配置缺失时返回固定结果 sender,由主流程统一落库为配置异常。
|
||||
if (ProviderFactorySupport.hasBlank(config.getAppKey(), config.getAppSecret())) {
|
||||
if (ProviderFactorySupport.hasBlank(config.getAppKey(), config.getSecret())) {
|
||||
return new FixedResultEmailSender(SendOutcome.CONFIG_INVALID, "当前服务商邮件渠道配置不完整");
|
||||
}
|
||||
AliYunMailSetting aliYunMailSetting = AliYunMailSetting.builder()
|
||||
.accessKeyId(config.getAppKey())
|
||||
.accessKeySecret(config.getAppSecret())
|
||||
.accessKeySecret(config.getSecret())
|
||||
.regionId("cn-hangzhou")
|
||||
.endpoint("dm.aliyuncs.com")
|
||||
.build();
|
||||
|
||||
@@ -19,12 +19,12 @@ public class TelecomProviderFactory implements MessageProviderFactory {
|
||||
@Override
|
||||
public SmsSender createSmsSender(ChannelProviderConfigDO config, Sender sender) {
|
||||
// 配置缺失时返回固定结果 sender,由主流程统一落库为配置异常。
|
||||
if (ProviderFactorySupport.hasBlank(config.getAppKey(), config.getAppSecret(), config.getApiUrl())) {
|
||||
if (ProviderFactorySupport.hasBlank(config.getAppKey(), config.getSecret(), config.getApiUrl())) {
|
||||
return new FixedResultSmsSender(SendOutcome.CONFIG_INVALID, "当前服务商短信渠道配置不完整");
|
||||
}
|
||||
TelecomSmsSetting telecomSmsSetting = TelecomSmsSetting.builder()
|
||||
.account(config.getAppKey())
|
||||
.password(config.getAppSecret())
|
||||
.password(config.getSecret())
|
||||
.apiUrl(config.getApiUrl())
|
||||
.extno(config.getExtno())
|
||||
.build();
|
||||
|
||||
@@ -19,8 +19,6 @@ import com.njcn.msgpush.module.push.dal.dataobject.channel.ChannelProviderConfig
|
||||
|
||||
public class UniPushProviderFactory implements MessageProviderFactory {
|
||||
|
||||
private static final String APP_ID = "appId";
|
||||
private static final String MASTER_SECRET = "masterSecret";
|
||||
|
||||
@Override
|
||||
public SmsSender createSmsSender(ChannelProviderConfigDO config, Sender sender) {
|
||||
@@ -36,18 +34,15 @@ public class UniPushProviderFactory implements MessageProviderFactory {
|
||||
|
||||
@Override
|
||||
public AppPushSender createAppPushSender(ChannelProviderConfigDO config, Sender sender) {
|
||||
JSONObject extraConfig = StrUtil.isBlank(config.getExtraConfig()) ? new JSONObject() : JSON.parseObject(config.getExtraConfig());
|
||||
String appId = extraConfig.getString(APP_ID);
|
||||
String masterSecret = extraConfig.getString(MASTER_SECRET);
|
||||
// 配置缺失时返回固定结果 sender,由主流程统一落库为配置异常。
|
||||
if (ProviderFactorySupport.hasBlank(appId, config.getAppKey(), config.getAppSecret(), masterSecret)) {
|
||||
if (ProviderFactorySupport.hasBlank(config.getSecret())) {
|
||||
return new FixedResultAppPushSender(SendOutcome.CONFIG_INVALID, "当前服务商 APP 推送渠道配置不完整");
|
||||
}
|
||||
UniPushAppPushSetting uniPushAppPushSetting = new UniPushAppPushSetting(
|
||||
appId,
|
||||
config.getAppId(),
|
||||
config.getAppKey(),
|
||||
config.getAppSecret(),
|
||||
masterSecret
|
||||
config.getSecret(),
|
||||
config.getApiUrl()
|
||||
);
|
||||
return new UniPushAppPushSender(uniPushAppPushSetting, sender);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
package com.njcn.msgpush.module.push.client.sender.impl.apppush;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.getui.push.v2.sdk.ApiHelper;
|
||||
import com.getui.push.v2.sdk.GtApiConfiguration;
|
||||
import com.getui.push.v2.sdk.api.PushApi;
|
||||
import com.getui.push.v2.sdk.common.ApiResult;
|
||||
import com.getui.push.v2.sdk.dto.req.Audience;
|
||||
import com.getui.push.v2.sdk.dto.req.Settings;
|
||||
import com.getui.push.v2.sdk.dto.req.message.PushChannel;
|
||||
import com.getui.push.v2.sdk.dto.req.message.PushDTO;
|
||||
import com.getui.push.v2.sdk.dto.req.message.PushMessage;
|
||||
import com.getui.push.v2.sdk.dto.req.message.android.AndroidDTO;
|
||||
import com.getui.push.v2.sdk.dto.req.message.android.GTNotification;
|
||||
import com.getui.push.v2.sdk.dto.req.message.android.ThirdNotification;
|
||||
import com.getui.push.v2.sdk.dto.req.message.android.Ups;
|
||||
import com.getui.push.v2.sdk.dto.req.message.ios.Alert;
|
||||
import com.getui.push.v2.sdk.dto.req.message.ios.Aps;
|
||||
import com.getui.push.v2.sdk.dto.req.message.ios.IosDTO;
|
||||
import com.njcn.msgpush.module.push.client.sender.AppPushSender;
|
||||
import com.njcn.msgpush.module.push.client.sender.SendResult;
|
||||
import com.njcn.msgpush.module.push.client.sender.Sender;
|
||||
@@ -34,7 +42,13 @@ public class UniPushAppPushSender implements AppPushSender {
|
||||
gtApiConfiguration.setAppId(uniPushAppPushSetting.getAppId());
|
||||
gtApiConfiguration.setAppKey(uniPushAppPushSetting.getAppKey());
|
||||
gtApiConfiguration.setMasterSecret(uniPushAppPushSetting.getMasterSecret());
|
||||
gtApiConfiguration.setDomain("https://restapi.getui.com/v2/");
|
||||
// 使用配置的 API 地址,如果未配置则使用默认地址
|
||||
String apiUrl = uniPushAppPushSetting.getApiUrl();
|
||||
if (StrUtil.isNotBlank(apiUrl)) {
|
||||
gtApiConfiguration.setDomain(apiUrl);
|
||||
} else {
|
||||
gtApiConfiguration.setDomain("https://restapi.getui.com/v2/");
|
||||
}
|
||||
ApiHelper apiHelper = ApiHelper.build(gtApiConfiguration);
|
||||
this.pushApi = apiHelper.creatApi(PushApi.class);
|
||||
} catch (Exception e) {
|
||||
@@ -89,13 +103,48 @@ public class UniPushAppPushSender implements AppPushSender {
|
||||
settings.setTtl(3600000);
|
||||
pushDTO.setSettings(settings);
|
||||
|
||||
// 创建 PushMessage,设置透传消息(可选)
|
||||
PushMessage pushMessage = new PushMessage();
|
||||
GTNotification notification = new GTNotification();
|
||||
notification.setTitle(title);
|
||||
notification.setBody(content);
|
||||
notification.setClickType("startapp");
|
||||
pushMessage.setNotification(notification);
|
||||
pushMessage.setTransmission("{\"title\":\"" + title + "\",\"body\":\"" + content + "\"}");
|
||||
|
||||
// 在线推送 - 使用 GTNotification
|
||||
GTNotification gtNotification = new GTNotification();
|
||||
gtNotification.setTitle(title);
|
||||
gtNotification.setBody(content);
|
||||
gtNotification.setClickType("startapp");
|
||||
pushMessage.setNotification(gtNotification);
|
||||
|
||||
pushDTO.setPushMessage(pushMessage);
|
||||
|
||||
// 创建 PushChannel 用于配置各平台的通知
|
||||
PushChannel pushChannel = new PushChannel();
|
||||
|
||||
// Android 离线推送配置 - 使用 ThirdNotification
|
||||
AndroidDTO androidDTO = new AndroidDTO();
|
||||
Ups ups = new Ups();
|
||||
ThirdNotification thirdNotification = new ThirdNotification();
|
||||
thirdNotification.setTitle(title);
|
||||
thirdNotification.setBody(content);
|
||||
thirdNotification.setClickType("startapp");
|
||||
ups.setNotification(thirdNotification);
|
||||
androidDTO.setUps(ups);
|
||||
pushChannel.setAndroid(androidDTO);
|
||||
|
||||
// iOS 通知配置
|
||||
IosDTO iosDTO = new IosDTO();
|
||||
Aps aps = new Aps();
|
||||
Alert alert = new Alert();
|
||||
alert.setTitle(title);
|
||||
alert.setBody(content);
|
||||
aps.setAlert(alert);
|
||||
aps.setSound("default");
|
||||
aps.setContentAvailable(0);
|
||||
iosDTO.setAps(aps);
|
||||
pushChannel.setIos(iosDTO);
|
||||
|
||||
// 将 PushChannel 设置到 PushDTO 中
|
||||
pushDTO.setPushChannel(pushChannel);
|
||||
|
||||
return pushDTO;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,15 +12,17 @@ import lombok.EqualsAndHashCode;
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class UniPushAppPushSetting extends AppPushSetting {
|
||||
// 个推应用ID
|
||||
private String appId;
|
||||
private String appKey;
|
||||
private String uniAppSecret;
|
||||
// 个推主密钥
|
||||
private String masterSecret;
|
||||
private String apiUrl;
|
||||
|
||||
public UniPushAppPushSetting(String appId, String appKey, String uniAppSecret, String masterSecret) {
|
||||
public UniPushAppPushSetting(String appId, String appKey, String masterSecret, String apiUrl) {
|
||||
this.appId = appId;
|
||||
this.appKey = appKey;
|
||||
this.uniAppSecret = uniAppSecret;
|
||||
this.masterSecret = masterSecret;
|
||||
this.apiUrl = apiUrl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,30 +32,30 @@ public class ChannelProviderConfigDO extends BaseDO {
|
||||
private String providerName;
|
||||
|
||||
/**
|
||||
* 服务商类型:telecom/cmcc/aliyun/twilio/unipush
|
||||
* 服务商类型:telecom/aliyun/unipush
|
||||
*/
|
||||
private String providerType;
|
||||
|
||||
/**
|
||||
* API地址
|
||||
* 对于 UniPush,可配置为自定义API地址,如未配置则使用默认地址 https://restapi.getui.com/v2/
|
||||
*/
|
||||
private String apiUrl;
|
||||
|
||||
/**
|
||||
* AppKey
|
||||
*/
|
||||
private String appKey;
|
||||
|
||||
/**
|
||||
* AppSecret
|
||||
*/
|
||||
private String appSecret;
|
||||
private String secret;
|
||||
|
||||
/**
|
||||
* 电信sms服务所需接入码
|
||||
*/
|
||||
private String extno;
|
||||
|
||||
/**
|
||||
* app推送服务所需的appId
|
||||
*/
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* 额外配置(JSON格式)
|
||||
*/
|
||||
|
||||
@@ -74,7 +74,7 @@ public class MsgPushClientTest {
|
||||
ChannelProviderConfigDO config = new ChannelProviderConfigDO();
|
||||
config.setApiUrl("https://sms.ymeeting.cn/smsv2");
|
||||
config.setAppKey("925631");
|
||||
config.setAppSecret("AMW2pOVrdky");
|
||||
config.setSecret("AMW2pOVrdky");
|
||||
config.setExtno("106905631");
|
||||
SmsSender smsSender = messageProviderFactory.createSmsSender(config, sender);
|
||||
String templateIdentifier = "SMS_481710295";
|
||||
|
||||
Reference in New Issue
Block a user