Exemple #1
0
from tornado.concurrent import Future

from itchatmp.server import WechatServer
from .mpapi.mp import common as mpCommon
from .mpapi.qy import common as qyCommon

server = WechatServer(None, None, None)


def determine_wrapper(mpFn=None, copFn=None, *args, **kwargs):
    if server.config.copId != '':
        if copFn is None:
            raise AttributeError('No such method for company platform')
        else:
            return copFn(*args, **kwargs)
    elif server.config.appId != '':
        if mpFn is None:
            raise AttributeError('No such method for massive platform')
        else:
            return mpFn(*args, **kwargs)
    else:
        raise AttributeError(
            'You must specific appId or copId before use this method')


def update_access_token():
    return determine_wrapper(mpCommon.update_access_token,
                             qyCommon.update_access_token)


def access_token(fn):
Exemple #2
0
from itchatmp.server import WechatServer
from .common import determine_wrapper
from .mpapi.mp import messages as mpMsg
from .mpapi.qy import messages as qyMsg

server = WechatServer(None, None, None)

def send_some(msgType, mediaId, additionalDict={},
        targetIdList=[], partyIdList=[], tagIdList=[],
        agentId=None):
    return determine_wrapper(mpMsg.send_some, qyMsg.send_some,
        msgTyp, mediaId, additionalDict,
        targetIdList, partyIdList, tagIdList, agentId)

def send_all(msgType, mediaId, additionalDict={}, tagId=None):
    return determine_wrapper(mpMsg.send_all, qyMsg.send_all,
        msgType, mediaId, additionalDict, tagId)

def preview(msgType, mediaId, additionalDict={}, toUserId=None, toWxAccount=None):
    return determine_wrapper(mpMsg.preview, None,
        msgType, mediaId, additionalDict, toUserId, toWxAccount)

def delete(msgId):
    return determine_wrapper(mpMsg.delete, None,
        msgId)

def get(msgId):
    return determine_wrapper(mpMsg.get, None,
        msgId)

def upload(fileType, fileDir, additionalDict={}, permanent=False):
Exemple #3
0
from requests.models import Response
from requests.sessions import session
from tornado import gen

from ..requests import requests
from itchatmp.config import COROUTINE
from itchatmp.server import WechatServer
from itchatmp.utils import retry
from itchatmp.returnvalues import ReturnValue

__all__ = ['update_access_token_producer', 'access_token', 'filter_request']

logger = logging.getLogger('itchatmp')

__server = WechatServer(None, None, None)
__AUTO_MAINTAIN = False
__serverList = None
__session = session()
__session.verify = False
get = __session.get


def auto_maintain_thread(firstCallResult=None, tokenUrl=None, appIdFn=None):
    r = firstCallResult or update_access_token_producer(
        tokenUrl, appIdFn, True)()
    if not r:
        __server.ioLoop.call_later((datetime.replace(
            datetime.now() + timedelta(days=1), hour=0, minute=5, second=0) -
                                    datetime.now()).seconds,
                                   maintain_access_token, None, tokenUrl,
Exemple #4
0
import pickle, logging

from itchatmp.server import WechatServer

logger = logging.getLogger('itchatmp')

__server = WechatServer.instance()


class AccessTokenStorage(object):
    def get_access_token(self):
        raise NotImplementedError()

    def store_access_token(self, accessToken, expireTime):
        raise NotImplementedError()

    def get_server_list(self):
        raise NotImplementedError()

    def store_server_list(self, serverList, fetchTime):
        raise NotImplementedError()


class TestStorage(AccessTokenStorage):
    ''' storage for test use
        {
            'accessToken': ('', 0),
            'serverList': ([], 0),
        }
    '''
    __storageDict = None
Exemple #5
0
from itchatmp.server import WechatServer
from .common import determine_wrapper as dwp
from .mpapi.mp import wrapped as mpWrapped

server = WechatServer(None, None, None)


def send(msg, toUserName, mediaId=None):
    return dwp(mpWrapped.send, None, msg, toUserName, mediaId)


server.send = send