Esempio n. 1
0
def set(agentId, **kwargs):
    kwargs['agentid'] = agentId
    data = encode_send_dict(kwargs)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/agent/set?access_token=%s' %
        (COMPANY_URL, kwargs['accessToken']), data=data).json()
    return ReturnValue(r)
Esempio n. 2
0
def get_material(mediaId, accessToken=None):
    data = {'media_id': mediaId}
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/material/get_material?access_token=%s' % 
        (SERVER_URL, accessToken), data=data, stream=True)
    def _wrap_result(result):
        if 'text/plain' in result.headers['Content-Type']:
            j = result.json()
            if 'down_url' in j or 'news_item' in j:
                j['errcode'] = 0
            return ReturnValue(j)
        else:
            tempStorage = io.BytesIO()
            for block in result.iter_content(1024):
                tempStorage.write(block)
            basicDict = {'File': tempStorage, 'errcode': 0}
            if 'Content-disposition' in result.headers:
                match = re.search('filename="(.*?)"', result.headers['Content-disposition'])
                if match:
                    basicDict['FileName'] = match.group(1)
            if 'Content-Type' in result.headers:
                basicDict['ContentType'] = result.headers['Content-Type']
            if 'Content-Length' in result.headers:
                basicDict['ContentLength'] = result.headers['Content-Length']
            return ReturnValue(basicDict)
    r._wrap_result = _wrap_result
    return r
Esempio n. 3
0
def create_tag(name, id=None, accessToken=None):
    data = {'tagname': name}
    if id is not None: data['tagid'] = id
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/tag/create?access_token=%s'
        % (COMPANY_URL, accessToken), data=data).json()
    return ReturnValue(r)
Esempio n. 4
0
def delete(accountDict, accessToken=None):
    data = encode_send_dict(accountDict)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/customservice/kfaccount/del?access_token=%s'
        % (SERVER_URL, accessToken), data=data)
    def _wrap_result(result):
        return ReturnValue(result.json())
    r._wrap_result = _wrap_result
    return r
Esempio n. 5
0
def quit(chatId, opUserId, accessToken=None):
    data = {
        'chatid': chatId,
        'op_user': opUserId, }
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/chat/quit?access_token=%s' % 
        (COMPANY_URL, accessToken), data=data).json()
    return ReturnValue(r)
Esempio n. 6
0
def delete_users_of_tag(id, userIdList=None, partyList=None, accessToken=None):
    if not userIdList: return ReturnValue({'errcode': 40035, 'errmsg': 'must have one userId'})
    data = encode_send_dict({'tagid': id, 'openid_list': userIdList})
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/tags/members/batchuntagging?access_token=%s'
        % (SERVER_URL, accessToken), data=data)
    def _wrap_result(result):
        return ReturnValue(result.json())
    r._wrap_result = _wrap_result
    return r
Esempio n. 7
0
def set_alias(userId, alias, accessToken=None):
    ''' this method is for verified service mp only '''
    data = encode_send_dict({'openid': userId, 'remark': alias})
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/user/info/updateremark?access_token=%s'
        % (SERVER_URL, accessToken), data=data)
    def _wrap_result(result):
        return ReturnValue(result.json())
    r._wrap_result = _wrap_result
    return r
Esempio n. 8
0
def long_url_to_short(url, accessToken=None):
    data = {'action': 'long2short', 'long_url': url}
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/shorturl?access_token=%s'
        % (SERVER_URL, accessToken), data=data)
    def _wrap_result(result):
        return ReturnValue(result.json())
    r._wrap_result = _wrap_result
    return r
Esempio n. 9
0
def update_department(id, name=None, parentId=None, order=None, accessToken=None):
    data = {'id': id}
    if name is not None: data['name'] = name
    if parentId is not None: data['parentid'] = parentId
    if order is not None: data['order'] = order
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/department/update?access_token=%s' % 
        (COMPANY_URL, accessToken), data=data).json()
    return ReturnValue(r)
