Exemplo n.º 1
0
def handle_system_message(msg):
    obj = json.loads(msg)
    appid = obj["appid"]
    receiver = obj["receiver"]

    appname = get_title(appid)
    try:
        content_obj = json.loads(obj.get('content'))
        voip_content = content_obj.get('voip_push')
        content = content_obj.get('push')
        if not voip_content and not content:
            return
        sound = content_obj.get('sound', 'default')
    except Exception as e:
        logging.info("exception:%s", e)
        return

    u = user.get_user(rds, appid, receiver)
    if u is None:
        logging.info("uid:%d nonexist", receiver)
        return

    #找出最近绑定的token
    ts = max(u.apns_timestamp, u.xg_timestamp, u.ng_timestamp, u.mi_timestamp,
             u.hw_timestamp, u.gcm_timestamp, u.ali_timestamp)

    if u.apns_device_token and u.apns_timestamp == ts:
        if voip_content and u.pushkit_device_token:
            IOSPush.voip_push(appid, u.pushkit_device_token, voip_content)
        elif content:
            IOSPush.push(appid,
                         u.apns_device_token,
                         content,
                         sound=sound,
                         badge=u.unread + 1)
            user.set_user_unread(rds, appid, receiver, u.unread + 1)
        return

    if not content:
        return

    if u.mi_device_token and u.mi_timestamp == ts:
        MiPush.push_message(appid, u.mi_device_token, content)
    elif u.hw_device_token and u.hw_timestamp == ts:
        HuaWeiPush.push_message(appid, u.hw_device_token, content)
    else:
        logging.info("uid:%d has't device token", receiver)
Exemplo n.º 2
0
    except Exception, e:
        logging.info("exception:%s", e)
        return

    u = user.get_user(rds, appid, receiver)
    if u is None:
        logging.info("uid:%d nonexist", receiver)
        return

    #找出最近绑定的token
    ts = max(u.apns_timestamp, u.xg_timestamp, u.ng_timestamp, u.mi_timestamp,
             u.hw_timestamp, u.gcm_timestamp, u.ali_timestamp)

    if u.apns_device_token and u.apns_timestamp == ts:
        if voip_content and u.pushkit_device_token:
            IOSPush.voip_push(appid, u.pushkit_device_token, voip_content)
        elif content:
            IOSPush.push(appid,
                         u.apns_device_token,
                         content,
                         sound=sound,
                         badge=u.unread + 1)
            user.set_user_unread(rds, appid, receiver, u.unread + 1)
        return

    if not content:
        return

    if u.mi_device_token and u.mi_timestamp == ts:
        MiPush.push_message(appid, u.mi_device_token, content)
    elif u.hw_device_token and u.hw_timestamp == ts:
Exemplo n.º 3
0
def ios_voip_push(appid, token, extra):
    IOSPush.voip_push(appid, token, extra)