|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
15 |
|
import six |
|
4
|
15 |
|
from werobot.messages.entries import StringEntry, IntEntry, FloatEntry |
|
5
|
|
|
from werobot.messages.base import WeRoBotMetaClass |
|
6
|
15 |
|
|
|
7
|
|
|
|
|
8
|
|
|
class EventMetaClass(WeRoBotMetaClass): |
|
9
|
15 |
|
pass |
|
10
|
15 |
|
|
|
11
|
15 |
|
|
|
12
|
|
|
@six.add_metaclass(EventMetaClass) |
|
13
|
15 |
|
class WeChatEvent(object): |
|
14
|
15 |
|
target = StringEntry('ToUserName') |
|
15
|
15 |
|
source = StringEntry('FromUserName') |
|
16
|
|
|
time = IntEntry('CreateTime') |
|
17
|
|
|
message_id = IntEntry('MsgID', 0) |
|
18
|
|
|
|
|
19
|
15 |
|
def __init__(self, message): |
|
20
|
15 |
|
self.__dict__.update(message) |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
15 |
|
class TicketEvent(WeChatEvent): |
|
24
|
15 |
|
key = StringEntry('EventKey') |
|
25
|
15 |
|
ticket = StringEntry('Ticket') |
|
26
|
15 |
|
|
|
27
|
15 |
|
|
|
28
|
|
|
class SubscribeEvent(TicketEvent): |
|
29
|
15 |
|
__type__ = 'subscribe_event' |
|
30
|
15 |
|
|
|
31
|
|
|
|
|
32
|
|
|
class UnSubscribeEvent(WeChatEvent): |
|
33
|
15 |
|
__type__ = 'unsubscribe_event' |
|
34
|
15 |
|
|
|
35
|
15 |
|
|
|
36
|
|
|
class ScanEvent(TicketEvent): |
|
37
|
|
|
__type__ = 'scan_event' |
|
38
|
15 |
|
|
|
39
|
15 |
|
|
|
40
|
|
|
class SimpleEvent(WeChatEvent): |
|
41
|
|
|
key = StringEntry('EventKey') |
|
42
|
15 |
|
|
|
43
|
15 |
|
|
|
44
|
|
|
class ClickEvent(SimpleEvent): |
|
45
|
|
|
__type__ = 'click_event' |
|
46
|
15 |
|
|
|
47
|
15 |
|
|
|
48
|
|
|
class ViewEvent(SimpleEvent): |
|
49
|
|
|
__type__ = 'view_event' |
|
50
|
15 |
|
|
|
51
|
15 |
|
|
|
52
|
|
|
class LocationEvent(WeChatEvent): |
|
53
|
|
|
__type__ = 'location_event' |
|
54
|
15 |
|
latitude = FloatEntry('Latitude') |
|
55
|
15 |
|
longitude = FloatEntry('Longitude') |
|
56
|
|
|
precision = FloatEntry('Precision') |
|
57
|
|
|
|
|
58
|
15 |
|
|
|
59
|
15 |
|
class TemplateSendJobFinishEvent(WeChatEvent): |
|
60
|
|
|
__type__ = 'templatesendjobfinish_event' |
|
61
|
|
|
status = StringEntry('Status') |
|
62
|
15 |
|
|
|
63
|
15 |
|
|
|
64
|
15 |
|
class UnknownEvent(WeChatEvent): |
|
65
|
|
|
__type__ = 'unknown_event' |
|
66
|
|
|
|