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