

发布于 2025-09-23 09:36537浏览最近不少影刀用户反馈:发票识别时备注字段突然丢失,导致报销核对、数据统计频频卡壳。
追根溯源后发现,核心原因是第三方 OCR 接口能力波动 —— 原基础接口精度下降,无法稳定抓取备注信息。而解决关键在于切换至腾讯高精度发票 OCR 接口,但开发打包需等待?别急,自定义指令能让你 “抢先用上”!
代码如下

魔法指令代码
# 使用此指令前,请确保安装必要的Python库,例如使用以下命令安装:# pip install requests
import requestsimport json
from typing import *try: from xbot.app.logging import trace as printexcept: from xbot import print
def call_ocr_api_with_requests(image_url, image_base64, auth_token): """ title: 使用requests调用OCR识别API description: 使用requests模块向影刀OCR服务发送POST请求,识别图片中的文字内容。需要提供图片URL % image_url %、图片Base64编码 % image_base64 % 和授权令牌 % auth_token %。 inputs: - image_url (str): 图片URL地址,eg: "https://example.com/image.jpg" - image_base64 (str): 图片的Base64编码字符串,eg: "iVBORw0KGgoAAAANSUhEUgAA..." - auth_token (str): API授权令牌,eg: "9c8ad121-f25f-4802-9528-896df0dac62e" outputs: - response_text (str): API返回的响应内容,eg: "{'code': 200, 'data': {...}}" """ # 检查输入参数 # if not image_url or not isinstance(image_url, str): # raise ValueError("图片URL不能为空且必须为字符串类型") if not image_base64 or not isinstance(image_base64, str): raise ValueError("图片Base64编码不能为空且必须为字符串类型") if not auth_token or not isinstance(auth_token, str): raise ValueError("授权令牌不能为空且必须为字符串类型") def _make_ocr_request(image_url, image_base64, auth_token): """ 发送OCR识别请求 """ url = "https://api.yingdao.com/api/v2/aiservice/call/ocr" payload = { "aiToolInterfaceCodeId": "tencent_bill_advance_ocr", "body": { # "ImageUrl": image_url, "ImageBase64": image_base64 } } headers = { 'Authorization': f'Bearer {auth_token}', 'Content-Type': 'application/json', } try: response = requests.post(url, json=payload, headers=headers) response.raise_for_status() # 检查HTTP错误 return response.text except requests.exceptions.RequestException as e: raise Exception(f"API请求失败: {str(e)}") response_text = _make_ocr_request(image_url, image_base64, auth_token) return response_text
Plain Text
model代码 这个代码的作用是获取本账号的token
# 使用提醒:# 1. xbot包提供软件自动化、数据表格、Excel、日志、AI等功能# 2. package包提供访问当前应用数据的功能,如获取元素、访问全局变量、获取资源文件等功能# 3. 当此模块作为流程独立运行时执行main函数# 4. 可视化流程中可以通过"调用模块"的指令使用此模块
import xbotfrom xbot import print, sleepfrom .import packagefrom .package import variables as glvfrom xbot._core import robotdef main(args): passdef get_xbot_client(): common_info = robot.execute(f'Common.CommonConfig', None) return common_info.get("token")
Plain Text