目录

创建优惠券模板

功能介绍

添加优惠券模板到钱包服务器。

场景描述

开发者可以调用该API,将某一种类的优惠券模板添加到钱包服务器。

使用约束

需在华为AGC网站上创建应用并申请卡券对应的服务。

接口原型

承载协议

HTTPS POST

接口方向

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

接口URL

{url}/hmspass/v1/offer/model

{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/offer/model 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
{
  "passVersion": "1.0",
  "passTypeIdentifier": "hwpass.com.huawei.wallet.offer.test",
  "passStyleIdentifier": "offerModelTest",
  "organizationName": "Huawei",
  "fields": {
    "countryCode": "CN",
    "locationList": [
      {
        "longitude": "114.0679603815",
        "latitude": "22.6592051284"
      }
    ],
    "commonFields": [
      {
        "key": "logo",
        "value": "https://www.huawei.com/XXX.png"
      },
      {
        "key": "name",
        "value": "50%-Off Coupon",
        "localizedValue": "nameI18N"
      },
      {
        "key": "subName",
        "value": "XXX Company"
      },
      {
        "key": "merchantName",
        "value": "HUAWEI Vmall",
        "localizedValue": "merchantNameI18N"
      }
    ],
    "appendFields": [
      {
        "key": "details",
        "value": "Detail information of this coupon.",
        "localizedValue": "detailsI18N"
      },
      {
        "key": "declaration",
        "value": "Coupon disclaimer provided by merchant.",
        "localizedValue": "declarationI18N"
      },
      {
        "key": "backgroundColor",
        "value": "#FF1C2635"
      }
    ],
    "messageList": [
      {
        "key": "message[0]",
        "value": "Don't miss this great offer!",
        "label": "Important!",
        "localizedValue": "message[0]I18N"
      }
    ],
    "imageList": [
      {
        "key": "mainImage[0]",
        "value": "https://www.huawei.com/XXX0.png"
      },
      {
        "key": "mainImage[1]",
        "value": "https://www.huawei.com/XXX1.png"
      },
      {
        "key": "mainImage[2]",
        "value": "https://www.huawei.com/XXX2.png"
      }
    ],
    "localized": [
      {
        "key": "merchantNameI18N",
        "language": "zh-cn",
        "value": "华为商城"
      },
      {
        "key": "merchantNameI18N",
        "language": "en",
        "value": "HUAWEI Vmall"
      },
      {
        "key": "message[0]I18N",
        "language": "zh-cn",
        "value": "不要错过这次的优惠!"
      },
      {
        "key": "message[0]I18N",
        "language": "en",
        "value": "Don't miss this great offer!"
      }
    ]
  }
}

响应参数

错误码为200时:

参数

参数类型

描述

详见HwWalletObject参数描述

HwWalletObject

已添加的卡券模板

响应示例

HTTP/1.1 200 OK
Content-Type: application/json
{
  "passVersion": "1.0",
  "passTypeIdentifier": "hwpass.com.huawei.wallet.offer.test",
  "passStyleIdentifier": "offerModelTest",
  "organizationName": "Huawei",
  "fields": {
    "countryCode": "CN",
    "locationList": [
      {
        "longitude": "114.0679603815",
        "latitude": "22.6592051284"
      }
    ],
    "commonFields": [
      {
        "key": "logo",
        "value": "https://www.huawei.com/XXX.png"
      },
      {
        "key": "name",
        "value": "50%-Off Coupon",
        "localizedValue": "nameI18N"
      },
      {
        "key": "providerName",
        "value": "XXX Company"
      },
      {
        "key": "merchantName",
        "value": "HUAWEI Vmall",
        "localizedValue": "merchantNameI18N"
      }
    ],
    "appendFields": [
      {
        "key": "details",
        "value": "Detail information of this coupon.",
        "localizedValue": "detailsI18N"
      },
      {
        "key": "declaration",
        "value": "Coupon disclaimer provided by merchant.",
        "localizedValue": "declarationI18N"
      },
      {
        "key": "backgroundColor",
        "value": "#FF1C2635"
      }
    ],
    "messageList": [
      {
        "key": "message[0]",
        "value": "Don't miss this great offer!",
        "label": "Important!",
        "localizedValue": "message[0]I18N"
      }
    ],
    "imageList": [
      {
        "key": "mainImage[0]",
        "value": "https://www.huawei.com/XXX0.png"
      },
      {
        "key": "mainImage[1]",
        "value": "https://www.huawei.com/XXX1.png"
      },
      {
        "key": "mainImage[2]",
        "value": "https://www.huawei.com/XXX2.png"
      }
    ],
    "localized": [
      {
        "key": "merchantNameI18N",
        "language": "zh-cn",
        "value": "华为商城"
      },
      {
        "key": "merchantNameI18N",
        "language": "en",
        "value": "HUAWEI Vmall"
      },
      {
        "key": "message[0]I18N",
        "language": "zh-cn",
        "value": "不要错过这次的优惠!"
      },
      {
        "key": "message[0]I18N",
        "language": "en",
        "value": "Don't miss this great offer!"
      }
    ]
  }
}

错误码

详见错误码。

调用示例

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();
}