完善了鉴权SDK开发,增加了测试代码

This commit is contained in:
董宏宇
2021-01-19 19:56:17 +08:00
parent d5075235a7
commit 409471b856
7 changed files with 159 additions and 5 deletions

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -25,6 +25,6 @@ dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation rootProject.ext.dependencies.androidxappcompat
implementation rootProject.ext.dependencies.androidxconstraintlayout
implementation project(path: ':foudations:mogo-passport')
}

View File

@@ -9,13 +9,16 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".PassPortActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,72 @@
package com.mogo.cloud;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.mogo.cloud.passport.IMoGoTokenCallback;
import com.mogo.cloud.passport.MoGoAiCloudClient;
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
import static com.mogo.cloud.passport.MoGoAiCloudClientConfig.NET_MODE_QA;
/**
* 鉴权sdk测试页面
*/
public class PassPortActivity extends AppCompatActivity {
private EditText etAppKey;
private EditText etDevicesId;
private EditText etSignSecret;
private Button btnRefreshToken;
private TextView tvSn;
private TextView tvToken;
private MoGoAiCloudClient mMoGoAiCloudClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pass_port_actvity);
etAppKey = findViewById(R.id.etAppKey);
etDevicesId = findViewById(R.id.etDevicesId);
etSignSecret = findViewById(R.id.etSignSecret);
btnRefreshToken = findViewById(R.id.btnRefreshToken);
tvSn = findViewById(R.id.tvSn);
tvToken = findViewById(R.id.tvToken);
MoGoAiCloudClientConfig clientConfig = new MoGoAiCloudClientConfig();
clientConfig.setNetMode(NET_MODE_QA);
clientConfig.setThirdLogin(true);
clientConfig.setThirdPartyAppKey("f8xx");
clientConfig.setThirdPartyDeviceId("f8xx");
clientConfig.setThirdPartySignSecret("f8xx");
clientConfig.setThirdPartyAppKey("6bbe7e0e1ecd8e2f8dc336e1678a2791");
mMoGoAiCloudClient = MoGoAiCloudClient.getInstance().init(this,clientConfig);
btnRefreshToken.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mMoGoAiCloudClient.refreshToken(new IMoGoTokenCallback() {
@Override
public void onTokenGot(String token, String sn) {
tvSn.setText(sn);
tvToken.setText(token);
}
@Override
public void onError(int code, String msg) {
}
});
}
});
}
}

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".PassPortActivity">
<EditText
android:id="@+id/etAppKey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="AppKey" />
<EditText
android:id="@+id/etDevicesId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:hint="DevicesId" />
<EditText
android:id="@+id/etSignSecret"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:hint="SignSecret" />
<Button
android:id="@+id/btnRefreshToken"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="刷新令牌" />
<TextView
android:id="@+id/tvSn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="SN"
android:textSize="20dp" />
<TextView
android:id="@+id/tvToken"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Token"
android:textSize="20dp" />
</LinearLayout>

View File

@@ -44,11 +44,12 @@ public class MoGoAiCloudClient {
* @param context 上下文
* @param config 配置信息
*/
public void init(Context context, MoGoAiCloudClientConfig config) {
public MoGoAiCloudClient init(Context context, MoGoAiCloudClientConfig config) {
mContext = context;
mConfig = config;
// 设置网络环境
LoginManager.getInstance(context).setNetEnviron(config.getNetMode());
return sInstance;
}
public MoGoAiCloudClientConfig getConfig() {
@@ -73,6 +74,10 @@ public class MoGoAiCloudClient {
tokenCallback.onTokenGot(result.token, result.sn);
}
if (mConfig != null) {
mConfig.sn = result.sn;
mConfig.token = result.token;
}
}
@Override

View File

@@ -49,8 +49,15 @@ public class MoGoAiCloudClientConfig {
*/
private boolean thirdLogin;
private String token;
private String sn;
/**
* 服务器分配给应用的令牌,用于网络请求校验
*/
String token;
/**
* 服务器根据设备ID 分配的SN用于网络请求校验
*/
String sn;
public String getThirdPartyDeviceId() {
return thirdPartyDeviceId;
@@ -91,4 +98,12 @@ public class MoGoAiCloudClientConfig {
public void setNetMode(int sNetMode) {
this.sNetMode = sNetMode;
}
public String getToken() {
return token;
}
public String getSn() {
return sn;
}
}