Esempio n. 10
0
def delete_tag(id, accessToken=None):
    data = encode_send_dict({'tag': {'id': id}})
    if data is None:
        return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/tags/delete?access_token=%s'
        % (SERVER_URL, accessToken), data=data)
    def _wrap_result(result):
        return ReturnValue(result.json())
    r._wrap_result = _wrap_result
    return r
Esempio n. 11
0
def clear_notify(ownerId, chatId=None, userId=None, accessToken=None):
    data = {
        'op_user': ownerId,
        'chat': {
            'type': 'group' if chatId else 'single',
            'id': chatId or userId, }}
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/chat/clearnotify?access_token=%s' % 
        (COMPANY_URL, accessToken), data=data).json()
    return ReturnValue(r)
Esempio n. 12
0
def create_department(name, parentId=1, order=None, id=None, accessToken=None):
    data = {
        'name': name,
        'parentid': parentId, }
    if order is not None: data['order'] = order
    if id is not None: data['id'] = id
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/department/create?access_token=%s' % 
        (COMPANY_URL, accessToken), data=data).json()
    return ReturnValue(r)
Esempio n. 13
0
 def _create(menuDict, agentId=None, accessToken=None):
     data = encode_send_dict(menuDict)
     if data is None: return ReturnValue({'errcode': -10001})
     url = '%s/cgi-bin/menu/create?access_token=%s' % \
         (serverUrl, accessToken)
     if agentId is not None: url += '&agentid=%s' % agentId
     r = requests.post(url, data=data)
     def _wrap_result(result):
         return ReturnValue(result.json())
     r._wrap_result = _wrap_result
     return r
Esempio n. 14
0
def get_tags_of_user(userId, accessToken=None):
    data = encode_send_dict({'openid': userId})
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/tags/getidlist?access_token=%s'
        % (SERVER_URL, accessToken), data=data)
    def _wrap_result(result):
        result = ReturnValue(result.json())
        if 'tagid_list' in result: result['errcode'] = 0
        return result
    r._wrap_result = _wrap_result
    return r
Esempio n. 15
0
 def __fn_producer(startTime, endTime, accessToken=None):
     data = {'begin_date': startTime, 'end_date': endTime}
     data = encode_send_dict(data)
     r = requests.post('%s/datacube/%s?access_token=%s' % 
         (SERVER_URL, fnName, accessToken), data=data)
     def _wrap_result(result):
         result = ReturnValue(result.json())
         if 'list' in result: result['errcode'] = 0
         return result
     r._wrap_result = _wrap_result
     return r
Esempio n. 16
0
def get_blacklist(beginOpenId='', accessToken=None):
    data = {'begin_openid': beginOpenId}
    data = encode_send_dict(data)
    r = requests.post('%s/cgi-bin/tags/members/getblacklist?access_token=%s' % 
        (SERVER_URL, accessToken), data=data)
    def _wrap_result(result):
        result = ReturnValue(result.json())
        if 'data' in result: result['errcode'] = 0
        return result
    r._wrap_result = _wrap_result
    return r
Esempio n. 17
0
def delete_users_of_blacklist(userId, accessToken=None):
    ''' userId can be a userId or a list of userId '''
    if not isinstance(userId, list):
        userId = [userId]
    data = {'openid_list': userId}
    data = encode_send_dict(data)
    r = requests.post('%s/cgi-bin/tags/members/batchunblacklist?access_token=%s' % 
        (SERVER_URL, accessToken), data=data)
    def _wrap_result(result):
        return ReturnValue(result.json())
    r._wrap_result = _wrap_result
    return r
Esempio n. 18
0
 def _send(msgType, mediaId, additionalDict, toUserId, accessToken=None):
     msgDict = __form_send_dict(msgType, mediaId, additionalDict)
     if not msgDict: return msgDict
     msgDict['touser'] = toUserId
     data = encode_send_dict(msgDict)
     if data is None: return ReturnValue({'errcode': -10001})
     try:
         r = requests.post('%s/cgi-bin/message/custom/send?access_token=%s'
             % (SERVER_URL, accessToken), data=data).json()
         return ReturnValue(r)
     except Exception as e:
         return ReturnValue({'errcode': -10001, 'errmsg': e.message})
