这里使用的mpvue

第一步组件DOM部分

/pages/index
<button class="app_btn" open-type="getUserInfo" @getuserinfo="getUserInfo" type="primary"> 欢迎使用XXX </button>

第二步登录方法

/pages/index
getUserInfo() {
let _this = this;
wx.login({
success: async function(res) {
if (res.code) {
//发起网络请求
let ares = await execteGet('/v1/inner/wechat/getOpenId',{code: res.code})
if(ares){
_this.operId = ares;
wx.setStorageSync('operId', ares);
// 存在groupId及通过组分享进来的,直接加入对应组
console.log('开始加入群组----:'+ _this.groupId)
if(_this.groupId){
let join_data = {
groupId: _this.groupId,
"weChatId": ares
}
let jres = await exectePost('/v1/inner/group/joinGroup', join_data)
console.log('加入群组参数---:' + JSON.stringify(join_data))
console.log('加入群组状态----:'+jres)
}
// 获取用户信息
wx.getSetting({
success(cres) {
if (cres.authSetting['scope.userInfo']) {
console.log("已授权=====")
// 已经授权,可以直接调用 getUserInfo 获取头像昵称
wx.getUserInfo({
success(zres) {
console.log("获取用户信息成功", zres);
_this.globalData.userInfo = zres.userInfo;
if(!wx.getStorageSync('nickName')){
wx.setStorageSync('nickName', zres.userInfo.nickName)
}
// 存用户数据
let sdata = {
address:`${zres.userInfo.country}-${zres.userInfo.province}-${zres.userInfo.city}`,
name: zres.userInfo.nickName,
sex: zres.userInfo.gender,
weChatId: _this.operId,
portrait: zres.userInfo.avatarUrl
}
exectePost('/v1/inner/task/loginOrInsertUser', sdata).then(data =>{
gotabbar()
})
},
fail(res) {
console.log("获取用户信息失败", res)
}
})
} else {
console.log("未授权=====")
that.showSettingToast("请授权")
}
}
})
}else{
wx.showToast({
title: '获取operid失败!',
icon: 'loading',
duration: 1500
})
}
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
}, // 打开权限设置页提示框
showSettingToast(e) {
wx.showModal({
title: '温馨提示提示!',
confirmText: '去设置',
showCancel: false,
content: e,
success: function(res) {
if (res.confirm) {
wx.navigateTo({
url: '../setting/main',
})
}
}
})
}

第三步编写授权页面

/pages/setting
<button class="primary_btn" type="primary" open-type="openSetting">去设置开启权限</button>

随便记录下分享

/pages/sharePage
<button type="primary" open-type='share'>直接分享</button>
//与methods方法同级
onShareAppMessage: function(options) {
console.log(JSON.stringify('分享来源'+ JSON.stringify(options)))
return {
title: '邀请组二维码',
path: `/pages/index/main?groupId=${this.$root.$mp.query.groupid}`,//被分享人点击进来的界面
// imageUrl: '../../static/images/user.png',
success: function (res) {
console.log(res)
wx.getShareInfo({
shareTicket: res.shareTickets[0],
success: function (res) { console.log(res) },
fail: function (res) { console.log(res) },
complete: function (res) { console.log(res) }
})
},
fail: function (res) {
console.log(res)
}
}
console.log('分享参数' + `/pages/index/main?groupId=${this.$root.$mp.query.groupid}`)
}

Q: 微信小程序登录的更多相关文章

  1. 微信小程序登录方案

    微信小程序登录方案 登录程序 app.js 调用wx.login获取code 将code作为参数请求自己业务登录接口获取session_key 存储session_key 如果有回调执行回调 App( ...

  2. 微信小程序登录,获取code,获取openid,获取session_key

    微信小程序登录 wx.login(Object object) 调用接口获取登录凭证(code).通过凭证进而换取用户登录态信息,包括用户的唯一标识(openid)及本次登录的会话密钥(session ...

  3. 基于Shiro,JWT实现微信小程序登录完整例子

    小程序官方流程图如下,官方地址 : https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html ...

  4. 微信小程序登录JAVA后台

    代码地址如下:http://www.demodashi.com/demo/12736.html 登录流程时序登录流程时序 具体的登录说明查看 小程序官方API 项目的结构图: springboot项目 ...

  5. 微信小程序登录对接Django后端实现JWT方式验证登录

    先上效果图 点击授权按钮后可以显示部分资料和头像,点击修改资料可以修改部分资料. 流程 1.使用微信小程序登录和获取用户信息Api接口 2.把Api获取的用户资料和code发送给django后端 3. ...

  6. 全栈项目|小书架|微信小程序-登录及token鉴权

    小程序登录 之前也写过微信小程序登录的相关文章: 微信小程序~新版授权用户登录例子 微信小程序-携带Token无感知登录的网络请求方案 微信小程序开通云开发并利用云函数获取Openid 也可以通过官方 ...

  7. Flask与微信小程序登录(后端)

    开发微信小程序时,接入小程序的授权登录可以快速实现用户注册登录的步骤,是快速建立用户体系的重要一步.这篇文章将介绍 python + flask + 微信小程序实现用户快速注册登录方案(本文主要进行后 ...

  8. Taro -- 微信小程序登录

    Taro微信小程序登录 1.调用Taro.login()获取登录凭证code: 2.调用Taro.request()将code传到服务器: 3.服务器端调用微信登录校验接口(appid+appsecr ...

  9. Spring Security 整合 微信小程序登录的思路探讨

    1. 前言 原本打算把Spring Security中OAuth 2.0的机制讲完后,用小程序登录来实战一下,发现小程序登录流程和Spring Security中OAuth 2.0登录的流程有点不一样 ...

  10. 微信小程序 登录流程规范解读

    一. 官方登录时序图 二. 简单理解 这里仅按照官方推荐的规范来 0. 前置条件 一共有三端: - 微信小程序客户端 - 第三方服务器端(自己搭建) - 微信服务器端 1. 客户端获得code,并将c ...

随机推荐

  1. python3 获取当前路径及os.path.dirname的使用

    方法一: import sys,os os.getcwd()#然后就可以看见结果了 方法二: import os os.path.dirname(os.path.realpath('__file__' ...

  2. xshell安装错解决方案

    之前安装过XShell后来因为各种原因不能使用了,卸载和再次安装的时候安装一直失败.研究了好久终于找到解决方案. 只需要删除在C:\Program Files (x86)\InstallShield ...

  3. 【JS学习】慕课网4-10 编程练习

    在一个大学的编程选修课班里,我们得到了一组参加该班级的学生数据,分别是姓名.性别.年龄和年级,接下来呢,我们要利用JavaScript的知识挑出其中所有是大一的女生的的名字哦. 学生信息如下: ('小 ...

  4. leetcode-160场周赛-5238-找出给定方程的正整数解

    题目描述: class Solution: def findSolution(self, customfunction: 'CustomFunction', z: int) -> List[Li ...

  5. Yii2增、删、改、查

    $order_model = OrderHeader::find()->where(['user_id'=>$user_id, 'order_type'=>'1'])->and ...

  6. BZOJ 1303: [CQOI2009]中位数图(思路题)

    传送门 解题思路 比较好想的思路题.首先肯定要把原序列转化一下,大于\(k\)的变成\(1\),小于\(k\)的变成\(-1\),然后求一个前缀和,还要用\(cnt[]\)记录一下前缀和每个数出现了几 ...

  7. js设计模式——3.观察者模式

    js设计模式——观察者模式 /*js设计模式——.观察者模式*/ // 主题,保存状态,状态变化之后触发所有观察者对象 class Subject { constructor() { this.sta ...

  8. sublime text3 nodejs控制台输出结果中文乱码

    在sublime text3安装完nodejs的插件后,运行console.log("你好"),发现控制台出现中文乱码,解决办法:Preferences-> Browser ...

  9. 4、APP FPS测试

    什么是FPS FPS是图像领域中的定义,是指画面每秒传输帧数,通俗来讲就是指动画或视频的画面数.FPS是测量用于保存.显示动态视频的信息数量.每秒钟帧数愈多,所显示的动作就会愈流畅.通常,要避免动作不 ...

  10. 技巧&注意事项合集

    技巧&注意事项合集 杂项 OI Wiki有很多实用的东西 编程环境 打开Dev-C++中工具-编译选项-代码生成/优化-代码警告-显示最多警告信息的开关,可以检查出一堆傻逼错误 define ...