8000 用户授权内容 · sam9831/mpvue-imooc-ebook-docs@21e7ce0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 21e7ce0

Browse files
committed
用户授权内容
1 parent 609c104 commit 21e7ce0

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

docs/guide/dev/auth.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,50 @@
1-
# 认证流程
1+
# 用户授权
22

3+
## 用户授权流程
34
![auth progress](../images/auth_process.jpg)
5+
6+
### 用户授权判断
7+
通过`mpvue.getSetting`判断小程序是否获得权限
8+
9+
::: tip
10+
查看[官方文档](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/setting/wx.getSetting.html)
11+
:::
12+
13+
### 用户申请授权
14+
如果小程序未获得授权,我们需要提供用户主动申请授权的功能,微信规定获取用户信息,必须用户主动触发,此时我们需要借助`button`组件完成用户授权事件绑定,关键步骤:
15+
```html
16+
<button
17+
@getuserinfo="getUserInfo"
18+
open-type="getUserInfo"
19+
>
20+
授权登录
21+
</button>
22+
```
23+
关于`getuserinfo``open-type`的官方说明如下:
24+
25+
| 属性 | 说明 |
26+
| --- | --- |
27+
| open-type | 微信开放能力 |
28+
| bindgetuserinfo | 用户点击该按钮时,会返回获取到的用户信息,回调的detail数据与wx.getUserInfo返回的一致,open-type="getUserInfo"时有效 |
29+
30+
::: tip
31+
查看[官方文档](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html)
32+
:::
33+
34+
### 获取用户信息
35+
通过`mpvue.getUserInfo`获取用户信息
36+
37+
::: tip
38+
查看[官方文档](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/user-info/wx.getUserInfo.html)
39+
:::
40+
41+
### 获取openId
42+
由于每个用户在每个小程序都会获得唯一的`openId`,所以`openId`非常适合用作用户的唯一标识,获取`openId`我们需要通过官方提供的`api` `auth.code2Session
43+
`来获取,为了简化`api`调用,课程提供了该`api`的封装版本,[立即查看](https://www.youbaobao.xyz/mpvue-docs/api/#%E8%8E%B7%E5%8F%96%E5%BE%AE%E4%BF%A1%E7%94%A8%E6%88%B7%E7%9A%84openid)
44+
45+
::: tip
46+
查看[官方文档](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html)
47+
:::
48+
49+
### 用户注册
50+
获得`openId`后,我们可以通过该`openId`和用户信息在小慕读书中进行注册,课程提供了注册的`api`[立即查看](https://www.youbaobao.xyz/mpvue-docs/api/#%E7%94%A8%E6%88%B7%E6%B3%A8%E5%86%8C)

0 commit comments

Comments
 (0)
0