Esempio n. 19
0
def delete_tag(id, accessToken=None):
    data = encode_send_dict({'tag': {'id': id}})
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/tags/delete?access_token=%s' %
                      (SERVER_URL, accessToken),
                      data=data)

    def _wrap_result(result):
        return ReturnValue(result.json())

    r._wrap_result = _wrap_result
    return r
Esempio n. 20
0
 def _send_some(msgType, mediaId, additionalDict, targetIdList, accessToken=None):
     msgDict = __form_send_dict(msgType, mediaId, additionalDict)
     if not msgDict: return msgDict
     if not isinstance(targetIdList, list) or len(targetIdList) < 2:
         return ReturnValue({'errcode': 40130})
     msgDict['touser'] = targetIdList
     try:
         r = requests.post('%s/cgi-bin/message/mass/send?access_token=%s' % 
             (SERVER_URL, accessToken), data=encode_send_dict(msgDict)).json()
         return ReturnValue(r)
     except Exception as e:
         return ReturnValue({'errcode': -10001, 'errmsg': e.message})
Esempio n. 21
0
 def _batch_get_user_info(userId, accessToken=None):
     data = {'user_list': [{'openid': id, 'lang': 'zh-CN'} for id in userId]}
     data = encode_send_dict(data)
     if data is None: return ReturnValue({'errcode': -10001})
     r = requests.post('%s/cgi-bin/user/info/batchget?access_token=%s'
         % (SERVER_URL, accessToken), data=data)
     def _wrap_result(result):
         result = ReturnValue(result.json())
         if 'user_info_list' in result: result['errcode'] = 0
         return result
     r._wrap_result = _wrap_result
     return result
Esempio n. 22
0
def set_mute(muteList=[], cancelList=[], accessToken=None):
    l = []
    for status, userIdList in enumerate((cancelList, muteList)):
        for userId in userIdList:
            l.append({'userid': userId,
                'status': status, })
    data = {'user_mute_list': l}
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/chat/setmute?access_token=%s' % 
        (COMPANY_URL, accessToken), data=data).json()
    return ReturnValue(r)
Esempio n. 23
0
def set_mute(muteList=[], cancelList=[], accessToken=None):
    l = []
    for status, userIdList in enumerate((cancelList, muteList)):
        for userId in userIdList:
            l.append({'userid': userId,
                'status': status, })
    data = {'user_mute_list': l}
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/chat/setmute?access_token=%s' % 
        (COMPANY_URL, accessToken), data=data).json()
    return ReturnValue(r)
Esempio n. 24
0
def add_template(templateId, accessToken=None):
    ''' add template for your massive platform '''
    data = {'template_id_short': templateId}
    r = requests.post('%s/cgi-bin/template/api_add_template?access_token=%s' %
                      (SERVER_URL, accessToken),
                      data=encode_send_dict(data))

    def _wrap_result(result):
        return ReturnValue(result.json())

    r._wrap_result = _wrap_result
    return r
Esempio n. 25
0
def set_industry(id1, id2, accessToken=None):
    ''' set industry for your massive platform '''
    data = {'industry_id1': str(id1), 'industry_id2': str(id2)}
    r = requests.post('%s/cgi-bin/template/api_set_industry?access_token=%s' %
                      (SERVER_URL, accessToken),
                      data=encode_send_dict(data))

    def _wrap_result(result):
        return ReturnValue(result.json())

    r._wrap_result = _wrap_result
    return r
Esempio n. 26
0
def add_users_into_tag(id, userIdList=None, partyList=None, accessToken=None):
    if not userIdList:
        return ReturnValue({
            'errcode': 40035,
            'errmsg': 'must have one userId'
        })
    data = encode_send_dict({'openid_list': userIdList, 'tagid': id})
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/tags/members/batchtagging?access_token=%s' %
                      (SERVER_URL, accessToken),
                      data=data).json()
    return ReturnValue(r)
