예제 #1
0
class DeviceEventReply(BaseReply):
    type = 'device_event'
    event = StringField('Event')
    device_type = StringField('DeviceType')
    device_id = StringField('DeviceID')
    session_id = StringField('SessionID')
    content = Base64EncodeField('Content')
예제 #2
0
class WiFiConnectedEvent(BaseEvent):
    event = 'wificconnected'
    connect_time = IntegerField('ConnectTime')
    expire_time = IntegerField('ExpireTime')
    vendor_id = StringField('VendorId')
    shop_id = StringField('PlaceId')
    bssid = StringField('DeviceNo')
예제 #3
0
class DeviceUnbindEvent(BaseEvent):
    event = 'unbind'
    device_type = StringField('DeviceType')
    device_id = StringField('DeviceID')
    session_id = StringField('SessionID')
    content = Base64DecodeField('Content')
    open_id = StringField('OpenID')
예제 #4
0
class ImageMessage(BaseMessage):
    """
    图片消息
    详情请参阅
    http://mp.weixin.qq.com/wiki/10/79502792eef98d6e0c6e1739da387346.html
    """
    type = 'image'
    media_id = StringField('MediaId')
    image = StringField('PicUrl')
예제 #5
0
class VideoMessage(BaseMessage):
    """
    视频消息
    详情请参阅
    http://mp.weixin.qq.com/wiki/10/79502792eef98d6e0c6e1739da387346.html
    """
    type = 'video'
    media_id = StringField('MediaId')
    thumb_media_id = StringField('ThumbMediaId')
예제 #6
0
class VoiceMessage(BaseMessage):
    """
    语音消息
    详情请参阅
    http://mp.weixin.qq.com/wiki/10/79502792eef98d6e0c6e1739da387346.html
    """
    type = 'voice'
    media_id = StringField('MediaId')
    format = StringField('Format')
    recognition = StringField('Recognition')
예제 #7
0
class UserScanProductEnterSessionEvent(BaseEvent):
    """
    进入公众号事件

    详情请参考
    http://mp.weixin.qq.com/wiki/15/f4109a5e44b4bfbc7eb1337eb739f3e3.html
    """
    event = 'user_scan_product_enter_session'
    standard = StringField('KeyStandard')
    key = StringField('KeyStr')
예제 #8
0
class ScanEvent(BaseEvent):
    """
    用户扫描二维码事件

    详情请参阅
    http://mp.weixin.qq.com/wiki/2/5baf56ce4947d35003b86a9805634b1e.html
    """
    event = 'scan'
    scene_id = StringField('EventKey')
    ticket = StringField('Ticket')
예제 #9
0
class LinkMessage(BaseMessage):
    """
    链接消息
    详情请参阅
    http://mp.weixin.qq.com/wiki/10/79502792eef98d6e0c6e1739da387346.html
    """
    type = 'link'
    title = StringField('Title')
    description = StringField('Description')
    url = StringField('Url')
예제 #10
0
class UserDeleteCardEvent(BaseEvent):
    """
    卡券删除事件推送

    详情请参阅
    http://mp.weixin.qq.com/wiki/16/28b34ee91675a04cb24853768debded4.html#.E5.88.A0.E9.99.A4.E4.BA.8B.E4.BB.B6.E6.8E.A8.E9.80.81
    """
    event = 'user_del_card'
    card_id = StringField('CardId')
    code = StringField('UserCardCode')
예제 #11
0
class UserScanProductAsyncEvent(BaseEvent):
    """
    地理位置信息异步推送事件

    详情请参考
    http://mp.weixin.qq.com/wiki/15/f4109a5e44b4bfbc7eb1337eb739f3e3.html
    """
    event = 'user_scan_product_async'
    standard = StringField('KeyStandard')
    key = StringField('KeyStr')
    region_code = StringField('RegionCode')
예제 #12
0
class UserScanProductVerifyActionEvent(BaseEvent):
    """
    商品审核结果事件

    详情请参考
    http://mp.weixin.qq.com/wiki/15/f4109a5e44b4bfbc7eb1337eb739f3e3.html
    """
    event = 'user_scan_product_verify_action'
    standard = StringField('KeyStandard')
    key = StringField('KeyStr')
    result = StringField('Result')
    reason = StringField('ReasonMsg')
