完善了鉴权SDK开发,增加了测试代码
This commit is contained in:
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal 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>
|
||||
@@ -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')
|
||||
|
||||
}
|
||||
@@ -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>
|
||||
72
app/src/main/java/com/mogo/cloud/PassPortActivity.java
Normal file
72
app/src/main/java/com/mogo/cloud/PassPortActivity.java
Normal 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) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
53
app/src/main/res/layout/activity_pass_port_actvity.xml
Normal file
53
app/src/main/res/layout/activity_pass_port_actvity.xml
Normal 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>
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user