Example #1
0
def send_push_android_data_message():
    """
    a sample to show hwo to send web push message
    :return:
    """
    message = messaging.Message(
        data="""
        {
          "pushtype": 0,
          "pushbody": {
            "title": "Welcome to use Huawei HMS Push Kit?",
            "description": "One of the best push platform on the planet!!!",
            "page": "/",
            "params": {
              "key1": "test1",
              "key2": "test2"
            },
            "ringtone": {
              "vibration": "true",
              "breathLight": "true"
            }
          }
        }
        """,
        android=android,
        token=[push_env.test_device_token]
    )

    try:
        response = messaging.send_message(message)
        print("response is ", json.dumps(vars(response)))
        assert (response.code == '80000000')
    except Exception as e:
        print(repr(e))
Example #2
0
def send_push_android_data_message():
    """
    a sample to show hwo to send web push message
    :return:
    """
    message = messaging.Message(
        # English sample
        # data = "{\"pushtype\":0,\"pushbody\":{\"title\":\"Welcome to use Huawei HMS Push Kit?\",\"description\":\"One "
        #       + "of the best push platform on the planet!!!\",\"page\":\"/\",\"params\":{\"key1\":\"test1\",\"key2\":\"test2\"},\"ringtone\":"
        #       + "{\"vibration\":\"true\",\"breathLight\":\"true\"}}}",
        # Chinese sample
        data = "{\"pushtype\":0,\"pushbody\":{\"title\":\"欢迎使用华为HMS Push Kit!\",\"description\":\"世界上最好,"
              + "最优秀的推送平台!!!\",\"page\":\"/\",\"params\":{\"key1\":\"test1\",\"key2\":\"test2\"},\"ringtone\":"
              + "{\"vibration\":\"true\",\"breathLight\":\"true\"}}}",
        android=android,
        # TODO
        token=['your token']
    )

    try:
        # Case 1: Local CA sample code
        # response = messaging.send_message(message, verify_peer="../Push-CA-Root.pem")
        # Case 2: No verification of HTTPS's certificate
        response = messaging.send_message(message)
        # Case 3: use certifi Library
        # import certifi
        # response = messaging.send_message(message, verify_peer=certifi.where())
        print "response is ", json.dumps(vars(response))
        assert (response.code == '80000000')
    except Exception as e:
        print repr(e)
Example #3
0
def send_push_android_data_message():
    """
    a sample to show how to send web push message
    :return:
    """
    message = messaging.Message(
        # English sample
        # data = "{\"pushtype\":0,\"pushbody\":{\"title\":\"Welcome to use Huawei HMS Push Kit?\",\"description\":\"One "
        #       + "of the best push platform on the planet!!!\",\"page\":\"/\",\"params\":{\"key1\":\"test1\",\"key2\":\"test2\"},\"ringtone\":"
        #       + "{\"vibration\":\"true\",\"breathLight\":\"true\"}}}",
        # Chinese sample
        data=
        "{\"pushtype\":0,\"pushbody\":{\"title\":\"欢迎使用华为HMS Push Kit!\",\"description\":\"世界上最好,"
        +
        "最优秀的推送平台!!!\",\"page\":\"/\",\"params\":{\"key1\":\"test1\",\"key2\":\"test2\"},\"ringtone\":"
        + "{\"vibration\":\"true\",\"breathLight\":\"true\"}}}",
        android=android,
        token=['your token'])

    try:
        response = messaging.send_message(message)
        print("response is ", json.dumps(vars(response)))
        assert (response.code == '80000000')
    except Exception as e:
        print(repr(e))
Example #4
0
def send_push_android_data_message():
    """
    a sample to show hwo to send web push message
    :return:
    """
    message = messaging.Message(web_push=web_push_config, token=['your token'])

    try:
        response = messaging.send_message(message)
        print("response is ", json.dumps(vars(response)))
        assert (response.code == '80000000')
    except Exception as e:
        print(repr(e))
def send_push_android_notify_message():
    """
    a sample to show how to send web push message
    :return:
    """
    message = messaging.Message(notification=notification,
                                android=android,
                                token=['your token'])

    try:
        response = messaging.send_message(message)
        print("response is ", json.dumps(vars(response)))
        assert (response.code == '80000000')
    except Exception as e:
        print(repr(e))
Example #6
0
def send_push_android_data_message():
    """
    a sample to show hwo to send web push message
    :return:
    """
    message = messaging.Message(data="{'k1':'v1', 'k2':'v2'}",
                                android=android,
                                token=[push_env.test_device_token])

    try:
        response = messaging.send_message(message)
        print("response is ", json.dumps(vars(response)))
        assert (response.code == '80000000')
    except Exception as e:
        print(repr(e))
Example #7
0
def send_push_android_data_message():
    """
    a sample to show hwo to send web push message
    :return:
    """
    message = messaging.Message(notification=notification,
                                android=android,
                                topic='topic1')

    try:
        response = messaging.send_message(message)
        print "response is ", json.dumps(vars(response))
        assert (response.code == '80000000')
    except Exception as e:
        print repr(e)
Example #8
0
def send_apns_push_message():
    """
    a sample to show hwo to send web push message
    :return:
    """
    message = messaging.Message(
        apns=apns_push_config,
        token=[push_env.test_device_token]
    )

    try:
        response = messaging.send_message(message)
        print("response is ", json.dumps(vars(response)))
        assert (response.code == '80000000')
    except Exception as e:
        print(repr(e))
Example #9
0
def send_push_android_data_message():
    """
    a sample to show how to send web push message
    :return:
    """
    message = messaging.Message(
        notification=notification,
        android=android,
        condition=
        "'topic1' in topics && ('TopicB' in topics || 'TopicC' in topics)")

    try:

        response = messaging.send_message(message)
        print("response is ", json.dumps(vars(response)))
        assert (response.code == '80000000')
    except Exception as e:
        print(repr(e))
def send_apns_push_message():
    """
    a sample to show hwo to send web push message
    :return:
    """
    message = messaging.Message(
        apns=apns_push_config,
        # TODO
        token=['your token'])

    try:
        # Case 1: Local CA sample code
        # response = messaging.send_message(message, verify_peer="../Push-CA-Root.pem")
        # Case 2: No verification of HTTPS's certificate
        response = messaging.send_message(message)
        # Case 3: use certifi Library
        # import certifi
        # response = messaging.send_message(message, verify_peer=certifi.where())
        print "response is ", json.dumps(vars(response))
        assert (response.code == '80000000')
    except Exception as e:
        print repr(e)
def send_push_android_data_message():
    """
    a sample to show hwo to send web push message
    :return:
    """
    message = messaging.Message(
        notification=notification,
        android=android,
        # TODO
        token=['Your Token'])

    try:
        # Case 1: Local CA sample code
        # response = messaging.send_message(message, validate_only=True, verify_peer="../Push-CA-Root.pem")
        # Case 2: No verification of HTTPS's certificate
        response = messaging.send_message(message, validate_only=True)
        # Case 3: use certifi Library
        # import certifi
        # response = messaging.send_message(message, validate_only=True, verify_peer=certifi.where())
        print "response is ", json.dumps(vars(response))
        assert (response.code == '80000000')
    except Exception as e:
        print repr(e)