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

生成二维码

GET POST https://apis.whrx.chat/api/qrcode/createqrcode.php
声明:本文档由 AI 根据平台配置自动生成;示例为片段。

接口简介

本API提供二维码生成功能,支持生成PNG位图或SVG矢量格式的二维码。用户可以自定义尺寸、纠错级别、边框宽度等参数。API通过GET或POST方法调用,返回JSON格式的数据。适用于需要集成二维码生成功能的Web应用、移动应用或第三方系统。

请求说明

  • 方法:GET, POST
  • 常用请求头:Content-Type: application/x-www-form-urlencoded(POST请求时)
  • 调用地址:https://api.xunjinlu.fun/api/qrcode/createqrcode.php

请求参数表

参数名类型必填默认值说明
datastring-二维码中包含的文本内容,建议不超过900个字符
sizestring256x256二维码尺寸,格式为'256'或'256x256'
formatstringpng输出格式,可选值:png(位图)、svg(矢量图)
error_correctionstringM纠错级别,可选值:L(7%)、M(15%)、Q(25%)、H(30%)
borderinteger2边框宽度(以码点为单位),最小0
rawinteger0直接输出图片模式,1=直接输出图片流到浏览器,0=返回JSON
downloadinteger0下载模式,1=触发浏览器下载图片,0=不下载。优先级低于raw

返回字段表

字段名类型说明
codeinteger状态码,200表示成功
dataobject返回数据,包含二维码相关信息
messagestring状态信息

data对象中的字段:

字段名类型说明
image_base64stringBase64编码的图片数据
image_urlstring图片URL
api_urlstringAPI调用地址
formatstring图片格式
sizestring图片尺寸
data_contentstring二维码内容
error_correctionstring纠错级别
borderinteger边框宽度
direct_image_urlstring直接获取图片的URL

返回示例

成功响应:

{
"code": 200,
"data": {
"image_base64": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...",
"image_url": "https://api.2dcode.biz/v1/create-qr-code?data=Example&size=256x256&format=png&error_correction=M&border=2",
"api_url": "https://api.xunjinlu.fun/api/qrcode/createqrcode.php",
"format": "png",
"size": "256x256",
"data_content": "Example",
"error_correction": "M",
"border": 2,
"direct_image_url": "https://api.xunjinlu.fun/api/qrcode/createqrcode.php?data=Example&raw=1&size=256x256&format=png"
},
"message": "success"
}

失败响应:

{
"code": 400,
"data": null,
"message": "参数验证失败: data参数不能为空"
}

错误码

错误码说明
200请求成功
400参数验证失败
502二维码生成失败
404API接口不存在
500服务器内部错误

调用示例

浏览器直接访问:

https://api.xunjinlu.fun/api/qrcode/createqrcode.php?data=HelloWorld&size=256x256&format=png

cURL:

curl "https://api.xunjinlu.fun/api/qrcode/createqrcode.php?data=HelloWorld&size=256x256&format=png"

Python:

import requests

url = "https://api.xunjinlu.fun/api/qrcode/createqrcode.php"
params = {
"data": "HelloWorld",
"size": "256x256",
"format": "png"
}
response = requests.get(url, params=params)
print(response.json())

PHP:

<?php
$url = "https://api.xunjinlu.fun/api/qrcode/createqrcode.php";
$data = array(
"data" => "HelloWorld",
"size" => "256x256",
"format" => "png"
);
$options = array(
"http" => array(
"header" => "Content-type: application/x-www-form-urlencoded\r\n",
"method" => "POST",
"content" => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo $result;
?>

HTML:

QR Code