From bb920e9a6044958969f88e5a406d03d914142dbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E8=A3=95=E8=B4=A2?= Date: Sun, 1 May 2022 16:33:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=BE=AE=E4=BF=A1=E7=99=BB?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/api/login.js | 14 ++++++++++ src/views/login/components/login.vue | 41 ++++++++++++++++++++++++---- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index d7632c75..c8fecee1 100644 --- a/package.json +++ b/package.json @@ -121,6 +121,7 @@ "vue-loader": "^15.9.8", "vue-style-loader": "^4.1.3", "vue-template-compiler": "^2.6.14", + "vue-wxlogin": "^1.0.4", "webpack": "^5.59.1", "webpack-bundle-analyzer": "2.9.1", "webpack-cli": "^4.9.1", diff --git a/src/api/login.js b/src/api/login.js index f01c13ec..da260998 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -143,3 +143,17 @@ export function validEmailCode(params) { params:params }) } + + +/** + * 获取第三方登录需要state参数,防止crfs攻击 + * @param + * @returns + */ +export function getTpaState( ) { + return axios({ + url: '/tpa/login/wechat/wxpub/state', + method: 'post', + data:{} + }) +} \ No newline at end of file diff --git a/src/views/login/components/login.vue b/src/views/login/components/login.vue index cb8019ca..1b4746da 100644 --- a/src/views/login/components/login.vue +++ b/src/views/login/components/login.vue @@ -1,5 +1,6 @@ @@ -80,8 +83,7 @@ import { sendSmsCode } from '@/api/sms/sms'; import { mapGetters } from 'vuex'; import md5 from 'js-md5'; -import { resetPasswordByPhoneno } from '@/api/login'; - +import { resetPasswordByPhoneno,getTpaState } from '@/api/login'; export default { name: 'login', @@ -178,6 +180,7 @@ export default { abledBut: false, //是否禁止 setTimeNum: 60, // 倒计时时间 timeWrap: null, // 定时器标识 + wxLoginCodeVisible:false, } }, @@ -324,6 +327,26 @@ export default { this.addBranchFormVisible=false; this.handleLogin(); }, + weixinLogin(){ + getTpaState().then(res=>{ + var tips = res.data.tips; + if(tips.isOk){ + this.wxLoginCodeVisible=true; + var state=res.data.data + var obj = new WxLogin({ + self_redirect:true, + id:"login_container", + appid: "wx2671d5db8346b6fc", + scope: "snsapi_login", + redirect_uri: encodeURIComponent("https://www.maimengcloud.com/api/m1/tpa/login/token?authType=wechat_wxpub&authId=mmxmcloud_wxopen_pc"), + state: state, + style: "", + href: "" + }); + } + }) + + }, afterQRScan() { // const hash = window.location.hash.slice(1) @@ -350,6 +373,12 @@ export default { destroyed() { // window.removeEventListener('hashchange', this.afterQRScan) }, + mounted(){ + const s = document.createElement('script'); + s.type = 'text/javascript'; + s.src = 'https://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js'; + document.body.appendChild(s); + } }