

**终止支持通知：** AWS 将于 2026 年 10 月 30 日终止对亚马逊 Pinpoint 的支持。2026 年 10 月 30 日之后，您将不再能够访问 Amazon Pinpoint 控制台或 Amazon Pinpoint 资源（端点、分段、活动、旅程和分析）。有关更多信息，请参阅 [Amazon Pinpoint 终止支持](https://docs.aws.amazon.com/console/pinpoint/migration-guide)。**注意：** APIs 与短信相关、语音、移动推送、OTP 和电话号码验证不受此更改的影响，并受 AWS 最终用户消息的支持。

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 向 Amazon Pinpoint 中添加端点
<a name="audience-define-endpoints"></a>

*端点*就是消息送达的目的地，如移动设备、电话号码或电子邮件地址。必须先为受众成员定义一个或多个端点，然后才能为此个体发送消息。

当您将端点添加到 Amazon Pinpoint 时，它将逐渐增长成为一个受众数据的存储库。此数据包含：
+ 您使用 Amazon Pinpoint API 添加或更新的端点。
+ 当用户进入您的应用程序时，您的客户端代码添加或更新的端点。

定义端点时，指定*渠道*和*地址*。渠道是向端点发送消息所使用的平台的类型。渠道的示例包括推送通知服务、短信或电子邮件。地址指定向端点发送消息时发送到哪里，如设备令牌、电话号码或电子邮件地址。

要添加有关受众的更多信息，可以使用自定义属性和标准属性丰富端点。这些属性包含有关您的用户、其首选项、其设备、其所用客户端的版本及其位置的数据。将此类数据添加到端点后，将能够：
+ 在 Amazon Pinpoint 控制台中查看有关受众的图表。
+ 基于端点属性细分受众，以便可以将消息发送到正确的目标受众。
+ 通过包含将被端点属性值所替换的消息变量来个性化设置消息。

如果您已使用 AWS Mobile SDK 或 AWS Amplify JavaScript 库集成了 Amazon Pinpoint，则移动或 JavaScript 客户端应用程序会自动注册端点。客户端将为每个新用户注册一个端点，并且它将更新再次使用用户的端点。要通过移动客户端或 JavaScript 客户端注册端点，请参阅[在应用程序中注册 Amazon Pinpoint 端点](integrate-endpoints.md)。

## 示例
<a name="audience-define-endpoints-examples"></a>

以下示例演示如何将端点添加到 Amazon Pinpoint 项目。此端点表示一个居住在西雅图、使用 iPhone 的受众成员。可通过 Apple Push Notification Service (APNs) 为此人发送消息。端点的地址是 APNs 提供的设备令牌。

------
#### [ AWS CLI ]

可以通过在 AWS CLI 中运行命令来使用 Amazon Pinpoint。

**Example 更新端点命令**  
要添加或更新端点，请使用 [update-endpoint](https://docs.aws.amazon.com/cli/latest/reference/pinpoint/update-endpoint.html) 命令：  

```
$ aws pinpoint update-endpoint \
> --application-id application-id \
> --endpoint-id endpoint-id \
> --endpoint-request file://endpoint-request-file.json
```
其中：  
+ *application-id* 是要在其中添加或更新端点的 Amazon Pinpoint 项目的 ID。
+ *example-endpoint* 是要分配给新端点的 ID，或者是要更新的现有端点的 ID。
+ *endpoint-request-file.json* 是包含 `--endpoint-request` 参数输入的本地 JSON 文件的文件路径。

**Example 端点请求文件**  
示例 `update-endpoint` 命令使用 JSON 文件作为 `--endpoint-request` 形参 (parameter) 的实参 (argument)。此文件包含与下类似的端点定义：  

```
{
  "ChannelType": "APNS",
  "Address": "1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7a8b9c0d1e2f",
  "Attributes": {
    "Interests": [
      "Technology",
      "Music",
      "Travel"
    ]
  },
  "Metrics": {
    "technology_interest_level": 9.0,
    "music_interest_level": 6.0,
    "travel_interest_level": 4.0
  },
  "Demographic": {
    "AppVersion": "1.0",
    "Make": "apple",
    "Model": "iPhone",
    "ModelVersion": "8",
    "Platform": "ios",
    "PlatformVersion": "11.3.1",
    "Timezone": "America/Los_Angeles"
  },
  "Location": {
    "Country": "US",
    "City": "Seattle",
    "PostalCode": "98121",
    "Latitude": 47.61,
    "Longitude": -122.33
  }
}
```
有关可用于定义一个端点的属性，请参阅《Amazon Pinpoint API 参考》中的 [EndpointBatchRequest](https://docs.aws.amazon.com/pinpoint/latest/apireference/apps-application-id-endpoints-endpoint-id.html#apps-application-id-endpoints-endpoint-id-schemas) 架构**。

------
#### [ 适用于 Java 的 AWS SDK ]

您可以通过使用 适用于 Java 的 AWS SDK 提供的客户端在您的 Java 应用程序中使用 Amazon Pinpoint API。

**Example 代码**  
要添加端点，请初始化 [https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/pinpoint/model/EndpointRequest.html](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/pinpoint/model/EndpointRequest.html) 对象并将其传递到 `AmazonPinpoint` 客户端的 [https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/pinpoint/model/UpdateEndpointRequest.html](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/pinpoint/model/UpdateEndpointRequest.html) 方法：  

```
import com.amazonaws.regions.Regions;
import com.amazonaws.services.pinpoint.AmazonPinpoint;
import com.amazonaws.services.pinpoint.AmazonPinpointClientBuilder;
import com.amazonaws.services.pinpoint.model.*;
import java.util.Arrays;

public class AddExampleEndpoint {

	public static void main(String[] args) {

		final String USAGE = "\n" +
				"AddExampleEndpoint - Adds an example endpoint to an Amazon Pinpoint application." +
				"Usage: AddExampleEndpoint <applicationId>" +
				"Where:\n" +
				"  applicationId - The ID of the Amazon Pinpoint application to add the example " +
				"endpoint to.";

		if (args.length < 1) {
			System.out.println(USAGE);
			System.exit(1);
		}

		String applicationId = args[0];

		// The device token assigned to the user's device by Apple Push Notification
		// service (APNs).
		String deviceToken = "1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7a8b9c0d1e2f";

		// Initializes an endpoint definition with channel type and address.
		EndpointRequest wangXiulansIphoneEndpoint = new EndpointRequest()
				.withChannelType(ChannelType.APNS)
				.withAddress(deviceToken);

		// Adds custom attributes to the endpoint.
		wangXiulansIphoneEndpoint.addAttributesEntry("interests", Arrays.asList(
				"technology",
				"music",
				"travel"));

		// Adds custom metrics to the endpoint.
		wangXiulansIphoneEndpoint.addMetricsEntry("technology_interest_level", 9.0);
		wangXiulansIphoneEndpoint.addMetricsEntry("music_interest_level", 6.0);
		wangXiulansIphoneEndpoint.addMetricsEntry("travel_interest_level", 4.0);

		// Adds standard demographic attributes.
		wangXiulansIphoneEndpoint.setDemographic(new EndpointDemographic()
				.withAppVersion("1.0")
				.withMake("apple")
				.withModel("iPhone")
				.withModelVersion("8")
				.withPlatform("ios")
				.withPlatformVersion("11.3.1")
				.withTimezone("America/Los_Angeles"));

		// Adds standard location attributes.
		wangXiulansIphoneEndpoint.setLocation(new EndpointLocation()
				.withCountry("US")
				.withCity("Seattle")
				.withPostalCode("98121")
				.withLatitude(47.61)
				.withLongitude(-122.33));

		// Initializes the Amazon Pinpoint client.
		AmazonPinpoint pinpointClient = AmazonPinpointClientBuilder.standard()
				.withRegion(Regions.US_EAST_1).build();

		// Updates or creates the endpoint with Amazon Pinpoint.
		UpdateEndpointResult result = pinpointClient.updateEndpoint(new UpdateEndpointRequest()
				.withApplicationId(applicationId)
				.withEndpointId("example_endpoint")
				.withEndpointRequest(wangXiulansIphoneEndpoint));

		System.out.format("Update endpoint result: %s\n", result.getMessageBody().getMessage());

	}
}
```

------
#### [ HTTP ]

可以通过直接向 REST API 发出 HTTP 请求来使用 Amazon Pinpoint。

**Example PUT 端点请求**  
要添加端点，请向位于以下 URI 的[端点](https://docs.aws.amazon.com/pinpoint/latest/apireference/apps-application-id-endpoints-endpoint-id.html)资源发出 `PUT` 请求：  
`/v1/apps/application-id/endpoints/endpoint-id`  
其中：  
+ *application-id* 是要在其中添加或更新端点的 Amazon Pinpoint 项目的 ID。
+ *endpoint-id* 是要分配给新端点的 ID，或者是要更新的现有端点的 ID。
在您的请求中，添加所需标头并提供 [EndpointRequest](https://docs.aws.amazon.com/pinpoint/latest/apireference/apps-application-id-endpoints-endpoint-id.html#apps-application-id-endpoints-endpoint-id-schemas) JSON 作为正文：  

```
PUT /v1/apps/application_id/endpoints/example_endpoint HTTP/1.1
Host: pinpoint.us-east-1.amazonaws.com
X-Amz-Date: 20180415T182538Z
Content-Type: application/json
Accept: application/json
X-Amz-Date: 20180428T004705Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE/20180428/us-east-1/mobiletargeting/aws4_request, SignedHeaders=accept;content-length;content-type;host;x-amz-date, Signature=c25cbd6bf61bd3b3667c571ae764b9bf2d8af61b875cacced95d1e68d91b4170
Cache-Control: no-cache

{
  "ChannelType": "APNS",
  "Address": "1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7a8b9c0d1e2f",
  "Attributes": {
    "Interests": [
      "Technology",
      "Music",
      "Travel"
    ]
  },
  "Metrics": {
    "technology_interest_level": 9.0,
    "music_interest_level": 6.0,
    "travel_interest_level": 4.0
  },
  "Demographic": {
    "AppVersion": "1.0",
    "Make": "apple",
    "Model": "iPhone",
    "ModelVersion": "8",
    "Platform": "ios",
    "PlatformVersion": "11.3.1",
    "Timezone": "America/Los_Angeles"
  },
  "Location": {
    "Country": "US",
    "City": "Seattle",
    "PostalCode": "98121",
    "Latitude": 47.61,
    "Longitude": -122.33
  }
}
```
如果您的请求成功，将收到与下类似的响应：  

```
{
    "RequestID": "67e572ed-41d5-11e8-9dc5-db288f3cbb72",
    "Message": "Accepted"
}
```

------

## 相关信息
<a name="audience-define-endpoints-related"></a>

有关 Amazon Pinpoint API 中的端点资源的更多信息，包括支持的 HTTP 方法和请求参数，请参阅《Amazon Pinpoint API 参考》中的[端点](https://docs.aws.amazon.com/pinpoint/latest/apireference/apps-application-id-endpoints-endpoint-id.html)**。

有关使用变量个性化设置消息的更多信息，请参阅《Amazon Pinpoint 用户指南》中的[消息变量](https://docs.aws.amazon.com/pinpoint/latest/userguide/campaigns-message.html#campaigns-message-variables.html)**。

有关应用于端点的限额的信息（例如可分配的属性数），请参阅[端点限额](quotas.md#quotas-endpoint)。