这里使用的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. String转list

    String l = "63, 47, 51, 35, 36, 52, 37, 53, 38, 54, 39, 55, 40, 56, 41, 57, 42";List<In ...

  2. Vulhub-漏洞环境的搭建

    安装Docker #安装pip curl -s https://bootstrap.pypa.io/get-pip.py | python3 #安装最新版docker curl -s https:// ...

  3. 【时间】Unix时间戳

    UNIX时间戳:Unix时间戳(英文为Unix epoch, Unix time, POSIX time 或 Unix timestamp) 是从1970年1月1日(UTC/GMT的午夜)开始所经过的 ...

  4. fiddler对浏览器、app抓包及证书安装

    1.fiddler对浏览器抓包 1.1 对浏览器的http的抓包 Capturing开启,进行抓包: Capturing关闭,停止抓包: 如下图:  1.2 对浏览器的https抓包 1.2.1 开启 ...

  5. 用 Windows Live Writer 和 SyntaxHighlighter 插件写高亮代码

    博客园内置支持SyntaxHighlighter代码着色,代码着色语法:<pre class='brush:编程语言'>代码</pre>. 需要注意的是:如何你使用Syntax ...

  6. linux python3 venv 虚拟环境报错 [-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 2.

    解决办法: 先创建没有pip的虚拟环境,然后启动虚拟环境后,再安装pip 办法一: 亲测失败了... python3 -m venv --without-pip py36env 办法二 sudo ap ...

  7. C语言中的数据类型转换函数

    头文件#include<stdlib.h> 1. 函数名: atof 功 能: 把字符串转换成浮点数 用 法: double atof(const char *nptr); 2.函数名: ...

  8. 记录解决java.io.IOException: Server returned HTTP response code: 500 for URL:xxxxxxxx

    踩坑经历 因为项目需要去对接别的接口,使用URLConnection POST请求https接口,发送json数组时遇到java.io.IOException: Server returned HTT ...

  9. flink学习之十一-window&EventTime实例

    上面试了Processing Time,在这里准备看下Event Time,以及必须需要关注的,在ET场景下的Watermarks. EventTime & Watermark Event t ...

  10. springboot1.5.x升级到2.1.x切换分支导致的maven依赖混乱

    背景:项目springboot版本由1.5.X升级到2.1.X,两个版本的分支需要共存,来回切换的时候,maven依赖各种报红 查看dependency发现1.5.X的jar和2.1.X的jar都存在 ...