def __init__(self, component_appid, component_appsecret, component_token, encoding_aes_key, session=None): """ :param component_appid: 第三方平台appid :param component_appsecret: 第三方平台appsecret :param component_token: 公众号消息校验Token :param encoding_aes_key: 公众号消息加解密Key """ self.component_appid = component_appid self.component_appsecret = component_appsecret self.expires_at = None self.crypto = WeChatCrypto(component_token, encoding_aes_key, component_appid) self.session = session or MemoryStorage() if isinstance(session, six.string_types): from shove import Shove from wechatpy.session.shovestorage import ShoveStorage querystring = get_querystring(session) prefix = querystring.get('prefix', ['wechatpy'])[0] shove = Shove(session) storage = ShoveStorage(shove, prefix) self.session = storage
def __init__(self, appid, access_token=None, session=None, timeout=None, auto_retry=True): self.appid = appid self.expires_at = None self.session = session or MemoryStorage() self.timeout = timeout self.auto_retry = auto_retry if isinstance(session, six.string_types): from shove import Shove from wechatpy.session.shovestorage import ShoveStorage querystring = get_querystring(session) prefix = querystring.get('prefix', ['wechatpy'])[0] shove = Shove(session) storage = ShoveStorage(shove, prefix) self.session = storage if access_token: self.session.set(self.access_token_key, access_token)
def __init__( self, component_appid, component_appsecret, component_token, encoding_aes_key, session=None, auto_retry=True, ): """ :param component_appid: 第三方平台appid :param component_appsecret: 第三方平台appsecret :param component_token: 公众号消息校验Token :param encoding_aes_key: 公众号消息加解密Key """ self._http = requests.Session() self.component_appid = component_appid self.component_appsecret = component_appsecret self.expires_at = None self.crypto = WeChatCrypto(component_token, encoding_aes_key, component_appid) self.session = session or MemoryStorage() self.auto_retry = auto_retry if isinstance(session, str): from shove import Shove from wechatpy.session.shovestorage import ShoveStorage querystring = get_querystring(session) prefix = querystring.get("prefix", ["wechatpy"])[0] shove = Shove(session) storage = ShoveStorage(shove, prefix) self.session = storage
def set_session(self, redis=None, shove=None, mc=None, prefix="wechatpy"): if redis is not None: from wechatpy.session.redisstorage import RedisStorage self.session = RedisStorage(redis, prefix) elif shove is not None: from wechatpy.session.shovestorage import ShoveStorage self.session = ShoveStorage(shove, prefix) elif mc is not None: from wechatpy.session.memcachedstorage import MemcachedStorage self.session = MemcachedStorage(mc, prefix)
def __init__(self, access_token=None, session=None): self.expires_at = None self.session = session or MemoryStorage() if isinstance(session, six.string_types): from shove import Shove from wechatpy.session.shovestorage import ShoveStorage querystring = get_querystring(session) prefix = querystring.get('prefix', ['wechatpy'])[0] shove = Shove(session) storage = ShoveStorage(shove, prefix) self.session = storage self.session.set('access_token', access_token)
def __init__(self, component_appid, component_appsecret, session=None): """ :param component_appid: 第三方平台appid :param component_appsecret: 第三方平台appsecret :param component_verify_ticket: 微信后台推送的ticket,此ticket会定时推送 """ self.component_appid = component_appid self.component_appsecret = component_appsecret self.expires_at = None self.session = session or MemoryStorage() if isinstance(session, six.string_types): from shove import Shove from wechatpy.session.shovestorage import ShoveStorage querystring = get_querystring(session) prefix = querystring.get('prefix', ['wechatpy'])[0] shove = Shove(session) storage = ShoveStorage(shove, prefix) self.session = storage
#coding: utf-8 from __future__ import unicode_literals, absolute_import import logging from django.conf import settings from wechatpy import WeChatClient from shove import Shove from wechatpy.session.shovestorage import ShoveStorage logger = logging.getLogger(__name__) shove = Shove('file:///tmp/wecron_storage', sync=1) storage = ShoveStorage(shove) """ A stateless client, there should be only one instance of wechat_client, for there is only one instance of access_token globally. """ wechat_client = WeChatClient(appid=settings.WX_APPID, secret=settings.WX_APPSECRET, session=storage)