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
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)))
def test_notification(): trigger.write_to_users(( ((-1, ), dict(cmd=1000, body=pack_data(dict( title=u'我是标题', content=u'我是内容', )))), ))
def test_notification(): trigger.write_to_users( (((-1, ), dict(cmd=1000, body=pack_data(dict( title=u'我是标题', content=u'我是内容', )))), ))
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
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
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
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')
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
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) ))