예제 #13
0
class UserConsumeCardEvent(BaseEvent):
    """
    卡券核销事件推送

    详情请参阅
    http://mp.weixin.qq.com/wiki/16/28b34ee91675a04cb24853768debded4.html#.E6.A0.B8.E9.94.80.E4.BA.8B.E4.BB.B6.E6.8E.A8.E9.80.81
    """
    event = 'user_consume_card'
    card_id = StringField('CardId')
    code = StringField('UserCardCode')
    consume_source = StringField('ConsumeSource')
    location_id = StringField('LocationId')
    staff = StringField('StaffOpenId')
예제 #14
0
class UserGetCardEvent(BaseEvent):
    """
    领取事件推送

    详情请参阅
    http://mp.weixin.qq.com/wiki/16/28b34ee91675a04cb24853768debded4.html#.E9.A2.86.E5.8F.96.E4.BA.8B.E4.BB.B6.E6.8E.A8.E9.80.81
    """
    event = 'user_get_card'
    card_id = StringField('CardId')
    is_given_by_friend = IntegerField('IsGiveByFriend')
    friend = StringField('FriendUserName')
    code = StringField('UserCardCode')
    old_code = StringField('OldUserCardCode')
    outer_id = StringField('OuterId')
예제 #15
0
class LocationMessage(BaseMessage):
    """
    地理位置消息
    详情请参阅
    http://mp.weixin.qq.com/wiki/10/79502792eef98d6e0c6e1739da387346.html
    """
    type = 'location'
    location_x = StringField('Location_X')
    location_y = StringField('Location_Y')
    scale = StringField('Scale')
    label = StringField('Label')

    @property
    def location(self):
        return self.location_x, self.location_y
예제 #16
0
class UserScanProductEvent(BaseEvent):
    """
    打开商品主页事件

    详情请参考
    http://mp.weixin.qq.com/wiki/15/f4109a5e44b4bfbc7eb1337eb739f3e3.html
    """
    event = 'user_scan_product'
    standard = StringField('KeyStandard')
    key = StringField('KeyStr')
    country = StringField('Country')
    province = StringField('Province')
    city = StringField('City')
    sex = IntegerField('Sex')
    scene = IntegerField('Scene')
예제 #17
0
class TextReply(BaseReply):
    """
    文本回复
    详情请参阅 http://mp.weixin.qq.com/wiki/9/2c15b20a16019ae613d413e30cac8ea1.html
    """
    type = 'text'
    content = StringField('Content')
예제 #18
0
class LocationSelectEvent(BaseEvent):
    """
    弹出地理位置选择器的事件

    详情请参阅
    http://mp.weixin.qq.com/wiki/9/981d772286d10d153a3dc4286c1ee5b5.html
    """
    event = 'location_select'
    key = StringField('EventKey')
    location_info = BaseField('SendLocationInfo', {})

    @property
    def location_x(self):
        return self.location_info['Location_X']

    @property
    def location_y(self):
        return self.location_info['Location_Y']

    @property
    def location(self):
        return self.location_x, self.location_y

    @property
    def scale(self):
        return self.location_info['Scale']

    @property
    def label(self):
        return self.location_info['Label']

    @property
    def poiname(self):
        return self.location_info['Poiname']
예제 #19
0
class TextMessage(BaseMessage):
    """
    文本消息
    详情请参阅
    http://mp.weixin.qq.com/wiki/10/79502792eef98d6e0c6e1739da387346.html
    """
    type = 'text'
    content = StringField('Content')
예제 #20
0
class BaseReply(six.with_metaclass(MessageMetaClass)):
    """Base class for all replies"""
    source = StringField('FromUserName')
    target = StringField('ToUserName')
    time = IntegerField('CreateTime', time.time())
    type = 'unknown'

    def __init__(self, **kwargs):
        self._data = {}
        message = kwargs.pop('message', None)
        if message and isinstance(message, BaseMessage):
            if 'source' not in kwargs:
                kwargs['source'] = message.target
            if 'target' not in kwargs:
                kwargs['target'] = message.source
            if hasattr(message, 'agent') and 'agent' not in kwargs:
                kwargs['agent'] = message.agent
        if 'time' not in kwargs:
            kwargs['time'] = time.time()
        for name, value in kwargs.items():
            field = self._fields.get(name)
            if field:
                self._data[field.name] = value
            else:
                setattr(self, name, value)

    def render(self):
        """Render reply from Python object to XML string"""
        tpl = '<xml>\n{data}\n</xml>'
        nodes = []
        msg_type = '<MsgType><![CDATA[{msg_type}]]></MsgType>'.format(
            msg_type=self.type)
        nodes.append(msg_type)
        for name, field in self._fields.items():
            value = getattr(self, name, field.default)
            node_xml = field.to_xml(value)
            nodes.append(node_xml)
        data = '\n'.join(nodes)
        return tpl.format(data=data)

    def __str__(self):
        if six.PY2:
            return to_binary(self.render())
        else:
            return to_text(self.render())
