Example #1
0
    def __init__(self, appid, secret, access_token=None):
        self.appid = appid
        self.secret = secret
        self._access_token = access_token
        self.expires_at = None

        weak_self = weakref.proxy(self)

        # APIs
        self.menu = api.WeChatMenu(weak_self)
        self.user = api.WeChatUser(weak_self)
        self.group = api.WeChatGroup(weak_self)
        self.media = api.WeChatMedia(weak_self)
        self.card = api.WeChatCard(weak_self)
        self.qrcode = api.WeChatQRCode(weak_self)
        self.message = api.WeChatMessage(weak_self)
        self.misc = api.WeChatMisc(weak_self)
        self.merchant = api.WeChatMerchant(weak_self)
        self.customservice = api.WeChatCustomService(weak_self)
        self.datacube = api.WeChatDataCube(weak_self)
        self.jsapi = api.WeChatJSAPI(weak_self)
        self.material = api.WeChatMaterial(weak_self)
        self.semantic = api.WeChatSemantic(weak_self)
        self.shakearound = api.WeChatShakeAround(weak_self)
        self.device = api.WeChatDevice(weak_self)
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()

    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 #3
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,
            },
        )