hookehuyr

授权接口正式版联调

1 <!-- 1 <!--
2 * @Date: 2022-09-19 14:11:06 2 * @Date: 2022-09-19 14:11:06
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-10-18 16:09:34 4 + * @LastEditTime: 2022-10-18 17:17:17
5 * @FilePath: /swx/src/pages/auth/index.vue 5 * @FilePath: /swx/src/pages/auth/index.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
8 <template> 8 <template>
9 <div> 9 <div>
10 - <button wx:if="{{canIUse}}" open-type="getUserInfo" @getuserinfo="bindGetUserInfo">授权登录</button> 10 + <!-- <button wx:if="{{canIUse}}" open-type="getUserInfo" @getuserinfo="bindGetUserInfo">授权登录</button>
11 - <view @tap="auth">授权登陆</view> 11 + <view @tap="auth">授权登陆</view> -->
12 </div> 12 </div>
13 </template> 13 </template>
14 14
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
16 import Taro from '@tarojs/taro' 16 import Taro from '@tarojs/taro'
17 import { ref } from "vue"; 17 import { ref } from "vue";
18 import request from '@/utils/request'; 18 import request from '@/utils/request';
19 -import { userInfo } from 'os';
20 19
21 </script> 20 </script>
22 21
...@@ -25,10 +24,13 @@ import "./index.less"; ...@@ -25,10 +24,13 @@ import "./index.less";
25 export default { 24 export default {
26 name: "authPage", 25 name: "authPage",
27 mounted () { 26 mounted () {
28 - // TODO: 现在先传openid,小程序的密钥还有搞到 27 + // 授权登陆
29 - // 小程序预览,接口没有跑起来,真机调试可以运行 28 + Taro.login({
29 + success: function (res) {
30 + if (res.code) {
31 + //发起网络请求
30 request.post('/srv/?a=openid', { 32 request.post('/srv/?a=openid', {
31 - openid: 'wxa2e50e76487d1d7b' 33 + code: res.code
32 }) 34 })
33 .then(res => { 35 .then(res => {
34 if (res.data.code) { 36 if (res.data.code) {
...@@ -49,6 +51,11 @@ export default { ...@@ -49,6 +51,11 @@ export default {
49 .catch(err => { 51 .catch(err => {
50 console.error(err); 52 console.error(err);
51 }); 53 });
54 + } else {
55 + console.log('登录失败!' + res.errMsg)
56 + }
57 + }
58 + })
52 }, 59 },
53 data () { 60 data () {
54 return { 61 return {
...@@ -57,18 +64,18 @@ export default { ...@@ -57,18 +64,18 @@ export default {
57 }, 64 },
58 onLoad: function() { 65 onLoad: function() {
59 // 查看是否授权 66 // 查看是否授权
60 - wx.getSetting({ 67 + // wx.getSetting({
61 - success (res){ 68 + // success (res){
62 - if (res.authSetting['scope.userInfo']) { 69 + // if (res.authSetting['scope.userInfo']) {
63 - // 已经授权,可以直接调用 getUserInfo 获取头像昵称 70 + // // 已经授权,可以直接调用 getUserInfo 获取头像昵称
64 - wx.getUserInfo({ 71 + // wx.getUserInfo({
65 - success: function(res) { 72 + // success: function(res) {
66 - console.warn(res.userInfo) 73 + // console.warn(res.userInfo)
67 - } 74 + // }
68 - }) 75 + // })
69 - } 76 + // }
70 - } 77 + // }
71 - }) 78 + // })
72 }, 79 },
73 methods: { 80 methods: {
74 bindGetUserInfo (e) { 81 bindGetUserInfo (e) {
......