通过 AWS Lambda/Python 作为 JSON 使用自定义变量消息发送 Apple 推送通知

Send Apple Push Notification via AWS Lambda/Python as JSON with custom variable Message

您好,我正在尝试发送这样的推送通知

message3 = {"APNS_SANDBOX":"{\"aps\": {\"alert\": \"some alert\",\"sound\": \"default\",\"badge\": 1},\"message\": \"additional information\",\"id\": 1234}"}

response = client.publish(
    #TopicArn='string',
    TargetArn = someEndpoint,
    Message = json.dumps(message3),
    MessageStructure= 'json'
    #Subject='string',
)

一切正常。但我需要警报是可变的。如果我尝试将自定义文本变量放入 message3 json 对象中,我会不断收到此错误:

"errorType": "ClientError",
"errorMessage": "An error occurred (InvalidParameter) when calling the Publish operation: Invalid parameter: Message Reason: Invalid notification for protocol APNS_SANDBOX: Notification is malformed"

有人可以帮忙吗?谢谢!!

好像是这样的

test = "test"
message = {'aps': {'alert': test, 'sound': 'default','badge': 1},'message': 'additional information','id': 1234}
dumped = json.dumps(message)

message3 = {"APNS_SANDBOX":dumped}

response = client.publish(
    #TopicArn='string',
    TargetArn = someEndpoint,
    Message = json.dumps(message3),
    MessageStructure= 'json'
    #Subject='string',
)

你是这个意思吗,@kichik?非常感谢!