1、云码网址: https://www.jfbym.com/test/70.html
2、调用语言:python
3、调用方式:API
4、调用的识别模型:通用数英5-8位
5、API调用参数如何获取:用户中心Token;type:10111
6、源码:# 使用此指令前,请确保安装必要的Python库:
# pip install requests
import base64
import requests
from typing import *
try:
from xbot.app.logging import trace as print
except:
from xbot import print
def recognize_image_text(image_path, token, type_id):
"""
title: 图片文本识别
description: 调用打码平台API识别图片中的文本内容,将%image_path%中的图片发送到API进行识别,返回%text_result%文本内容。
inputs:
- image_path (file): 图片文件路径,eg: "C:/images/captcha.png"
- token (str): API令牌,eg: "your_api_token_here"
- type_id (str): 打码类型ID,eg: "1001"
outputs:
- text_result (str): 识别结果文本,eg: "验证码内容"
"""
# 读取图片并转为base64编码
with open(image_path, 'rb') as f:
base64_image = base64.b64encode(f.read()).decode()
# 准备API请求参数
url = "http://api.jfbym.com/api/YmServer/customApi"
data = {
"token": token,
"type": type_id,
"image": base64_image,
}
headers = {
"Content-Type": "application/json"
}
# 发送请求并获取响应
try:
response = requests.post(url, headers=headers, json=data).json()
# 检查响应是否成功
if response.get("code") == 10000: # 假设10000是成功的状态码,根据实际API调整
# 返回文本内容
return response.get("data", {}).get("data", "")
else:
error_msg = response.get("msg", "未知错误")
return f"识别失败: {error_msg}"
except Exception as e:
return f"请求异常: {str(e)}"