文档管理中心
我的

新增交通卡个人化实例

功能介绍

添加交通卡个人化实例到钱包服务器。

场景描述

开发者可以调用该API,将某一用户的交通卡实例添加到钱包服务器。使用此接口后,需发送瘦JWE绑定用户。另外可以发送JWE直接把个人化实例添加到服务器并且绑定用户,而不使用此接口。

使用约束

需在华为AGC网站上创建应用并申请卡券对应的服务。需先添加个人化实例所属的卡券模板到华为钱包服务器。

接口原型

承载协议

HTTPS POST

接口方向

开发者服务器->华为钱包服务器

接口URL

{url}/hmspass/v1/transit/instance

{url}变量需要开发者根据服务器所属区域自行选择,请参见钱包服务器地址。

数据格式

请求消息:Content-Type: application/json

响应消息:Content-Type: application/json

请求参数

Request Header:

展开

参数

是否必选

参数类型

描述

Authorization

是

String

鉴权码。获取方式详见基于OAuth 2.0开放鉴权,请使用“客户端模式”。“client_id”和“client_secret”即为开发者在华为AGC网站上创建应用后获取的“App ID”和“App key”。将获取到的“access_token”的值拼接在字符串“Bearer”之后,以空格符相隔,组成“Authorization”参数的值。

Content-Type

是

String

固定值:“application/json;charset=utf-8”。

Accept

是

String

固定值:“application/json;charset=utf-8”。

Request Body:

展开

参数

是否必选

参数类型

描述

详见HwWalletObject参数描述

是

HwWalletObject

待添加的卡券个人化实例

请求示例

POST /hmspass/v1/transit/instance HTTP/1.1
Content-Type: application/json;charset=utf-8
Authorization: Bearer ***
Host: wallet-passentrust-drcn.cloud.huawei.com.cn
Accept: application/json;charset=utf-8
{
  "organizationPassId": "5623489611",
  "passTypeIdentifier": "hwpass.com.huawei.wallet.transit.test",
  "passStyleIdentifier": "transitModelTest",
  "serialNumber": "60001",
  "fields": {
    "status": {
      "state": "active",
      "effectTime": "2019-11-13T00:00:00.111Z",
      "expireTime": "2020-11-20T00:00:00.111Z"
    },
    "barCode": {
      "text": "562348969211212",
      "type": "codabar",
      "value": "562348969211212",
      "encoding": "UTF-8"
    },
    "commonFields": [
      {
        "key": "ticketStatus",
        "value": "Not Used"
      }
    ],
    "ticketInfoList": [
      {
        "key": "carriage",
        "value": "8"
      },
      {
        "key": "seatNumber",
        "value": "7A"
      },
      {
        "key": "seatCoach",
        "value": "14"
      }
    ]
  }
}

响应参数

错误码为200时:

展开

参数

参数类型

描述

详见HwWalletObject参数描述

HwWalletObject

已添加的卡券实例

响应示例

HTTP/1.1 200 OK
Content-Type: application/json
{
  "passTypeIdentifier": "hwpass.com.huawei.wallet.loyalty.test",
  "passStyleIdentifier": "loyaltyModelTest",
  "organizationPassId": "356688115",
  "serialNumber": "40001",
  "fields": {
    "status": {
      "state": "active",
      "effectTime": "2019-11-13T00:00:00.111Z",
      "expireTime": "2028-11-20T00:00:00.111Z"
    },
    "barCode": {
      "text": "1118466050",
      "type": "codabar",
      "value": "1118466050",
      "encoding": "UTF-8"
    },
    "commonFields": [
      {
        "key": "cardNumber",
        "value": "356688115",
        "label": "Card Number"
      },
      {
        "key": "balance",
        "value": "$199",
        "label": "Balance"
      },
      {
        "key": "memberName",
        "value": "Joe Wiley",
        "label": "Name"
      }
    ],
    "appendFields": [
      {
        "key": "points",
        "value": "2000",
        "label": "Points"
      }
    ]
  }
}

错误码

详见错误码。

调用示例

public HwWalletObject postHwWalletObjectToWalletServer(String url, HwWalletObject hwWalletObject) {
    // Construct the http header.
    HttpHeaders header = constructHttpHeaders();
    // Construct the http body.
    String body = CommonUtil.toJson(hwWalletObject);
    JSONObject jsonObj = JSONObject.parseObject(body);
    System.out.println("Request JSON : " + jsonObj);
    // Construct the http URL.
    String baseUrl = ConfigHelper.instants().getValue("walletServerBaseUrl");
    String walletServerUrl = baseUrl + url;

    // Send the http request and get response.
    HttpEntity<JSONObject> entity = new HttpEntity<>(jsonObj, header);
    ResponseEntity<HwWalletObject> exchange =
        REST_TEMPLATE.exchange(walletServerUrl, HttpMethod.POST, entity, HwWalletObject.class);

    // Return the posted wallet model.
    return exchange.getBody();
}