線上購買(buy)
按次購買套餐,回傳訂單及專屬憑證。僅支援套餐制 API,買斷制 API 不支援按次購買。僅限銷售/管理員角色呼叫。
介面資訊
| 項目 | 說明 |
|---|
| 介面位址 | POST /api.php |
| action | buy |
| 認證方式 | 全域應用 APP ID / APP KEY |
| 角色限制 | 僅銷售/管理員 |
請求參數
| 參數 | 類型 | 必填 | 說明 |
|---|
api_id | int | 是 | API ID |
calls | int | 是 | 購買次數(>0) |
months | int | 是 | 有效期月數(1-12) |
請求範例
{
"action": "buy",
"app_id": "68B0FA47FEC9E7EBC4BF80F8",
"app_key": "2b901515a427b6c0b68f866eece70e0d2ecf687146022412",
"api_id": 4,
"calls": 100,
"months": 1
}
PHP
<?php
$app_id = '68B0FA47FEC9E7EBC4BF80F8';
$app_key = '2b901515a427b6c0b68f866eece70e0d2ecf687146022412';
$url = 'https://yunsapi.com/api.php';
$params = [
'action' => 'buy',
'app_id' => $app_id,
'app_key' => $app_key,
'api_id' => 4,
'calls' => 100,
'months' => 1,
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($ch);
curl_close($ch);
echo $resp;
Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class ApiDemo {
static final String URL = "https://yunsapi.com/api.php";
static final String APP_ID = "68B0FA47FEC9E7EBC4BF80F8";
static final String APP_KEY = "2b901515a427b6c0b68f866eece70e0d2ecf687146022412";
public static void main(String[] args) throws Exception {
String body = "{\"action\":\"buy\",\"app_id\":\"" + APP_ID + "\",\"app_key\":\"" + APP_KEY + "\",\"api_id\":4,\"calls\":100,\"months\":1}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest req = HttpRequest.newBuilder()
.uri(URI.create(URL))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> resp = client.send(req, HttpResponse.BodyHandlers.ofString());
System.out.println(resp.body());
}
}
回應範例
{
"code": 0,
"msg": "購買成功",
"data": {
"order_id": "34",
"amount": 2.8000,
"calls": 100,
"expire_time": "2027-08-14 01:45:01",
"order_app_id": "15AC1BF22009DB47C72358E0",
"order_app_key": "f3847539631cc4c4e4da1e8bece180b129e02bb60ec3234a"
}
}
回應參數
| 參數 | 類型 | 說明 |
|---|
data.order_id | string | 訂單 ID |
data.amount | float | 實際支付金額 |
data.calls | int | 購買次數 |
data.expire_time | string | 到期時間 |
data.order_app_id | string | 專屬 APP ID |
data.order_app_key | string | 專屬 APP KEY |