You need to create an app in AppGallery Connect and apply for services corresponding to the passes. In addition, messages can be added only to an instance that has been added to the Huawei server.
Protocol |
HTTPS POST |
|---|---|
Direction |
Developer server -> HUAWEI Account Kit server |
URL |
{url}/hmspass/v2/{cardType}/instance/{instanceId}/addMessage Set the {url} variable based on the region where the server is located. For details, please refer to Wallet Server Addresses. |
Data Format |
Request: Content-Type: application/json Response: Content-Type: application/json |
Parameter |
Mandatory/Optional |
Type |
Description |
|---|---|---|---|
cardType |
Mandatory |
String |
Pass type. Set this parameter as required. For supported pass types, please refer to Other Passes Supported. |
instanceId |
Mandatory |
String |
Unique identifier of an instance. It must be unique across all instances sharing the same appId. The value contains only letters, digits, dots (.), hyphens (-), and underscores (_). |
Request Header
Parameter |
Mandatory/Optional |
Type |
Description |
|---|---|---|---|
Authorization |
Mandatory |
String |
Authorization code. For details about how to obtain the value, please refer to the Client Credentials mode in OAuth 2.0-based Authentication. In this mode, client_id and client_secret are respectively the App ID and App key of the app that you created in AppGallery Connect. Concatenate the value of access_token to the end of Bearer, with a space in between, to generate the value of Authorization. |
Content-Type |
Mandatory |
String |
The value is always application/json;charset=utf-8. |
Accept |
Mandatory |
String |
The value is always application/json;charset=utf-8. |
Request Body
Parameter |
Mandatory/Optional |
Type |
Description |
|---|---|---|---|
messageList |
Mandatory |
List<ValueObject> |
Messages to be added. |
POST /hmspass/v2/key_parkcard/instance/70001/addMessage HTTP/1.1
Content-Type: application/json;charset=utf-8
Authorization: Bearer ***
Accept: application/json;charset=utf-8
Host: wallet-passentrust-drcn.cloud.huawei.com.cn
{
"messageList": [
{
"key": "message[10]",
"value": "Hello everyone!"
}
]
}
{
"messageList": [
{
"key": "message[0]",
"value": "Welcome to the park!"
}
]
}
When the result code is 200:
Parameter |
Type |
Description |
|---|---|---|
For details, please refer to the HwWalletObject Parameters. |
Updated pass instance. |
HTTP/1.1 200 OK
Content-Type: application/json
{
"organizationPassId": "5623489234",
"passTypeIdentifier": "hwpass.type.parkcard.test",
"passStyleIdentifier": "class_parkcard_Test",
"serialNumber": "70001",
"fields": {
"status": {
"state": "active",
"effectTime": "2019-11-14T00:00:00.111Z",
"expireTime": "2020-11-27T00:00:00.111Z"
},
"barCode": {
"text": "562348965624365412",
"type": "codabar",
"value": "562348965624365412",
"encoding": "UTF-8"
},
"commonFields": [
{
"key": "cardNumber",
"value": "12345678"
"label": "cardNumber"
}
],
"appendFields": [
{
"key": "isCreateWhiteCard",
"value": "true",
"label": "NFCCardFlag"
}
],
"messageList": [
{
"key": "message[0]",
"value": "Welcome to the park!"
}
]
}
}
public HwWalletObject addMessageToHwWalletObject(String url, String resourceId, String body) {
// Construct the HTTP header.
HttpHeaders header = constructHttpHeaders();
// Construct the HTTP URL.
String baseUrl = ConfigHelper.instants().getValue("walletServerBaseUrl");
String walletServerUrl = baseUrl + url.replace("addMessage", "") + resourceId + "/addMessage";
// Construct the HTTP body.
JSONObject jsonObj = JSONObject.parseObject(body);
// Send the HTTP request and obtain the response.
HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObj, header);
ResponseEntity<HwWalletObject> response =
REST_TEMPLATE.exchange(walletServerUrl, HttpMethod.POST, entity, HwWalletObject.class);
// Return the updated HwWalletObject.
return response.getBody();
}