Example #1
0
class WeChatClient(BaseWeChatClient):
    """
    微信 API 操作类
    通过这个类可以操作微信 API,发送主动消息、群发消息和创建自定义菜单等。
    """

    API_BASE_URL = 'https://api.weixin.qq.com/cgi-bin/'

    card = api.WeChatCard()
    customservice = api.WeChatCustomService()
    datacube = api.WeChatDataCube()
    device = api.WeChatDevice()
    group = api.WeChatGroup()
    invoice = api.WeChatInvoice()
    jsapi = api.WeChatJSAPI()
    material = api.WeChatMaterial()
    media = api.WeChatMedia()
    menu = api.WeChatMenu()
    merchant = api.WeChatMerchant()
    message = api.WeChatMessage()
    misc = api.WeChatMisc()
    poi = api.WeChatPoi()
    qrcode = api.WeChatQRCode()
    scan = api.WeChatScan()
    semantic = api.WeChatSemantic()
    shakearound = api.WeChatShakeAround()
    tag = api.WeChatTag()
    template = api.WeChatTemplate()
    user = api.WeChatUser()
    wifi = api.WeChatWiFi()
    wxa = api.WeChatWxa()
    marketing = api.WeChatMarketing()

    def __init__(self,
                 appid,
                 secret,
                 access_token=None,
                 session=None,
                 timeout=None,
                 auto_retry=True):
        super(WeChatClient, self).__init__(appid, access_token, session,
                                           timeout, auto_retry)
        self.appid = appid
        self.secret = secret

    def fetch_access_token(self):
        """
        获取 access token
        详情请参考 http://mp.weixin.qq.com/wiki/index.php?title=通用接口文档

        :return: 返回的 JSON 数据包
        """
        return self._fetch_access_token(
            url='https://api.weixin.qq.com/cgi-bin/token',
            params={
                'grant_type': 'client_credential',
                'appid': self.appid,
                'secret': self.secret
            })
Example #2
0
class WeChatClient(BaseWeChatClient):
    """
    微信 API 操作类
    通过这个类可以操作微信 API,发送主动消息、群发消息和创建自定义菜单等。
    """

    API_BASE_URL = "https://api.weixin.qq.com/cgi-bin/"

    card = api.WeChatCard()
    customservice = api.WeChatCustomService()
    datacube = api.WeChatDataCube()
    device = api.WeChatDevice()
    group = api.WeChatGroup()
    invoice = api.WeChatInvoice()
    jsapi = api.WeChatJSAPI()
    material = api.WeChatMaterial()
    media = api.WeChatMedia()
    menu = api.WeChatMenu()
    merchant = api.WeChatMerchant()
    message = api.WeChatMessage()
    misc = api.WeChatMisc()
    poi = api.WeChatPoi()
    qrcode = api.WeChatQRCode()
    scan = api.WeChatScan()
    semantic = api.WeChatSemantic()
    shakearound = api.WeChatShakeAround()
    tag = api.WeChatTag()
    template = api.WeChatTemplate()
    user = api.WeChatUser()
    wifi = api.WeChatWiFi()
    wxa = api.WeChatWxa()
    marketing = api.WeChatMarketing()
    cloud = api.WeChatCloud()

    def __init__(
        self,
        appid,
        secret,
        access_token=None,
        session=None,
        timeout=None,
        auto_retry=True,
    ):
        super().__init__(appid, access_token, session, timeout, auto_retry)
        self.appid = appid
        self.secret = secret

    def fetch_access_token(self):
        """
        获取 access token
        详情请参考
        https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html

        :return: 返回的 JSON 数据包
        """
        return self._fetch_access_token(
            url="https://api.weixin.qq.com/cgi-bin/token",
            params={
                "grant_type": "client_credential",
                "appid": self.appid,
                "secret": self.secret,
            },
        )