首页 全部接口 API文档 文章 贡献者 友链 关于
登录/注册

二维码解析

GET POST https://api.xunjinlu.fun/api/qrcode/decodeqrcode.php

二维码解析API接口文档

接口简介

本API提供二维码识别功能,支持通过图片URL、上传本地图片文件或Base64编码的图片数据进行二维码解码。适用于需要集成二维码扫描功能的Web应用、移动应用或第三方系统。

请求说明

  • 完整接口地址:https://api.xunjinlu.fun/api/qrcode/decodeqrcode.php
  • 请求方法:GET, POST
  • 请求头:无特殊要求,根据实际需要设置Content-Type

请求参数

参数名类型是否必填说明
----------------------------------------------------------------------------------------------
file_urlstring选填二维码图片的URL地址,需URL编码,与file、image_base64三选一
filefile选填上传的本地图片文件,支持png/jpg/gif/bmp/webp,最大5MB
image_base64string选填Base64编码的图片数据,支持data:image/png;base64,xxx格式或纯Base64字符串

返回参数

参数名类型说明
---------------------------------------------------------------------------------------
codeinteger状态码,200表示成功,其他值表示错误
dataobject返回数据对象
- contentsarray识别到的二维码内容列表
- countinteger识别到的二维码数量
- raw_responseobject原始响应数据
messagestring返回信息

返回示例

成功响应(识别到内容)

{
  "code": 200,
  "data": {
    "contents": [
      "https://www.example.com",
      "Hello World"
    ],
    "count": 2,
    "raw_response": {
      "code": 0,
      "message": "ok",
      "data": {
        "contents": [
          "https://www.example.com",
          "Hello World"
        ]
      }
    }
  },
  "message": "识别成功"
}

成功响应(未识别到内容)

{
  "code": 200,
  "data": {
    "contents": [],
    "count": 0,
    "raw_response": {
      "code": 0,
      "message": "ok",
      "data": {
        "contents": []
      }
    }
  },
  "message": "未识别到二维码内容"
}

错误响应示例

{
  "code": 400,
  "data": null,
  "message": "参数错误: file_url不能为空"
}

错误码说明

  • 400:参数错误
  • 400:不支持的文件类型
  • 502:识别失败

调用示例

直接访问链接

https://api.xunjinlu.fun/api/qrcode/decodeqrcode.php?file_url=https%3A%2F%2Fexample.com%2Fqrcode.png

cURL命令示例

curl -X GET "https://api.xunjinlu.fun/api/qrcode/decodeqrcode.php" -H "Content-Type: application/json" -d '{"file_url": "https://example.com/qrcode.png"}'

JavaScript (fetch) 示例

fetch('https://api.xunjinlu.fun/api/qrcode/decodeqrcode.php', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ file_url: 'https://example.com/qrcode.png' })
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

jQuery AJAX 示例

$.ajax({
  url: 'https://api.xunjinlu.fun/api/qrcode/decodeqrcode.php',
  type: 'POST',
  contentType: 'application/json',
  data: JSON.stringify({ file_url: 'https://example.com/qrcode.png' }),
  success: function(data) {
    console.log(data);
  },
  error: function(error) {
    console.error('Error:', error);
  }
});

Python (requests) 示例

import requests

url = 'https://api.xunjinlu.fun/api/qrcode/decodeqrcode.php'
data = {'file_url': 'https://example.com/qrcode.png'}
response = requests.post(url, json=data)
print(response.json())

PHP (curl) 示例

$url = 'https://api.xunjinlu.fun/api/qrcode/decodeqrcode.php';
$data = array('file_url' => 'https://example.com/qrcode.png');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;

HTML (iframe/img/script标签)

<!-- iframe -->
<iframe src="https://api.xunjinlu.fun/api/qrcode/decodeqrcode.php?file_url=https%3A%2F%2Fexample.com%2Fqrcode.png" width="500" height="500"></iframe>

<!-- img -->
<img src="https://api.xunjinlu.fun/api/qrcode/decodeqrcode.php?file_url=https%3A%2F%2Fexample.com%2Fqrcode.png" width="500" height="500" />

<!-- script -->
<script>
fetch('https://api.xunjinlu.fun/api/qrcode/decodeqrcode.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ file_url: 'https://example.com/qrcode.png' })
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
</script>