抖音登录

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. 45
      pages/login/login.vue

@ -5,6 +5,14 @@ export const login = (data) => {
return post('users/users/user/weChatAppletCallbackByPartner', 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 = () => { export const queryProvince = () => {
return get('nakadai/nakadai/province/queryProvince') return get('nakadai/nakadai/province/queryProvince')
} }

@ -6,7 +6,7 @@
export default { export default {
baseURL: 'https://www.occupationlab.com/', 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/', // baseURL: 'http://121.37.12.51/',
headers: { headers: {
'Content-Type': 'application/json;charset=UTF-8' 'Content-Type': 'application/json;charset=UTF-8'

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

@ -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,10 +74,37 @@
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) => { }
//
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()
uni.setStorageSync('token', data.token)
} else {
this.isLogin = true
}
}).catch(e => {
this.submiting = false
})
} else {
fn(param).then((res) => {
const { data, status } = res const { data, status } = res
this.submiting = false this.submiting = false
// //
@ -112,6 +140,8 @@
}).catch(e => { }).catch(e => {
this.submiting = false 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.使js2.使 // 1.使js2.使 ()
// 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

Loading…
Cancel
Save