# Payment Request API

## :white\_check\_mark: Payment **Request API**

### :ballot\_box\_with\_check: **Request Message Parameters(JSON Format)**

| **Params Name** | **Description**                                                                       | **Required** | **Notes**                                                         |
| --------------- | ------------------------------------------------------------------------------------- | ------------ | ----------------------------------------------------------------- |
| userId          | APP ID registered in WeChat [https://open.weixin.qq.com](https://open.weixin.qq.com/) | Y            | e.g. wxcbb0a73d2d5a8888                                           |
| amount          | Transaction amount in cent                                                            | Y            | String, "100" for 1.00 dollar                                     |
| bizType         | Business type                                                                         | Y            | WECHATPAY                                                         |
| merchant\_id    | Merchant ID in OTT PAY                                                                | Y            | Provided by OTTPay                                                |
| operator\_id    | Operator ID from OTT PAY                                                              | Y            | Provided by OTTPay                                                |
| order\_id       | you own order id                                                                      | N            | string, your own order id                                         |
| call\_back\_url | Call back URL                                                                         | Y            | Call back data from OTT Pay, shown in the payment completion page |

### :ballot\_box\_with\_check: **Request Data Example**

```
{
 "userId": "wxcbb0a73d2d5a8888”, 
 "amount": "100", 
 "bizType": "WECHATPAY", 
 "merchant_id": "AB00000004", 
 "shopId": "", 
 "operator_id": "0000000005", 
 "tip": ""
}
```

### :white\_check\_mark: **Response Message Parameter**

The response message contains all the required parameters to activate the client’s **WeChat Wallet.**

| **Params Name** | **Description**                                                                                                              | **Required** | **Notes**                            |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------- | ------------ | ------------------------------------ |
| appId           | <p>APP ID registered <a href="https://open.weixin.qq.com/"><https://open.weixin.qq.com></a></p><p>required by WeChat Pay</p> | Y            | wxcbb0a73d2d5a8888                   |
| bizType         | Business type                                                                                                                | Y            | WECHATPAY                            |
| nonceStr        | <p>Random string</p><p>required by WeChat Pay</p>                                                                            | Y            | Random string                        |
| package\_       | String, required by WeChat Pay, must be “Sign=WXPay”                                                                         | Y            | Sign=WXPay                           |
| partnerId       | PartnerId required by WeChat Pay                                                                                             | Y            | XXXXXXXXXXX                          |
| paySign         | Sign Key in OTT Pay request                                                                                                  | N            | DBC7B6ED46BE81E927CAA1922A83BE91     |
| prepayId        | prepayId obtained from WeChat Pay associated with the current transaction, required by WeChat Pay                            | Y            | wx22014816274706c6ad56f2412344704275 |
| reAmount        | Available refund amount for this transaction                                                                                 | N            | String, "100" for 1.00 dollar        |
| timeStamp       | Time Stamp required by WeChat Pay                                                                                            | Y            | 2018112112                           |
| tradeNo         | Transaction Id for OTT Pay                                                                                                   | N            | 1542822494862703                     |
| wxapikey        | API key, required by WeChat Pay                                                                                              | Y            | XXXXXXXXXXXXXXXXXXXXXXXXXXXXX        |

### :ballot\_box\_with\_check: **Response Message Data Example:**

```
{
"appId":"wxcbb0a73d2d5a8888",
"bizType":"WECHATPAY",
"nonceStr":"hieqzx0aK8sXTdMq",
"package_":"Sign=WXPay",
"partnerId":"XXXXXXXXXX",
"paySign":"DBC7B6ED46BE81E927CAA1922A83BE91",
"prepay_id":"wx22014816274706c6ad56f2412344704275",
"reAmount":"100",
"timeStamp":"2018112112",
"tradeNo":"1542822494862703",
"wxapikey":"XXXXXXXXXXXXXXXXXXXXXX"
}
```

通过WeChat SDK jar包调起WeChat Wallet支付, 需要用 appId, partnerId, prepayId, packageValue, timestamp, nonceStr, timestamp and Sign参数。其中Sign需要用WeChat Pay的**sign creation logic** 产生，示例如下：

To activate WeChat Wallet through WeChat SDK jar package needs following parameters: appId, partnerId, prepayId, packageValue, timestamp, nonceStr, timestamp and Sign. The Sign needs the WeChat Pay’s **sign creation logic** to generate, for example:

```
private String genAppSign(List<NameValuePair> params, String WECHAT_API_KEY) {
 StringBuilder sb = new StringBuilder();for (int i = 0; i < params.size(); i++) {
 sb.append(params.get(i).getName());
 sb.append('=');
 sb.append(params.get(i).getValue());
 sb.append('&');
 }
 sb.append("key=");
 sb.append(WECHAT_API_KEY);
 String appSign = MD5.getMessageDigest(sb.toString().getBytes()).toUpperCase();
 Log.d("test_api", "sign=" + appSign);
 return appSign;
}
 where params list is created by:
List<NameValuePair> signParams = new LinkedList<NameValuePair>();
signParams.add(new BasicNameValuePair("appid", appid));
signParams.add(new BasicNameValuePair("noncestr", nonceStr));
signParams.add(new BasicNameValuePair("package", packageValue));
signParams.add(new BasicNameValuePair("partnerid", partnerId));
signParams.add(new BasicNameValuePair("prepayid", prepayId));
signParams.add(new BasicNameValuePair("timestamp", timeStamp));
String sign = ss(signParams, );
 Finally， we can use these parameters to construct the PayReq request as:
PayReq req = new PayReq();
req.appId = appid;
req.partnerId = partnerId;
req.prepayId = prepayId;
req.packageValue = packageValue;
req.nonceStr = nonceStr;
req.timeStamp = timeStamp;
req.sign = sign;
Which can be used to raise the Wechat Wallet as:
private IWXAPI api;
…
api.sendReq(req);
```

Please note: IWXAP, PayReq are java class defined by WeChat SDK.

:ballot\_box\_with\_check: **Call-Back Message Data**

| **Params Name** | **Description**    | **Required** | **Notes**                     |
| --------------- | ------------------ | ------------ | ----------------------------- |
| rsp\_code       | Response code      | Y            | Refer to Appendix B           |
| rsp\_msg        | Response message   | Y            |                               |
| merchant\_id    | Merchant ID        | Y            | Merchant ID                   |
| finish\_time    | Payment time       | Y            | YYYYMMDDHHMMSS (Beijing time) |
| order\_id       | Order ID           | Y            |                               |
| amount          | Transaction amount | Y            | String, "100" for 1.00 dollar |
| md5             | Message Digest     | Y            |                               |

:ballot\_box\_with\_check: **Call-Back Message Example(JSON Data):**

```
 {
  "data":"hy0yiXxPH4TDXeY5ET7gqIsUcgY5ykO1vQYOahS5SsbN7/5Ha7+hvcXhgY1hz9kHuf5OxqNfv28kVeiYACrLzngk+hA2o8dVAcifT6h3AquN5micrIi3L9owj6cHT1nJRExC74sNUqF8CDY5fb4jLh9it9tq7r8xFOpcpf19VNWceo/Jt1nHca6HPMvMUEDeX1aUjnxOs7R7B2TUQbAENg\u003d\u003d",
  "rsp_code":"SUCCESS",
  "rsp_msg":"success",
  "merchant_id":"QC00005496",
  "md5":"F70CA0472D1AAA596E720C19A1DD36A0"
 }

```

#### :ballot\_box\_with\_check: Transaction Data (JSON format, after decrypted)

|    Params Name    |       Description      | Required |                                Notes                               |
| :---------------: | :--------------------: | :------: | :----------------------------------------------------------------: |
|    finish\_time   |      Payment time      |     Y    |                    YYYYMMDDHHMMSS (Beijing time)                   |
|     order\_id     |        Order ID        |     Y    |                                                                    |
|       amount      |   Transaction amount   |     Y    |                    String, "100" for 1.00 dollar                   |
|        tip        |       Tip Amount       |     N    |                    String, "100" for 1.00 dollar                   |
| bizpay\_order\_id | order id from Acquirer |     Y    | Returned by the Payment Service Provider (e.g. WeChat Pay, Alipay) |
|    merchant\_id   |       Merchant ID      |     Y    |                         Provided by OTT Pay                        |

:ballot\_box\_with\_check: **Data Example(JSON Data, after decrypted):**

```
{
 "amount":"1",
 "bizpay_order_id":"AL781266859681754",
 "tip":"0",
 "merchant_id":"QC00005496",
 "order_id":"2020041553699O153O0407",
 "finish_time":"20200416050429"
}
```

:point\_right: Call back data中的 **data**是加密过的数据，参考appendix A进行解密处理。

&#x20;        **Data** in Call back data in encrypted, refer to appendix A for decryption.

:point\_right: **Please reference our Android demo code for details.**

{% file src="/files/-M6lZzcoQRa1e7XAYGnD" %}
WebChat Pay for Mobile App Demo Codes
{% endfile %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ottpay.com/payment-api/in-app-wechat-pay/apis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
