请求示例
curl -X POST https://value.yoga/api/verify_card.php \
-H "Content-Type: application/json" \
-H "X-Requested-With: XMLHttpRequest" \
-d '{
"api_key": "your_api_key_here",
"card_code": "XXXXXXXXXXXXXXXXXXXX"
}'
// API验证示例
$api_key = 'your_api_key_here';
$card_code = 'XXXXXXXXXXXXXXXXXXXX';
// 初始化cURL会话
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://value.yoga/api/verify_card.php',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode([
'api_key' => $api_key,
'card_code' => $card_code
]),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'X-Requested-With: XMLHttpRequest'
],
CURLOPT_TIMEOUT => 10 // 设置超时时间为10秒
]);
try {
$response = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($response === false) {
throw new Exception('cURL错误: ' . curl_error($curl));
}
curl_close($curl);
if ($http_code === 200) {
$result = json_decode($response, true);
if ($result && $result['success']) {
// 验证成功
$data = $result['data'];
echo "卡密验证成功!\n";
echo "卡密:{$data['card_code']}\n";
echo "状态:{$data['status_text']}\n";
echo "时长:{$data['duration_text']}\n";
echo "到期时间:{$data['expire_at']}\n";
} else {
// 验证失败
echo "验证失败:" . ($result['message'] ?? '未知错误') . "\n";
}
} else {
echo "请求失败,HTTP状态码:{$http_code}\n";
}
} catch (Exception $e) {
echo "请求异常:" . $e->getMessage() . "\n";
}
import requests
import json
def verify_card(api_key, card_code):
"""验证卡密函数"""
url = 'https://value.yoga/api/verify_card.php'
headers = {
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
}
payload = {
'api_key': api_key,
'card_code': card_code
}
try:
# 发送POST请求,超时设置为10秒
response = requests.post(url, headers=headers, json=payload, timeout=10)
# 检查HTTP状态码
response.raise_for_status()
# 解析JSON响应
result = response.json()
if result.get('success'):
# 验证成功
data = result['data']
print(f"卡密验证成功!")
print(f"卡密:{data['card_code']}")
print(f"状态:{data['status_text']}")
print(f"时长:{data['duration_text']}")
print(f"到期时间:{data['expire_at']}")
return data
else:
# 验证失败
print(f"验证失败:{result.get('message', '未知错误')}")
return None
except requests.exceptions.HTTPError as e:
print(f"HTTP错误:{e}")
except requests.exceptions.ConnectionError as e:
print(f"连接错误:{e}")
except requests.exceptions.Timeout:
print("请求超时")
except requests.exceptions.RequestException as e:
print(f"请求错误:{e}")
except ValueError as e:
print(f"JSON解析错误:{e}")
except Exception as e:
print(f"其他错误:{e}")
return None
# 调用示例
if __name__ == "__main__":
api_key = 'your_api_key_here'
card_code = 'XXXXXXXXXXXXXXXXXXXX'
verify_card(api_key, card_code)
/**
* 卡密验证函数
* @param {string} apiKey - API密钥
* @param {string} cardCode - 卡密字符串
* @returns {Promise} - 返回验证结果的Promise
*/
async function verifyCard(apiKey, cardCode) {
const url = 'https://value.yoga/api/verify_card.php';
try {
// 设置请求超时
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10秒超时
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
},
body: JSON.stringify({
api_key: apiKey,
card_code: cardCode
}),
signal: controller.signal
});
clearTimeout(timeoutId); // 清除超时
if (!response.ok) {
throw new Error(`网络响应不正常: ${response.status} ${response.statusText}`);
}
const result = await response.json();
if (result.success) {
// 验证成功
const data = result.data;
console.log('卡密验证成功!');
console.log('卡密:', data.card_code);
console.log('状态:', data.status_text);
console.log('时长:', data.duration_text);
console.log('到期时间:', data.expire_at);
return data;
} else {
// 验证失败
console.error('验证失败:', result.message);
return null;
}
} catch (error) {
if (error.name === 'AbortError') {
console.error('请求超时');
} else {
console.error('请求错误:', error.message);
}
return null;
}
}
// 使用示例
const apiKey = 'your_api_key_here';
const cardCode = 'XXXXXXXXXXXXXXXXXXXX';
verifyCard(apiKey, cardCode)
.then(data => {
if (data) {
// 在这里处理成功的结果
document.getElementById('result').textContent = `验证成功: ${data.card_code}`;
} else {
// 处理失败情况
document.getElementById('result').textContent = '验证失败';
}
});
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
public class CardVerifier {
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
private static final String API_URL = "https://value.yoga/api/verify_card.php";
/**
* 验证卡密
* @param apiKey API密钥
* @param cardCode 卡密字符串
* @return 验证结果,成功返回数据,失败返回null
*/
public static JSONObject verifyCard(String apiKey, String cardCode) {
// 创建OkHttpClient,设置超时
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.build();
try {
// 构建请求JSON
JSONObject jsonPayload = new JSONObject();
jsonPayload.put("api_key", apiKey);
jsonPayload.put("card_code", cardCode);
// 创建请求体
RequestBody body = RequestBody.create(
jsonPayload.toString(), JSON
);
// 创建请求
Request request = new Request.Builder()
.url(API_URL)
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("X-Requested-With", "XMLHttpRequest")
.build();
// 执行请求
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
System.out.println("请求失败,HTTP状态码:" + response.code());
return null;
}
// 处理响应
String responseBody = response.body().string();
JSONObject result = new JSONObject(responseBody);
if (result.getBoolean("success")) {
// 验证成功
JSONObject data = result.getJSONObject("data");
System.out.println("卡密验证成功!");
System.out.println("卡密:" + data.getString("card_code"));
System.out.println("状态:" + data.getString("status_text"));
System.out.println("时长:" + data.getString("duration_text"));
System.out.println("到期时间:" + data.getString("expire_at"));
return data;
} else {
// 验证失败
System.out.println("验证失败:" + result.getString("message"));
return null;
}
}
} catch (JSONException e) {
System.out.println("JSON解析错误:" + e.getMessage());
} catch (IOException e) {
System.out.println("网络错误:" + e.getMessage());
} catch (Exception e) {
System.out.println("发生错误:" + e.getMessage());
}
return null;
}
// 使用示例
public static void main(String[] args) {
String apiKey = "your_api_key_here";
String cardCode = "XXXXXXXXXXXXXXXXXXXX";
JSONObject result = verifyCard(apiKey, cardCode);
if (result != null) {
// 处理成功结果
System.out.println("验证成功,可以在这里处理结果");
}
}
}
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace CardVerificationExample
{
public class CardVerifier
{
private static readonly HttpClient client = new HttpClient();
private const string ApiUrl = "https://value.yoga/api/verify_card.php";
///
/// 验证卡密
///
/// API密钥
/// 卡密字符串
/// 验证结果
public static async Task VerifyCardAsync(string apiKey, string cardCode)
{
try
{
// 设置超时时间
client.Timeout = TimeSpan.FromSeconds(10);
// 构建请求数据
var payload = new
{
api_key = apiKey,
card_code = cardCode
};
// 序列化为JSON
var content = new StringContent(
JsonSerializer.Serialize(payload),
Encoding.UTF8,
"application/json"
);
// 添加请求头
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Add("X-Requested-With", "XMLHttpRequest");
// 发送请求
var response = await client.PostAsync(ApiUrl, content);
// 检查HTTP状态码
response.EnsureSuccessStatusCode();
// 读取响应内容
var responseBody = await response.Content.ReadAsStringAsync();
// 解析JSON
using (JsonDocument doc = JsonDocument.Parse(responseBody))
{
var root = doc.RootElement;
bool success = root.GetProperty("success").GetBoolean();
if (success)
{
// 验证成功
var data = root.GetProperty("data");
Console.WriteLine("卡密验证成功!");
Console.WriteLine($"卡密:{data.GetProperty("card_code").GetString()}");
Console.WriteLine($"状态:{data.GetProperty("status_text").GetString()}");
Console.WriteLine($"时长:{data.GetProperty("duration_text").GetString()}");
Console.WriteLine($"到期时间:{data.GetProperty("expire_at").GetString()}");
return new VerificationResult
{
Success = true,
CardCode = data.GetProperty("card_code").GetString(),
StatusText = data.GetProperty("status_text").GetString(),
DurationText = data.GetProperty("duration_text").GetString(),
ExpireAt = data.GetProperty("expire_at").GetString()
};
}
else
{
// 验证失败
string message = root.GetProperty("message").GetString();
Console.WriteLine($"验证失败:{message}");
return new VerificationResult { Success = false, Message = message };
}
}
}
catch (HttpRequestException e)
{
Console.WriteLine($"HTTP请求错误:{e.Message}");
return new VerificationResult { Success = false, Message = $"HTTP请求错误:{e.Message}" };
}
catch (TaskCanceledException)
{
Console.WriteLine("请求超时");
return new VerificationResult { Success = false, Message = "请求超时" };
}
catch (Exception e)
{
Console.WriteLine($"验证错误:{e.Message}");
return new VerificationResult { Success = false, Message = $"验证错误:{e.Message}" };
}
}
}
// 验证结果类
public class VerificationResult
{
public bool Success { get; set; }
public string Message { get; set; }
public string CardCode { get; set; }
public string StatusText { get; set; }
public string DurationText { get; set; }
public string ExpireAt { get; set; }
}
// 使用示例
public class Program
{
public static async Task Main(string[] args)
{
string apiKey = "your_api_key_here";
string cardCode = "XXXXXXXXXXXXXXXXXXXX";
var result = await CardVerifier.VerifyCardAsync(apiKey, cardCode);
if (result.Success)
{
Console.WriteLine("验证成功,可以继续处理...");
// 在这里处理验证成功的逻辑
}
else
{
Console.WriteLine($"验证失败:{result.Message}");
// 在这里处理验证失败的逻辑
}
}
}
}
成功响应示例
{
"success": true,
"data": {
"card_code": "卡密代码",
"status": 1,
"status_text": "已使用",
"duration_days": "持续天数",
"duration_text": "时长文本",
"created_at": "创建时间",
"used_at": "使用时间",
"expire_at": "过期时间",
"remark": "备注信息"
}
}
卡密已使用示例
{
"code": 1002,
"message": "卡密已被使用",
"data": {
"card_code": "XXXX********XXXX",
"verify_time": "2024-03-21 10:00:00",
"expire_time": "2024-04-20 10:00:00",
"duration_days": 30,
"card_type": "月卡"
}
}
错误响应示例
{
"code": 1001,
"message": "API密钥不能为空"
}