接口簡介
AI面診接口主要通過拍攝面部圖片進(jìn)行識別,返回兩頰、鼻子、眼睛、嘴唇的類型和對應(yīng)的概率值,面診的證型結(jié)論和對應(yīng)的食療方案
接口地址
訪問地址:http://mnpc.com.cn/admin/api/face_analysis
請求方式:POST
請求格式:application/x-www-form-urlencode
* 所有的請求和響應(yīng)數(shù)據(jù)編碼皆為utf-8格式,URL里的所有參數(shù)名和參數(shù)值請做URL編碼
請求參數(shù)
字段 | 類型 | 是否必傳 | 說明 |
---|---|---|---|
appid | String | 是 | 開放平臺創(chuàng)建的appid |
imgpath | String | 是 | 傳入進(jìn)行識別的網(wǎng)絡(luò)圖片地址 |
timestamp | String | 是 | 請求端口的時間,時間格式y(tǒng)yyyMMddHHmmss |
version | String | 是 | api版本,默認(rèn)為1.0 |
sign | String | 是 | 簽名。先把timestamp用MD5進(jìn)行加密加上appid對應(yīng)的key,然后再次用MD5再次進(jìn)行加密生成簽名,所有的MD5加密為大寫。 |
響應(yīng)參數(shù)
字段 | 類型 | 說明 |
---|---|---|
msg | String | 響應(yīng)信息,成功為ok,錯誤為對應(yīng)的錯誤信息 |
code | Int | 響應(yīng)碼,200-成功 201-沒有可用次數(shù) 400-參數(shù)缺失或錯誤 500-異常 |
data | json | 識別結(jié)果數(shù)據(jù) |
返回結(jié)果示例:
{ "msg":"成功", "code":200, "data":{ "data":[ { "type":"深紅唇", "probability":0.9999 }, { "type":"正常鼻", "probability":0.9882 }, { "type":"無眼袋", "probability":0.8187 }, { "type":"面色正常", "probability":0.8511 } ], "completion":[ { "completion":"血熱或者心火旺盛", "diet":"血熱:1、蘆根茶:蘆根100g切小段,鮮蘿卜200g切小塊,蔥白7莖,青橄欖7個拍碎,再加入適量水,煎湯代茶飲。2. 桑葉止血茶:桑葉焙干研末,5g,綠茶3g,用沸水沖泡或加水煎煮。3.薄荷粥:鮮薄荷30g洗凈入鍋,加水適量,煎熬取汁,粳米100g洗凈,武火燒沸,再用文火煮粥,最后加入冰糖、薄荷汁。心火旺盛:蓮子湯:蓮子30克(不去蓮心),桅子15克(用紗布包扎),加冰糖適量,水煎,吃蓮子喝湯。 " } ], "message":"識別成功" } }
java調(diào)用代碼示例
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對應(yīng)的key")); } catch (Exception e) { e.printStackTrace(); } try { String s = new HttpClient().doPostMap("http://mnpc.com.cn/admin/api/face_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調(diào)用代碼示例
import hashlib # 導(dǎo)入time模塊 import time import requests import json def Md5(res): print(res) md = hashlib.md5() # 構(gòu)造一個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" #傳入?yún)?shù) tures['timestamp']=restime tures['appid']="你的APPID" tures['version']='1.0' tures['imgpath']='https://wxr-tongue.oss-cn-beijing.aliyuncs.com/images/tongue/IMG_20200913_134618.jpg' tures['sign']=Md5(Md5(restime)+"你的APPID對應(yīng)的key") url = "http://api.bjbayes.com/api/face_analysis" response = requests.post(url, params=tures) # print(response.text) print(type(response.text)) load=json.loads(response.text) print(load)
C#調(diào)用代碼示例
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", "待測圖片的云服務(wù)地址"); myDictionary.Add("sign",GetMD5(GetMD5(ds)+ "你的APPID對應(yīng)的key")); string finalresult = Post("http://mnpc.com.cn/admin/api/face_analysis",myDictionary); Object jo = JsonConvert.DeserializeObject(finalresult); //此處結(jié)果為最后的調(diào)用結(jié)果 Console.WriteLine(jo); Console.ReadKey(); } //構(gòu)造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 參數(shù) 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(); //獲取響應(yīng)內(nèi)容 using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) { result = reader.ReadToEnd(); } return result; } } }
javascript調(diào)用代碼示例
$.ajax({ type: "POST", url: "http://mnpc.com.cn/admin/api/face_analysis", data: { timestamp:restime, #restime時間格式為YYmmddHHMMSS appid='你的APPID', version='1.0', imgpath='https://wxr-tongue.oss-cn-beijing.aliyuncs.com/images/tongue/IMG_20200913_134618.jpg', sign=Md5(Md5(restime)+'你的APPID對應(yīng)的key') }, success: function(msg) { console.log('返回的數(shù)據(jù):'+msg); } });