Esempio n. 27
0
    def _delete(accountDict, accessToken):
        data = encode_send_dict(accountDict)
        if data is None: return ReturnValue({'errcode': -10001})
        r = requests.post('%s/customservice/kfaccount/del?access_token=%s' %
                          (SERVER_URL, accessToken),
                          data=data)

        def _wrap_result(result):
            return ReturnValue(result.json())

        r._wrap_result = _wrap_result
        return r
Esempio n. 28
0
def create_news(newsDict, permanent=False, accessToken=None):
    if permanent:
        url = '%s/cgi-bin/material/add_news?access_token=%s'
    else:
        url = '%s/cgi-bin/media/uploadnews?access_token=%s'
    try:
        r = requests.post(url % (SERVER_URL, accessToken),
            data=encode_send_dict(newsDict)).json()
        if 'media_id' in r: r['errcode'] = 0
        return ReturnValue(r)
    except Exception as e:
        return ReturnValue({'errcode': -10001, 'errmsg': e.message})
Esempio n. 29
0
def upload(fileType, fileDir, additionalDict={}, permanent=False, accessToken=None):
    if additionalDict: # format additionalDict
        for key in ('description',):
            if key in additionalDict and isinstance(additionalDict[key], dict):
                for k, v in additionalDict[key].items():
                    if k not in additionalDict:
                        additionalDict[k] = v
        additionalDict = {k.lower().replace('_', ''): v
            for k, v in additionalDict.items()}
        if 'introduction' in additionalDict:
            additionalDict['description'] = additionalDict['introduction']
    if not fileType in (IMAGE, VOICE, VIDEO, THUMB):
        return ReturnValue({'errcode': 40004,})
    elif fileType == VIDEO and permanent and not ('title' in additionalDict
            and 'description' in additionalDict):
        return ReturnValue({'errcode': -10003, 'errmsg':
            'additionalDict for type VIDEO should be: ' +
            "{'Title' : 'title', 'Description' :'des'}"})
    try:
        with open(fileDir, 'rb') as f:
            file_ = f.read()
    except:
        return ReturnValue({'errcode': -10004,})
    fileName = 'file' + os.path.splitext(fileDir)[1]
    if hasattr(fileName, 'decode'):
        fileName = fileName.decode('utf8', 'replace')
    fileMime = mimetypes.guess_type(fileName)[0] or 'application/octet-stream'
    if permanent:
        url = '%s/cgi-bin/material/add_material?access_token=%s&type=%s'
    else:
        url = '%s/cgi-bin/media/upload?access_token=%s&type=%s' 
    files = {'media': (fileName, file_, fileMime), }
    if fileType == VIDEO and permanent:
        files['description'] = (None, encode_send_dict({
            'title': additionalDict['title'],
            'introduction': additionalDict['description'], }
            ), 'application/json')
    r = requests.post(url % (SERVER_URL, accessToken, fileType),
        files=files)
    def _wrap_result(result):
        result = ReturnValue(result.json())
        if 'media_id' in result:
            result['errcode'] = 0
        else:
            for k in result:
                if 'media_id' in k:
                    result['media_id'] = result[k]
                    result['errcode'] = 0
                    break
        return result
    r._wrap_result = _wrap_result
    return r
