订单取消
取消指定回执订单,仅限订单处于待处理状态时使用。
接口地址:https://api.zjzapi.com/receipt/cancel
请求方式:POST(application/x-www-form-urlencoded)
返回格式:json
请求参数:
| 名称 | 必填 | 类型 | 说明 |
|---|---|---|---|
| key | 是 | string | 应用的key |
| order_no | 是 | int | 上次提交的订单号 |
返回参数:
| 名称 | 类型 | 说明 |
|---|---|---|
| code | int | 状态码 |
| msg | string | 返回说明 |
| data | array | 数据集 |
JSON返回示例:
{
"data": {},
"code": 0,
"msg": "取消成功"
}
请求示例代码:
请替换占位值后在服务端运行;凭据和应用 key 不要放入浏览器代码。HTTP 成功后仍需按接口文档检查业务 code。 仅可取消符合当前文档状态限制的订单。
# Bash / zsh,cURL 7.76+;Windows 可使用 Git Bash 或 WSL。
curl --fail-with-body --max-time 60 --request POST 'https://api.zjzapi.com/receipt/cancel' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'key=YOUR_APP_KEY' \
--data-urlencode 'order_no=YOUR_ORDER_NO'
// Java 11+,保存为 Main.java,编译运行:javac -encoding UTF-8 Main.java && java Main
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) throws Exception {
Map<String, String> form = new LinkedHashMap<>();
form.put("key", "YOUR_APP_KEY");
form.put("order_no", "YOUR_ORDER_NO");
String body = form.entrySet().stream()
.map(entry -> URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8)
+ "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8))
.collect(Collectors.joining("&"));
HttpClient client = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(10)).build();
HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.zjzapi.com/receipt/cancel"))
.timeout(Duration.ofSeconds(60))
.header("Content-Type", "application/x-www-form-urlencoded")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = client.send(
request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
if (response.statusCode() < 200 || response.statusCode() >= 300) {
throw new IllegalStateException("HTTP " + response.statusCode());
}
// HTTP 成功不代表业务成功,还需检查响应 JSON 中的 code。
System.out.println(response.body());
}
}
# Python 3.8+,需先安装 requests:pip install requests
import requests
response = requests.post(
"https://api.zjzapi.com/receipt/cancel",
headers={"Content-Type": "application/x-www-form-urlencoded"},
data={
"key": "YOUR_APP_KEY",
"order_no": "YOUR_ORDER_NO",
},
timeout=(10, 60),
)
response.raise_for_status()
# 按接口文档检查业务 code,再读取 data。
print(response.json())
<?php
// PHP 7.2+,需启用 cURL 扩展。
// 使用 http_build_query 编码表单,不能直接向 CURLOPT_POSTFIELDS 传数组。
$form = [
'key' => 'YOUR_APP_KEY',
'order_no' => 'YOUR_ORDER_NO',
];
$curl = curl_init('https://api.zjzapi.com/receipt/cancel');
curl_setopt_array($curl, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($form),
CURLOPT_HTTPHEADER => ['Content-Type: application/x-www-form-urlencoded'],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 60,
]);
$result = curl_exec($curl);
$error = curl_error($curl);
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($result === false) {
throw new RuntimeException($error);
}
if ($status_code < 200 || $status_code >= 300) {
throw new RuntimeException('HTTP ' . $status_code);
}
// 按接口文档检查响应 JSON 中的业务 code,再读取 data。
echo $result;
// Go 1.16+,仅使用标准库。
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"strings"
"time"
)
func main() {
form := url.Values{
"key": {"YOUR_APP_KEY"},
"order_no": {"YOUR_ORDER_NO"},
}
request, err := http.NewRequest("POST", "https://api.zjzapi.com/receipt/cancel", strings.NewReader(form.Encode()))
if err != nil {
panic(err)
}
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
client := &http.Client{Timeout: 60 * time.Second}
response, err := client.Do(request)
if err != nil {
panic(err)
}
defer response.Body.Close()
if response.StatusCode < 200 || response.StatusCode >= 300 {
panic(fmt.Errorf("HTTP %d", response.StatusCode))
}
result, err := io.ReadAll(response.Body)
if err != nil {
panic(err)
}
// 按接口文档检查响应 JSON 中的业务 code,再读取 data。
fmt.Println(string(result))
}
// Node.js 18+,保存为 request.mjs;仅在服务端运行,勿将凭据放进浏览器代码。
const form = new URLSearchParams([
["key", "YOUR_APP_KEY"],
["order_no", "YOUR_ORDER_NO"],
]);
const response = await fetch('https://api.zjzapi.com/receipt/cancel', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: form,
signal: AbortSignal.timeout(60000),
});
if (!response.ok) {
throw new Error('HTTP ' + response.status);
}
// 按接口文档检查业务 code,再读取 data。
console.log(await response.json());
// C# 10 / .NET 6+,放入控制台项目的 Program.cs。
using System;
using System.Collections.Generic;
using System.Net.Http;
using var client = new HttpClient { Timeout = TimeSpan.FromSeconds(60) };
using var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("key", "YOUR_APP_KEY"),
new KeyValuePair<string, string>("order_no", "YOUR_ORDER_NO"),
});
// FormUrlEncodedContent 自动设置 application/x-www-form-urlencoded 并编码字段。
using var response = await client.PostAsync("https://api.zjzapi.com/receipt/cancel", content);
response.EnsureSuccessStatusCode();
// 按接口文档检查响应 JSON 中的业务 code,再读取 data。
Console.WriteLine(await response.Content.ReadAsStringAsync());