Skill: freedompixels/cn-qrcode-generator (version 1.2.5)

--- slug: cn-qrcode-generator name: 二维码生成工具 version: "1.0.0" author: 千策 --- # 二维码生成器 输入URL或文本，生成PNG二维码。 ## 功能 - 输入URL/文本，生成二维码 - 自定义尺寸（默认300px） ## 用法 python3 scripts/qrcode_generator.py "https://example.com" python3 scripts/qrcode_generator.py "Hello World" ## 依赖 - Python 3.7+ - certifi（SSL证书验证） ## 数据来源 使用 qrserver.com 公开API生成二维码，无需API Key。 ## 版本 - v1.2.0: 文档优化，更新依赖说明

path: generate.py
content: #!/usr/bin/env python3
"""中文二维码生成器 - Google Chart API（qrserver.com）"""
import sys
import os
import json
import argparse
import urllib.parse
import subprocess

DEFAULT_OUTPUT = os.path.expanduser("~/Downloads/qrcode.png")

def generate_qr(text, output=DEFAULT_OUTPUT, size=300,
                fg_color="000000", bg_color="FFFFFF"):
    """生成二维码图片（Google Chart API，国内外均稳定）"""
    if not text.startswith("http"):
        text = "https://" + text

    # Google Chart API (qrserver.com) - 全球最稳定的免费QR API
    encoded = urllib.parse.quote(text)
    url = (
        f"https://api.qrserver.com/v1/create-qr-code/"
        f"?size={size}x{size}"
        f"&data={encoded}"
        f"&color={fg_color}"
        f"&bgcolor={bg_color}"
        f"&margin=1"
    )

    os.makedirs(os.path.dirname(output) or ".", exist_ok=True)
    try:
        cmd = ["curl", "-s", "--max-time", "15", "-L", "-o", output, url]
        r = subprocess.run(cmd, capture_output=True, text=True, timeout=18)
        if os.path.exists(output) and os.path.getsize(output) > 100:
            return {"text": text, "file": os.path.abspath(output),
                    "size": size, "api": "qrserver.com", "status": "ok"}
        else:
            return {"text": text, "file": None, "error": "空响应或文件过小",
                    "status": "failed", "curl_stderr": r.stderr[:200]}
    except Exception as e:
        return {"text": text, "file": None, "error": str(e), "status": "failed"}

if __name__ == "__main__":
    p = argparse.ArgumentParser(description="二维码生成器")
    p.add_argument("text", help="二维码内容（URL或文本）")
    p.add_argument("--output", "-o", default=DEFAULT_OUTPUT, help="输出文件路径")
    p.add_argument("--size", "-s", type=int, default=300, help="二维码尺寸（像素）")
    p.add_argument("--fg", default="000000", help="前景色HEX")
    p.add_argument("--bg", default="FFFFFF", help="背景色HEX")
    args = p.parse_args()

    result = generate_qr(args.text, args.output, args.size, args.fg, args.bg)
    print(json.dumps(result, ensure_ascii=False, indent=2))
    sys.exit(0 if result["status"] == "ok" else 1)


path: scripts/qrcode_generator.py
content: #!/usr/bin/env python3
"""cn-qrcode-generator - 二维码生成工具"""
import sys, os, base64, ssl, urllib.request, urllib.parse, certifi

def generate_qrcode(text, size=300, margin=4, format='png'):
    """生成二维码
    
    使用qrserver.com API，无需安装依赖
    SSL标准验证（certifi根证书）
    """
    encoded_text = urllib.parse.quote(text)
    url = f"https://api.qrserver.com/v1/create-qr-code/?size={size}x{size}&margin={margin}&format={format}&data={encoded_text}"
    
    headers = {
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36'
    }
    
    try:
        ctx = ssl.create_default_context()
        ctx.load_verify_locations(certifi.where())
        req = urllib.request.Request(url, headers=headers)
        response = urllib.request.urlopen(req, timeout=15, context=ctx)
        data = response.read()
        return {
            "success": True,
            "data": f"data:image/{format};base64,{base64.b64encode(data).decode()}",
            "url": url
        }
    except Exception as e:
        return {"success": False, "error": str(e)}

if __name__ == '__main__':
    text = sys.argv[1] if len(sys.argv) > 1 else "https://example.com"
    result = generate_qrcode(text)
    if result["success"]:
        print(f"✅ 二维码生成成功!")
        print(f"   Base64长度: {len(result['data'])} 字符")
    else:
        print(f"❌ 生成失败: {result['error']}")


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (CRITICAL)