Esempio n. 30
0
def upload(fileType, fileDir, additionalDict={}, permanent=False, accessToken=None):
    if additionalDict: # format additionalDict
        for key in ('description',):
            if key in additionalDict and isinstance(additionalDict[key], dict):
                for k, v in additionalDict[key].items():
                    if k not in additionalDict:
                        additionalDict[k] = v
        additionalDict = {k.lower().replace('_', ''): v
            for k, v in additionalDict.items()}
        if 'introduction' in additionalDict:
            additionalDict['description'] = additionalDict['introduction']
    if not fileType in (IMAGE, VOICE, VIDEO, THUMB):
        return ReturnValue({'errcode': 40004,})
    elif fileType == VIDEO and permanent and not ('title' in additionalDict
            and 'description' in additionalDict):
        return ReturnValue({'errcode': -10003, 'errmsg':
            'additionalDict for type VIDEO should be: ' +
            "{'Title' : 'title', 'Description' :'des'}"})
    try:
        with open(fileDir, 'rb') as f:
            file_ = f.read()
    except:
        return ReturnValue({'errcode': -10004,})
    fileName = 'file' + os.path.splitext(fileDir)[1]
    if hasattr(fileName, 'decode'):
        fileName = fileName.decode('utf8', 'replace')
    fileMime = mimetypes.guess_type(fileName)[0] or 'application/octet-stream'
    if permanent:
        url = '%s/cgi-bin/material/add_material?access_token=%s&type=%s'
    else:
        url = '%s/cgi-bin/media/upload?access_token=%s&type=%s' 
    files = {'media': (fileName, file_, fileMime), }
    if fileType == VIDEO and permanent:
        files['description'] = (None, encode_send_dict({
            'title': additionalDict['title'],
            'introduction': additionalDict['description'], }
            ), 'application/json')
    r = requests.post(url % (SERVER_URL, accessToken, fileType),
        files=files)
    def _wrap_result(result):
        result = ReturnValue(result.json())
        if 'media_id' in result:
            result['errcode'] = 0
        else:
            for k in result:
                if 'media_id' in k:
                    result['media_id'] = result[k]
                    result['errcode'] = 0
                    break
        return result
    r._wrap_result = _wrap_result
    return r
Esempio n. 31
0
def user_id_open_id_switch(userId=None, openId=None, agentId=None, accessToken=None):
    data = {}
    if userId:
        data['userid'] = userId
        if agentId: data['agentid'] = agentId
        url = '%s/cgi-bin/user/convert_to_openid?access_token=' + accessToken
    elif openId:
        data['openid'] = openId
        url = '%s/cgi-bin/user/convert_to_userid?access_token=' + accessToken
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post(url % COMPANY_URL, data=data).json()
    return ReturnValue(r)
Esempio n. 32
0
def send_all(msgType, mediaId, additionalDict={}, tagId=None, accessToken=None):
    msgDict = __form_send_dict(msgType, mediaId, additionalDict)
    if not msgDict: return msgDict
    msgDict['touser']  = '******'
    msgDict['toparty'] = '@all'
    msgDict['totag']   = '@all'
    msgDict['agentid'] = agentId
    msgDict['safe']    = 0
    data = encode_send_dict(msgDict)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/message/send?access_token=%s' % 
        (COMPANY_URL, accessToken), data=data).json()
    return ReturnValue(r)
Esempio n. 33
0
def user_id_open_id_switch(userId=None, openId=None, agentId=None, accessToken=None):
    data = {}
    if userId:
        data['userid'] = userId
        if agentId: data['agentid'] = agentId
        url = '%s/cgi-bin/user/convert_to_openid?access_token=' + accessToken
    elif openId:
        data['openid'] = openId
        url = '%s/cgi-bin/user/convert_to_userid?access_token=' + accessToken
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post(url % COMPANY_URL, data=data).json()
    return ReturnValue(r)
Esempio n. 34
0
def send(msgType, mediaId, additionalDict={}, senderId=None,
        userId=None, chatId=None, accessToken=None):
    msgDict = __form_send_dict(msgType, mediaId, additionalDict)
    if not msgDict: return msgDict
    msgDict['receiver'] = {
        'type': 'single' if userId else 'group',
        'id': userId or chatId, }
    msgDict['sender'] = senderId
    data = encode_send_dict(msgDict)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/chat/send?access_token=%s' % 
        (COMPANY_URL, accessToken), data=data).json()
    return ReturnValue(r)
Esempio n. 35
0
    def _delete_users_of_blacklist(userId, accessToken=None):
        data = {'openid_list': userId}
        data = encode_send_dict(data)
        r = requests.post(
            '%s/cgi-bin/tags/members/batchunblacklist?access_token=%s' %
            (SERVER_URL, accessToken),
            data=data)

        def _wrap_result(result):
            return ReturnValue(result.json())

        r._wrap_result = _wrap_result
        return r
