mirror of
https://gitee.com/willfree/min-vpn-client_v2.git
synced 2026-10-04 19:42:00 +08:00
将VMSRequestAPI中的注册登录接口改为子线程网络请求,测试注册登录通过
This commit is contained in:
1 parent
9237f63f07
commit
2ff884a27f
6 files changed
+79
-21
No files matched your search
Binary file not shown.
@@ -125,15 +125,19 @@ public class LoginActivity extends MINVpnBaseActivity<LoginActivityPresenter>
|
||||
|
||||
// 显示账号
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
etUsername.setText(Base64Util.Base64PlusDecode(MINVpnSettingAPI.INSTANCE.getUsername()));
|
||||
// todo: 测试时自动填充
|
||||
etUsername.setText("wefree");
|
||||
// etUsername.setText(MINVpnSettingAPI.INSTANCE.getUsername());
|
||||
}else{
|
||||
System.out.println("Base64Util.Base64PlusDecode error");
|
||||
}
|
||||
|
||||
// 如果设置了密码保存,则显示密码
|
||||
if(savePasswordBox.isChecked()){
|
||||
etPassword.setText(MINVpnSettingAPI.INSTANCE.getPassword());
|
||||
}
|
||||
// todo: 测试时自动填充
|
||||
etPassword.setText("free@1898");
|
||||
// if(savePasswordBox.isChecked()){
|
||||
// etPassword.setText(MINVpnSettingAPI.INSTANCE.getPassword());
|
||||
// }
|
||||
|
||||
// 登录按钮
|
||||
btnLogin.setBackgroundResource(R.drawable.button_shape_default);
|
||||
|
||||
@@ -24,7 +24,9 @@ public class LoginActivityModel implements LoginActivityContract.Model{
|
||||
@Override
|
||||
public void login(OriginalLoginRequest loginRequest) {
|
||||
Integer resCode= VMSRequestAPI.INSTANCE.login(loginRequest);
|
||||
if(resCode==200) {
|
||||
if(resCode==null) {
|
||||
mPresenter.loginFailed("登录失败,未成功收到VMS的合法应答");
|
||||
}else if(resCode==200) {
|
||||
mPresenter.loginSuccess();
|
||||
}else{
|
||||
mPresenter.loginFailed("登录失败,VMS应答码为"+resCode);
|
||||
|
||||
@@ -89,6 +89,14 @@ public class RegisterActivity extends MINVpnBaseActivity<RegisterActivityPresent
|
||||
.circleCrop()
|
||||
.into(imgLogo);
|
||||
|
||||
// todo: 测试时自动填充
|
||||
etUsername.setText("wefree");
|
||||
etPassword.setText("free@1898");
|
||||
etRePassword.setText("free@1898");
|
||||
etPhoneNumber.setText("15239970973");
|
||||
etEmail.setText("255526727@qq.com");
|
||||
etInviteCode.setText("1234");
|
||||
|
||||
btnRegister.setBackgroundResource(R.drawable.button_shape_default);
|
||||
btnRegister.setOnClickListener(v->{
|
||||
ContextExtensionKt.hideSoftKeyboard(this,btnRegister);
|
||||
|
||||
+3
-1
@@ -23,7 +23,9 @@ public class RegisterActivityModel implements RegisterActivityContract.Model{
|
||||
@Override
|
||||
public void register(OriginalRegisterRequest registerRequest) {
|
||||
Integer resCode=VMSRequestAPI.INSTANCE.register(registerRequest);
|
||||
if(resCode==200) {
|
||||
if(resCode==null) {
|
||||
mPresenter.registerFailed("注册失败,未成功收到VMS的合法应答");
|
||||
}else if(resCode==200) {
|
||||
mPresenter.registerSuccess();
|
||||
}else{
|
||||
mPresenter.registerFailed("注册失败,VMS应答码为"+resCode);
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
@@ -29,7 +30,6 @@ import VMSConnection.Model.LoginWithSignRequest;
|
||||
import VMSConnection.Model.RegisterWithSignRequest;
|
||||
import VMSConnection.TCPNet.Message.NetworkResponse;
|
||||
import VMSConnection.Utils.Base64Helper;
|
||||
import examples.KeyManagerExample;
|
||||
import minsecurity.certificate.cert.CertException;
|
||||
|
||||
public enum VMSRequestAPI {
|
||||
@@ -45,7 +45,7 @@ public enum VMSRequestAPI {
|
||||
|
||||
// 2. 签名(签名用户名) & 公钥(用户本地保存的公钥)
|
||||
byte[] registerSign=this.signBytes(original.username);
|
||||
String pubKey=new String(KeyManagerExample.INSTANCE.getKeyChain().getCurrentIdentity().getPubkey()
|
||||
String pubKey=new String(KeyManager.INSTANCE.getKeyChain().getCurrentIdentity().getPubkey()
|
||||
.getBytes(),StandardCharsets.UTF_8);
|
||||
System.out.println("register pubkey: "+pubKey);
|
||||
|
||||
@@ -61,27 +61,48 @@ public enum VMSRequestAPI {
|
||||
}
|
||||
|
||||
// 4. 调用bc-api,发送注册请求到VMS:ip tcpPort sslPort VMSPubkey(可选,有默认key)
|
||||
BC_API bc_api=new BC_API(MINVpnSettingAPI.INSTANCE.getBlockChainIpAddress(),
|
||||
MINVpnSettingAPI.INSTANCE.getBcTcpPort(),MINVpnSettingAPI.INSTANCE.getBcSslPort());
|
||||
NetworkResponse networkResponse=bc_api.register(request);
|
||||
AtomicReference<NetworkResponse> networkResponse = new AtomicReference<>();
|
||||
Thread netRequestThread = new Thread(() -> {
|
||||
BC_API bc_api = new BC_API(MINVpnSettingAPI.INSTANCE.getBlockChainIpAddress(),
|
||||
MINVpnSettingAPI.INSTANCE.getBcTcpPort(), MINVpnSettingAPI.INSTANCE.getBcSslPort());
|
||||
networkResponse.set(bc_api.register(request));
|
||||
});
|
||||
netRequestThread.start();
|
||||
// 等待五秒,五秒内收不到包就放弃,收到包就停止等待
|
||||
long startTime=System.currentTimeMillis();
|
||||
while ((System.currentTimeMillis()-startTime)/1000<5){
|
||||
if(networkResponse.get()!=null){
|
||||
break;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if(networkResponse.get()==null){
|
||||
System.out.println("注册未收到合法应答信息");
|
||||
return null;
|
||||
}
|
||||
// 输出注册应答信息
|
||||
try {
|
||||
System.out.println("注册应答: "+networkResponse.toJson());
|
||||
System.out.println("注册应答: " + networkResponse.get().toJson());
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("注册应答码: "+networkResponse.Code);
|
||||
System.out.println("注册应答码: " + networkResponse.get().Code);
|
||||
|
||||
// 5. 保存注册应答中的证书到本地
|
||||
boolean flag=false;
|
||||
try {
|
||||
this.importVMSCert(networkResponse.Data, MINVpnSettingAPI.INSTANCE.getVMSCertPasswd());
|
||||
this.importVMSCert(networkResponse.get().Data, MINVpnSettingAPI.INSTANCE.getVMSCertPasswd());
|
||||
}catch (Exception e){
|
||||
System.out.println("保存注册证书失败: "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("保存证书应答: "+flag);
|
||||
|
||||
return networkResponse.Code;
|
||||
return networkResponse.get().Code;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,17 +128,38 @@ public enum VMSRequestAPI {
|
||||
}
|
||||
|
||||
// 4. 调用bc-api,发送登录请求到VMS:ip tcpPort sslPort VMSPubkey(可选,有默认key)
|
||||
BC_API bc_api=new BC_API(MINVpnSettingAPI.INSTANCE.getBlockChainIpAddress(),
|
||||
MINVpnSettingAPI.INSTANCE.getBcTcpPort(),MINVpnSettingAPI.INSTANCE.getBcSslPort());
|
||||
NetworkResponse networkResponse=bc_api.login(loginWithSignRequest);
|
||||
AtomicReference<NetworkResponse> networkResponse = new AtomicReference<>();
|
||||
Thread netRequestThread = new Thread(() -> {
|
||||
BC_API bc_api = new BC_API(MINVpnSettingAPI.INSTANCE.getBlockChainIpAddress(),
|
||||
MINVpnSettingAPI.INSTANCE.getBcTcpPort(), MINVpnSettingAPI.INSTANCE.getBcSslPort());
|
||||
networkResponse.set(bc_api.login(loginWithSignRequest));
|
||||
});
|
||||
netRequestThread.start();
|
||||
// 等待五秒,五秒内收不到包就放弃,收到包就停止等待
|
||||
long startTime=System.currentTimeMillis();
|
||||
while ((System.currentTimeMillis()-startTime)/1000<5){
|
||||
if(networkResponse.get()!=null){
|
||||
break;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if(networkResponse.get()==null){
|
||||
System.out.println("登录未收到合法应答信息");
|
||||
return null;
|
||||
}
|
||||
// 输出登录应答信息
|
||||
try {
|
||||
System.out.println("登录应答: "+networkResponse.toJson());
|
||||
System.out.println("登录应答: "+networkResponse.get().toJson());
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("登录应答码: "+networkResponse.Code);
|
||||
System.out.println("登录应答码: "+networkResponse.get().Code);
|
||||
|
||||
return networkResponse.Code;
|
||||
return networkResponse.get().Code;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user