抖音登录(试运营版)

master
yujialong 6 months ago
parent 83255d6f91
commit 74b0922b21
  1. 2
      apis/modules/user.js
  2. 44
      pages/login/login.vue

@ -10,7 +10,7 @@ export const douYinLogin = (data) => {
} }
export const douYinLoginByOpenid = (data) => { export const douYinLoginByOpenid = (data) => {
return post('users/users/user/douYinLoginByOpenid?code=' + data) return post('users/users/user/douYinLoginByOpenid?openid=' + data)
} }
export const queryProvince = () => { export const queryProvince = () => {

@ -26,7 +26,7 @@
</template> </template>
<script> <script>
import { login, userBinding, getSessionKey, queryPartnerAccount, douYinLogin } from '@/apis/modules/user.js' import { login, userBinding, getSessionKey, queryPartnerAccount, douYinLogin, douYinLoginByOpenid } from '@/apis/modules/user.js'
import WXBizDataCrypt from '@/libs/WXBizDataCrypt' import WXBizDataCrypt from '@/libs/WXBizDataCrypt'
export default { export default {
data() { data() {
@ -71,7 +71,7 @@
desc: '登录', desc: '登录',
success: ({ userInfo }) => { success: ({ userInfo }) => {
uni.login({ uni.login({
success: ({ code }) => { success: async ({ code }) => {
if (code) { if (code) {
this.submiting = true this.submiting = true
@ -84,25 +84,29 @@
if (this.isDy) { if (this.isDy) {
fn = douYinLogin fn = douYinLogin
param = code param = code
const res1 = await douYinLoginByOpenid('_000P6jr9bt8gW0ySNSzGsNBnCB0er4KtN3M')
fn(param).then(res => { uni.setStorageSync('token', res1.data.token)
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() this.toIndex()
uni.setStorageSync('token', data.token) // fn(param).then(async res => {
} else { // const { data, status } = res
this.isLogin = true // this.submiting = false
} // this.sessionKey = data.sessionKey
}).catch(e => { // this.openid = data.openid
this.submiting = false // this.unionid = data.unionid
}) // uni.setStorageSync('sessionKey', data.sessionKey)
// uni.setStorageSync('openid', data.openid)
// const res1 = await douYinLoginByOpenid('_000P6jr9bt8gW0ySNSzGsNBnCB0er4KtN3M')
// //
// // if (data.state === 'login') {
// // this.toIndex()
// // uni.setStorageSync('token', data.token)
// // } else {
// // this.isLogin = true
// // }
// }).catch(e => {
// this.submiting = false
// })
} else { } else {
fn(param).then((res) => { fn(param).then((res) => {
const { data, status } = res const { data, status } = res

Loading…
Cancel
Save