目录

代理发卡接口

功能介绍

开发者可以调用此接口让华为服务器代理生成卡券实例,无需传入详细参数。

场景描述

开发者在开发者联盟申请钱包服务号时,接入方式可选择“代理接入”。开发者在选择“代理接口”且配置“托管服务”后,可使用此接口生成卡券实例,获取一个领卡token用于绑定用户。选择此方式生成卡券实例可省略推送卡券模板和生成JWE的步骤。

使用约束

需在华为AGC网站上创建应用,并在申请服务号时选择“代理接入”,然后配置“托管服务”。

接口原型

承载协议

HTTPS POST

接口方向

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

接口URL

{url}/hmspass/v1/common/applyCard

{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:

参数

是否必选

参数类型

描述

passTypeIdentifier

是

String(64)

服务号

authInfo

否

String(20480)

激活授权信息,创建具备NFC能力的卡券时需传入。

请求示例

POST /hmspass/v1/common/applyCard 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
{
  "passTypeIdentifier": "hwpass.com.huawei.wallet.agent"
}

响应参数

错误码为200时:

参数

参数类型

描述

token

String(64)

领卡token,用于绑定用户。

expireIn

int

token有效时间(秒),返回固定值300。

响应示例

HTTP/1.1 200 OK
Content-Type: application/json
{
  "token": "11afd72d2c4322f5b1a77ecbc14dfcb50c83ef1c70c4817a99afd100fd1a3ad0",
  "expireIn": 300
}

错误码

详见错误码。

调用示例

public JSONObject applyCard(String url, String passTypeIdentifier, String authInfo) {
    // Construct the http header.
    HttpHeaders header = constructHttpHeaders();
    // Construct the http URL.
    String baseUrl = ConfigHelper.instants().getValue("walletServerBaseUrl");
    String walletServerUrl = baseUrl + url;

    // Construct the http body.
    JSONObject jsonObj = new JSONObject();
    jsonObj.put("passTypeIdentifier", passTypeIdentifier);
    jsonObj.put("authInfo", authInfo);

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

    // Return the token and expire time.
    return response.getBody();
}