Exemplo n.º 1
0
def test_pushMessage_to_tag():
    c = BaiduPush(apikey, secretkey)
    push_type = BaiduPush.PUSH_TO_TAG
    tag_name = 'push'
    optional = dict()
    optional[BaiduPush.TAG_NAME] = tag_name
    ret = c.push_msg(push_type, message, message_key, optional)
    print ret
Exemplo n.º 2
0
def test_pushMessage_to_tag():
    c = BaiduPush(apikey, secretkey)
    push_type = BaiduPush.PUSH_TO_TAG
    tag_name = 'push'
    optional = dict()
    optional[BaiduPush.TAG_NAME] = tag_name
    ret = c.push_msg(push_type, message, message_key, optional)
    print ret
Exemplo n.º 3
0
def test_pushMessage_to_user():
    c = BaiduPush(apikey, secretkey)
    push_type = BaiduPush.PUSH_TO_USER
    optional = dict()
    optional[BaiduPush.USER_ID] = user_id
    optional[BaiduPush.CHANNEL_ID] = channel_id
    # 推送通知类型
    optional[BaiduPush.MESSAGE_TYPE] = BaiduPush.PUSH_NOTIFICATION
    ret = c.push_msg(push_type, message, message_key, optional)
    print ret
Exemplo n.º 4
0
def test_pushMessage_to_user():
    c = BaiduPush(apikey, secretkey)
    push_type = BaiduPush.PUSH_TO_USER
    optional = dict()
    optional[BaiduPush.USER_ID] = user_id
    optional[BaiduPush.CHANNEL_ID] = channel_id
    # 推送通知类型
    optional[BaiduPush.MESSAGE_TYPE] = BaiduPush.PUSH_NOTIFICATION
    ret = c.push_msg(push_type, message, message_key, optional)
    print ret
Exemplo n.º 5
0
def send_toggle_notification(user, device, address):
    """
    """
    message = "Your device is toggled."

    gcm_devices = GCMDevice.objects.filter(user=device.user)
    gcm_devices.send_message(message=message, extra={"address": device.address.replace(' ', ':'), "username": user.username})


    c = BaiduPush(apikey, secretkey)
    push_type = BaiduPush.PUSH_TO_USER
    optional = dict()
    optional[BaiduPush.USER_ID] = user_id
    optional[BaiduPush.CHANNEL_ID] = channel_id
    optional[BaiduPush.MESSAGE_TYPE] = BaiduPush.PUSH_NOTIFICATION
    ret = c.push_msg(push_type, message=={"address": device.address.replace(' ', ':'), "username": user.username}, message_key, optional)

    ToggleHistory.objects.create(user=user, address=address)
Exemplo n.º 6
0
def send_toggle_notification(user, device, address):
    """
    """
    message1 = "Your device is toggled.(GCM)"
    message2 = "Your device is toggled.(Baidu)"

    numb = random.randint(100, 10000)
    ToggleHistory.objects.create(user=user, address=address)
    dev_usr = device.user
    gcm_devices = GCMDevice.objects.filter(user=dev_usr)
    gcm_devices.send_message(message=message1,
                             extra={
                                 "address": device.address.replace(' ', ':'),
                                 "username": user.username,
                                 "numb": str(numb)
                             })

    bdu_devices = BaiduDevice.objects.filter(user=dev_usr).values(
        'buser_id', 'bchannel_id').first()
    #bdu_devices.send_message(message=message2, extra={"address": device.address.replace(' ', ':'), "username": user.username})

    if not bdu_devices:
        return
    c = BaiduPush(apikey, secretkey)
    push_type = BaiduPush.PUSH_TO_USER
    optional = dict()
    userID = bdu_devices['buser_id']
    channelID = bdu_devices['bchannel_id']
    optional[BaiduPush.USER_ID] = userID
    optional[BaiduPush.CHANNEL_ID] = channelID
    optional[
        BaiduPush.MESSAGE_TYPE] = BaiduPush.PUSH_MESSAGE  #PUSH_NOTIFICATION
    #optional[BaiduPush.MESSAGE_TYPE] = BaiduPush.PUSH_NOTIFICATION

    allmsg = message2 + "%%" + device.address.replace(
        ' ', ':') + "%%" + user.username + "%%" + str(numb)
    #allmsg = "{'title':'baidu push','description':'message from python sdk'}"
    ret = c.push_msg(push_type, allmsg, message_key, optional)
    sleep(0.3)
    ret = c.push_msg(push_type, allmsg, message_key, optional)
    sleep(0.3)
    ret = c.push_msg(push_type, allmsg, message_key, optional)
