<template>
<!-- v-show="needWxUserInfo" -->
<view class="weixin_auth_modal" >
<view class='header'>
<image src='../../static/public/douyin.jpg'></image>
</view>
<view class='content'>
<view>申请获取以下权限</view>
<view>获得你的公开信息(昵称,头像、地区等)</view>
</view>
<p class="dyuserinfo" @click="getDYuserinfo">获取抖音授权</p>
<!-- <button type="primary" open-type="getUserInfo" scope="userInfo" @getUserInfo="getDYuserinfo">
登陆
</button>
@click="back"
-->
<button class='bottom' style="margin-top: 0px; background-color: #e5e5e5;" type='primary' >
暂不登陆
</button>
</view>
</template>
<script>
export default {
data() {
return {
result: '' // 用于存储获取到的内容
}
},
methods: {
getDYuserinfo() {
uni.login({
provider: 'toutiao',
success: function(loginRes) {
console.log(loginRes);
uni.getUserInfo({
success(res) {
console.log(res)
// _this.needWxUserInfo = false;
// _this.needWxMobile = true;
//_this.authInfo = res.userInfo
console.log(res.userInfo);
console.log(loginRes.code);
console.log(loginRes.anonymousCode);
uni.setStorageSync('authInfo', res.userInfo);
if (res) {
uni.request({
//https://open-sandbox.douyin.com
//https://developer.toutiao.com/api/apps/v2/jscode2session
url: 'https://developer.toutiao.com/api/apps/v2/jscode2session',
// options: {
// method: 'POST'
// },
method: 'POST',
data: {
appid:"你的appid",
secret:"你的secret",
code: loginRes.code,
anonymous_code: loginRes.anonymousCode
},
success: (result) => {
console.log(result)
console.log(result.data)
console.log(result.data.data.openid)
},
fail:(result) => {
console.log(result)
},
})
}
}
})
}
});
}
},
}
</script>
直接贴代码,可以使用的要填写appid和secret,之前有一篇文章写过,但是到了最后一步请求可能是他封装了一下,需要查看文档请求这个接口,这样数据才对。https://developer.toutiao.com/api/apps/v2/jscode2session文章来源地址https://uudwc.com/A/rZEy6
文章来源:https://uudwc.com/A/rZEy6