首页 > 编程语言 >直播app开发搭建,uniapp中微信小程序账号登录

直播app开发搭建,uniapp中微信小程序账号登录

时间:2023-07-14 14:11:06浏览次数:38  
标签:uniapp code console log 登录 res app uni 中微信

直播app开发搭建,uniapp中微信小程序账号登录

<template>
<view>
        <!-- 登录适配 -->
             <!-- 最新版登录方法 -->
<button 
           
            type='primary' @tap="getUserProfile">新
            </button>
            <!-- 老版本登录方法 -->
<button  type='primary' 
            open-type="getUserInfo" @getuserinfo="bindGetUserInfo">老
            </button>
</view>
</template>
<script>
export default {
data() {
return {
                //用来判断用哪个登录
               appid:'去微信公众平台查看',
   secret:'去微信公众平台->开发->开发设置获取生成',
   code:''
            }
       },
       //监听页面加载
onLoad() {
uni.getSetting({
   success(res) {
      console.log(res.authSetting)
  if(res.authSetting['scope.userInfo']){
  console.log('登录了');
  }else {
  console.log('未登录');
  }
   }
})
            //如果手机支持最新版登录就用新方法
if (wx.getUserProfile) {
this.canIUseGetUserProfile = true
}
 
},
        methods: {
            //老版登录接口(不再弹出登录弹框)
            bindGetUserInfo(e){
console.log(e);
if (e.detail.userInfo) {
// console.log(e.detail.userInfo);
uni.showLoading({
title: '登录中'
});
//业务逻辑
// console.log(res1);
uni.login({
success: res => {
if (res.code) {
//在此发起网络请求
//请求后端给的登录接口,把res.code等相关参数带上
} else {
// console.log('登录失败!' + res.errMsg)
}
}
})
}
},
            // 弹出登录弹框(新版)
getUserProfile() {
//推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息                                              均需用户确认
// 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
uni.getUserProfile({
desc: '用于获取您的个人信息', // s声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: res1 => {
console.log(res1);
uni.showLoading({
title: '登录中'
});
//业务逻辑
// console.log(res1);
uni.login({
success: res => {
if (res) {
console.log(res.code);
this.code = res.code
uni.request({
url:`https://api.weixin.qq.com/sns/jscode2session?appid=${this.appid}&secret=${this.secret}&js_code=${this.code}&grant_type=authorization_code`,
    success:(res)=>{
console.log(res);
                                    //发起网络请求
                                    //请求后端给的登录接口,把res.code等相关参数带上
}
})
} else {
// console.log('登录失败!' + res.errMsg)
}
}
}) 
}
})
},
        }
   }
</script>

​以上就是 直播app开发搭建,uniapp中微信小程序账号登录,更多内容欢迎关注之后的文章

 

标签:uniapp,code,console,log,登录,res,app,uni,中微信
From: https://www.cnblogs.com/yunbaomengnan/p/17553533.html

相关文章

  • uniapp请求数据流在真机上预览pdf
    1.请求后端的数据流image-tools.js的代码自行到网上下载,放到utils文件夹里//映入image-tools插件import{base64ToPath}from'@/utils/image-tools.js'//省略部分代码.....//请求数据流方法lookBg(){letparams={}......
  • 使用HttpUtil时报javax.net.ssl.SSLHandshakeException: No appropriate protocol异常
    在使用HttpUtil类时,针对某一个接口报错出现异常HttpGetInforesult=HttpUtil.getInfo(token,Url);但是这个getInfoUrl在postman上调用是成功的后来查找后发现问题是:在Java8及高版本以上的版本在调用ssl时会出现javax.net.ssl.SSLHandshakeException:Noappropriateprotoc......
  • 前端uni-app自定义精美全端复制文本插件,支持全端文本复制插件 可设置复制按钮颜色
    随着技术的发展,开发的复杂度也越来越高,传统开发方式将一个系统做成了整块应用,经常出现的情况就是一个小小的改动或者一个小功能的增加可能会引起整体逻辑的修改,造成牵一发而动全身。通过组件化开发,可以有效实现单独开发,单独维护,而且他们之间可以随意的进行组合。大大提升开发效率......
  • Spring源码剖析-BeanFactory和ApplicationContext(其一)
    1.在Spring中,BeanFactory和ApplicationContext是两种容器,它们之间的关系是怎样的?我们使用的是哪个?它们的底层原理是什么?以一个SpringBoot的启动类为例:packagecom.example.demo3;importorg.springframework.boot.SpringApplication;importorg.springframework.boot.auto......
  • startapp时出现 CommandError错误
    startapp时出现CommandError:'xxxxx'conflictswiththenameofanexistingPythonmoduleandcannotbeusedasanappname.Pleasetryanothername.错误原因可能是在settings.py中加入了sys.path.append(os.path.join(BASE_DIR,'app'))解决办法,先将上面这行代码......
  • windbg.appinstaller打不开分析蓝屏工具安装,无法使用微软商店
    蓝屏分析工具windbg,正常应该是在微软商店直接安装的。但是,微软商店各种方式都搞不定,官方的资料回答显示得重置(不过我们重置应该也是没有的,可能是因为破解windows的缘故)所以得从别的方式下载,windows商店实际就是下载的windbg.msixbundle文件安装,然后在使用该配置windbg.appinst......
  • mybatis-plus QueryWrapper and or 连用组成查询条件
    我的代码片段StringnumberCode=(String)params.get("numberCode");if(StringUtils.isNotBlank(numberCode)){wrapper.and(qw->qw.eq("number",numberCode).or().eq("code",numberCode));//wr......
  • Power APP Canvas组件简单控制画布控件
    效果图:图中绿色部分是组件,通过组件控制画布中按钮的点击事件。具体实现:1、组件按钮中赋值一个变量比如左按钮给yyy赋值false右按钮赋值true;2、增加输出属性                          将其赋值为此变量,此处用布尔......
  • csapp二进制炸弹实验个人总结
    2023/7/13完成了这个实验,算是我的第一次逆向实战,对我来说很有挑战性。总结如下:1.对于汇编的熟练度,尤其是“层次”问题,mov0x8(%rsp),%rax和lea0x8(%rsp),%rax并不同;要注意某一个值本身是“地址”还是“数值”2.理解机器码工作原理后,拓宽思路,经验+寻找新的方法3.看待问题的视角......
  • uni.app 微信登录
      配置方面一定要配置appid 和  appsecret appsecret在视图源码里面手动写一下。 "weixin":{"appid":"xxxxxx","appsecret":"xxxxxxxx","Univers......