예제 #21
0
class ViewEvent(BaseEvent):
    """
    点击菜单跳转链接事件

    详情请参阅
    http://mp.weixin.qq.com/wiki/2/5baf56ce4947d35003b86a9805634b1e.html
    """
    event = 'view'
    url = StringField('EventKey')
예제 #22
0
class ClickEvent(BaseEvent):
    """
    点击菜单拉取消息事件

    详情请参阅
    http://mp.weixin.qq.com/wiki/2/5baf56ce4947d35003b86a9805634b1e.html
    """
    event = 'click'
    key = StringField('EventKey')
예제 #23
0
class TemplateSendJobFinishEvent(BaseEvent):
    """
    模板消息任务完成事件

    详情请参阅
    http://mp.weixin.qq.com/wiki/17/304c1885ea66dbedf7dc170d84999a9d.html
    """
    id = IntegerField('MsgID')
    event = 'templatesendjobfinish'
    status = StringField('Status')
예제 #24
0
class QualificationVerifyFailEvent(BaseEvent):
    """
    资质认证失败事件

    详情请参阅
    http://mp.weixin.qq.com/wiki/1/7f81dec16b801b34629091094c099439.html
    """
    event = 'qualification_verify_fail'
    fail_time = DateTimeField('FailTime')
    fail_reason = StringField('FailReason')
예제 #25
0
class NamingVerifyFailEvent(BaseEvent):
    """
    名称认证失败事件

    客户端不打勾,但仍有接口权限。详情请参阅
    http://mp.weixin.qq.com/wiki/1/7f81dec16b801b34629091094c099439.html
    """
    event = 'naming_verify_fail'
    fail_time = DateTimeField('FailTime')
    fail_reason = StringField('FailReason')
예제 #26
0
class BaseMessage(six.with_metaclass(MessageMetaClass)):
    """Base class for all messages and events"""
    type = 'unknown'
    id = IntegerField('MsgId', 0)
    source = StringField('FromUserName')
    target = StringField('ToUserName')
    create_time = DateTimeField('CreateTime')
    time = IntegerField('CreateTime')

    def __init__(self, message):
        self._data = message

    def __repr__(self):
        _repr = "{klass}({msg})".format(klass=self.__class__.__name__,
                                        msg=repr(self._data))
        if six.PY2:
            return to_binary(_repr)
        else:
            return to_text(_repr)
예제 #27
0
class BaseScanCodeEvent(BaseEvent):
    key = StringField('EventKey')
    scan_code_info = BaseField('ScanCodeInfo', {})

    @property
    def scan_type(self):
        return self.scan_code_info['ScanType']

    @property
    def scan_result(self):
        return self.scan_code_info['ScanResult']
예제 #28
0
class MassSendJobFinishEvent(BaseEvent):
    """
    群发消息任务完成事件

    详情请参阅
    http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
    """
    id = IntegerField('MsgID', 0)
    event = 'masssendjobfinish'
    status = StringField('Status')
    total_count = IntegerField('TotalCount', 0)
    filter_count = IntegerField('FilterCount', 0)
    sent_count = IntegerField('SentCount', 0)
    error_count = IntegerField('ErrorCount', 0)
예제 #29
0
class BaseComponentMessage(six.with_metaclass(MessageMetaClass)):
    """Base class for all component messages and events"""
    type = 'unknown'
    appid = StringField('AppId')
    create_time = DateTimeField('CreateTime')

    def __init__(self, message):
        self._data = message

    def __repr__(self):
        _repr = "{klass}({msg})".format(klass=self.__class__.__name__,
                                        msg=repr(self._data))
        if six.PY2:
            return to_binary(_repr)
        else:
            return to_text(_repr)
예제 #30
0
class BasePictureEvent(BaseEvent):
    key = StringField('EventKey')
    pictures_info = BaseField('SendPicsInfo', {})

    @property
    def count(self):
        return int(self.pictures_info['Count'])

    @property
    def pictures(self):
        if self.pictures_info['PicList']:
            items = self.pictures_info['PicList']['item']
            if self.count > 1:
                return items
            return [items]
        return []