提交 e637b7ab 编写于 作者: N ninecents

跨域问题修改;逻辑调整

上级 18d7a165
import { contextBridge } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'
import axios from 'axios'
// Custom APIs for renderer
const api = {}
const api = {
axios: axios
}
// Use `contextBridge` APIs to expose Electron APIs to
// renderer only if context isolation is enabled, otherwise
......
......@@ -10,6 +10,7 @@
http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'"
/> -->
<meta name="referrer" content="no-referrer">
</head>
<body>
......
......@@ -19,10 +19,12 @@ class MyMp {
islogin: boolean;
cache: any;
data: any;
el_imgage: any;
constructor(username, pwd) {
constructor(username, pwd, el_imgage=null) {
this.el_imgage = el_imgage;
this.username = username;
this.pwd = CryptoJS.MD5(pwd.substr(0, 16));
this.pwd = CryptoJS.MD5(pwd.substr(0, 16)).toString();
// this.pwd = createHash('md5')
// .update(pwd.substr(0, 16))
// .digest('hex');
......@@ -65,14 +67,18 @@ class MyMp {
});
}
// 直接通过二维码登录
login_qrcode() {
return new Promise((resolve, reject) => {
console.log(resolve, reject)
let url = `${Config.api.loginqrcode}?action=getqrcode&param=4300`;
resolve(url);
this.el_imgage.src = url;
WechatRequest.get(`${Config.api.loginqrcode}?action=getqrcode&param=4300`)
.then(d => {
console.log(d);
})
// WechatRequest.get(`${Config.api.loginqrcode}?action=getqrcode&param=4300`)
// .then(d => {
// console.log(d);
// })
// let filename = 'qrcode-login.png';
// let writeStream = createWriteStream(filename);
// WechatRequest.get(`${Config.api.loginqrcode}?action=getqrcode&param=4300`)
......@@ -86,11 +92,22 @@ class MyMp {
});
}
/**
* 循环检测是否扫过验证码了
* @returns
*/
checkLogin() {
const chklogin = (resolve, reject) => {
WechatRequest.get(`${Config.api.loginqrcode}?action=ask&random=${Math.random()}`)
.then((body: any) => {
if (body.status === 1) {
.then((d: any) => {
let body = d.data;
// 失败
// body = {"acct_size":0,"base_resp":{"err_msg":"ok","ret":0},"binduin":0,"status":0,"user_category":0}
// 成功
// body = {"acct_size":0,"base_resp":{"err_msg":"ok","ret":0},"binduin":0,"status":1,"user_category":0}
// 异常数据
// body = {base_resp: {err_msg: "default", ret: 1}}
if (body && body.status === 1) {
resolve(body);
} else {
setTimeout(() => {
......@@ -171,11 +188,24 @@ class MyMp {
});
}
/**
* 1. 已经登录,直接返回this.data
* 2. 从cache中获取token,测试是否能够登录成功
* 3. 直接reject拒绝
*
* @returns
* @memberof MyMp
*/
loginchk() {
return new Promise((resolve, reject) => {
// * 1. 已经登录,直接返回
if (this.islogin) {
resolve(this.data);
} else if (this.data.token) {
return;
}
// * 2. 从cache中获取token,测试是否能够登录成功
if (this.data.token) {
WechatRequest.get(Config.baseurl)
.then((d) => {
console.log(d);
......@@ -196,9 +226,10 @@ class MyMp {
// }
// }
});
} else {
reject();
}
// 3. 直接reject拒绝
reject();
});
}
......@@ -207,7 +238,9 @@ class MyMp {
* @param {string} imgcode - [可选]验证码
* @return {Promise<object>} data
*/
login(imgcode = '') {
login(usr='', pwd='', imgcode = '') {
this.username = usr;
this.pwd = CryptoJS.MD5(pwd.substr(0, 16)).toString();
return new Promise((resolve, reject) => {
this.loginchk()
.then(resolve)
......
import axios from 'axios'
// import axios from 'axios'
// import {httpAdapter} from 'axios/lib/adapters/http'
// import httpAdapter2 from 'axios/lib/adapters/http'
// console.log('httpAdapter = ', httpAdapter, httpAdapter2)
......@@ -7,6 +7,10 @@ import Config from './config';
// import FileCookieStore from 'tough-cookie-filestore';
// import Cache from './cache';
// @ts-ignore
let axios = window.api?.axios
console.log('axios: ', axios, window.api)
// axios.defaults.adapter = httpAdapter;
axios.defaults.headers.common['Referer'] = Config.baseurl;
// const cookieCache = new Cache('cookie');
......
......@@ -70,7 +70,7 @@
<!-- right -->
<div class="right">
<img ref="qrcode" src="" alt="" style="width:100%">
</div>
</div>
......@@ -116,7 +116,9 @@ export default {
this.mp_info = my.settings.wechat_mps[k]
}
this.mp = new MyMp(this.mp_info.usr, this.mp_info.pwd)
this.mp = new MyMp(this.mp_info.usr, this.mp_info.pwd, this.$refs.qrcode)
},
created() {
},
methods: {
mp_server() {
......@@ -125,7 +127,8 @@ export default {
console.log(cmd, wx)
},
mp_lg() {
this.mp.login()
// this.mp.checklogin();
this.mp.login(this.mp_info.usr, this.mp_info.pwd)
},
mp_open() {},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册