推送鉴权模块
This commit is contained in:
@@ -26,4 +26,6 @@ dependencies {
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
implementation rootProject.ext.dependencies.androidxappcompat
|
||||
|
||||
// passport
|
||||
implementation 'com.zhidao.tcloginsdk:tclogin:1.1.5.1'
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.mogo.cloud.passport;
|
||||
|
||||
/**
|
||||
* AI 云平台接口中Token的获取回碉
|
||||
*/
|
||||
public interface IMoGoTokenCallback {
|
||||
void onTokenGot(String token, String sn);
|
||||
|
||||
void onError(int code, String msg);
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.mogo.cloud.passport;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
import com.zhidao.tcloginsdk.LoginManager;
|
||||
import com.zhidao.tcloginsdk.model.ThirdLoginParam;
|
||||
import com.zhidao.tcloginsdk.model.TokenData;
|
||||
import com.zhidao.tcloginsdk.network.LoginCallback;
|
||||
|
||||
/**
|
||||
* 蘑菇AI云平台配置文件
|
||||
*/
|
||||
@Keep
|
||||
public class MoGoAiCloudClient {
|
||||
private static final String TAG = "MoGoAiCloudClient";
|
||||
private static volatile MoGoAiCloudClient sInstance;
|
||||
|
||||
private MoGoAiCloudClientConfig mConfig;
|
||||
private Context mContext;
|
||||
|
||||
|
||||
private MoGoAiCloudClient() {
|
||||
|
||||
}
|
||||
|
||||
@Keep
|
||||
public static MoGoAiCloudClient getInstance() {
|
||||
if (sInstance == null) {
|
||||
synchronized (MoGoAiCloudClient.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new MoGoAiCloudClient();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param config 配置信息
|
||||
*/
|
||||
public void init(Context context, MoGoAiCloudClientConfig config) {
|
||||
mContext = context;
|
||||
mConfig = config;
|
||||
// 设置网络环境
|
||||
LoginManager.getInstance(context).setNetEnviron(config.getNetMode());
|
||||
}
|
||||
|
||||
public MoGoAiCloudClientConfig getConfig() {
|
||||
return mConfig;
|
||||
}
|
||||
|
||||
public void refreshToken(final IMoGoTokenCallback tokenCallback) {
|
||||
if (mConfig != null) {
|
||||
ThirdLoginParam thirdLoginParam = ThirdLoginParam.of(
|
||||
mConfig.getThirdPartyDeviceId(),
|
||||
mConfig.getThirdPartyAppKey(),
|
||||
mConfig.getThirdPartySignSecret()
|
||||
);
|
||||
|
||||
LoginManager.getInstance(mContext).login(
|
||||
mConfig.isThirdLogin(),
|
||||
thirdLoginParam,
|
||||
new LoginCallback() {
|
||||
@Override
|
||||
public void onSuccess(TokenData.TokenResult result) {
|
||||
if (tokenCallback != null) {
|
||||
tokenCallback.onTokenGot(result.token, result.sn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int code, String msg) {
|
||||
if (tokenCallback != null) {
|
||||
tokenCallback.onError(code, msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Log.e(TAG, "SDK MoGoAiCloudClientConfig 为 null,请检查!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.mogo.cloud.passport;
|
||||
|
||||
/**
|
||||
* SDK 中的参数
|
||||
*/
|
||||
public class MoGoAiCloudClientConfig {
|
||||
|
||||
/**
|
||||
* 研发环境
|
||||
*/
|
||||
public static final int NET_MODE_DEV = 1;
|
||||
|
||||
/**
|
||||
* 测试环境
|
||||
*/
|
||||
public static final int NET_MODE_QA = 2;
|
||||
|
||||
/**
|
||||
* 演示环境
|
||||
*/
|
||||
public static final int NET_MODE_DEMO = 4;
|
||||
|
||||
/**
|
||||
* 生产环境
|
||||
*/
|
||||
public static final int NET_MODE_RELEASE = 3;
|
||||
|
||||
/**
|
||||
* 网络模式
|
||||
*/
|
||||
private int sNetMode = NET_MODE_RELEASE;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
private String thirdPartyDeviceId;
|
||||
/**
|
||||
* APP key
|
||||
*/
|
||||
private String thirdPartyAppKey;
|
||||
|
||||
/**
|
||||
* 签名信息
|
||||
*/
|
||||
private String thirdPartySignSecret;
|
||||
|
||||
/**
|
||||
* 是否是第三方登录
|
||||
*/
|
||||
private boolean thirdLogin;
|
||||
|
||||
private String token;
|
||||
private String sn;
|
||||
|
||||
public String getThirdPartyDeviceId() {
|
||||
return thirdPartyDeviceId;
|
||||
}
|
||||
|
||||
public void setThirdPartyDeviceId(String thirdPartyDeviceId) {
|
||||
this.thirdPartyDeviceId = thirdPartyDeviceId;
|
||||
}
|
||||
|
||||
public String getThirdPartyAppKey() {
|
||||
return thirdPartyAppKey;
|
||||
}
|
||||
|
||||
public void setThirdPartyAppKey(String thirdPartyAppKey) {
|
||||
this.thirdPartyAppKey = thirdPartyAppKey;
|
||||
}
|
||||
|
||||
public String getThirdPartySignSecret() {
|
||||
return thirdPartySignSecret;
|
||||
}
|
||||
|
||||
public void setThirdPartySignSecret(String thirdPartySignSecret) {
|
||||
this.thirdPartySignSecret = thirdPartySignSecret;
|
||||
}
|
||||
|
||||
public boolean isThirdLogin() {
|
||||
return thirdLogin;
|
||||
}
|
||||
|
||||
public void setThirdLogin(boolean thirdLogin) {
|
||||
this.thirdLogin = thirdLogin;
|
||||
}
|
||||
|
||||
public int getNetMode() {
|
||||
return sNetMode;
|
||||
}
|
||||
|
||||
public void setNetMode(int sNetMode) {
|
||||
this.sNetMode = sNetMode;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user