AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
与 AWS SDK或GetSmsChannel
一起使用 CLI
以下代码示例演示如何使用 GetSmsChannel
。
- CLI
-
- AWS CLI
-
检索有关应用程序SMS频道状态和设置的信息
以下
get-sms-channel
示例检索应用程序的短信渠道的状态和设置。aws pinpoint get-sms-channel \ --application-id
6e0b7591a90841d2b5d93fa11143e5a7
\ --regionus-east-1
输出:
{ "SMSChannelResponse": { "ApplicationId": "6e0b7591a90841d2b5d93fa11143e5a7", "CreationDate": "2019-10-08T18:39:18.511Z", "Enabled": true, "Id": "sms", "IsArchived": false, "LastModifiedDate": "2019-10-08T18:39:18.511Z", "Platform": "SMS", "PromotionalMessagesPerSecond": 20, "TransactionalMessagesPerSecond": 20, "Version": 1 } }
-
有关API详细信息,请参阅 “GetSmsChannel AWS CLI
命令参考”。
-
- Java
-
- SDK适用于 Java 2.x
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.pinpoint.PinpointClient; import software.amazon.awssdk.services.pinpoint.model.SMSChannelResponse; import software.amazon.awssdk.services.pinpoint.model.GetSmsChannelRequest; import software.amazon.awssdk.services.pinpoint.model.PinpointException; import software.amazon.awssdk.services.pinpoint.model.SMSChannelRequest; import software.amazon.awssdk.services.pinpoint.model.UpdateSmsChannelRequest; import software.amazon.awssdk.services.pinpoint.model.UpdateSmsChannelResponse; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class UpdateChannel { public static void main(String[] args) { final String usage = """ Usage: CreateChannel <appId> Where: appId - The name of the application whose channel is updated. """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String appId = args[0]; PinpointClient pinpoint = PinpointClient.builder() .region(Region.US_EAST_1) .build(); SMSChannelResponse getResponse = getSMSChannel(pinpoint, appId); toggleSmsChannel(pinpoint, appId, getResponse); pinpoint.close(); } private static SMSChannelResponse getSMSChannel(PinpointClient client, String appId) { try { GetSmsChannelRequest request = GetSmsChannelRequest.builder() .applicationId(appId) .build(); SMSChannelResponse response = client.getSmsChannel(request).smsChannelResponse(); System.out.println("Channel state is " + response.enabled()); return response; } catch (PinpointException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return null; } private static void toggleSmsChannel(PinpointClient client, String appId, SMSChannelResponse getResponse) { boolean enabled = !getResponse.enabled(); try { SMSChannelRequest request = SMSChannelRequest.builder() .enabled(enabled) .build(); UpdateSmsChannelRequest updateRequest = UpdateSmsChannelRequest.builder() .smsChannelRequest(request) .applicationId(appId) .build(); UpdateSmsChannelResponse result = client.updateSmsChannel(updateRequest); System.out.println("Channel state: " + result.smsChannelResponse().enabled()); } catch (PinpointException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }
-
有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 GetSmsChannel” 中的。
-
GetSegments
GetUserEndpoints