百度人脸真人认证
2021-01-13 16:28 qgbo 阅读(239) 评论(0) 编辑 收藏 举报文档:
https://ai.baidu.com/ai-doc/FACE/7k37c1ucj
身份证文档 https://ai.baidu.com/tech/ocr_cards/idcard
活体检测 https://ai.baidu.com/ai-doc/FACE/lk37c1tag
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | // 调用getAccessToken()获取的 access_token建议根据expires_in 时间 设置缓存 // 返回token示例 public static String TOKEN = "24.adda70c11b9786206253ddb70affdc46.2592000.1493524354.282335-1234567" ; // 百度云中开通对应服务应用的 API Key 建议开通应用的时候多选服务 private static String clientId = "百度云应用的AK" ; // 百度云中开通对应服务应用的 Secret Key private static String clientSecret = "百度云应用的SK" ; public static String getAccessToken() { String authHost = "https://aip.baidubce.com/oauth/2.0/token" ; HttpClient client = new HttpClient(); List<KeyValuePair<String, String>> paraList = new List<KeyValuePair< string , string >>(); paraList.Add( new KeyValuePair< string , string >( "grant_type" , "client_credentials" )); paraList.Add( new KeyValuePair< string , string >( "client_id" , clientId)); paraList.Add( new KeyValuePair< string , string >( "client_secret" , clientSecret)); HttpResponseMessage response = client.PostAsync(authHost, new FormUrlEncodedContent(paraList)).Result; String result = response.Content.ReadAsStringAsync().Result; Console.WriteLine(result); return result; } public static string personVerify() { string token = "[调用鉴权接口获取的token]" ; string host = "https://aip.baidubce.com/rest/2.0/face/v3/person/verify?access_token=" + token; Encoding encoding = Encoding.Default; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(host); request.Method = "post" ; request.KeepAlive = true ; String str = $ "{" image\ ":\"sfasq35sadvsvqwr5q...\",\"image_type\":\"BASE64\",\"id_card_number\":\"110...\",\"name\":\"张三\",\"quality_control\":\"LOW\",\"liveness_control\":\"HIGH\"}" ; byte [] buffer = encoding.GetBytes(str); request.ContentLength = buffer.Length; request.GetRequestStream().Write(buffer, 0, buffer.Length); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default); string result = reader.ReadToEnd(); Console.WriteLine( "身份验证:" ); Console.WriteLine(result); return result; } public static string idcard() { string token = "[调用鉴权接口获取的token]" ; string host = "https://aip.baidubce.com/rest/2.0/ocr/v1/idcard?access_token=" + token; Encoding encoding = Encoding.Default; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(host); request.Method = "post" ; request.KeepAlive = true ; // 图片的base64编码 string base64 = getFileBase64( "[本地图片文件]" ); String str = "id_card_side=" + "front" + "&image=" + HttpUtility.UrlEncode(base64); byte [] buffer = encoding.GetBytes(str); request.ContentLength = buffer.Length; request.GetRequestStream().Write(buffer, 0, buffer.Length); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default); string result = reader.ReadToEnd(); Console.WriteLine( "身份证识别:" ); Console.WriteLine(result); return result; } public static String getFileBase64(String fileName) { FileStream filestream = new FileStream(fileName, FileMode.Open); byte [] arr = new byte [filestream.Length]; filestream.Read(arr, 0, ( int )filestream.Length); string baser64 = Convert.ToBase64String(arr); filestream.Close(); return baser64; } |
气功波(18037675651)
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· PPT革命!DeepSeek+Kimi=N小时工作5分钟完成?
· What?废柴, 还在本地部署DeepSeek吗?Are you kidding?
· DeepSeek企业级部署实战指南:从服务器选型到Dify私有化落地
· 程序员转型AI:行业分析
· 重磅发布!DeepSeek 微调秘籍揭秘,一键解锁升级版全家桶,AI 玩家必备神器!