cordova-plugins-ths-h3c-vpn
v1.0.6
Published
H3C VPN插件
Downloads
5
Maintainers
Readme
cordova.plugins.H3cVpn
基于 H3C 提供的 jar 包进行二次开发的 VPN 插件(插件开发者 Mr. Liu)
2022.1.6 完成初版开发
前置工作
安装完插件后,打包前需要修改 MainActivity 代码,添加以下代码:
MainActivity 一般所在路径 android\app\src\main\java\包ID的路径\MainActivity.java
// 顶部导入
import cn.com.ths.h3cvpn.VpnUtils;
public class MainActivity extends BridgeActivity {
// 在类中添加以下方法
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.e("MainActivity","onActivityResult");
if(requestCode==8300){
VpnUtils.onSdkActivityResult(requestCode, resultCode, data);
}
}
}
使用示例
1 VPN 连接
/**
* VPN 连接
* @param addr VPN地址,例如IP+端口,例如:219.232.203.138:8888
* @param domain 域名,没有域名时,填空字符串
*/
(window as any).cordova.plugins.H3cVpn.vpnConnect('219.232.203.138:8888','',(res)=> {
alert(res);
},(err) =>{
alert(err);
});
2 登录VPN
/**
* 登录VPN,需要先调用VPN连接方法,成功后调用该方法
* @param {*} userName 用户名
* @param {*} password 密码
* @param {*} dynpwd 动态密码,可为空字符串
* @param {*} success
* @param {*} error
*/
(window as any).cordova.plugins.H3cVpn.vpnLogin('1112121212','232323','',(res)=> {
alert(res);
},(err) =>{
alert(err);
});
3 VPN检查在线状态
/**
* VPN检查在线
* @param {*} success
* @param {*} error
*/
(window as any).cordova.plugins.H3cVpn.isOnline((res)=> {
alert(res);
},(err) =>{
alert(err);
});
4 vpn 下线
/**
* vpn 下线
* @param {*} success
* @param {*} error
*/
(window as any).cordova.plugins.H3cVpn.vpnlogout((res)=> {
alert(res);
},(err) =>{
alert(err);
});
5 监听VPN登录状态(需要放在页面初始化位置,页面销毁,需要移除对应的监听回调)
/**
* 监听VPN 回调消息
* data {'vpnCallback':'succeed'}
* {'vpnCallback':'failed'}
* {'vpnCallback':'userCancelled'}
* {'vpnCallback':'networkError'}
* {'vpnCallback':'logOut'}
*/
document.addEventListener('H3cVpn.onVpnListenerInAndroidCallback', data => {
console.log(data);
alert(JSON.stringify(data));
}, false);