# 聚合二维码生成接口

生成不落单的付款二维码短链。调用成功后，设备端使用 qr_code 生成二维码供顾客扫码。

约束：
- terminal_sn 与 wosai_store_id 至少提供一个；
- longitude 与 latitude 必须同时有值或同时不传；
- 本接口不创建真实订单。

## 接口说明

- 请求方式：`POST`
- 请求地址：`https://vsi-api.shouqianba.com/upay/support/precreateQrcode`
- Operation ID：`precreateQrcode`

## 请求参数

无请求参数。

## 请求体

| 字段名 | 类型 | 必填 | 描述 |
| --- | --- | --- | --- |
| client_sn | string | 是 | 商户订单号，1～32 字符 |
| description | string | 否 | 订单详情，不超过255字符 |
| extended | object | 否 | 扩展参数，必须为 Map 结构 |
| latitude | string | 否 | 纬度，必须与 longitude 同时有值或同时为空 |
| longitude | string | 否 | 经度，必须与 latitude 同时有值或同时为空 |
| notify_url | string(uri) | 否 | 异步通知地址 |
| operator | string | 是 | 收银员，不超过45字符 |
| payway | string | 否 | 支付通道：1 支付宝；3 微信；4 百付宝；5 京东钱包；6 QQ钱包；17 银联二维码；18 翼支付；21 网银支付；105 储值卡 可选值：`1`、`3`、`4`、`5`、`6`、`17`、`18`、`21`、`105` |
| profit_sharing | object | 否 | 分账参数，必须为 Map 结构 |
| sub_payway | string | 否 | 支付模式：2 QRCODE（默认）；3 WAP；4 MINI；5 APP；6 H5 可选值：`2`、`3`、`4`、`5`、`6` |
| subject | string | 是 | 订单标题，1～64 字符 |
| terminal_sn | string | 否 | 终端号，与 wosai_store_id 不能同时为空 |
| total_amount | string | 是 | 金额，单位为分；正整数，长度不超过11位 |
| wosai_store_id | string | 否 | 收钱吧门店号，与 terminal_sn 不能同时为空 |

## 请求示例

```json
{
  "client_sn": "20260709001",
  "operator": "test",
  "payway": "3",
  "subject": "test",
  "terminal_sn": "21010002460619",
  "total_amount": "1"
}
```

## 响应体

| 字段名 | 类型 | 必填 | 描述 |
| --- | --- | --- | --- |
| biz_response | object | 是 |  |
| biz_response.data | object | 是 |  |
| biz_response.data.qr_code | string(uri) | 是 | 二维码短链内容，设备端用它生成二维码供顾客扫码 |
| biz_response.data.qr_code_image_url | string(uri) | 是 | 二维码图片直链 |
| biz_response.error_code | string | 否 | 业务失败时返回的错误码 |
| biz_response.error_message | string | 否 | 业务失败时返回的错误信息 |
| biz_response.result_code | string | 是 | 业务结果码，PRECREATE_SUCCESS 表示生成成功 可选值：`PRECREATE_SUCCESS` |
| error_code | string | 否 | 通信失败时返回的错误码 |
| error_message | string | 否 | 通信失败时返回的错误信息 |
| result_code | string | 是 | 通信层结果码，200 表示通信成功 |

## 响应示例

```json
{
  "biz_response": {
    "data": {
      "qr_code": "https://short-url.iwosai.com/1diQG",
      "qr_code_image_url": "https://upay-gateway.iwosai.com/upay/qrcode?content=https%3A%2F%2Fshort-url.iwosai.com%2F1diQG"
    },
    "result_code": "PRECREATE_SUCCESS"
  },
  "result_code": "200"
}
```

## 示例代码

### cURL

```bash
curl -X POST "https://vsi-api.shouqianba.com/upay/support/precreateQrcode" \
  -H "Authorization: 100000000000000000 0123456789abcdef0123456789abcdef" \
  -H "Content-Type: application/json" \
  -d '{"client_sn":"20260709001","operator":"test","payway":"3","subject":"test","terminal_sn":"21010002460619","total_amount":"1"}'
```

### Python

```python
import requests

url = "https://vsi-api.shouqianba.com/upay/support/precreateQrcode"
headers = {"Content-Type": "application/json",
    "Authorization": "100000000000000000 0123456789abcdef0123456789abcdef",
}
json_data = {
    "client_sn": "20260709001",
    "operator": "test",
    "payway": "3",
    "subject": "test",
    "terminal_sn": "21010002460619",
    "total_amount": "1"
}

response = requests.post(
    url,
    headers=headers,
    json=json_data,
)

print(response.json())
```

### Java

```java
// 聚合二维码生成接口
OkHttpClient client = new OkHttpClient();
String json = "{\"client_sn\":\"20260709001\",\"operator\":\"test\",\"payway\":\"3\",\"subject\":\"test\",\"terminal_sn\":\"21010002460619\",\"total_amount\":\"1\"}";
RequestBody body = RequestBody.create(json, MediaType.parse("application/json"));

Request request = new Request.Builder()
    .url("https://vsi-api.shouqianba.com/upay/support/precreateQrcode")
    .addHeader("Authorization", "100000000000000000 0123456789abcdef0123456789abcdef")
    .post(body)
    .build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
```

### Go

```go
package main

import (
    "fmt"
    "io"
    "net/http"
    "bytes"
)

func main() {
	jsonBody := []byte(`{"client_sn":"20260709001","operator":"test","payway":"3","subject":"test","terminal_sn":"21010002460619","total_amount":"1"}`)
	reqBody := bytes.NewBuffer(jsonBody)
	req, err := http.NewRequest("POST", "https://vsi-api.shouqianba.com/upay/support/precreateQrcode", reqBody)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", "100000000000000000 0123456789abcdef0123456789abcdef")
	resp, err := (&http.Client{}).Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	respBytes, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(respBytes))
}
```

### Node.js

```javascript
const https = require("https");

const options = {
  method: "POST",
  hostname: "vsi-api.shouqianba.com",
  path: "/upay/support/precreateQrcode",
  headers: {
    "Authorization": "100000000000000000 0123456789abcdef0123456789abcdef",
    "Content-Type": "application/json"
  }
};

const postData = JSON.stringify({"client_sn":"20260709001","operator":"test","payway":"3","subject":"test","terminal_sn":"21010002460619","total_amount":"1"});

const req = https.request(options, (res) => {
  let data = "";
  res.on("data", (chunk) => { data += chunk; });
  res.on("end", () => { console.log(JSON.parse(data)); });
});
req.write(postData);
req.end();
```
