调用示例
1. GET请求(图片URL解析)
https://tool.4759.cn/api/qrcode_decode.php?key=你的API_KEY&file_url=https://tool.4759.cn/demo.png
2. PHP GET调用示例
<?php
$api_key = "你的API授权码";
$file_url = "https://tool.4759.cn/demo.png";
$api_url = "https://tool.4759.cn/api/qrcode_decode.php?key=" . urlencode($api_key) . "&file_url=" . urlencode($file_url);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $api_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => false
]);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
if ($result['success']) {
echo "解码成功:" . implode(',', $result['data']['contents']);
} else {
echo "失败:" . $result['msg'] . "(状态码:{$result['code']})";
}
?>
3. PHP POST上传文件示例
<?php
$api_key = "你的API授权码";
$api_url = "https://tool.4759.cn/api/qrcode_decode.php";
$file_path = "本地图片路径/xxx.png";
$file_name = basename($file_path);
$file_type = 'application/octet-stream';
if (file_exists($file_path)) {
$finfo = new finfo(FILEINFO_MIME_TYPE);
$file_type = $finfo->file($file_path);
}
$post_data = [
'key' => $api_key,
'file' => new CURLFile($file_path, $file_type, $file_name)
];
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $api_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $post_data,
CURLOPT_TIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => false
]);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
if ($result['success']) {
echo "解码成功:" . implode(',', $result['data']['contents']);
} else {
echo "失败:" . $result['msg'] . "(状态码:{$result['code']})";
}
?>
4. 成功返回示例
{
"code": 200,
"msg": "解码成功",
"data": {
"contents": ["https://4759.cn"]
},
"success": true,
"call_stats": {
"used_day": 5,
"remaining_day": 995,
"tips": "小时调用次数暂不统计"
},
"used_api": "4759.cn 二维码解码接口"
}
5. 失败返回示例
{
"code": -1,
"msg": "file_url参数不能为空",
"data": {
"contents": []
},
"success": false
}