{"id":34039230,"url":"https://github.com/fapiaoapi/invoice-sdk-python","last_synced_at":"2026-03-12T15:02:12.568Z","repository":{"id":287714698,"uuid":"965531917","full_name":"fapiaoapi/invoice-sdk-python","owner":"fapiaoapi","description":"发票sdk python 电子发票/数电发票/全电发票/数电票/开票","archived":false,"fork":false,"pushed_at":"2025-05-10T08:43:59.000Z","size":25,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-01-14T09:26:35.703Z","etag":null,"topics":["api","fapiao","invoice","sdk","sdk-python"],"latest_commit_sha":null,"homepage":"https://fa-piao.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fapiaoapi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-13T11:25:23.000Z","updated_at":"2025-10-18T18:50:27.000Z","dependencies_parsed_at":"2025-04-13T14:29:21.015Z","dependency_job_id":"fac8ca20-8901-4cf3-a985-5cfcaec30ce8","html_url":"https://github.com/fapiaoapi/invoice-sdk-python","commit_stats":null,"previous_names":["fapiaoapi/invoice-python-sdk"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fapiaoapi/invoice-sdk-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fapiaoapi%2Finvoice-sdk-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fapiaoapi%2Finvoice-sdk-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fapiaoapi%2Finvoice-sdk-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fapiaoapi%2Finvoice-sdk-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fapiaoapi","download_url":"https://codeload.github.com/fapiaoapi/invoice-sdk-python/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fapiaoapi%2Finvoice-sdk-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30429298,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T14:34:45.044Z","status":"ssl_error","status_checked_at":"2026-03-12T14:09:33.793Z","response_time":114,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","fapiao","invoice","sdk","sdk-python"],"created_at":"2025-12-13T21:30:17.342Z","updated_at":"2026-03-12T15:02:12.560Z","avatar_url":"https://github.com/fapiaoapi.png","language":"Python","readme":"# 电子发票/数电发票 Python SDK | 开票、验真、红冲一站式集成\n\n[![PyPI version](https://img.shields.io/pypi/v/tax-invoice.svg)](https://pypi.org/project/tax-invoice/)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/fapiaoapi/invoice-sdk-python/blob/master/LICENSE)\n[![Python 3.7+](https://img.shields.io/badge/Python-3.7%2B-blue.svg)](https://www.python.org/downloads/)\n\n**发票 Python SDK** 专为电子发票、数电发票（全电发票）场景设计，支持**开票、红冲、版式文件下载**等核心功能，快速对接税务平台API。\n\n**关键词**: 电子发票SDK,数电票Python,开票接口,发票api,发票开具,发票红冲,全电发票集成\n\n---\n\n## 📖 核心功能\n\n### 基础认证\n- ✅ **获取授权** - 快速接入税务平台身份认证\n- ✅ **人脸二维码登录** - 支持数电发票平台扫码登录\n- ✅ **认证状态查询** - 实时获取纳税人身份状态\n\n### 发票开具\n- 🟦 **数电蓝票开具** - 支持增值税普通/专用电子发票\n- 📄 **版式文件下载** - 自动获取销项发票PDF/OFD/XML文件\n\n### 发票红冲\n- 🔍 **红冲前蓝票查询** - 精确检索待红冲的电子发票\n- 🛑 **红字信息表申请** - 生成红冲凭证\n- 🔄 **负数发票开具** - 自动化红冲流程\n\n---\n\n## 🚀 快速安装\n\n```bash\npip install tax-invoice\n```\n\n[📦 查看pypi地址](https://pypi.org/project/tax-invoice/ \"发票sdk\")\n\n---\n\n\n\n[📚 查看完整中文文档](https://fa-piao.com/doc.html) | [💡 更多示例代码](https://github.com/fapiaoapi/invoice-sdk-python/tree/master/examples)\n\n---\n\n## 🔍 为什么选择此SDK？\n- **精准覆盖中国数电发票标准** - 严格遵循国家最新接口规范\n- **开箱即用** - 无需处理XML/签名等底层细节，专注业务逻辑\n- **企业级验证** - 已在生产环境处理超100万张电子发票\n\n---\n\n## 📊 支持的开票类型\n| 发票类型       | 状态   |\n|----------------|--------|\n| 数电发票（普通发票） | ✅ 支持 |\n| 数电发票（增值税专用发票） | ✅ 支持 |\n| 数电发票（铁路电子客票）  | ✅ 支持 |\n| 数电发票（航空运输电子客票行程单） | ✅ 支持  |\n| 数电票（二手车销售统一发票） | ✅ 支持  |\n| 数电纸质发票（增值税专用发票） | ✅ 支持  |\n| 数电纸质发票（普通发票） | ✅ 支持  |\n| 数电纸质发票（机动车发票） | ✅ 支持  |\n| 数电纸质发票（二手车发票） | ✅ 支持  |\n\n---\n\n## 🤝 贡献与支持\n- 提交Issue: [问题反馈](https://github.com/fapiaoapi/invoice-sdk-python/issues)\n- 商务合作: yuejianghe@qq.com\n```bash\nfrom tax.invoice import InvoiceClient\nfrom tax.invoice.utils.other import calculate_tax\nimport time\nimport traceback  # 新增导入\n\n# 配置信息\nappKey = \"YOUR_APP_KEY\"\"\"\nappSecret = \"YOUR_APP_SECRET\"\nnsrsbh = \"91500112MADFAQ9xxx\"  # 统一社会信用代码\ntitle = \"重庆悦江河科技有限公司\"  # 名称（营业执照）\nusername = \"1912284xxxx\"  # 手机号码（电子税务局）\npassword = \"\"  # 个人用户密码（电子税务局）\nsf = \"01\"  # 身份（电子税务局）\nfphm = \"24502000000045823936\"\ntoken = \"\"\n\n\n# 初始化客户端\nclient = InvoiceClient(\n    app_key=appKey,\n    app_secret=appSecret,\n    base_url=\"https://api.fa-piao.com\"\n)\n\n\n\ntry:\n    # 获取授权\n    if token :\n        client.auth.set_token(token)\n    else:\n        auth_response = client.auth.get_authorization(nsrsbh=nsrsbh)\n        if auth_response.get(\"code\") == 200:\n            print(f\"授权成功，Token: {auth_response.get('data', {}).get('token')}\")\n            token = auth_response.get('data', {}).get('token')\n\n    # 获取认证状态\n    status_response = client.auth.query_face_auth_state(nsrsbh=nsrsbh, username=username)\n    status_code = status_response.get(\"code\")\n\n    if status_code == 200:\n        print(\"认证状态: 无需认证\")\n        \n        # amount = 200\n        # taxRate = 0.01\n        # isIncludeTax = False # 是否含税\n        # # 税额计算\n        # se =  calculate_tax(amount,taxRate,isIncludeTax,2)  # 强制转换为浮点数\n        # print(\"价税合计：\" + str(amount))\n        # print(\"税率：\" + str(taxRate))\n        # print(\"合计金额：\" + str(amount - se))\n        # print((\"含税\" if isIncludeTax else \"不含税\") + \" 合计税额：\" + str(se))\n\n        # 开具蓝票示例\n        invoice_params = {\n            \"fpqqlsh\": appKey + str(int(time.time() * 1000)),\n            \"fplxdm\": \"82\",\n            \"kplx\": \"0\",\n            \"xhdwsbh\": nsrsbh,\n            \"xhdwmc\": title,\n            \"xhdwdzdh\": \"重庆市渝北区仙桃街道汇业街1号17-2 19122840xxxx\",\n            \"xhdwyhzh\": \"中国工商银行 310008670920023xxxx\",\n            \"ghdwmc\": \"个人\",\n            \"zsfs\": \"0\",\n            \n            # 添加商品明细\n            \"fyxm\": [\n                {\n                    \"fphxz\": \"0\",\n                    \"spmc\": \"*信息技术服务*软件开发服务\",\n                    \"je\": \"10\",\n                    \"sl\": \"0.01\",\n                    \"se\": \"0.1\",\n                    \"hsbz\": \"1\",\n                    \"spbm\": \"3040201010000000000\"\n                }\n            ],\n            \n            # 合计金额\n            \"hjje\": \"9.9\",\n            \"hjse\": \"0.1\",\n            \"jshj\": \"10\"\n        }\n        \n        invoice_response = client.invoice.issue_blue_invoice(**invoice_params)\n        print(f\"{invoice_response.get('code')} 开票结果: {invoice_response.get('msg')}\")\n        \n        if invoice_response.get(\"code\") == 200:\n            print(f\"发票号码: {invoice_response.get('data', {}).get('Fphm')}\")\n            print(f\"开票日期: {invoice_response.get('data', {}).get('Kprq')}\")\n            fphm = invoice_response.get('data', {}).get('Fphm')\n            time.sleep(10)  # 等待10秒\n        \n        # 下载发票\n        pdf_params = {\n            \"downflag\": \"4\",\n            \"nsrsbh\": nsrsbh,\n            \"username\": username,\n            \"fphm\": fphm\n        }\n        \n        pdf_response = client.invoice.get_pdf_ofd_xml(**pdf_params)\n        if pdf_response.get(\"code\") == 200:\n            print(pdf_response.get(\"data\"))\n\n    elif status_code == 420:\n        print(\"登录(短信认证)\")\n        # 登录数电发票平台 短信\n        \n        # # 1 发短信验证码\n        # sms_code = \"\"\n        # login_response = client.auth.login_dppt(nsrsbh=nsrsbh, username=username, password=password, sms_code=None)\n        # if login_response.get(\"code\") == 200:\n        #     print(login_response.get(\"msg\"))\n        #     print(f\"请{username}接收验证码\")\n        #     time.sleep(60)  # 模拟等待60秒\n        \n        # # 2 输入验证码\n        # print(\"请输入验证码\")\n        # sms_code = input(\"验证码: \")  # 这里可以根据实际情况获取验证码\n        # login_response2 = client.auth.login_dppt(nsrsbh=nsrsbh, username=username, password=password, sms_code=sms_code)\n        # if login_response2.get(\"code\") == 200:\n        #     print(login_response2.get(\"data\"))\n        #     print(\"验证成功\")\n    \n    elif status_code == 430:\n        print(\"人脸认证\")\n        # 1 获取人脸二维码\n        qr_code_response = client.auth.get_face_img(nsrsbh=nsrsbh, username=username, type=\"1\")\n        print(\"二维码: \" + str(qr_code_response.get(\"data\")))\n        \n        ewmlyx = qr_code_response.get(\"data\", {}).get(\"ewmlyx\")\n        if ewmlyx == \"swj\":\n            print(\"请使用税务局app扫码\")  # ewm自己生成二维码\n        elif ewmlyx == \"grsds\":\n            print(\"个人所得税app扫码\")  # ewm是二维码的base64\n        \n        # 2 认证完成后 获取人脸二维码认证状态\n        rzid = qr_code_response.get(\"data\", {}).get(\"rzid\")\n        # rzid = \"5c028e62f23e4b5ca57668bc74c0de98\"\n        face_status_response = client.auth.get_face_state(nsrsbh=nsrsbh, rzid=rzid, username=username, type=\"1\")\n        print(\"code: \" + str(face_status_response.get(\"code\")))\n        print(\"data: \" + str(face_status_response.get(\"data\")))\n        \n        if face_status_response.get(\"data\") is not None:\n            slzt = face_status_response.get(\"data\", {}).get(\"slzt\")\n            if slzt == \"1\":\n                print(\"未认证\")\n            elif slzt == \"2\":\n                print(\"成功\")\n            elif slzt == \"3\":\n                print(\"二维码过期--\u003e重新获取人脸二维码\")\n    \n    elif status_code == 401:\n        # 重新授权\n        print(f\"{status_response.get('code')}授权失败:{status_response.get('msg')}\")\n    \n    else:\n        print(f\"{status_response.get('code')}  {status_response.get('msg')}\")\n\nexcept Exception as e:\n    # 打印完整堆栈信息（包含行号）\n    traceback.print_exc()  # 新增堆栈跟踪\n    \n    # 添加上下文信息（可选）\n    print(f\"\\n错误发生时参数状态：\")\n    print(f\"当前时间戳: {int(time.time())}\")\n\n```\n[发票红冲](examples\\red_invoice_example.py \"发票红冲\")\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffapiaoapi%2Finvoice-sdk-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffapiaoapi%2Finvoice-sdk-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffapiaoapi%2Finvoice-sdk-python/lists"}