Exemplo n.º 7
0
def test_fetchTag():
    c = BaiduPush(apikey, secretkey)
    ret = c.fetch_tag()
    print ret
Exemplo n.º 8
0
def test_deleteMessage():
    c = BaiduPush(apikey, secretkey)
    msg_id = "111"
    ret = c.delete_msg(user_id, msg_id)
    print ret
Exemplo n.º 9
0
def test_fetchMessage():
    c = BaiduPush(apikey, secretkey)
    ret = c.fetch_msg(user_id)
    print ret
Exemplo n.º 10
0
def test_verifyBind():
    c = BaiduPush(apikey, secretkey)
    optional = dict()
    optional[BaiduPush.DEVICE_TYPE] = BaiduPush.DEVICE_ANDRIOD
    ret = c.verify_bind(user_id, optional)
    print ret
Exemplo n.º 11
0
def test_queryBindList():
    c = BaiduPush(apikey, secretkey)
    optional = dict()
    optional[BaiduPush.CHANNEL_ID] = channel_id
    ret = c.query_bindlist(user_id, optional)
    print ret
Exemplo n.º 12
0
def test_fetchMessage():
    c = BaiduPush(apikey, secretkey)
    ret = c.fetch_msg(user_id)
    print ret
Exemplo n.º 13
0
def test_queryDeviceType():
    c = BaiduPush(apikey, secretkey)
    ret = c.query_device_type(channel_id)
    print ret
Exemplo n.º 14
0
def test_queryBindList():
    c = BaiduPush(apikey, secretkey)
    optional = dict()
    optional[BaiduPush.CHANNEL_ID] = channel_id
    ret = c.query_bindlist(user_id, optional)
    print ret
Exemplo n.º 15
0
def test_queryDeviceType():
    c = BaiduPush(apikey, secretkey)
    ret = c.query_device_type(channel_id)
    print ret
Exemplo n.º 16
0
def test_queryUserTag():
    c = BaiduPush(apikey, secretkey)
    ret = c.query_user_tag(user_id)
    print ret
Exemplo n.º 17
0
def test_deleteTag():
    c = BaiduPush(apikey, secretkey)
    optional = dict()
    optional[BaiduPush.USER_ID] = user_id
    ret = c.delete_tag(tagname, optional)
    print ret
Exemplo n.º 18
0
def test_fetchTag():
    c = BaiduPush(apikey, secretkey)
    ret = c.fetch_tag()
    print ret
Exemplo n.º 19
0
def test_deleteMessage():
    c = BaiduPush(apikey, secretkey)
    msg_id = "111"
    ret = c.delete_msg(user_id, msg_id)
    print ret
Exemplo n.º 20
0
def test_deleteTag():
    c = BaiduPush(apikey, secretkey)
    optional = dict()
    optional[BaiduPush.USER_ID] = user_id
    ret = c.delete_tag(tagname, optional)
    print ret
Exemplo n.º 21
0
def test_queryUserTag():
    c = BaiduPush(apikey, secretkey)
    ret = c.query_user_tag(user_id)
    print ret
Exemplo n.º 22
0
def test_pushMessage_to_all():
    c = BaiduPush(apikey, secretkey)
    push_type = BaiduPush.PUSH_TO_ALL
    optional = dict()
    ret = c.push_msg(push_type, message, message_key, optional)
    print ret
Exemplo n.º 23
0
def test_pushMessage_to_all():
    c = BaiduPush(apikey, secretkey)
    push_type = BaiduPush.PUSH_TO_ALL
    optional = dict()
    ret = c.push_msg(push_type, message, message_key, optional)
    print ret
Exemplo n.º 24
0
def test_verifyBind():
    c = BaiduPush(apikey, secretkey)
    optional = dict()
    optional[BaiduPush.DEVICE_TYPE] = BaiduPush.DEVICE_ANDRIOD
    ret = c.verify_bind(user_id, optional)
    print ret