Example #1
0
        static void Main(string[] args)
        {
            #region 01,百度AI识别
            var obj2 = IdCardValidateService.GetIdCardInfo(@"http://aip.bdstatic.com/portal/dist/1547780921660/ai_images/technology/ocr-cards/idcard/demo-card-1.png");

            Console.WriteLine(JsonConvert.SerializeObject(obj2));
            Console.ReadKey();
            #endregion
        }
Example #2
0
        /// <summary>
        /// 获取行驶证信息
        /// </summary>
        /// <param name="imagePath">图片路径</param>
        public static bool IdCardValidate(string imagePath, string imageType, string idCardNumber, string name)
        {
            var getTokenResult = IdCardValidateService.GetBaidu_AccessToken();

            if (getTokenResult.Status == 0)
            {
                return(false);
            }

            string url = idCardvalidatehost + idCard;


            var request = HttpHelper.GetGetResponseEx(imagePath);
            var base64  = HttpHelper.GetResponseStream(request);

            Dictionary <string, string> param = new Dictionary <string, string>();

            //param.Add("image", HttpUtility.UrlEncode(Convert.ToBase64String(base64)));
            param.Add("image", imagePath);
            param.Add("id_card_number", idCardNumber);
            param.Add("image_type", imageType);
            param.Add("name", name);
            param.Add("access_token", getTokenResult.Data);

            var result = WebRequestHelper.WebPostRequest <JObject>(url, param, false);

            var obj      = result["result"];
            var errorMsg = result["error_msg"];

            if (obj != null)
            {
                var dic = JsonConvert.DeserializeObject <IDictionary <string, int> >(obj.ToString());
                if (dic.Keys.Contains("score"))
                {
                    int value = dic["score"];
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        /// <summary>
        /// 获取身份证信息
        /// </summary>
        /// <param name="imagePath">图书路径</param>
        /// <returns></returns>
        public static HttpResult GetIdCardInfo(string imagePath)
        {
            var getTokenResult = IdCardValidateService.GetBaidu_AccessToken();

            if (getTokenResult.Status == 0)
            {
                return(new HttpResult(0, getTokenResult.Message));
            }

            string url = host + idCardValidate;


            var request = HttpHelper.GetGetResponseEx(imagePath);
            var base64  = HttpHelper.GetResponseStream(request);


            Dictionary <string, string> param = new Dictionary <string, string>();

            param.Add("id_card_side", "front");
            param.Add("image", HttpUtility.UrlEncode(base64.ToByteBase64()));
            param.Add("access_token", getTokenResult.Data);

            var result = WebRequestHelper.WebPostRequest <JObject>(url, param, false);

            var obj      = result["words_result"];
            var errorMsg = result["error"];

            if (obj != null)
            {
                var dic = JsonConvert.DeserializeObject <IDictionary <string, object> >(obj.ToString());
                return(new HttpResult(dic.ToEntity <IdCardInfo>()));
            }
            else
            {
                return(new HttpResult(0, errorMsg.ToString()));
            }
        }