zoukankan      html  css  js  c++  java
  • 在uni-app中进行第三方登录(微信,qq)

     1 login_weixin() {
     2                 var vm = this;
     3                 uni.getProvider({
     4                     service: 'oauth',
     5                     success: function (res) {
     6                         console.log(res.provider) //qq,xiaomi,sinaweibo,weixin
     7                         vm.log.log1 = res.provider
     8                         if (~res.provider.indexOf('weixin')) {
     9                             uni.login({
    10                                 provider: 'weixin', 
    11                                 success: function (loginRes) {
    12                                     vm.$HTTP({
    13                                       method: 'GET',
    14                                       baseURL:'https://api.weixin.qq.com/sns/userinfo',
    15                                       url: '',
    16                                       data: {
    17                                           openid:loginRes.authResult.openid,
    18                                           access_token:loginRes.authResult.access_token
    19                                       },
    20                                       load:true
    21                                     }).then((data) =>{
    22                                       uni.setStorage({
    23                                         key: 'userInfo',
    24                                         data:{
    25                                             name:data.nickname,
    26                                             picUrl:data.headimgurl
    27                                         }
    28                                       });
    29                                       uni.switchTab({
    30                                         url: "../../tabBar/me/me"
    31                                       })
    32                                     }, (err) => {
    33                                       console.log(err)
    34                                     });
    35                                 }
    36                             });
    37                         }
    38                     }
    39                 });
    40             },
    41             login_qq() {
    42                 var vm = this;
    43                 uni.getProvider({
    44                     service: 'oauth',
    45                     success: function (res) {
    46                         console.log(res.provider) //qq,xiaomi,sinaweibo,weixin
    47                         vm.log.log1 = res.provider
    48                         if (~res.provider.indexOf('qq')) {
    49                             uni.login({
    50                                 provider: 'qq', 
    51                                 success: function (loginRes) {
    52                                     vm.$HTTP({
    53                                       method: 'GET',
    54                                       baseURL:'https://graph.qq.com/user/get_user_info',
    55                                       url: '',
    56                                       data: {
    57                                           openid:loginRes.authResult.openid,
    58                                           access_token:loginRes.authResult.access_token,
    59                                           appid:'101832674'
    60                                       },
    61                                       load:true
    62                                     }).then((data) =>{
    63                                       console.log(data)
    64                                       uni.setStorage({
    65                                         key: 'userInfo',
    66                                         data:{
    67                                             name:data.nickname,
    68                                             picUrl:data.figureurl_qq
    69                                         }
    70                                       });
    71                                       uni.switchTab({
    72                                         url: "../../tabBar/me/me"
    73                                       })
    74                                     }, (err) => {
    75                                       console.log(err)
    76                                     });
    77                                 }
    78                             });
    79                         }
    80                     }
    81                 });
    82             }
  • 相关阅读:
    java中判断文件存在与否
    crontab安装以及定时任务的执行
    su命令学习
    linux中如何查看哪些用户允许登录
    linux中的压缩文件的格式
    R语言学习(瑞士军刀)
    linux下mysql导入导出sql文件
    创建线程池的7种方法
    docker运行tomcat
    Docker之镜像
  • 原文地址:https://www.cnblogs.com/qdjj/p/13432213.html
Copyright © 2011-2022 走看看