Esempio n. 36
0
def long_url_to_short(url, accessToken=None):
    data = {'action': 'long2short', 'long_url': url}
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/shorturl?access_token=%s' %
                      (SERVER_URL, accessToken),
                      data=data)

    def _wrap_result(result):
        return ReturnValue(result.json())

    r._wrap_result = _wrap_result
    return r
Esempio n. 37
0
def set_alias(userId, alias, accessToken=None):
    ''' this method is for verified service mp only '''
    data = encode_send_dict({'openid': userId, 'remark': alias})
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/user/info/updateremark?access_token=%s' %
                      (SERVER_URL, accessToken),
                      data=data)

    def _wrap_result(result):
        return ReturnValue(result.json())

    r._wrap_result = _wrap_result
    return r
Esempio n. 38
0
def get_users_of_tag(id, nextOpenId='', accessToken=None):
    data = encode_send_dict({'tagid': id, 'next_openid': nextOpenId})
    if data is None:
        return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/user/tag/get?access_token=%s'
        % (SERVER_URL, accessToken), data=data)
    def _wrap_result(result):
        result = ReturnValue(result.json())
        if 'count' in result:
            result['errcode'] = 0
        return result
    r._wrap_result = _wrap_result
    return r
Esempio n. 39
0
    def _create(menuDict, agentId=None, accessToken=None):
        data = encode_send_dict(menuDict)
        if data is None: return ReturnValue({'errcode': -10001})
        url = '%s/cgi-bin/menu/create?access_token=%s' % \
            (serverUrl, accessToken)
        if agentId is not None: url += '&agentid=%s' % agentId
        r = requests.post(url, data=data)

        def _wrap_result(result):
            return ReturnValue(result.json())

        r._wrap_result = _wrap_result
        return r
Esempio n. 40
0
def send(msgType, mediaId, additionalDict={}, senderId=None,
        userId=None, chatId=None, accessToken=None):
    msgDict = __form_send_dict(msgType, mediaId, additionalDict)
    if not msgDict: return msgDict
    msgDict['receiver'] = {
        'type': 'single' if userId else 'group',
        'id': userId or chatId, }
    msgDict['sender'] = senderId
    data = encode_send_dict(msgDict)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/chat/send?access_token=%s' % 
        (COMPANY_URL, accessToken), data=data).json()
    return ReturnValue(r)
Esempio n. 41
0
def addconditional(menuDict, accessToken=None):
    if not ('button' in menuDict and 'matchrule' in menuDict):
        return ReturnValue({'errcode': 40035})
    data = encode_send_dict(menuDict)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/menu/addconditional?access_token=%s' % (
        SERVER_URL, accessToken), data=data)
    def _wrap_result(result):
        result = ReturnValue(result.json())
        if 'menuid' in result: result['errcode'] = 0
        return result
    r._wrap_result = _wrap_result
    return r
Esempio n. 42
0
def update_news(mediaId, newsDict, index=0, accessToken=None):
    data = {
        'media_id': mediaId,
        'index': index,
        'articles': newsDict, }
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/material/update_news?access_token=%s' %
        (SERVER_URL, accessToken), data=data)
    def _wrap_result(result):
        return ReturnValue(result.json())
    r._wrap_result = _wrap_result
    return r
Esempio n. 43
0
def create_news(newsDict, permanent=False, accessToken=None):
    if permanent:
        url = '%s/cgi-bin/material/add_news?access_token=%s'
    else:
        url = '%s/cgi-bin/media/uploadnews?access_token=%s'
    r = requests.post(url % (SERVER_URL, accessToken),
        data=encode_send_dict(newsDict))
    def _wrap_result(result):
        result = ReturnValue(result.json())
        if 'media_id' in result: result['errcode'] = 0
        return result
    r._wrap_result = _wrap_result
    return r
Esempio n. 44
0
def batchget_material(fileType, offset=0, count=20, accessToken=None):
    if not fileType in (IMAGE, VOICE, VIDEO, THUMB):
        return ReturnValue({'errcode': 40004,})
    if 20 < count: count = 20
    data = {'type': fileType,
        'offset': offset,
        'count': count, }
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/material/batchget?access_token=%s'
        % (SERVER_URL, accessToken), data=data).json()
    if 'total_count' in r: r['errcode'] = 0
    return ReturnValue(r)
