查询订单退款资格
本页内容
查询企业签名订单当前是否符合退款条件。
适用场景
使用者提出退款申请,准备展示退款金额和影响时使用。
完整流程见:退款、扩容与订单对账。
开始前
请先在开发者中心完成 API 接入配置,并为目标应用授予本次操作所需的权限。尚未完成首次调用时,请先阅读快速开始。
- 准备此应用的原订单 ID。开通密钥没有可通过此接口退款的付款订单;按天订单是否可退取决于当前规则及订单资格。
- 所需权限
- enterprise:ReadRefunds,并匹配精确来源 IP
- 认证方式
- 长期 AccessKey(AKP),服务端 HMAC 签名
权限、应用范围和来源 IP 均需符合接入配置。详细说明见访问权限。
调用步骤
- 确认原订单 ID。
- 查询资格、截止时间和拒绝原因。
- 向使用者说明退款会撤销的权益。
确认符合条件并取得同意后,调用 确认退款并撤销签名权益。
请求方式
/api/v1/apps/{app_id}/orders/{order_id}/refund- 操作标识
getOrderRefund- 请求域名
https://www.onesignios.com- 频率限制
- 账号与 API 应用的额度同时生效。达到限额时按
Retry-After等待。
请求参数
| 字段 | 必填 | 说明 |
|---|---|---|
app_id |
是 | 业务应用的完整 ID,来自列出应用或预留新应用的响应。 查看取值约束
示例: |
order_id |
是 | 订单 ID,可从付款回执获得。 查看取值约束
示例: |
AccessKey 认证请求头
下表适用于 AccessKey 调用,由服务端 SDK 自动生成。使用长期或临时凭据自行实现 HTTP 调用时,请按照请求签名说明处理。
| 字段 | 必填 | 说明 |
|---|---|---|
Authorization |
是 | AccessKey 调用的认证签名,格式为 CS1-HMAC-SHA256 Credential=密钥ID,Signature=签名。使用 SDK 时自动生成。 |
X-Api-Date |
是 | UTC 时间,格式 YYYY-MM-DDTHH:mm:ssZ。与服务器的时间偏差最多 300 秒。 查看取值约束
|
X-Api-Nonce |
是 | 每次请求生成 16 个随机字节,转为 32 位小写十六进制。重试时重新生成。 查看取值约束
|
X-Api-Content-Sha256 |
是 | 实际发送的正文原始字节的 SHA-256 小写十六进制。GET 计算空字节串。 查看取值约束
|
X-Api-Environment |
是 | 生产环境传 production。 查看取值约束
|
本接口仅支持长期 AccessKey,不支持临时凭据或 OAuth Bearer。查看认证方式对照。
请求体
GET 请求不发送正文。签名中的正文摘要取零字节内容的 SHA-256。
成功响应
HTTP 200 返回 JSON。请记录 request_id,排查问题时可提供此值。查看成功、失败与异步结果的区别。
如何判断结果
先看 eligible、deadline 和说明,已退款时读取 receipt。符合资格的查询只代表当前可申请,提交时仍会再次检查。
退款退至原付款账号的站内余额,并撤销该笔订单增加的签名有效期;API 付款预算不返还。
返回字段
字段按对象层级列出,[] 表示数组元素。“必返”指该对象出现时字段是否必须存在,值仍可能允许为 null;具体类型见展开说明。
| 字段 | 必返 | 说明 |
|---|---|---|
request_id |
是 | 平台生成的请求标识。排查问题时请提供此值。 查看取值约束
示例: |
data |
是 | 本次调用的业务结果,结构取决于操作。 |
data.app_id |
是 | 业务应用的完整 ID,来自列出应用或预留新应用的响应。 查看取值约束
示例: |
data.order_id |
是 | 订单 ID,可从付款回执获得。 查看取值约束
示例: |
data.state |
是 | 原订单的退款处理状态;是否可新申请还要检查 eligible。 查看取值约束
示例: |
data.eligible |
是 | 按查询时的订单、时间和设备条件,当前是否具备退款资格。 查看示例示例: |
data.amount |
是 | 以站内单位表示的金额,小数字符串应原样传递。 查看取值约束
示例: |
data.currency |
是 | 站内金额单位及展示信息,按本站配置解释所有金额。 |
data.currency.code |
是 | 站内金额单位代码,例如 CNY、USD 或 POINT。 查看示例示例: |
data.currency.unit |
是 | 站点配置的金额单位名称。 查看示例示例: |
data.currency.external_settlement |
是 | 外部支付的结算币种以支付渠道为准。 查看取值约束
示例: |
data.currency.revision |
是 | 此金额单位配置的修订标识。确认付款时使用报价返回的原值。 查看取值约束
示例: |
data.days |
是 | 所购买的服务天数,按天 SKU 须在站点当前允许范围内。 查看取值约束
示例: |
data.deadline |
是 | 本笔订单当前退款窗口的截止时间,Unix 秒;实际申请时会重新检查资格。 查看取值约束
示例: |
data.message |
是 | 供人阅读的业务说明。程序分支应使用状态或错误码。 查看取值约束
示例: |
data.receipt |
是 | 已经完成退款时的原回执;未退款时为空。 查看示例示例: |
data.receipt.id |
是 | 该条记录的公开标识。调用后续接口时请完整保留,包括前缀。 查看取值约束
|
data.receipt.app_id |
是 | 业务应用的完整 ID,来自列出应用或预留新应用的响应。 查看取值约束
|
data.receipt.order_id |
是 | 订单 ID,可从付款回执获得。 查看取值约束
|
data.receipt.quote_id |
是 | 本次购买或扩容的报价 ID。两种报价分别在各自的接口下查询。 查看取值约束
|
data.receipt.state |
是 | 当前记录的处理状态或请求筛选的状态。 查看取值约束
|
data.receipt.amount |
是 | 以站内单位表示的金额,小数字符串应原样传递。 查看取值约束
|
data.receipt.currency |
是 | 站内金额单位及展示信息,按本站配置解释所有金额。 |
data.receipt.currency.code |
是 | 站内金额单位代码,例如 CNY、USD 或 POINT。 |
data.receipt.currency.unit |
是 | 站点配置的金额单位名称。 |
data.receipt.currency.external_settlement |
是 | 外部支付的结算币种以支付渠道为准。 查看取值约束
|
data.receipt.currency.revision |
是 | 此金额单位配置的修订标识。确认付款时使用报价返回的原值。 查看取值约束
|
data.receipt.balance_before |
是 | 本次扣款或退款前的站内余额。 查看取值约束
|
data.receipt.balance_after |
是 | 本次扣款或退款后的站内余额。 查看取值约束
|
data.receipt.refunded_at |
是 | 退款完成时间,Unix 秒。 查看取值约束
|
data.receipt.revoked_days |
是 | 退款撤销的签名服务天数。 查看取值约束
|
data.receipt.sign_expires_at |
是 | 签名权益的到期时间,Unix 秒。 查看取值约束
|
data.receipt.refund_destination |
是 | 退款入账的目的地,为原付款账号站内余额。 查看取值约束
|
data.receipt.budget_restored |
是 | 退款后是否恢复原 API 付款预算。 查看取值约束
|
data.refund_destination |
是 | 退款入账的目的地,为原付款账号站内余额。 查看取值约束
示例: |
data.budget_restored |
是 | 退款后是否恢复原 API 付款预算。 查看取值约束
示例: |
data.confirmation |
是 | 确认撤销订单权益的值,执行退款时按接口要求提交。 查看取值约束
示例: |
调用示例
请把示例中的应用 ID、资源 ID和业务数据替换为自己账号的真实返回值,再选择一种语言运行。安装、文件放置和 CLOUDSIGN_BASE_URL 等配置见SDK 使用说明。
下载示例依赖
Python 标准库示例使用 cloudsign_request.py;使用 SDK 时仅需准备所选语言。长期 Secret 保存在服务端,浏览器和移动端使用OAuth 授权。
可以退款
GET /api/v1/apps/A11111111111111111111111111111111/orders/O88888888888888888888888888888888/refund HTTP/1.1
Host: www.onesignios.com
Authorization: CS1-HMAC-SHA256 Credential=<AccessKey ID>,Signature=<签名>
X-Api-Date: <当前 UTC 时间>
X-Api-Nonce: <新生成的 32 位十六进制值>
X-Api-Content-Sha256: <正文摘要>
X-Api-Environment: productionPython 标准库调用
from cloudsign_request import request
result = request(
'GET',
'/api/v1/apps/A11111111111111111111111111111111/orders/O88888888888888888888888888888888/refund',
)
print(result["request_id"])Python SDK 调用
import os
from cloudsign import Client
client = Client(
"https://www.onesignios.com",
os.environ["CLOUDSIGN_ACCESS_KEY_ID"],
os.environ["CLOUDSIGN_ACCESS_KEY_SECRET"],
os.environ.get("CLOUDSIGN_SECURITY_TOKEN", ""),
)
result = client.get_order_refund(
app='A11111111111111111111111111111111',
order='O88888888888888888888888888888888',
)
print(result["request_id"])PHP SDK 调用
<?php
declare(strict_types=1);
// Extract the PHP SDK source ZIP beside this file. Keep credentials on your server.
require_once __DIR__ . '/cloudsign-sdk/php/Client.php';
$requiredEnv = static function (string $name): string {
$value = getenv($name);
if ($value === false || $value === '') { throw new RuntimeException('Missing environment variable'); }
return $value;
};
try {
$client = new \Cloudsign\Sdk\Client(
$requiredEnv('CLOUDSIGN_BASE_URL'),
$requiredEnv('CLOUDSIGN_ACCESS_KEY_ID'),
$requiredEnv('CLOUDSIGN_ACCESS_KEY_SECRET'),
getenv('CLOUDSIGN_SECURITY_TOKEN') ?: '',
);
$result = $client->getOrderRefund(
'A11111111111111111111111111111111',
'O88888888888888888888888888888888'
);
echo $result['request_id'], PHP_EOL;
} catch (\Cloudsign\Sdk\ApiError $error) {
fwrite(STDERR, 'HTTP ' . $error->status . ' ' . $error->apiCode . '; RequestId: ' . $error->requestId . PHP_EOL);
exit(1);
} catch (Throwable $error) {
fwrite(STDERR, "Check SDK path, runtime and environment variables.\n");
exit(1);
}
Node.js SDK 调用
// Node.js 20+ on a trusted server. Do not bundle this SDK in browsers or Vue.
import { ApiError, Client } from './cloudsign-sdk/node/client.mjs';
const requiredEnv = name => {
const value = process.env[name];
if (!value) throw new Error('Missing environment variable');
return value;
};
try {
const client = new Client(
requiredEnv('CLOUDSIGN_BASE_URL'),
requiredEnv('CLOUDSIGN_ACCESS_KEY_ID'),
requiredEnv('CLOUDSIGN_ACCESS_KEY_SECRET'),
process.env.CLOUDSIGN_SECURITY_TOKEN || '',
);
const result = await client.getOrderRefund(
"A11111111111111111111111111111111",
"O88888888888888888888888888888888"
);
console.log(result.request_id);
} catch (error) {
if (error instanceof ApiError) console.error(`HTTP ${error.status} ${error.code}; RequestId: ${error.requestId}`);
else console.error('Check SDK path, runtime and environment variables.');
process.exitCode = 1;
}
Go SDK 调用
// Go 1.22+, trusted server. Extract the Go SDK ZIP beside example.go.
package main
import (
"context"
"errors"
"fmt"
"os"
"time"
cloudsign "cloudsign/sdk"
)
func main() {
fail := func(err error) {
var api *cloudsign.APIError
if errors.As(err, &api) {
fmt.Fprintf(os.Stderr, "HTTP %d %s; RequestId: %s\n", api.Status, api.Code, api.RequestID)
} else {
fmt.Fprintln(os.Stderr, "Check SDK path, runtime and environment variables.")
}
os.Exit(1)
}
client, err := cloudsign.New(
os.Getenv("CLOUDSIGN_BASE_URL"),
os.Getenv("CLOUDSIGN_ACCESS_KEY_ID"),
os.Getenv("CLOUDSIGN_ACCESS_KEY_SECRET"),
os.Getenv("CLOUDSIGN_SECURITY_TOKEN"),
)
if err != nil { fail(err); return }
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
result, err := client.GetOrderRefund(
ctx,
"A11111111111111111111111111111111",
"O88888888888888888888888888888888",
)
if err != nil { fail(err); return }
fmt.Println(result.RequestID)
}
Java SDK 调用
// Java 17+, server-side. Extract the Java SDK ZIP beside Example.java.
import com.cloudsign.openapi.Client;
import java.util.*;
public class Example {
private static String env(String name) {
String value = System.getenv(name);
if (value == null || value.isEmpty()) throw new IllegalArgumentException("Missing environment variable");
return value;
}
private static Map<String,Object> object(Object... pairs) {
var result = new LinkedHashMap<String,Object>();
for (int i = 0; i < pairs.length; i += 2) result.put((String)pairs[i], pairs[i+1]);
return result;
}
public static void main(String[] args) {
try {
var client = new Client(
env("CLOUDSIGN_BASE_URL"),
env("CLOUDSIGN_ACCESS_KEY_ID"),
env("CLOUDSIGN_ACCESS_KEY_SECRET"),
System.getenv().getOrDefault("CLOUDSIGN_SECURITY_TOKEN", "")
);
var result = client.getOrderRefund(
"A11111111111111111111111111111111",
"O88888888888888888888888888888888"
);
System.out.println(result.requestId());
} catch (Client.ApiException error) {
System.err.printf("HTTP %d %s; RequestId: %s%n", error.status, error.code, error.requestId);
System.exit(1);
} catch (Exception error) {
if (error instanceof InterruptedException) Thread.currentThread().interrupt();
System.err.println("Check SDK path, runtime and environment variables.");
System.exit(1);
}
}
}
Rust SDK 调用
// Rust 1.88+, trusted server. Save as cloudsign-sdk/rust/examples/example.rs.
use cloudsign_openapi::{Client, Credentials, GetOrderRefund};
use serde_json::json;
use std::{env, error::Error};
async fn run() -> Result<(), Box<dyn Error>> {
let origin = env::var("CLOUDSIGN_BASE_URL")?;
let credentials = Credentials::new(
env::var("CLOUDSIGN_ACCESS_KEY_ID")?,
env::var("CLOUDSIGN_ACCESS_KEY_SECRET")?,
env::var("CLOUDSIGN_SECURITY_TOKEN").ok().filter(|v| !v.is_empty()),
None,
)?;
let client = Client::new(&origin, credentials)?;
let input: GetOrderRefund = serde_json::from_value(json!({
"app_id": "A11111111111111111111111111111111",
"order_id": "O88888888888888888888888888888888"
}))?;
let result = client.get_order_refund(&input).await?;
println!("{}", result.request_id);
Ok(())
}
#[tokio::main]
async fn main() {
if let Err(error) = run().await {
if let Some(api) = error.downcast_ref::<cloudsign_openapi::Error>() {
eprintln!("HTTP {} {}; RequestId: {}", api.status, api.code, api.request_id.as_deref().unwrap_or(""));
} else {
eprintln!("Check SDK path, runtime, environment variables and business input.");
}
std::process::exit(1);
}
}
C SDK 调用
请求对象和响应对象的使用方式见C SDK 请求与响应。
/* C11, trusted server. Save as example.c in the source ZIP root. */
#include <cloudsign/openapi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int copy_env(char *out, size_t capacity, const char *name, int required) {
const char *value = getenv(name);
if (!value || !*value) return !required;
size_t length = strlen(value);
if (length >= capacity) return 0;
memcpy(out, value, length + 1);
return 1;
}
int main(void) {
cloudsign_credentials credentials = {0};
cloudsign_client *client = NULL;
cloudsign_result *result = NULL;
cloudsign_decoded_response *decoded = NULL;
cloudsign_built_request *built = NULL;
cloudsign_status status = CLOUDSIGN_INVALID_CONFIGURATION;
int initialized = 0, exit_code = 1;
const char *origin = getenv("CLOUDSIGN_BASE_URL");
if (!origin || !copy_env(credentials.access_key_id, sizeof(credentials.access_key_id), "CLOUDSIGN_ACCESS_KEY_ID", 1)
|| !copy_env(credentials.access_key_secret, sizeof(credentials.access_key_secret), "CLOUDSIGN_ACCESS_KEY_SECRET", 1)
|| !copy_env(credentials.security_token, sizeof(credentials.security_token), "CLOUDSIGN_SECURITY_TOKEN", 0)) goto done;
status = cloudsign_global_init();
if (status != CLOUDSIGN_OK) goto done;
initialized = 1;
cloudsign_options options = {.origin = origin, .credentials = &credentials, .timeout_ms = 15000};
status = cloudsign_client_create(&options, &client);
cloudsign_credentials_clear(&credentials);
if (status != CLOUDSIGN_OK) goto done;
const cloudsign_input_get_order_refund input = {.presence_app_id = CLOUDSIGN_FIELD_VALUE, .app_id = "A11111111111111111111111111111111", .presence_order_id = CLOUDSIGN_FIELD_VALUE, .order_id = "O88888888888888888888888888888888"};
status = cloudsign_build_get_order_refund(&input, &built);
if (status != CLOUDSIGN_OK) goto done;
status = cloudsign_send_built_request(client, built, &result);
if (status == CLOUDSIGN_OK) {
status = cloudsign_decode_get_order_refund(result, &decoded);
if (status != CLOUDSIGN_OK) goto done;
const cloudsign_model_order_refund *data = cloudsign_response_get_order_refund(decoded);
if (!data) { status = CLOUDSIGN_INVALID_RESPONSE; goto done; }
/* Read typed fields here; NULL/absent is distinct from zero/false. */
(void)data;
puts(cloudsign_decoded_request_id(decoded));
exit_code = 0;
}
done:
if (exit_code) {
if (status == CLOUDSIGN_API_ERROR) fprintf(stderr, "HTTP %ld %s; RequestId: %s\n", cloudsign_result_http_status(result), cloudsign_result_error_code(result), cloudsign_result_request_id(result));
else fputs("Check SDK path, runtime, environment variables and business input.\n", stderr);
}
cloudsign_result_free(result);
cloudsign_decoded_free(decoded);
cloudsign_built_request_free(built);
cloudsign_client_free(client);
if (initialized) cloudsign_global_cleanup();
cloudsign_credentials_clear(&credentials);
return exit_code;
}
{
"request_id": "00000000000000000000000000000000",
"data": {
"app_id": "A11111111111111111111111111111111",
"order_id": "O88888888888888888888888888888888",
"state": "eligible",
"eligible": true,
"amount": "14.21",
"currency": {
"code": "CUSTOM",
"unit": "积分",
"external_settlement": "payment_provider",
"revision": "Ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
},
"days": 30,
"deadline": 1794086400,
"message": "",
"receipt": null,
"refund_destination": "site_balance",
"budget_restored": false,
"confirmation": "revoke_order_entitlement"
}
}当前不可退
GET /api/v1/apps/A11111111111111111111111111111111/orders/O88888888888888888888888888888888/refund HTTP/1.1
Host: www.onesignios.com
Authorization: CS1-HMAC-SHA256 Credential=<AccessKey ID>,Signature=<签名>
X-Api-Date: <当前 UTC 时间>
X-Api-Nonce: <新生成的 32 位十六进制值>
X-Api-Content-Sha256: <正文摘要>
X-Api-Environment: productionPython 标准库调用
from cloudsign_request import request
result = request(
'GET',
'/api/v1/apps/A11111111111111111111111111111111/orders/O88888888888888888888888888888888/refund',
)
print(result["request_id"])Python SDK 调用
import os
from cloudsign import Client
client = Client(
"https://www.onesignios.com",
os.environ["CLOUDSIGN_ACCESS_KEY_ID"],
os.environ["CLOUDSIGN_ACCESS_KEY_SECRET"],
os.environ.get("CLOUDSIGN_SECURITY_TOKEN", ""),
)
result = client.get_order_refund(
app='A11111111111111111111111111111111',
order='O88888888888888888888888888888888',
)
print(result["request_id"])PHP SDK 调用
<?php
declare(strict_types=1);
// Extract the PHP SDK source ZIP beside this file. Keep credentials on your server.
require_once __DIR__ . '/cloudsign-sdk/php/Client.php';
$requiredEnv = static function (string $name): string {
$value = getenv($name);
if ($value === false || $value === '') { throw new RuntimeException('Missing environment variable'); }
return $value;
};
try {
$client = new \Cloudsign\Sdk\Client(
$requiredEnv('CLOUDSIGN_BASE_URL'),
$requiredEnv('CLOUDSIGN_ACCESS_KEY_ID'),
$requiredEnv('CLOUDSIGN_ACCESS_KEY_SECRET'),
getenv('CLOUDSIGN_SECURITY_TOKEN') ?: '',
);
$result = $client->getOrderRefund(
'A11111111111111111111111111111111',
'O88888888888888888888888888888888'
);
echo $result['request_id'], PHP_EOL;
} catch (\Cloudsign\Sdk\ApiError $error) {
fwrite(STDERR, 'HTTP ' . $error->status . ' ' . $error->apiCode . '; RequestId: ' . $error->requestId . PHP_EOL);
exit(1);
} catch (Throwable $error) {
fwrite(STDERR, "Check SDK path, runtime and environment variables.\n");
exit(1);
}
Node.js SDK 调用
// Node.js 20+ on a trusted server. Do not bundle this SDK in browsers or Vue.
import { ApiError, Client } from './cloudsign-sdk/node/client.mjs';
const requiredEnv = name => {
const value = process.env[name];
if (!value) throw new Error('Missing environment variable');
return value;
};
try {
const client = new Client(
requiredEnv('CLOUDSIGN_BASE_URL'),
requiredEnv('CLOUDSIGN_ACCESS_KEY_ID'),
requiredEnv('CLOUDSIGN_ACCESS_KEY_SECRET'),
process.env.CLOUDSIGN_SECURITY_TOKEN || '',
);
const result = await client.getOrderRefund(
"A11111111111111111111111111111111",
"O88888888888888888888888888888888"
);
console.log(result.request_id);
} catch (error) {
if (error instanceof ApiError) console.error(`HTTP ${error.status} ${error.code}; RequestId: ${error.requestId}`);
else console.error('Check SDK path, runtime and environment variables.');
process.exitCode = 1;
}
Go SDK 调用
// Go 1.22+, trusted server. Extract the Go SDK ZIP beside example.go.
package main
import (
"context"
"errors"
"fmt"
"os"
"time"
cloudsign "cloudsign/sdk"
)
func main() {
fail := func(err error) {
var api *cloudsign.APIError
if errors.As(err, &api) {
fmt.Fprintf(os.Stderr, "HTTP %d %s; RequestId: %s\n", api.Status, api.Code, api.RequestID)
} else {
fmt.Fprintln(os.Stderr, "Check SDK path, runtime and environment variables.")
}
os.Exit(1)
}
client, err := cloudsign.New(
os.Getenv("CLOUDSIGN_BASE_URL"),
os.Getenv("CLOUDSIGN_ACCESS_KEY_ID"),
os.Getenv("CLOUDSIGN_ACCESS_KEY_SECRET"),
os.Getenv("CLOUDSIGN_SECURITY_TOKEN"),
)
if err != nil { fail(err); return }
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
result, err := client.GetOrderRefund(
ctx,
"A11111111111111111111111111111111",
"O88888888888888888888888888888888",
)
if err != nil { fail(err); return }
fmt.Println(result.RequestID)
}
Java SDK 调用
// Java 17+, server-side. Extract the Java SDK ZIP beside Example.java.
import com.cloudsign.openapi.Client;
import java.util.*;
public class Example {
private static String env(String name) {
String value = System.getenv(name);
if (value == null || value.isEmpty()) throw new IllegalArgumentException("Missing environment variable");
return value;
}
private static Map<String,Object> object(Object... pairs) {
var result = new LinkedHashMap<String,Object>();
for (int i = 0; i < pairs.length; i += 2) result.put((String)pairs[i], pairs[i+1]);
return result;
}
public static void main(String[] args) {
try {
var client = new Client(
env("CLOUDSIGN_BASE_URL"),
env("CLOUDSIGN_ACCESS_KEY_ID"),
env("CLOUDSIGN_ACCESS_KEY_SECRET"),
System.getenv().getOrDefault("CLOUDSIGN_SECURITY_TOKEN", "")
);
var result = client.getOrderRefund(
"A11111111111111111111111111111111",
"O88888888888888888888888888888888"
);
System.out.println(result.requestId());
} catch (Client.ApiException error) {
System.err.printf("HTTP %d %s; RequestId: %s%n", error.status, error.code, error.requestId);
System.exit(1);
} catch (Exception error) {
if (error instanceof InterruptedException) Thread.currentThread().interrupt();
System.err.println("Check SDK path, runtime and environment variables.");
System.exit(1);
}
}
}
Rust SDK 调用
// Rust 1.88+, trusted server. Save as cloudsign-sdk/rust/examples/example.rs.
use cloudsign_openapi::{Client, Credentials, GetOrderRefund};
use serde_json::json;
use std::{env, error::Error};
async fn run() -> Result<(), Box<dyn Error>> {
let origin = env::var("CLOUDSIGN_BASE_URL")?;
let credentials = Credentials::new(
env::var("CLOUDSIGN_ACCESS_KEY_ID")?,
env::var("CLOUDSIGN_ACCESS_KEY_SECRET")?,
env::var("CLOUDSIGN_SECURITY_TOKEN").ok().filter(|v| !v.is_empty()),
None,
)?;
let client = Client::new(&origin, credentials)?;
let input: GetOrderRefund = serde_json::from_value(json!({
"app_id": "A11111111111111111111111111111111",
"order_id": "O88888888888888888888888888888888"
}))?;
let result = client.get_order_refund(&input).await?;
println!("{}", result.request_id);
Ok(())
}
#[tokio::main]
async fn main() {
if let Err(error) = run().await {
if let Some(api) = error.downcast_ref::<cloudsign_openapi::Error>() {
eprintln!("HTTP {} {}; RequestId: {}", api.status, api.code, api.request_id.as_deref().unwrap_or(""));
} else {
eprintln!("Check SDK path, runtime, environment variables and business input.");
}
std::process::exit(1);
}
}
C SDK 调用
请求对象和响应对象的使用方式见C SDK 请求与响应。
/* C11, trusted server. Save as example.c in the source ZIP root. */
#include <cloudsign/openapi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int copy_env(char *out, size_t capacity, const char *name, int required) {
const char *value = getenv(name);
if (!value || !*value) return !required;
size_t length = strlen(value);
if (length >= capacity) return 0;
memcpy(out, value, length + 1);
return 1;
}
int main(void) {
cloudsign_credentials credentials = {0};
cloudsign_client *client = NULL;
cloudsign_result *result = NULL;
cloudsign_decoded_response *decoded = NULL;
cloudsign_built_request *built = NULL;
cloudsign_status status = CLOUDSIGN_INVALID_CONFIGURATION;
int initialized = 0, exit_code = 1;
const char *origin = getenv("CLOUDSIGN_BASE_URL");
if (!origin || !copy_env(credentials.access_key_id, sizeof(credentials.access_key_id), "CLOUDSIGN_ACCESS_KEY_ID", 1)
|| !copy_env(credentials.access_key_secret, sizeof(credentials.access_key_secret), "CLOUDSIGN_ACCESS_KEY_SECRET", 1)
|| !copy_env(credentials.security_token, sizeof(credentials.security_token), "CLOUDSIGN_SECURITY_TOKEN", 0)) goto done;
status = cloudsign_global_init();
if (status != CLOUDSIGN_OK) goto done;
initialized = 1;
cloudsign_options options = {.origin = origin, .credentials = &credentials, .timeout_ms = 15000};
status = cloudsign_client_create(&options, &client);
cloudsign_credentials_clear(&credentials);
if (status != CLOUDSIGN_OK) goto done;
const cloudsign_input_get_order_refund input = {.presence_app_id = CLOUDSIGN_FIELD_VALUE, .app_id = "A11111111111111111111111111111111", .presence_order_id = CLOUDSIGN_FIELD_VALUE, .order_id = "O88888888888888888888888888888888"};
status = cloudsign_build_get_order_refund(&input, &built);
if (status != CLOUDSIGN_OK) goto done;
status = cloudsign_send_built_request(client, built, &result);
if (status == CLOUDSIGN_OK) {
status = cloudsign_decode_get_order_refund(result, &decoded);
if (status != CLOUDSIGN_OK) goto done;
const cloudsign_model_order_refund *data = cloudsign_response_get_order_refund(decoded);
if (!data) { status = CLOUDSIGN_INVALID_RESPONSE; goto done; }
/* Read typed fields here; NULL/absent is distinct from zero/false. */
(void)data;
puts(cloudsign_decoded_request_id(decoded));
exit_code = 0;
}
done:
if (exit_code) {
if (status == CLOUDSIGN_API_ERROR) fprintf(stderr, "HTTP %ld %s; RequestId: %s\n", cloudsign_result_http_status(result), cloudsign_result_error_code(result), cloudsign_result_request_id(result));
else fputs("Check SDK path, runtime, environment variables and business input.\n", stderr);
}
cloudsign_result_free(result);
cloudsign_decoded_free(decoded);
cloudsign_built_request_free(built);
cloudsign_client_free(client);
if (initialized) cloudsign_global_cleanup();
cloudsign_credentials_clear(&credentials);
return exit_code;
}
{
"request_id": "00000000000000000000000000000000",
"data": {
"app_id": "A11111111111111111111111111111111",
"order_id": "O88888888888888888888888888888888",
"state": "unavailable",
"eligible": false,
"amount": "14.21",
"currency": {
"code": "CUSTOM",
"unit": "积分",
"external_settlement": "payment_provider",
"revision": "Ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
},
"days": null,
"deadline": null,
"message": "当前订单不符合退款规则",
"receipt": null,
"refund_destination": "site_balance",
"budget_restored": false,
"confirmation": "revoke_order_entitlement"
}
}已完成退款
GET /api/v1/apps/A11111111111111111111111111111111/orders/O88888888888888888888888888888888/refund HTTP/1.1
Host: www.onesignios.com
Authorization: CS1-HMAC-SHA256 Credential=<AccessKey ID>,Signature=<签名>
X-Api-Date: <当前 UTC 时间>
X-Api-Nonce: <新生成的 32 位十六进制值>
X-Api-Content-Sha256: <正文摘要>
X-Api-Environment: productionPython 标准库调用
from cloudsign_request import request
result = request(
'GET',
'/api/v1/apps/A11111111111111111111111111111111/orders/O88888888888888888888888888888888/refund',
)
print(result["request_id"])Python SDK 调用
import os
from cloudsign import Client
client = Client(
"https://www.onesignios.com",
os.environ["CLOUDSIGN_ACCESS_KEY_ID"],
os.environ["CLOUDSIGN_ACCESS_KEY_SECRET"],
os.environ.get("CLOUDSIGN_SECURITY_TOKEN", ""),
)
result = client.get_order_refund(
app='A11111111111111111111111111111111',
order='O88888888888888888888888888888888',
)
print(result["request_id"])PHP SDK 调用
<?php
declare(strict_types=1);
// Extract the PHP SDK source ZIP beside this file. Keep credentials on your server.
require_once __DIR__ . '/cloudsign-sdk/php/Client.php';
$requiredEnv = static function (string $name): string {
$value = getenv($name);
if ($value === false || $value === '') { throw new RuntimeException('Missing environment variable'); }
return $value;
};
try {
$client = new \Cloudsign\Sdk\Client(
$requiredEnv('CLOUDSIGN_BASE_URL'),
$requiredEnv('CLOUDSIGN_ACCESS_KEY_ID'),
$requiredEnv('CLOUDSIGN_ACCESS_KEY_SECRET'),
getenv('CLOUDSIGN_SECURITY_TOKEN') ?: '',
);
$result = $client->getOrderRefund(
'A11111111111111111111111111111111',
'O88888888888888888888888888888888'
);
echo $result['request_id'], PHP_EOL;
} catch (\Cloudsign\Sdk\ApiError $error) {
fwrite(STDERR, 'HTTP ' . $error->status . ' ' . $error->apiCode . '; RequestId: ' . $error->requestId . PHP_EOL);
exit(1);
} catch (Throwable $error) {
fwrite(STDERR, "Check SDK path, runtime and environment variables.\n");
exit(1);
}
Node.js SDK 调用
// Node.js 20+ on a trusted server. Do not bundle this SDK in browsers or Vue.
import { ApiError, Client } from './cloudsign-sdk/node/client.mjs';
const requiredEnv = name => {
const value = process.env[name];
if (!value) throw new Error('Missing environment variable');
return value;
};
try {
const client = new Client(
requiredEnv('CLOUDSIGN_BASE_URL'),
requiredEnv('CLOUDSIGN_ACCESS_KEY_ID'),
requiredEnv('CLOUDSIGN_ACCESS_KEY_SECRET'),
process.env.CLOUDSIGN_SECURITY_TOKEN || '',
);
const result = await client.getOrderRefund(
"A11111111111111111111111111111111",
"O88888888888888888888888888888888"
);
console.log(result.request_id);
} catch (error) {
if (error instanceof ApiError) console.error(`HTTP ${error.status} ${error.code}; RequestId: ${error.requestId}`);
else console.error('Check SDK path, runtime and environment variables.');
process.exitCode = 1;
}
Go SDK 调用
// Go 1.22+, trusted server. Extract the Go SDK ZIP beside example.go.
package main
import (
"context"
"errors"
"fmt"
"os"
"time"
cloudsign "cloudsign/sdk"
)
func main() {
fail := func(err error) {
var api *cloudsign.APIError
if errors.As(err, &api) {
fmt.Fprintf(os.Stderr, "HTTP %d %s; RequestId: %s\n", api.Status, api.Code, api.RequestID)
} else {
fmt.Fprintln(os.Stderr, "Check SDK path, runtime and environment variables.")
}
os.Exit(1)
}
client, err := cloudsign.New(
os.Getenv("CLOUDSIGN_BASE_URL"),
os.Getenv("CLOUDSIGN_ACCESS_KEY_ID"),
os.Getenv("CLOUDSIGN_ACCESS_KEY_SECRET"),
os.Getenv("CLOUDSIGN_SECURITY_TOKEN"),
)
if err != nil { fail(err); return }
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
result, err := client.GetOrderRefund(
ctx,
"A11111111111111111111111111111111",
"O88888888888888888888888888888888",
)
if err != nil { fail(err); return }
fmt.Println(result.RequestID)
}
Java SDK 调用
// Java 17+, server-side. Extract the Java SDK ZIP beside Example.java.
import com.cloudsign.openapi.Client;
import java.util.*;
public class Example {
private static String env(String name) {
String value = System.getenv(name);
if (value == null || value.isEmpty()) throw new IllegalArgumentException("Missing environment variable");
return value;
}
private static Map<String,Object> object(Object... pairs) {
var result = new LinkedHashMap<String,Object>();
for (int i = 0; i < pairs.length; i += 2) result.put((String)pairs[i], pairs[i+1]);
return result;
}
public static void main(String[] args) {
try {
var client = new Client(
env("CLOUDSIGN_BASE_URL"),
env("CLOUDSIGN_ACCESS_KEY_ID"),
env("CLOUDSIGN_ACCESS_KEY_SECRET"),
System.getenv().getOrDefault("CLOUDSIGN_SECURITY_TOKEN", "")
);
var result = client.getOrderRefund(
"A11111111111111111111111111111111",
"O88888888888888888888888888888888"
);
System.out.println(result.requestId());
} catch (Client.ApiException error) {
System.err.printf("HTTP %d %s; RequestId: %s%n", error.status, error.code, error.requestId);
System.exit(1);
} catch (Exception error) {
if (error instanceof InterruptedException) Thread.currentThread().interrupt();
System.err.println("Check SDK path, runtime and environment variables.");
System.exit(1);
}
}
}
Rust SDK 调用
// Rust 1.88+, trusted server. Save as cloudsign-sdk/rust/examples/example.rs.
use cloudsign_openapi::{Client, Credentials, GetOrderRefund};
use serde_json::json;
use std::{env, error::Error};
async fn run() -> Result<(), Box<dyn Error>> {
let origin = env::var("CLOUDSIGN_BASE_URL")?;
let credentials = Credentials::new(
env::var("CLOUDSIGN_ACCESS_KEY_ID")?,
env::var("CLOUDSIGN_ACCESS_KEY_SECRET")?,
env::var("CLOUDSIGN_SECURITY_TOKEN").ok().filter(|v| !v.is_empty()),
None,
)?;
let client = Client::new(&origin, credentials)?;
let input: GetOrderRefund = serde_json::from_value(json!({
"app_id": "A11111111111111111111111111111111",
"order_id": "O88888888888888888888888888888888"
}))?;
let result = client.get_order_refund(&input).await?;
println!("{}", result.request_id);
Ok(())
}
#[tokio::main]
async fn main() {
if let Err(error) = run().await {
if let Some(api) = error.downcast_ref::<cloudsign_openapi::Error>() {
eprintln!("HTTP {} {}; RequestId: {}", api.status, api.code, api.request_id.as_deref().unwrap_or(""));
} else {
eprintln!("Check SDK path, runtime, environment variables and business input.");
}
std::process::exit(1);
}
}
C SDK 调用
请求对象和响应对象的使用方式见C SDK 请求与响应。
/* C11, trusted server. Save as example.c in the source ZIP root. */
#include <cloudsign/openapi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int copy_env(char *out, size_t capacity, const char *name, int required) {
const char *value = getenv(name);
if (!value || !*value) return !required;
size_t length = strlen(value);
if (length >= capacity) return 0;
memcpy(out, value, length + 1);
return 1;
}
int main(void) {
cloudsign_credentials credentials = {0};
cloudsign_client *client = NULL;
cloudsign_result *result = NULL;
cloudsign_decoded_response *decoded = NULL;
cloudsign_built_request *built = NULL;
cloudsign_status status = CLOUDSIGN_INVALID_CONFIGURATION;
int initialized = 0, exit_code = 1;
const char *origin = getenv("CLOUDSIGN_BASE_URL");
if (!origin || !copy_env(credentials.access_key_id, sizeof(credentials.access_key_id), "CLOUDSIGN_ACCESS_KEY_ID", 1)
|| !copy_env(credentials.access_key_secret, sizeof(credentials.access_key_secret), "CLOUDSIGN_ACCESS_KEY_SECRET", 1)
|| !copy_env(credentials.security_token, sizeof(credentials.security_token), "CLOUDSIGN_SECURITY_TOKEN", 0)) goto done;
status = cloudsign_global_init();
if (status != CLOUDSIGN_OK) goto done;
initialized = 1;
cloudsign_options options = {.origin = origin, .credentials = &credentials, .timeout_ms = 15000};
status = cloudsign_client_create(&options, &client);
cloudsign_credentials_clear(&credentials);
if (status != CLOUDSIGN_OK) goto done;
const cloudsign_input_get_order_refund input = {.presence_app_id = CLOUDSIGN_FIELD_VALUE, .app_id = "A11111111111111111111111111111111", .presence_order_id = CLOUDSIGN_FIELD_VALUE, .order_id = "O88888888888888888888888888888888"};
status = cloudsign_build_get_order_refund(&input, &built);
if (status != CLOUDSIGN_OK) goto done;
status = cloudsign_send_built_request(client, built, &result);
if (status == CLOUDSIGN_OK) {
status = cloudsign_decode_get_order_refund(result, &decoded);
if (status != CLOUDSIGN_OK) goto done;
const cloudsign_model_order_refund *data = cloudsign_response_get_order_refund(decoded);
if (!data) { status = CLOUDSIGN_INVALID_RESPONSE; goto done; }
/* Read typed fields here; NULL/absent is distinct from zero/false. */
(void)data;
puts(cloudsign_decoded_request_id(decoded));
exit_code = 0;
}
done:
if (exit_code) {
if (status == CLOUDSIGN_API_ERROR) fprintf(stderr, "HTTP %ld %s; RequestId: %s\n", cloudsign_result_http_status(result), cloudsign_result_error_code(result), cloudsign_result_request_id(result));
else fputs("Check SDK path, runtime, environment variables and business input.\n", stderr);
}
cloudsign_result_free(result);
cloudsign_decoded_free(decoded);
cloudsign_built_request_free(built);
cloudsign_client_free(client);
if (initialized) cloudsign_global_cleanup();
cloudsign_credentials_clear(&credentials);
return exit_code;
}
{
"request_id": "00000000000000000000000000000000",
"data": {
"app_id": "A11111111111111111111111111111111",
"order_id": "O88888888888888888888888888888888",
"state": "refunded",
"eligible": false,
"amount": "14.21",
"currency": {
"code": "CUSTOM",
"unit": "积分",
"external_settlement": "payment_provider",
"revision": "Ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
},
"days": null,
"deadline": null,
"message": "该订单已退款",
"receipt": {
"id": "R77777777777777777777777777777777",
"app_id": "A11111111111111111111111111111111",
"order_id": "O88888888888888888888888888888888",
"quote_id": "Q99999999999999999999999999999999",
"state": "refunded",
"amount": "14.21",
"currency": {
"code": "CUSTOM",
"unit": "积分",
"external_settlement": "payment_provider",
"revision": "Ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
},
"balance_before": "85.79",
"balance_after": "100.00",
"refunded_at": 1794000123,
"revoked_days": 30,
"sign_expires_at": 1794000000,
"refund_destination": "site_balance",
"budget_restored": false
},
"refund_destination": "site_balance",
"budget_restored": false,
"confirmation": "revoke_order_entitlement"
}
}错误处理
失败或中断后
资格已失效时不要继续展示可提交的退款操作。查询失败时先恢复资格读取,不根据旧缓存直接申请退款。
相关错误码
| HTTP | 错误码 | 处理方式 |
|---|---|---|
| 403 | FinancialIpRequired | 此操作需要精确来源 IP。核对服务端实际出口和该 API 应用授权。 |
| 404 | NotFound | 核对路径中各标识是否完整、属于同一业务应用且在当前授权范围内。 |
| 503 | RefundsUnavailable | 暂时无法核实退款或权益数据,保留原订单号和 request_id。 |
| 401 | InvalidCredentials | 凭据无效、已停用,或请求签名不匹配。核对 AK、环境、正文摘要和签名头。 |
| 429 | Throttled | 请求达到限额,按 Retry-After 返回的秒数等待,再以新 nonce 发起请求。 |