接口简介
AI舌诊基础版接口主要通过拍摄舌头图片进行识别,返回十种舌像出现的概率值,加上身体可能出现的证型和对应的调理方法。
接口地址
访问地址:https://www.bjbayes.com/admin/api/tongue_analysis
请求方式:POST
请求格式:application/x-www-form-urlencode
* 所有的请求和响应数据编码皆为utf-8格式,URL里的所有参数名和参数值请做URL编码
请求参数
字段 | 类型 | 是否必传 | 说明 |
---|---|---|---|
appid | String | 是 | 开放平台创建的appid |
imgpath | String | 是 | 传入进行识别的网络图片地址 |
timestamp | String | 是 | 请求端口的时间,时间格式yyyyMMddHHmmss |
version | String | 是 | api版本,默认为1.0 |
sign | String | 是 | 签名。先把timestamp用MD5进行加密加上appid对应的key,然后再次用MD5再次进行加密生成签名,所有的MD5加密为大写。 |
响应参数
字段 | 类型 | 说明 |
---|---|---|
msg | String | 响应信息,成功为ok,错误为对应的错误信息 |
code | Int | 响应码,200-成功 201-没有可用次数 400-参数缺失或错误 500-异常 |
data | json | 识别结果数据 |
返回结果示例:
{ "msg":"成功", "code":200, "data":{ "cutTongue":"http://tonguecut.oss-cn-beijing.aliyuncs.com/ff1e1a54-1508-11eb-ac43-f990dea5f70f.jpg", "message":"调用成功", "char":[ { "type":"深白苔", "probability":"0.99271363" }, { "type":"薄苔", "probability":"0.99126816" }, { "type":"有齿痕", "probability":"0.61665225" }, { "type":"无点刺", "probability":"0.99993527" }, { "type":"无裂纹", "probability":"0.8993225" }, { "type":"腻苔", "probability":"0.9810058" }, { "type":"舌形正常", "probability":"0.5198991" }, { "type":"滑苔", "probability":"0.9249092" }, { "type":"淡白舌", "probability":"0.9212495" }, { "type":"舌苔不剥", "probability":"0.9940807" } ], "zhengxing":[ { "zhengxing_name":"肾阳不足", "jieshi":"肾脏的功能活动弱,阳气不足", "shiyishiwu":"红枣、小米、大米、核桃仁、芝麻、榴莲、冬瓜、黑芝麻、 羊肾、牛骨髓、猪腰子、驴肉、乌骨鸡、鸭肉、泥鳅等", "jinjishiwu":"性质寒凉、易损伤脾气的食品、忌吃味厚滋腻、苦瓜、冬瓜、海带、螃蟹、鸭子、饮啤酒等", "shiyiyundong":"八段锦、五禽戏、太极拳、易筋经、慢跑、室外有氧运动、吐呐法", "jinjiyundong":"激烈运动", "shiyiyaoshan":"锁阳苁蓉粥", "shiyiyinyue":"广陵散(戴紫茹)" }, { "zhengxing_name":"气血两虚", "jieshi":"指气血均亏损不足的证候。多由久病不愈,气血两伤所致", "shiyishiwu":"山药、豆角、紫薯、梨、豆腐、藕、粟子、石榴、青菜、芹菜、菠菜、苹果、香蕉、葡萄、红枣、椰子、橄榄、草莓等", "jinjishiwu":"吸烟、饮酒、忌生冷寒凉、油炸食品、腌制品、咖啡等刺激性食物、芒果、韭菜、生姜、辣椒、胡椒、花椒等", "shiyiyundong":"慢跑、散步、八段锦、五禽戏、太极拳、易筋经、室外有氧运动", "jinjiyundong":"激烈运动", "shiyiyaoshan":"红枣煲大鱼鱼头", "shiyiyinyue":" 广陵散(戴紫茹)" }, { "zhengxing_name":"寒症或者寒湿症", "jieshi":"寒证分外肝风寒和内寒(是脏腑阳气不足,主要是肾阳不足所致)。寒湿证,中医认为寒湿包括外感寒湿和内生寒湿两个方面。外感寒湿:外感寒湿邪气,气血运行受阻。内生寒湿:寒湿内困而损伤脾阳,或脾肾阳虚而寒湿内停", "shiyishiwu":"马蹄、橄榄、石榴、青菜、芹菜、菠菜、柑橘、乌梅、柠檬、鱼肉等", "jinjishiwu":"吸烟、饮酒、忌生冷寒凉、油炸食品、腌制品、咖啡等刺激性食物、茶叶、酱油、蟹蚌、辣椒、胡椒、花椒等", "shiyiyundong":"慢跑、散步、八段锦、五禽戏、太极拳、易筋经、室外有氧运动", "jinjiyundong":"激烈运动", "shiyiyaoshan":"生姜羊肉汤", "shiyiyinyue":"紫竹调(纯乐古筝)" }, { "zhengxing_name":"阳虚证", "jieshi":"大肠阳气虚衰而不能固摄所表现的证候", "shiyishiwu":"番薯、豆腐,藕、粟子、山药、扁豆、豇豆、扁豆、豇豆、胡萝卜、马铃薯、洋葱、平菇、猪肚、桂鱼、乌鸡,桃、杏", "jinjishiwu":"忌吃性质寒凉,易损伤脾气的食品,忌吃味厚滋腻,苦瓜、冬瓜、海带、螃蟹、鸭子,饮啤酒", "shiyiyundong":"散步,八段锦,五禽戏", "jinjiyundong":"激烈运动", "shiyiyaoshan":"山药炖牛肉", "shiyiyinyue":"十面埋伏传奇乐坊" }, { "zhengxing_name":"寒湿症", "jieshi":"外感寒湿以关节、筋骨疼痛为常见症的证候;内生寒湿以畏寒肢冷,腹痛泄泻,或浮肿为常见症的证候", "shiyishiwu":"马蹄、橄榄、石榴、青菜、芹菜、菠菜、柑橘、乌梅、柠檬、鱼肉等", "jinjishiwu":"吸烟、饮酒、忌生冷寒凉、油炸食品、腌制品、咖啡等刺激性食物、茶叶、酱油、蟹蚌、辣椒、胡椒、花椒等", "shiyiyundong":"慢跑、散步、八段锦、五禽戏、太极拳、易筋经、室外有氧运动", "jinjiyundong":"激烈运动", "shiyiyaoshan":"生姜羊肉汤", "shiyiyinyue":"十面埋伏传奇乐坊" } ] } }
返回参数说明
返回参数 | 说明 |
---|---|
cutTongue | 切割后的舌头图片url路径 |
tizhi | 九种体质对应的概率 |
xueyu | 血瘀体质对应的概率 |
shire | 湿热体质对应的概率 |
tebing | 特禀体质对应的概率 |
yangxu | 阳虚体质对应的概率 |
yinxu | 阴虚体质对应的概率 |
tanshi | 痰湿体质对应的概率 |
pinghe | 平和体质对应的概率 |
qiyu | 气郁体质对应的概率 |
qixu | 气虚体质对应的概率 |
tiaoli | 概率最高的体质对应的调理建议 |
tizhi_name | 体质名称 |
changjianbiaoxian | 常见表现 |
jingshentiaoyang | 精神调养 |
fabingqingxiang | 发病倾向 |
yuletiaoshe | 娱乐调摄 |
sijiyangsheng | 四季养生 |
tiyuduanlian | 体育锻炼 |
qijutiaoshe | 起居调摄 |
yinyuetiaoli | 音乐调理 |
jingluobaojian | 经络保健 |
yongyaojinji | 用药禁忌 |
shiliao | 两种具体的药膳、适合吃的食物和禁忌食物 |
zhengxing | 可能的证型和对应的调理方法 |
zhengxing_name | 证型名称 |
jieshi | 证型具体的解释 |
shiyishiwu | 适宜食物 |
jinjishiwu | 禁忌食物 |
shiyiyundong | 适宜运动 |
jinjiyundong | 禁忌运动 |
shiyiyaoshan | 适宜药膳 |
shiyiyinyue | 适宜音乐 |
message | 返回的各种情况,具体说明如下 |
message参数 | 说明 |
---|---|
图片路径有误 | 原始图片url路径有误 |
图片质量过低 | 拍摄舌头图片模糊或无舌头图片 |
服务器繁忙 | 服务器并发过高 |
切割图片失败 | 舌头图片不完整 |
无对应证型 | 有舌头和体质相关结果,没有对应的证型结果 |
调用成功 | 正常返回所有结果 |
java调用代码示例
import com.alibaba.fastjson.JSON; import com.util.HttpClient; import java.io.IOException; import java.security.MessageDigest; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; public class DemoObj { public static String MD5(String data) throws Exception { System.out.println(data); MessageDigest md = MessageDigest.getInstance("MD5"); byte[] array = md.digest(data.getBytes("UTF-8")); StringBuilder sb = new StringBuilder(); for (byte item : array) { sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3)); } System.out.println(sb.toString().toUpperCase()); return sb.toString().toUpperCase(); } public static void main(String[] args) { DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); String timestamp=df.format(new Date()); Mapbody = new HashMap<>(); body.put("appid", "你的APPID"); System.out.println(timestamp); body.put("timestamp", timestamp); body.put("version", "1.0"); body.put("imgpath", "舌头图片地址"); try { body.put("sign", MD5(MD5(timestamp)+"你的APPID对应的key")); } catch (Exception e) { e.printStackTrace(); } try { String s = new HttpClient().doPostMap("https://www.bjbayes.com/admin/api/tongue_analysis", body); System.out.println(s); Map maps = (Map) JSON.parse(s); for (Object map : maps.entrySet()){ System.out.println(((Map.Entry)map).getKey()+" " + ((Map.Entry)map).getValue()); } } catch (IOException e) { e.printStackTrace(); } } }
python调用代码示例
import hashlib # 导入time模块 import time import requests import json def Md5(res): print(res) md = hashlib.md5() # 构造一个md5 md.update(res.encode(encoding='utf-8')) # 加密 print(md.hexdigest().upper()) return md.hexdigest().upper() def testapi(): tures={} restime=time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) # restime="20190829114035" #传入参数 tures['timestamp']=restime tures['appid']="你的APPID" tures['version']='1.0' tures['imgpath']='https://bys-tonguepicture.oss-cn-beijing.aliyuncs.com/1563412989396.jpg' tures['sign']=Md5(Md5(restime)+"你的APPID对应的key") url = "http://api.bjbayes.com/api/tongue_analysis" response = requests.post(url, params=tures) # print(response.text) print(type(response.text)) load=json.loads(response.text) print(load)
C#调用代码示例
using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Net; using System.Security.Cryptography; using System.Text; namespace APITest { class Program { static void Main(string[] args) { DictionarymyDictionary = new Dictionary (); DateTime dt = DateTime.Now; string ds = dt.ToString("yyyyMMddHHmmss"); myDictionary.Add("timestamp",ds); myDictionary.Add("appid", "你的APPID"); myDictionary.Add("version","1.0"); myDictionary.Add("imgpath", "待测图片的云服务地址"); myDictionary.Add("sign",GetMD5(GetMD5(ds)+ "你的APPID对应的key")); string finalresult = Post("https://www.bjbayes.com/admin/api/tongue_analysis",myDictionary); Object jo = JsonConvert.DeserializeObject(finalresult); //此处结果为最后的调用结果 Console.WriteLine(jo); Console.ReadKey(); } //构造MD5 public static string GetMD5(string sDataIn) { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); byte[] bytValue, bytHash; bytValue = System.Text.Encoding.UTF8.GetBytes(sDataIn); bytHash = md5.ComputeHash(bytValue); md5.Clear(); string sTemp = ""; for (int i = 0; i < bytHash.Length; i++) { sTemp += bytHash[i].ToString("X").PadLeft(2, '0'); } return sTemp.ToUpper(); } /// /// 指定Post地址使用Get 方式获取全部字符串 /// /// 请求后台地址 ///public static string Post(string url, Dictionary dic) { string result = ""; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; #region 添加Post 参数 StringBuilder builder = new StringBuilder(); int i = 0; foreach (var item in dic) { if (i > 0) builder.Append("&"); builder.AppendFormat("{0}={1}", item.Key, item.Value); i++; } byte[] data = Encoding.UTF8.GetBytes(builder.ToString()); req.ContentLength = data.Length; using (Stream reqStream = req.GetRequestStream()) { reqStream.Write(data, 0, data.Length); reqStream.Close(); } #endregion HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); Stream stream = resp.GetResponseStream(); //获取响应内容 using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) { result = reader.ReadToEnd(); } return result; } } }
javascript调用代码示例
$.ajax({ type: "POST", url: "https://www.bjbayes.com/admin/api/tongue_analysis", data: { timestamp:restime, #restime时间格式为YYmmddHHMMSS appid='你的APPID', version='1.0', imgpath='https://bys-tonguepicture.oss-cn-beijing.aliyuncs.com/1563412989396.jpg', sign=Md5(Md5(restime)+'你的APPID对应的key') }, success: function(msg) { console.log('返回的数据:'+msg); } });