Example #1
0
def api_msg_list(request):
    """
        获取指定channel的所有消息(分页)
        channel_code last_msg_id page_size user_id
    """
    payload = {
        'function_name':
        'get_msg_list',
        'parameter':
        json.dumps(
            {
                'user_id': str(request.user.id),
                'last_msg_id': request.POST.get('last_msg_id', '0'),
                'page_size': request.POST.get('page_size', '10'),
                'channel_code': request.POST.get('channel', ''),
            },
            ensure_ascii=False)
    }
    try:
        remote_response = _remote_call(payload)
    except Exception as e:
        logger.exception(e)
        return helper.response200({
            'c': ERR_CODE_CONNECT_MSG_CENTER_FAIL,
            'm': ERR_MSG_CONNECT_MSG_CENTER_FAIL
        })
    return remote_response
Example #2
0
def send_msg(recipients, category, content, api_version='1'):
    """
        向消息中心发送消息
        suggest: use celery task to send msg
    """
    if not category or not content:
        logger.error('try to send message but without category or content')
        return helper.response200({'c': ERR_CODE_WRONG_MSG_FORMAT, 'm': ERR_MSG_WRONG_MSG_FORMAT})
    payload = {
        'function_name': 'create_msg',
        'parameter': json.dumps({
            'api_version': api_version,
            'recipients': recipients,   # format: account_id,user_type,school_id, e.g. 2,2,1;2,2,1;2,2,1
            'category_code': category,
            'content': json.dumps(content, ensure_ascii=False),
        }, ensure_ascii=False)
    }
    try:
        logger.info('send message to message_center:')
        logger.info(payload)
        remote_response = _remote_call(payload)
    except Exception as e:
        logger.exception(e)
        return helper.response200({'c': ERR_CODE_CONNECT_MSG_CENTER_FAIL, 'm': ERR_MSG_CONNECT_MSG_CENTER_FAIL})
    logger.info('message_center return response:')
    logger.info(remote_response)
    # remote_response  e.g:
    # {'tracking_num': str(tracking.id)}
    return remote_response
Example #3
0
def api_msg_delete(request):
    payload = {
        'function_name':
        'delete_msg',
        'parameter':
        json.dumps(
            {
                'msg_id': request.POST.get('msg_id', ''),
                'user_id': str(request.user.id),
            },
            ensure_ascii=False)
    }
    try:
        remote_response = _remote_call(payload)
    except Exception as e:
        logger.exception(e)
        return helper.response200({
            'c': ERR_CODE_CONNECT_MSG_CENTER_FAIL,
            'm': ERR_MSG_CONNECT_MSG_CENTER_FAIL
        })
    return remote_response
Example #4
0
def api_msg_overview(request):
    """
        获取个人消息概览
    """
    payload = {
        'function_name':
        'overview',
        'parameter':
        json.dumps({
            'user_id': str(request.user.id),
        }, ensure_ascii=False)
    }
    try:
        remote_response = _remote_call(payload)
    except Exception as e:
        logger.exception(e)
        return helper.response200({
            'c': ERR_CODE_CONNECT_MSG_CENTER_FAIL,
            'm': ERR_MSG_CONNECT_MSG_CENTER_FAIL
        })
    return remote_response