Esempio n. 45
0
def create_news(newsDict, permanent=False, accessToken=None):
    if permanent:
        url = '%s/cgi-bin/material/add_news?access_token=%s'
    else:
        url = '%s/cgi-bin/media/uploadnews?access_token=%s'
    r = requests.post(url % (SERVER_URL, accessToken),
        data=encode_send_dict(newsDict))
    def _wrap_result(result):
        result = ReturnValue(result.json())
        if 'media_id' in result: result['errcode'] = 0
        return result
    r._wrap_result = _wrap_result
    return r
Esempio n. 46
0
def update_news(mediaId, newsDict, index=0, accessToken=None):
    data = {
        'media_id': mediaId,
        'index': index,
        'articles': newsDict, }
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/material/update_news?access_token=%s' %
        (SERVER_URL, accessToken), data=data)
    def _wrap_result(result):
        return ReturnValue(result.json())
    r._wrap_result = _wrap_result
    return r
Esempio n. 47
0
def create_department(name, parentId=1, order=None, id=None, accessToken=None):
    data = {
        'name': name,
        'parentid': parentId,
    }
    if order is not None: data['order'] = order
    if id is not None: data['id'] = id
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/department/create?access_token=%s' %
                      (COMPANY_URL, accessToken),
                      data=data).json()
    return ReturnValue(r)
Esempio n. 48
0
def delete_templates(templateId, accessToken=None):
    ''' delete template of your massive platform '''
    data = {'template_id': templateId}
    r = requests.post(
        '%s/cgi-bin/template/del_private_template?access_token=%s' %
        (SERVER_URL, accessToken),
        data=encode_send_dict(data))

    def _wrap_result(result):
        return ReturnValue(result.json())

    r._wrap_result = _wrap_result
    return r
Esempio n. 49
0
        def __fn_producer(startTime, endTime, accessToken=None):
            data = {'begin_date': startTime, 'end_date': endTime}
            data = encode_send_dict(data)
            r = requests.post('%s/datacube/%s?access_token=%s' %
                              (SERVER_URL, fnName, accessToken),
                              data=data)

            def _wrap_result(result):
                result = ReturnValue(result.json())
                if 'list' in result: result['errcode'] = 0
                return result

            r._wrap_result = _wrap_result
            return r
Esempio n. 50
0
def send_some(msgType, mediaId, additionalDict={},
        targetIdList=[], partyIdList=[], tagIdList=[],
        agentId=None, accessToken=None):
    msgDict = __form_send_dict(msgType, mediaId, additionalDict)
    if not msgDict: return msgDict
    if not isinstance(targetIdList, list) or len(targetIdList) < 2:
        return ReturnValue({'errcode': 40130})
    msgDict['touser'] = targetIdList
    r = requests.post('%s/cgi-bin/message/mass/send?access_token=%s' % 
        (SERVER_URL, accessToken), data=encode_send_dict(msgDict))
    def _wrap_result(result):
        return ReturnValue(result.json())
    r._wrap_result = _wrap_result
    return r
Esempio n. 51
0
def send_some(msgType, mediaId, additionalDict={},
        targetIdList=[], partyIdList=[], tagIdList=[],
        agentId=None, accessToken=None):
    msgDict = __form_send_dict(msgType, mediaId, additionalDict)
    if not msgDict: return msgDict
    if not isinstance(targetIdList, list) or len(targetIdList) < 2:
        return ReturnValue({'errcode': 40130})
    msgDict['touser'] = targetIdList
    r = requests.post('%s/cgi-bin/message/mass/send?access_token=%s' % 
        (SERVER_URL, accessToken), data=encode_send_dict(msgDict))
    def _wrap_result(result):
        return ReturnValue(result.json())
    r._wrap_result = _wrap_result
    return r
