抖音登录

master
yujialong 6 months ago
parent 913886a897
commit 83255d6f91
  1. 8
      apis/modules/user.js
  2. 2
      config/request.js
  3. 1
      libs/util.js
  4. 101
      pages/login/login.vue

@ -5,6 +5,14 @@ export const login = (data) => {
return post('users/users/user/weChatAppletCallbackByPartner', data)
}
export const douYinLogin = (data) => {
return post('users/users/user/douYinLogin?code=' + data)
}
export const douYinLoginByOpenid = (data) => {
return post('users/users/user/douYinLoginByOpenid?code=' + data)
}
export const queryProvince = () => {
return get('nakadai/nakadai/province/queryProvince')
}

@ -6,7 +6,7 @@
export default {
baseURL: 'https://www.occupationlab.com/',
// baseURL: 'http://192.168.31.152:9000/',
// baseURL: 'http://192.168.31.51:9000/',
// baseURL: 'http://121.37.12.51/',
headers: {
'Content-Type': 'application/json;charset=UTF-8'

@ -86,6 +86,7 @@ export default {
uni.downloadFile({
url: files[id],
success: function(res) {
console.log(11, res)
uni.hideLoading();
uni.showLoading({
title: '正在打开',

@ -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) {
// unilogincode
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) {
// unilogincode
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.使js2.使
// const WXBizDataCrypt = require('@/libs/WXBizDataCrypt')
const accountInfo = uni.getAccountInfoSync() // appid
const pc = new WXBizDataCrypt(accountInfo.miniProgram.appId , this.sessionKey)
// 1.使js2.使 ()
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

Loading…
Cancel
Save