|
|
|
@ -26,11 +26,12 @@ |
|
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
|
import { login, userBinding, getSessionKey, queryPartnerAccount } from '@/apis/modules/user.js' |
|
|
|
|
import { login, userBinding, getSessionKey, queryPartnerAccount, douYinLogin } from '@/apis/modules/user.js' |
|
|
|
|
import WXBizDataCrypt from '@/libs/WXBizDataCrypt' |
|
|
|
|
export default { |
|
|
|
|
data() { |
|
|
|
|
return { |
|
|
|
|
isDy: uni.getSystemInfoSync().uniPlatform === 'mp-toutiao', // 抖音小程序标识 |
|
|
|
|
agree: [], |
|
|
|
|
agreeData: [{ |
|
|
|
|
text: '同意', |
|
|
|
@ -73,34 +74,25 @@ |
|
|
|
|
success: ({ code }) => { |
|
|
|
|
if (code) { |
|
|
|
|
this.submiting = true |
|
|
|
|
login({ |
|
|
|
|
|
|
|
|
|
let fn = login |
|
|
|
|
let param = { |
|
|
|
|
code, |
|
|
|
|
avatarUrl: userInfo.avatarUrl |
|
|
|
|
}).then((res) => { |
|
|
|
|
const { data, status } = res |
|
|
|
|
this.submiting = false |
|
|
|
|
// 用户不存在,则让用户授权手机号,直接去注册 |
|
|
|
|
if (status == 10028) { |
|
|
|
|
// 这里需要再调一次uni的login,因为code用过了一次,已经失效了 |
|
|
|
|
uni.login({ |
|
|
|
|
success: ({ code }) => { |
|
|
|
|
getSessionKey({ |
|
|
|
|
code, |
|
|
|
|
}).then(({ sessionKey }) => { |
|
|
|
|
this.sessionKey = sessionKey.session_key |
|
|
|
|
this.openid = sessionKey.openid |
|
|
|
|
this.isLogin = true |
|
|
|
|
}).catch(e => {}) |
|
|
|
|
this.isReg = true |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
const e = data.sessionKey |
|
|
|
|
this.sessionKey = e.session_key |
|
|
|
|
this.openid = e.openid |
|
|
|
|
this.unionid = e.unionid |
|
|
|
|
uni.setStorageSync('sessionKey', e.session_key) |
|
|
|
|
uni.setStorageSync('openid', e.openid) |
|
|
|
|
} |
|
|
|
|
// 抖音登录 |
|
|
|
|
if (this.isDy) { |
|
|
|
|
fn = douYinLogin |
|
|
|
|
param = code |
|
|
|
|
|
|
|
|
|
fn(param).then(res => { |
|
|
|
|
const { data, status } = res |
|
|
|
|
this.submiting = false |
|
|
|
|
this.sessionKey = data.sessionKey |
|
|
|
|
this.openid = data.openid |
|
|
|
|
this.unionid = data.unionid |
|
|
|
|
uni.setStorageSync('sessionKey', data.sessionKey) |
|
|
|
|
uni.setStorageSync('openid', data.openid) |
|
|
|
|
// 如果没有绑定手机号,则显示绑定按钮,引导用户绑定,否则,直接跳到首页 |
|
|
|
|
if (data.state === 'login') { |
|
|
|
|
this.toIndex() |
|
|
|
@ -108,10 +100,48 @@ |
|
|
|
|
} else { |
|
|
|
|
this.isLogin = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}).catch(e => { |
|
|
|
|
this.submiting = false |
|
|
|
|
}) |
|
|
|
|
}).catch(e => { |
|
|
|
|
this.submiting = false |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
fn(param).then((res) => { |
|
|
|
|
const { data, status } = res |
|
|
|
|
this.submiting = false |
|
|
|
|
// 用户不存在,则让用户授权手机号,直接去注册 |
|
|
|
|
if (status == 10028) { |
|
|
|
|
// 这里需要再调一次uni的login,因为code用过了一次,已经失效了 |
|
|
|
|
uni.login({ |
|
|
|
|
success: ({ code }) => { |
|
|
|
|
getSessionKey({ |
|
|
|
|
code, |
|
|
|
|
}).then(({ sessionKey }) => { |
|
|
|
|
this.sessionKey = sessionKey.session_key |
|
|
|
|
this.openid = sessionKey.openid |
|
|
|
|
this.isLogin = true |
|
|
|
|
}).catch(e => {}) |
|
|
|
|
this.isReg = true |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
const e = data.sessionKey |
|
|
|
|
this.sessionKey = e.session_key |
|
|
|
|
this.openid = e.openid |
|
|
|
|
this.unionid = e.unionid |
|
|
|
|
uni.setStorageSync('sessionKey', e.session_key) |
|
|
|
|
uni.setStorageSync('openid', e.openid) |
|
|
|
|
// 如果没有绑定手机号,则显示绑定按钮,引导用户绑定,否则,直接跳到首页 |
|
|
|
|
if (data.state === 'login') { |
|
|
|
|
this.toIndex() |
|
|
|
|
uni.setStorageSync('token', data.token) |
|
|
|
|
} else { |
|
|
|
|
this.isLogin = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}).catch(e => { |
|
|
|
|
this.submiting = false |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
this.submiting = false |
|
|
|
|
that.$util.errMsg('登录失败!') |
|
|
|
@ -131,10 +161,11 @@ |
|
|
|
|
onGetPhoneNumber(e){ |
|
|
|
|
if (this.submiting) return false |
|
|
|
|
const { encryptedData, iv } = e.detail |
|
|
|
|
// 获取手机号有两种方法,1.前端使用js完成;2.使用接口完成 |
|
|
|
|
// const WXBizDataCrypt = require('@/libs/WXBizDataCrypt') |
|
|
|
|
const accountInfo = uni.getAccountInfoSync() // 获取小程序appid |
|
|
|
|
const pc = new WXBizDataCrypt(accountInfo.miniProgram.appId , this.sessionKey) |
|
|
|
|
// 获取手机号有两种方法,1.前端使用js完成;2.使用接口完成 (抖音) |
|
|
|
|
const appId = this.isDy ? 'tt2192572fbea04fe601' : uni.getAccountInfoSync().miniProgram.appId |
|
|
|
|
console.log(1121, appId, this.sessionKey) |
|
|
|
|
const pc = new WXBizDataCrypt(appId , this.sessionKey) |
|
|
|
|
console.log(22, pc, encryptedData, e) |
|
|
|
|
const data = pc.decryptData(encryptedData , iv) |
|
|
|
|
this.submiting = true |
|
|
|
|
const phone = data.phoneNumber |
|
|
|
|