Esempio n. 52
0
def create(chatId, name, ownerId, userIdList, accessToken=None):
    if ownerId not in userIdList:
        return ReturnValue({'errcode': -10003, 'errmsg':
            'owner should be in userIdList'})
    data = {
        'chatid': chatId,
        'name': name,
        'owner': ownerId,
        'userlist': userIdList, }
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/chat/create?access_token=%s' % 
        (COMPANY_URL, accessToken), data=data).json()
    return ReturnValue(r)
Esempio n. 53
0
def batchget_material(fileType, offset=0, count=20, accessToken=None):
    if not fileType in (NEWS, IMAGE, VOICE, VIDEO, FILE):
        return ReturnValue({'errcode': 40004,})
    if fileType == NEWS: fileType = 'mpnews'
    if 50 < count: count = 50
    data = {'type': fileType,
        'offset': offset,
        'count': count, }
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/material/batchget?access_token=%s'
        % (COMPANY_URL, accessToken), data=data).json()
    if 'itemlist' in r: r['errcode'] = 0
    return ReturnValue(r)
Esempio n. 54
0
def clear_notify(ownerId, chatId=None, userId=None, accessToken=None):
    data = {
        'op_user': ownerId,
        'chat': {
            'type': 'group' if chatId else 'single',
            'id': chatId or userId,
        }
    }
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/chat/clearnotify?access_token=%s' %
                      (COMPANY_URL, accessToken),
                      data=data).json()
    return ReturnValue(r)
Esempio n. 55
0
 def _batch_get_user_info(userId, accessToken=None):
     data = {
         'user_list': [{
             'openid': id,
             'lang': 'zh-CN'
         } for id in userId]
     }
     data = encode_send_dict(data)
     if data is None: return ReturnValue({'errcode': -10001})
     r = requests.post('%s/cgi-bin/user/info/batchget?access_token=%s' %
                       (SERVER_URL, accessToken),
                       data=data).json()
     if 'user_info_list' in r: r['errcode'] = 0
     return ReturnValue(r)
Esempio n. 56
0
def send(msgType, mediaId, additionalDict={}, toUserId='', accessToken=None):
    msgDict = __form_send_dict(msgType, mediaId, additionalDict)
    if not msgDict:
        return msgDict
    msgDict['touser'] = toUserId
    data = encode_send_dict(msgDict)
    if data is None:
        return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/message/custom/send?access_token=%s'
        % (SERVER_URL, accessToken), data=data)
    def _wrap_result(result):
        return ReturnValue(result.json())
    r._wrap_result = _wrap_result
    return r
Esempio n. 57
0
def get_tags_of_user(userId, accessToken=None):
    data = encode_send_dict({'openid': userId})
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/tags/getidlist?access_token=%s' %
                      (SERVER_URL, accessToken),
                      data=data)

    def _wrap_result(result):
        result = ReturnValue(result.json())
        if 'tagid_list' in result: result['errcode'] = 0
        return result

    r._wrap_result = _wrap_result
    return r
Esempio n. 58
0
def get_blacklist(beginOpenId='', accessToken=None):
    data = {'begin_openid': beginOpenId}
    data = encode_send_dict(data)
    r = requests.post('%s/cgi-bin/tags/members/getblacklist?access_token=%s' %
                      (SERVER_URL, accessToken),
                      data=data)

    def _wrap_result(result):
        result = ReturnValue(result.json())
        if 'data' in result: result['errcode'] = 0
        return result

    r._wrap_result = _wrap_result
    return r
Esempio n. 59
0
def delete_users_of_tag(id, userIdList=None, partyList=None, accessToken=None):
    if not (userIdList or partyList):
        return ReturnValue({'errcode': 40035,
            'errmsg': 'either userId or partyList should be set'})
    data = {'tagid': id}
    if userIdList:
        data['userlist'] = userIdList
    if partyList:
        data['partylist'] = partyList
    data = encode_send_dict(data)
    if data is None: return ReturnValue({'errcode': -10001})
    r = requests.post('%s/cgi-bin/tag/deltagusers?access_token=%s'
        % (COMPANY_URL, accessToken), data=data).json()
    if 'invalidlist' in r or 'invalidparty' in r: r['errcode'] = 40070
    return ReturnValue(r)