Skip to content

Commit 886eed8

Browse files
committed
Add: 添加WechatMessage API文档
1 parent a71dda7 commit 886eed8

File tree

4 files changed

+129
-39
lines changed

4 files changed

+129
-39
lines changed

docs/docs/api/basic.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

docs/docs/api/ext.md

Whitespace-only changes.

docs/docs/api/wechatmessage.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# WechatMessage API
2+
3+
目前此开发包提供以下几种消息类:``TextMessage`` (文本消息类), ``ImageMessage`` (图片消息类), ``VideoMessage`` (视频消息类), ``LocationMessage`` (位置消息类), ``LinkMessage`` (链接消息类), ``EventMessage`` (事件消息类), ``VoiceMessage`` (语音消息类),它们都继承自 ``WechatMessage`` (公共消息类)
4+
5+
这些消息类都在 ``wechat_sdk.messages`` 中定义。
6+
7+
## WechatMessage 公共基类
8+
9+
下面所有的消息类均有此处的公共属性
10+
11+
|name|value|
12+
|----|-----|
13+
|`id`|消息ID|
14+
|`target`|目标用户 OpenID|
15+
|`source`|来源用户 OpenID|
16+
|`time`|信息发送时间,一个UNIX时间戳|
17+
|`raw`|信息的原始 XML 格式|
18+
19+
## 文本消息类 TextMessage
20+
21+
|name|value|
22+
|----|-----|
23+
|`type`|'text'|
24+
|`content`|信息的内容|
25+
26+
## 图片消息类 ImageMessage
27+
28+
|name|value|
29+
|----|-----|
30+
|`type`|'image'|
31+
|`picurl`|图片网址,可以从这个网址访问到图片|
32+
33+
## 视频消息类 VideoMessage
34+
35+
|name|value|
36+
|----|-----|
37+
|`type`|'video'|
38+
|`media_id`|视频消息媒体 ID|
39+
|`thumb_media_id`|视频消息缩略图的媒体 ID|
40+
41+
## 小视频消息类 ShortVideoMessage
42+
43+
|name|value|
44+
|----|-----|
45+
|`type`|'shortvideo'|
46+
|`media_id`|视频消息媒体 ID|
47+
|`thumb_media_id`|视频消息缩略图的媒体 ID|
48+
49+
## 链接消息类 LinkMessage
50+
51+
|name|value|
52+
|----|-----|
53+
|`type`|'link'|
54+
|`title`|消息标题|
55+
|`description`|消息描述|
56+
|`url`|消息链接|
57+
58+
## 地理位置消息类 LocationMessage
59+
60+
|name|value|
61+
|----|-----|
62+
|`type`|'location'|
63+
|`location`|一个元组(纬度, 经度)|
64+
|`scale`|地图缩放大小|
65+
|`label`|地理位置信息|
66+
67+
## 语音消息类 VoiceMessage
68+
69+
|name|value|
70+
|----|-----|
71+
|`type`|'voice'|
72+
|`media_id`|语音消息媒体 ID|
73+
|`format`|声音格式|
74+
|`recognition`|语音识别结果(如未开通语音识别功能,则值为 `None` )|
75+
76+
## 事件消息类 EventMessage
77+
78+
### 关注事件
79+
80+
|name|value|
81+
|----|-----|
82+
|`type`|'subscribe'|
83+
|`key`|`None`|
84+
|`ticket`|`None`|
85+
86+
请注意,普通的关注事件和扫描二维码造成的关注事件的 type 均为 `subscribe` ,如果是普通的关注事件,则 `key``ticket` 均为 `None` ,可以通过判断它们来识别是普通关注事件还是扫描二维码造成的关注事件。
87+
88+
### 取消关注事件
89+
90+
|name|value|
91+
|----|-----|
92+
|`type`|'unsubscribe'|
93+
94+
### 二维码事件
95+
96+
|name|value|
97+
|----|-----|
98+
|`type`|'subscribe' 或 'scan'|
99+
|`key`|事件 key 值<br/>当用户未关注时(type = 'subscribe'),qrscene_为前缀,后面为二维码的参数值;<br/>当用户已关注时(type = 'scan'),是一个32位无符号整数,即创建二维码时的二维码scene_id|
100+
|`ticket`|二维码 Ticket,可用来换取二维码图片|
101+
102+
### 上报地理位置事件
103+
104+
|name|value|
105+
|----|-----|
106+
|`type`|'location'|
107+
|`latitude`|地理位置纬度|
108+
|`longitude `|地理位置经度|
109+
|`precision `|地理位置精度|
110+
111+
### 自定义菜单事件
112+
113+
|name|value|
114+
|----|-----|
115+
|`type`|'click'<br/>'view'<br/>'scancode_push'<br/>'scancode_waitmsg'<br/>'pic_sysphoto'<br/>'pic_photo_or_album'<br/>'pic_weixin'<br/>'location_select'<br/>|
116+
|`key`|事件 key 值<br/>当 type = 'click' 时,它与自定义菜单接口中KEY值对应;<br/>当 type = 'view' 时,它是设置的跳转URL<br/>当 type 为其他取值时,它是事件KEY值,由开发者在创建菜单时设定|
117+
|`ScanCodeInfo`|扫描信息,当且仅当 type = 'scancode_push' 或 'scancode_waitmsg' 时存在|
118+
|`SendPicsInfo`|发送的图片信息,当且仅当 type = 'pic_sysphoto' 或 'pic_photo_or_album' 或 'pic_weixin' 时存在|
119+
|`SendLocationInfo`|发送的位置信息,当且仅当 type = 'location_select' 时存在|
120+
121+
### 模板消息事件
122+
123+
|name|value|
124+
|----|-----|
125+
|`type`|'templatesendjobfinish'|
126+
|`status`|发送状态|
127+
128+

docs/mkdocs.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ pages:
3434
- '1. 登录': 'extension/login.md'
3535
- 'API 文档':
3636
- '1. WechatConf': 'api/wechatconf.md'
37-
- '2. WechatBasic': 'api/basic.md'
38-
- '2. WechatExt': 'api/ext.md'
37+
- '2. WechatMessage': 'api/wechatmessage.md'
3938
- '3. 异常类': 'api/exception.md'
4039
- 'FAQ': 'faq.md'
4140
- '功能完成度': 'feature.md'

0 commit comments

Comments
 (0)