Commit acca90cd by konghaorui

补充云信初始化参数接口

parent c0443700
ext { ext {
kotlin_version = "1.3.21" kotlin_version = "1.3.21"
dev_mode = true dev_mode = false
ydl_app = [ ydl_app = [
appName : "心理咨询壹点灵", appName : "心理咨询壹点灵",
...@@ -47,7 +47,7 @@ ext { ...@@ -47,7 +47,7 @@ ext {
"m-fm" : "0.0.29.2", "m-fm" : "0.0.29.2",
"m-user" : "0.0.59.5", "m-user" : "0.0.59.5",
"m-home" : "0.0.20.3", "m-home" : "0.0.20.3",
"m-im" : "0.0.15.5", "m-im" : "0.0.15.7",
"m-dynamic" : "0.0.7.3", "m-dynamic" : "0.0.7.3",
"m-muse" : "0.0.28.8", "m-muse" : "0.0.28.8",
...@@ -64,12 +64,12 @@ ext { ...@@ -64,12 +64,12 @@ ext {
"m-tests-api" : "0.0.2", "m-tests-api" : "0.0.2",
"m-user-api" : "0.0.10.15", "m-user-api" : "0.0.10.15",
"m-home-api" : "0.0.4.1", "m-home-api" : "0.0.4.1",
"m-im-api" : "0.0.12.17", "m-im-api" : "0.0.12.18",
"m-dynamic-api" : "0.0.3.7", "m-dynamic-api" : "0.0.3.7",
//-------------- 功能组件 -------------- //-------------- 功能组件 --------------
//第一步 //第一步
"ydl-platform" : "0.0.39.4", "ydl-platform" : "0.0.39.5",
//第二步 若干 //第二步 若干
"ydl-webview" : "0.0.38.4", "ydl-webview" : "0.0.38.4",
...@@ -110,12 +110,12 @@ ext { ...@@ -110,12 +110,12 @@ ext {
"m-tests-api" : "0.0.2", "m-tests-api" : "0.0.2",
"m-user-api" : "0.0.10.15", "m-user-api" : "0.0.10.15",
"m-home-api" : "0.0.4.1", "m-home-api" : "0.0.4.1",
"m-im-api" : "0.0.12.17", "m-im-api" : "0.0.12.18",
"m-dynamic-api" : "0.0.3.7", "m-dynamic-api" : "0.0.3.7",
//-------------- 功能组件 -------------- //-------------- 功能组件 --------------
//第一步 //第一步
"ydl-platform" : "0.0.39.3", "ydl-platform" : "0.0.39.5",
//第二步 若干 //第二步 若干
"ydl-webview" : "0.0.38.4", "ydl-webview" : "0.0.38.4",
......
...@@ -4,7 +4,6 @@ import android.app.Application; ...@@ -4,7 +4,6 @@ import android.app.Application;
import android.content.Context; import android.content.Context;
import com.netease.nimlib.sdk.NIMClient; import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.SDKOptions;
import com.netease.nimlib.sdk.auth.LoginInfo; import com.netease.nimlib.sdk.auth.LoginInfo;
import com.netease.nimlib.sdk.uinfo.model.UserInfo; import com.netease.nimlib.sdk.uinfo.model.UserInfo;
import com.netease.nimlib.sdk.util.NIMUtil; import com.netease.nimlib.sdk.util.NIMUtil;
...@@ -14,6 +13,7 @@ import com.yidianling.avchatkit.config.AVChatOptions; ...@@ -14,6 +13,7 @@ import com.yidianling.avchatkit.config.AVChatOptions;
import com.yidianling.avchatkit.model.ITeamDataProvider; import com.yidianling.avchatkit.model.ITeamDataProvider;
import com.yidianling.avchatkit.model.IUserInfoProvider; import com.yidianling.avchatkit.model.IUserInfoProvider;
import com.yidianling.im.R; import com.yidianling.im.R;
import com.yidianling.im.api.bean.IMInitConfigBean;
import com.yidianling.im.api.event.AccountChangeEvent; import com.yidianling.im.api.event.AccountChangeEvent;
import com.yidianling.im.config.constants.UserPreferences; import com.yidianling.im.config.constants.UserPreferences;
import com.yidianling.im.helper.ImObserversHelper; import com.yidianling.im.helper.ImObserversHelper;
...@@ -45,13 +45,13 @@ public class NimApplication { ...@@ -45,13 +45,13 @@ public class NimApplication {
} }
public void initIm(Application app,Class activity) { public void initIm(Application app,Class activity) {
initIm(app,activity,new SDKOptions()); initIm(app,activity,null);
} }
public void initIm(Application app, Class activity, SDKOptions sdkOptions) { public void initIm(Application app, Class activity, IMInitConfigBean configBean) {
IMCache.setContext(app); IMCache.setContext(app);
// 初始化云信SDK // 初始化云信SDK
NIMClient.init(app, loginInfo(), NimSDKOptionConfig.prepareSDKOptions(app,activity,sdkOptions)); NIMClient.init(app, loginInfo(), NimSDKOptionConfig.prepareSDKOptions(app,activity,configBean));
// 以下逻辑只在主进程初始化时执行 // 以下逻辑只在主进程初始化时执行
if (NIMUtil.isMainProcess(app)) { if (NIMUtil.isMainProcess(app)) {
......
...@@ -14,6 +14,7 @@ import com.ydl.ydlcommon.base.BaseApp; ...@@ -14,6 +14,7 @@ import com.ydl.ydlcommon.base.BaseApp;
import com.ydl.ydlcommon.base.config.YDLConstants; import com.ydl.ydlcommon.base.config.YDLConstants;
import com.ydl.ydlcommon.utils.YDLCacheUtils; import com.ydl.ydlcommon.utils.YDLCacheUtils;
import com.yidianling.im.R; import com.yidianling.im.R;
import com.yidianling.im.api.bean.IMInitConfigBean;
import com.yidianling.im.config.constants.UserPreferences; import com.yidianling.im.config.constants.UserPreferences;
import com.yidianling.im.config.provider.CustomUserInfoProvider; import com.yidianling.im.config.provider.CustomUserInfoProvider;
import com.yidianling.im.preference.IMCache; import com.yidianling.im.preference.IMCache;
...@@ -30,39 +31,14 @@ import java.io.IOException; ...@@ -30,39 +31,14 @@ import java.io.IOException;
class NimSDKOptionConfig { class NimSDKOptionConfig {
static SDKOptions prepareSDKOptions(Context context, Class activity,SDKOptions options) { static SDKOptions prepareSDKOptions(Context context, Class activity, IMInitConfigBean configBean) {
SDKOptions options = new SDKOptions();
//线上环境关闭 //线上环境关闭
if (BaseApp.Companion.getInstance().getGlobalConfig().getAppDebug()) { if (BaseApp.Companion.getInstance().getGlobalConfig().getAppDebug()) {
//配置检查 //配置检查
options.checkManifestConfig = true; options.checkManifestConfig = true;
} }
options.appKey = getIMAppKey(configBean);
if(TextUtils.isEmpty(options.appKey)) {
//key配置---逻辑更改:修复切换环境功能
if (BaseApp.Companion.getInstance().getGlobalConfig().getAppDebug()) {
String appEnv = BaseApp.Companion.getInstance().getGlobalConfig().getAppEnv();
//debug包根据url判断使用正式或者测试key
String cacheAppEnv = YDLCacheUtils.Companion.getCacheApi();
//这边不能加BuildConfig.DEBUG,因为发布了aar之后,必定为release,导致切换云信的环境失败
if (!TextUtils.isEmpty(cacheAppEnv)) {
if (YDLConstants.ENV_TEST.equals(cacheAppEnv)) {
options.appKey = "9a8cefe97b7690537fc1334091af9208";
} else {
options.appKey = "4e258ba5cdf489fa188274ebf0fb5669";
}
} else {
if (YDLConstants.ENV_TEST.equals(appEnv)|| YDLConstants.ENV_AUTO_TEST.equals(appEnv)) {
options.appKey = "9a8cefe97b7690537fc1334091af9208";
} else {
options.appKey = "4e258ba5cdf489fa188274ebf0fb5669";
}
}
} else {
//release包始终使用正式key
options.appKey = "4e258ba5cdf489fa188274ebf0fb5669";
}
}
// 如果将新消息通知提醒托管给SDK完成,需要添加以下配置。 // 如果将新消息通知提醒托管给SDK完成,需要添加以下配置。
initStatusBarNotificationConfig(context, options, activity); initStatusBarNotificationConfig(context, options, activity);
...@@ -103,12 +79,12 @@ class NimSDKOptionConfig { ...@@ -103,12 +79,12 @@ class NimSDKOptionConfig {
// 打开消息撤回未读数-1的开关 // 打开消息撤回未读数-1的开关
options.shouldConsiderRevokedMessageUnreadCount = true; options.shouldConsiderRevokedMessageUnreadCount = true;
if(options.mixPushConfig==null) { options.mixPushConfig = buildMixPushConfig(configBean);
options.mixPushConfig = buildMixPushConfig();
}
return options; return options;
} }
/** /**
* 配置 APP 保存图片/语音/文件/log等数据的目录 * 配置 APP 保存图片/语音/文件/log等数据的目录
* 这里示例用SD卡的应用扩展存储目录 * 这里示例用SD卡的应用扩展存储目录
...@@ -198,42 +174,105 @@ class NimSDKOptionConfig { ...@@ -198,42 +174,105 @@ class NimSDKOptionConfig {
} }
}; };
private static MixPushConfig buildMixPushConfig() {
private static String getIMAppKey(IMInitConfigBean configBean) {
String debugKey = "9a8cefe97b7690537fc1334091af9208";
String releaseKey = "4e258ba5cdf489fa188274ebf0fb5669";
String finalKey = "";
if(configBean!=null&&!TextUtils.isEmpty(configBean.debugAppKey)&&!TextUtils.isEmpty(configBean.releaseAppKey)) {
debugKey = configBean.debugAppKey;
releaseKey = configBean.releaseAppKey;
}
//key配置---逻辑更改:修复切换环境功能
if (BaseApp.Companion.getInstance().getGlobalConfig().getAppDebug()) {
String appEnv = BaseApp.Companion.getInstance().getGlobalConfig().getAppEnv();
//debug包根据url判断使用正式或者测试key
String cacheAppEnv = YDLCacheUtils.Companion.getCacheApi();
if (!TextUtils.isEmpty(cacheAppEnv)) {
appEnv = cacheAppEnv;
}
if (YDLConstants.ENV_TEST.equals(appEnv)|| YDLConstants.ENV_AUTO_TEST.equals(appEnv)) {
finalKey = debugKey;
} else {
finalKey = releaseKey;
}
} else {
//release包始终使用正式key
finalKey = releaseKey;
}
return finalKey;
}
private static MixPushConfig buildMixPushConfig(IMInitConfigBean configBean) {
// 第三方推送配置 // 第三方推送配置
MixPushConfig config = new MixPushConfig(); MixPushConfig config = new MixPushConfig();
String appFrom = BaseApp.Companion.getInstance().getGlobalConfig().getAppFrom();
if (YDLConstants.FROM_YDL.equals(appFrom)) { if(configBean!=null && !TextUtils.isEmpty(configBean.hwCertificateName)) {
// 小米推送
config.xmAppId = "2882303761517432980";
config.xmAppKey = "5241743243980";
config.xmCertificateName = "ydlUser";
// 华为推送
config.hwCertificateName = "ydlUserHw";
//OPPO 推送
config.oppoAppId = "3245516";
config.oppoAppKey = "afk71f35VogGw0w0wKsookksc";
config.oppoAppSercet = "691184F044acA7a6851F578451f67616";
config.oppoCertificateName = "ydlUserOPPO";
//VIVO 推送
config.vivoCertificateName = "ydlUserVIVO";
} else if(YDLConstants.FROM_XLZX.equals(appFrom)) {
// 小米推送 // 小米推送
config.xmAppId = "2882303761517549919"; config.xmAppId = splitString(configBean.xmAppId);
config.xmAppKey = "5111754949919"; config.xmAppKey = splitString(configBean.xmAppKey);
config.xmCertificateName = "ydlXLZXXM"; config.xmCertificateName = splitString(configBean.xmCertificateName);
//魅族
config.mzAppId = splitString(configBean.mzAppId);
config.mzAppKey = splitString(configBean.mzAppKey);
config.mzCertificateName = splitString(configBean.mzCertificateName);
// 华为推送 // 华为推送
config.hwCertificateName = "ydlXLZX"; config.hwCertificateName = splitString(configBean.hwCertificateName);
//OPPO 推送 //OPPO 推送
config.oppoAppId = "3601521"; config.oppoAppId = splitString(configBean.oppoAppId);
config.oppoAppKey = "c500cJ5mzvSow848048gOsG4G"; config.oppoAppKey = splitString(configBean.oppoAppKey);
config.oppoAppSercet = "F13EbCf4380b683Fb0e316336eeC9Deb"; config.oppoAppSercet = splitString(configBean.oppoAppSercet);
config.oppoCertificateName = "ydlXLZXOPPO"; config.oppoCertificateName = splitString(configBean.oppoCertificateName);
//VIVO 推送 //VIVO 推送
config.vivoCertificateName = "ydlXLZXVIVO"; config.vivoCertificateName = splitString(configBean.vivoCertificateName);
} else {
String appFrom = BaseApp.Companion.getInstance().getGlobalConfig().getAppFrom();
if (YDLConstants.FROM_YDL.equals(appFrom)) {
// 小米推送
config.xmAppId = "2882303761517432980";
config.xmAppKey = "5241743243980";
config.xmCertificateName = "ydlUser";
// 华为推送
config.hwCertificateName = "ydlUserHw";
//OPPO 推送
config.oppoAppId = "3245516";
config.oppoAppKey = "afk71f35VogGw0w0wKsookksc";
config.oppoAppSercet = "691184F044acA7a6851F578451f67616";
config.oppoCertificateName = "ydlUserOPPO";
//VIVO 推送
config.vivoCertificateName = "ydlUserVIVO";
} else if(YDLConstants.FROM_XLZX.equals(appFrom)) {
// 小米推送
config.xmAppId = "2882303761517549919";
config.xmAppKey = "5111754949919";
config.xmCertificateName = "ydlXLZXXM";
// 华为推送
config.hwCertificateName = "ydlXLZX";
//OPPO 推送
config.oppoAppId = "3601521";
config.oppoAppKey = "c500cJ5mzvSow848048gOsG4G";
config.oppoAppSercet = "F13EbCf4380b683Fb0e316336eeC9Deb";
config.oppoCertificateName = "ydlXLZXOPPO";
//VIVO 推送
config.vivoCertificateName = "ydlXLZXVIVO";
}
} }
return config; return config;
} }
private static String splitString(String string) {
if(string.contains("-")) {
string = string.substring(string.lastIndexOf("-")+1);
}
return string;
}
} }
...@@ -14,14 +14,13 @@ import com.netease.nimlib.sdk.auth.LoginInfo ...@@ -14,14 +14,13 @@ import com.netease.nimlib.sdk.auth.LoginInfo
import com.netease.nimlib.sdk.msg.MessageBuilder import com.netease.nimlib.sdk.msg.MessageBuilder
import com.netease.nimlib.sdk.msg.MsgService import com.netease.nimlib.sdk.msg.MsgService
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum
import com.ydl.webview.NewH5Activity
import com.ydl.ydlcommon.modular.ModularServiceManager
import com.ydl.ydlcommon.router.YdlCommonOut import com.ydl.ydlcommon.router.YdlCommonOut
import com.ydl.ydlcommon.utils.StringUtils import com.ydl.ydlcommon.utils.StringUtils
import com.ydl.ydlcommon.utils.remind.HttpErrorUtils import com.ydl.ydlcommon.utils.remind.HttpErrorUtils
import com.yidianling.avchatkit.common.util.NetworkUtil import com.yidianling.avchatkit.common.util.NetworkUtil
import com.yidianling.common.tools.ToastUtil import com.yidianling.common.tools.ToastUtil
import com.yidianling.im.R import com.yidianling.im.R
import com.yidianling.im.api.bean.IMInitConfigBean
import com.yidianling.im.api.bean.IMLoginInfo import com.yidianling.im.api.bean.IMLoginInfo
import com.yidianling.im.api.bean.IMRequestCallback import com.yidianling.im.api.bean.IMRequestCallback
import com.yidianling.im.api.listener.ApiStringResponseCallback import com.yidianling.im.api.listener.ApiStringResponseCallback
...@@ -366,6 +365,14 @@ class IMServiceImpl : IImService { ...@@ -366,6 +365,14 @@ class IMServiceImpl : IImService {
NimApplication.getInstance().initIm(app, activity) NimApplication.getInstance().initIm(app, activity)
} }
override fun initIm(
app: Application,
activity: Class<out Activity>,
imInitBean: IMInitConfigBean
) {
NimApplication.getInstance().initIm(app, activity,imInitBean)
}
override fun isWifiOr3G(activity: Activity): Boolean { override fun isWifiOr3G(activity: Activity): Boolean {
return NetworkUtil.isWifiOr3G(activity) return NetworkUtil.isWifiOr3G(activity)
} }
......
package com.yidianling.im.api.bean;
/**
* Created by haorui on 2020/3/6.
* Des:
*/
public class IMInitConfigBean {
/**
* 测试环境AppKey
*/
public String debugAppKey;
/**
* 正式环境AppKey
*/
public String releaseAppKey;
/**
* 小米推送 appId
*/
public String xmAppId;
/**
* 小米推送 appKey
*/
public String xmAppKey;
/**
* 小米推送证书,请在云信管理后台申请
*/
public String xmCertificateName;
/**
* 华为推送 appId 请在 AndroidManifest.xml 文件中配置
* 华为推送证书,请在云信管理后台申请
*/
public String hwCertificateName;
/**
* 魅族推送 appId
*/
public String mzAppId;
/**
* 魅族推送 appKey
*/
public String mzAppKey;
/**
* 魅族推送证书,请在云信管理后台申请
*/
public String mzCertificateName;
/**
* FCM 推送证书,请在云信管理后台申请
* 海外客户使用
*/
public String fcmCertificateName;
/**
* VIVO推送 appId apiKey请在 AndroidManifest.xml 文件中配置
* VIVO推送证书,请在云信管理后台申请
*/
public String vivoCertificateName;
/**
* oppo 推送appId
*/
public String oppoAppId;
/**
* oppo 推送appKey
*/
public String oppoAppKey;
/**
* oppo 推送AppSecret
*/
public String oppoAppSercet;
/**
* OPPO推送证书,请在云信管理后台申请
*/
public String oppoCertificateName;
}
...@@ -5,6 +5,7 @@ import android.app.Application ...@@ -5,6 +5,7 @@ import android.app.Application
import android.content.Context import android.content.Context
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import com.alibaba.android.arouter.facade.template.IProvider import com.alibaba.android.arouter.facade.template.IProvider
import com.yidianling.im.api.bean.IMInitConfigBean
import com.yidianling.im.api.bean.IMLoginInfo import com.yidianling.im.api.bean.IMLoginInfo
import com.yidianling.im.api.bean.IMRequestCallback import com.yidianling.im.api.bean.IMRequestCallback
import com.yidianling.im.api.listener.ApiStringResponseCallback import com.yidianling.im.api.listener.ApiStringResponseCallback
...@@ -123,5 +124,7 @@ interface IImService : IProvider { ...@@ -123,5 +124,7 @@ interface IImService : IProvider {
fun initIm(app: Application, activity: Class<out Activity>) fun initIm(app: Application, activity: Class<out Activity>)
fun initIm(app: Application, activity: Class<out Activity>,imInitBean: IMInitConfigBean)
fun isWifiOr3G(activity: Activity): Boolean fun isWifiOr3G(activity: Activity): Boolean
} }
\ 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