Skip to content

Commit

Permalink
Chore: removed jsencrpty
Browse files Browse the repository at this point in the history
  • Loading branch information
Youke XIANG committed May 7, 2022
1 parent b955ad8 commit 6986b42
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 89 deletions.
52 changes: 9 additions & 43 deletions Publish/bmw-linker.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,13 +869,11 @@ const Running = async (Widget, default_args = '') => {
};

let WIDGET_FILE_NAME = 'bmw-linker.js';
let WIDGET_VERSION = 'v2.2.0';
let WIDGET_BUILD = '22050701';
let WIDGET_VERSION = 'v2.2.1';
let WIDGET_BUILD = '22050702';
let WIDGET_PREFIX = '[bmw-linker] ';

let DEPENDENCIES = [
'jsencrypt.js' //本地化加密
];
let DEPENDENCIES = [];

let WIDGET_FONT = 'SF UI Display';
let WIDGET_FONT_BOLD = 'SF UI Display Bold';
Expand Down Expand Up @@ -973,7 +971,7 @@ class Widget extends Base {

constructor(arg) {
super(arg);
this.name = 'BMW-Linker';
this.name = 'BMW-Linker ' + WIDGET_VERSION;
this.desc = '宝马My BMW互联App小组件';

// load settings
Expand Down Expand Up @@ -1120,7 +1118,7 @@ class Widget extends Base {
userLoginAlert.title = '配置BMW登录';
userLoginAlert.message = '使用短信授权登录';

userLoginAlert.addTextField('短信验证码', this.userConfigData['pass_code']);
userLoginAlert.addTextField('短信验证码', null);

userLoginAlert.addAction('确定');
userLoginAlert.addCancelAction('取消');
Expand All @@ -1130,15 +1128,15 @@ class Widget extends Base {
if (id == -1) {
return;
}
this.userConfigData['pass_code'] = userLoginAlert.textFieldValue(0);
let passCode = userLoginAlert.textFieldValue(0);

let req = new Request(BMW_SERVER_HOST + `/eadrax-coas/v1/login/sms`);
req.method = 'POST';

req.body = JSON.stringify({
mobile: Number(this.userConfigData.username).toString(),
otpId: otpId,
otpMsg: Number(this.userConfigData['pass_code']).toString()
otpMsg: Number(passCode).toString()
});

req.headers = BMW_HEADERS;
Expand Down Expand Up @@ -1324,10 +1322,10 @@ class Widget extends Base {
console.warn('hasUpdate');
const updateAlert = new Alert();
updateAlert.title = '暂无更新';
let changeLogText = await this.loadChangeLogs();

if (hasUpdate) {
// load changes log
let changeLogText = await this.loadChangeLogs();
updateAlert.title = '找到更新';

updateAlert.message = changeLogText;
Expand All @@ -1336,7 +1334,7 @@ class Widget extends Base {

updateAlert.addAction('开始下载');
} else {
updateAlert.message = '但您可重新下载小组件\n\r\n是否重新下载?';
updateAlert.message = '但您可重新下载小组件\n\r\n是否重新下载? \n\r\n' + changeLogText;

updateAlert.addAction('重新下载');
}
Expand Down Expand Up @@ -2544,21 +2542,6 @@ class Widget extends Base {
return await this.getVehicleDetails(accessToken, forceRefresh);
}

async getPublicKey() {
let req = new Request(BMW_SERVER_HOST + '/eadrax-coas/v1/cop/publickey');

req.headers = {};

const res = await req.loadJSON();
if (res.code == 200 && res.data.value) {
console.log('Getting public key success');
return res.data.value;
} else {
console.log('Getting public key failed');
return '';
}
}

async getAccessToken(forceRefresh = false) {
let accessToken = '';
let refreshToken = Keychain.get(MY_BMW_REFRESH_TOKEN);
Expand Down Expand Up @@ -2635,23 +2618,6 @@ class Widget extends Base {
return null;
}

async getEncryptedPassword() {
let publicKey = await this.getPublicKey();

try {
// 感谢沙包大佬提供思路
let JSEncrypt = importModule(`lib/jsencrypt`);

let encrypt = new JSEncrypt();
encrypt.setPublicKey(publicKey);

return encrypt.encrypt(this.userConfigData.password);
} catch (e) {
console.error('Encrypt error ' + e.message);
return null;
}
}

async refreshToken(refresh_token) {
let req = new Request(BMW_SERVER_HOST + '/eadrax-coas/v1/oauth/token');
req.headers = {
Expand Down
3 changes: 1 addition & 2 deletions Publish/change_logs.text
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

*修复 - 之前由于BMW更换新的接口,导致无法登录,现在经由BMW官方短信验证登录

希望BMW以后能出官方的接口方便我们第三方软件使用
*优化 - 删除部分冗余代码
2 changes: 1 addition & 1 deletion Publish/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let files = FILE_MGR.listContents(FILE_MGR.documentsDirectory());

await Promise.all(
['bmw-linker.js'].map(async (js) => {
const REQ = new Request(`https://cdn.jsdelivr.net/gh/opp100/bmw-scriptable-widgets@latest/Publish/${encodeURIComponent(js)}`);
const REQ = new Request(`https://cdn.jsdelivr.net/gh/opp100/bmw-scriptable-widgets@main/Publish/${encodeURIComponent(js)}`);
const RES = await REQ.load();
try {
FILE_MGR.remove(FILE_MGR.joinPath(FILE_MGR.documentsDirectory(), js));
Expand Down
4 changes: 2 additions & 2 deletions Publish/version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"WIDGET_VERSION": "v2.2.0",
"WIDGET_BUILD": "22050701",
"WIDGET_VERSION": "v2.2.1",
"WIDGET_BUILD": "22050702",
"BMW_USER_AGENT": "ios(15.4.1);bmw;2.3.0(13603)"
}
49 changes: 8 additions & 41 deletions Scripts/「源码」bmw-linker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ const {Base} = require('./「小件件」开发环境');

// @组件代码开始
let WIDGET_FILE_NAME = 'bmw-linker.js';
let WIDGET_VERSION = 'v2.2.0';
let WIDGET_BUILD = '22050701';
let WIDGET_VERSION = 'v2.2.1';
let WIDGET_BUILD = '22050702';
let WIDGET_PREFIX = '[bmw-linker] ';

let DEPENDENCIES = [
'jsencrypt.js' //本地化加密
];

let WIDGET_FONT = 'SF UI Display';
Expand Down Expand Up @@ -117,7 +116,7 @@ class Widget extends Base {

constructor(arg) {
super(arg);
this.name = 'BMW-Linker';
this.name = 'BMW-Linker ' + WIDGET_VERSION;
this.desc = '宝马My BMW互联App小组件';

// load settings
Expand Down Expand Up @@ -264,7 +263,7 @@ class Widget extends Base {
userLoginAlert.title = '配置BMW登录';
userLoginAlert.message = '使用短信授权登录';

userLoginAlert.addTextField('短信验证码', this.userConfigData['pass_code']);
userLoginAlert.addTextField('短信验证码', null);

userLoginAlert.addAction('确定');
userLoginAlert.addCancelAction('取消');
Expand All @@ -274,15 +273,15 @@ class Widget extends Base {
if (id == -1) {
return;
}
this.userConfigData['pass_code'] = userLoginAlert.textFieldValue(0);
let passCode = userLoginAlert.textFieldValue(0);

let req = new Request(BMW_SERVER_HOST + `/eadrax-coas/v1/login/sms`);
req.method = 'POST';

req.body = JSON.stringify({
mobile: Number(this.userConfigData.username).toString(),
otpId: otpId,
otpMsg: Number(this.userConfigData['pass_code']).toString()
otpMsg: Number(passCode).toString()
});

req.headers = BMW_HEADERS;
Expand Down Expand Up @@ -468,10 +467,10 @@ class Widget extends Base {
console.warn('hasUpdate');
const updateAlert = new Alert();
updateAlert.title = '暂无更新';
let changeLogText = await this.loadChangeLogs();

if (hasUpdate) {
// load changes log
let changeLogText = await this.loadChangeLogs();
updateAlert.title = '找到更新';

updateAlert.message = changeLogText;
Expand All @@ -480,7 +479,7 @@ class Widget extends Base {

updateAlert.addAction('开始下载');
} else {
updateAlert.message = '但您可重新下载小组件\n\r\n是否重新下载?';
updateAlert.message = '但您可重新下载小组件\n\r\n是否重新下载? \n\r\n' + changeLogText;

updateAlert.addAction('重新下载');
}
Expand Down Expand Up @@ -1688,21 +1687,6 @@ class Widget extends Base {
return await this.getVehicleDetails(accessToken, forceRefresh);
}

async getPublicKey() {
let req = new Request(BMW_SERVER_HOST + '/eadrax-coas/v1/cop/publickey');

req.headers = {};

const res = await req.loadJSON();
if (res.code == 200 && res.data.value) {
console.log('Getting public key success');
return res.data.value;
} else {
console.log('Getting public key failed');
return '';
}
}

async getAccessToken(forceRefresh = false) {
let accessToken = '';
let refreshToken = Keychain.get(MY_BMW_REFRESH_TOKEN);
Expand Down Expand Up @@ -1779,23 +1763,6 @@ class Widget extends Base {
return null;
}

async getEncryptedPassword() {
let publicKey = await this.getPublicKey();

try {
// 感谢沙包大佬提供思路
let JSEncrypt = importModule(`lib/jsencrypt`);

let encrypt = new JSEncrypt();
encrypt.setPublicKey(publicKey);

return encrypt.encrypt(this.userConfigData.password);
} catch (e) {
console.error('Encrypt error ' + e.message);
return null;
}
}

async refreshToken(refresh_token) {
let req = new Request(BMW_SERVER_HOST + '/eadrax-coas/v1/oauth/token');
req.headers = {
Expand Down

0 comments on commit 6986b42

Please sign in to comment.