예제 #1
0
파일: client.py 프로젝트: zeus911/kpush
def login():
    req = dict(
        uid=199,
        key='4b91e0cd5d534a8c9cb41d2517415260',
    )
    worker_client.write(dict(cmd=proto.CMD_LOGIN, body=pack_data(req)))

    box = worker_client.read()
    print 'box:', box
    if not box:
        return False

    # worker_client.write(dict(
    #     cmd=proto.CMD_SET_ALIAS_AND_TAGS,
    #     body=pack_data(dict(
    #         alias='dante',
    #     ))
    # ))
    #
    # box = worker_client.read()
    # print 'box:', box
    # if not box:
    #     return False

    return True
예제 #2
0
파일: user.py 프로젝트: hongzhu007/kpush
def register(request):
    """
    (未使用)注册
    :param request:
    :return:
    """
    appinfo = get_appinfo_by_appkey(request.json_data["appkey"])

    if appinfo is None:
        # 报错
        request.write_to_client(dict(ret=proto.RET_INVALID_PARAMS))
        return

    user = create_or_update_user(
        dict(
            appid=appinfo["appid"],
            channel=request.json_data["channel"],
            device_id=request.json_data["device_id"],
            device_name=request.json_data.get("device_name"),
            os=request.json_data.get("os"),
            os_version=request.json_data.get("os_version"),
            sdk_version=request.json_data.get("sdk_version"),
        )
    )

    rsp = dict(uid=user["uid"])

    request.login_client(rsp["uid"])

    request.write_to_client(dict(ret=0, body=pack_data(rsp)))
예제 #3
0
파일: trigger.py 프로젝트: Ladyia/kpush
def test_notification():
    trigger.write_to_users((
        ((-1, ), dict(cmd=1000, body=pack_data(dict(
            title=u'我是标题',
            content=u'我是内容',
        )))),
    ))
예제 #4
0
def test_notification():
    trigger.write_to_users(
        (((-1, ),
          dict(cmd=1000,
               body=pack_data(dict(
                   title=u'我是标题',
                   content=u'我是内容',
               )))), ))
예제 #5
0
    def push_notification(self, title, content, appid, query, silent=None):
        """
        发送通知
        :param title: 标题
        :param content: 内容
        :param appid: 如果有appid就直接用
        :param silent: 不弹出
        :param query 为{}代表不过滤
            alias: 为None代表不过滤
            tags_or: [
                ["x", "y", "z"],
                ["a", "b", "c"],
            ]
        即顶上一层使用 or,底下那层是and
        :return:
        """

        silent = silent or False

        match_uids = self.find_match_uids(appid, query)

        # 保存消息
        notification_id = self.save_notification(dict(
            title=title,
            content=content,
            appid=appid,
            silent=silent,
            query=query,
        ),
            dst_users_count=len(match_uids),
        )

        if not match_uids:
            return notification_id, match_uids

        # 要对uids分组
        uids_list = [[] for it in range(0, len(kit.triggers))]

        for uid in match_uids:
            i = uid % len(uids_list)
            uids_list[i].append(uid)

        for i, uids in enumerate(uids_list):
            if not uids:
                continue
            kit.triggers[i].write_to_users([
                [uids, dict(
                    cmd=proto.EVT_NOTIFICATION,
                    body=pack_data(dict(
                        id=notification_id,
                        title=title,
                        content=content,
                        silent=silent,
                    ))
                )],
            ])

        return notification_id, match_uids
예제 #6
0
파일: client.py 프로젝트: zeus911/kpush
def test_alloc_server():
    # url = 'http://115.28.224.64:7555/server/alloc'
    url = 'http://127.0.0.1:5000/server/alloc'

    post_body = pack_data(
        dict(
            appkey='7d357c9b4ce1414fb27f077b54fb5a8f',
            channel='M',
            device_id='23423',
            device_name='fefer',
        ))

    rsp = requests.post(url, post_body)

    print rsp.text
예제 #7
0
파일: client.py 프로젝트: Ladyia/kpush
def test_alloc_server():
    # url = 'http://115.28.224.64:7555/server/alloc'
    url = 'http://127.0.0.1:5000/server/alloc'

    post_body = pack_data(
        dict(
            appkey='7d357c9b4ce1414fb27f077b54fb5a8f',
            channel='M',
            device_id='23423',
            device_name='fefer',
        )
    )

    rsp = requests.post(url, post_body)

    print rsp.text
예제 #8
0
파일: frontend.py 프로젝트: Ladyia/kpush
def alloc_server():
    """
    # 方便测试
    if not request.json_data:
        return jsonify(
            ret=proto.RET_INVALID_PARAMS
        )
    """

    appinfo = get_appinfo_by_appkey(request.json_data['appkey'])
    logger.debug("appinfo: %s", appinfo)

    if appinfo is None:
        # 报错
        jsonify(
            ret=proto.RET_INVALID_PARAMS
        )
        return

    user = create_or_update_user(dict(
        appid=appinfo['appid'],
        channel=request.json_data['channel'],
        device_id=request.json_data['device_id'],
        device_name=request.json_data.get('device_name'),
        os=request.json_data.get('os'),
        os_version=request.json_data.get('os_version'),
        sdk_version=request.json_data.get('sdk_version'),
    ))

    server_list = current_app.config['SERVER_LIST']

    # 取模
    server = server_list[user['uid'] % len(server_list)]

    return current_app.response_class(pack_data(
        dict(
            ret=0,
            user=dict(
                uid=user['uid'],
                key=user['key'],
            ),
            server=dict(
                host=server['outer_host'],
                port=server['outer_port'],
            )
        )
    ), mimetype='application/json')
예제 #9
0
파일: client.py 프로젝트: hongzhu007/kpush
def login():
    req = dict(uid=199, key="4b91e0cd5d534a8c9cb41d2517415260")
    worker_client.write(dict(cmd=proto.CMD_LOGIN, body=pack_data(req)))

    box = worker_client.read()
    print "box:", box
    if not box:
        return False

    # worker_client.write(dict(
    #     cmd=proto.CMD_SET_ALIAS_AND_TAGS,
    #     body=pack_data(dict(
    #         alias='dante',
    #     ))
    # ))
    #
    # box = worker_client.read()
    # print 'box:', box
    # if not box:
    #     return False

    return True
예제 #10
0
def register(request):
    """
    (未使用)注册
    :param request:
    :return:
    """
    appinfo = get_appinfo_by_appkey(request.json_data['appkey'])

    if appinfo is None:
        # 报错
        request.write_to_client(
            dict(
                ret=proto.RET_INVALID_PARAMS
            )
        )
        return

    user = create_or_update_user(dict(
        appid=appinfo['appid'],
        channel=request.json_data['channel'],
        device_id=request.json_data['device_id'],
        device_name=request.json_data.get('device_name'),
        os=request.json_data.get('os'),
        os_version=request.json_data.get('os_version'),
        sdk_version=request.json_data.get('sdk_version'),
    ))

    rsp = dict(
        uid=user['uid'],
    )

    request.login_client(rsp['uid'])

    request.write_to_client(dict(
        ret=0,
        body=pack_data(rsp)
    ))