예제 #1
0
        public bool IsValid()
        {
            if (Name.IsNullOrWhiteSpace())
            {
                throw new ArgumentException("O nome do campo está inválido");
            }

            if (JsonId.IsNullOrWhiteSpace())
            {
                throw new ArgumentException("O JSON ID do campo está inválido");
            }

            return(true);
        }
예제 #2
0
        /// <summary>
        /// 身份证识别
        /// </summary>
        /// <param name="path"></param>
        /// <param name="img"></param>
        /// <returns></returns>
        public static string Idcard(Image img)
        {
            string url     = "https://openapi.youdao.com/ocr_structure";
            string base64  = WebExt.ImageToBase64(img);
            string salt    = DateTime.Now.Millisecond.ToString();
            string curTime = WebExt.GetTimeSpan();
            string sign    = ComputeHash(YoudaoKey.AppKey + Truncate(base64) + salt + curTime + YoudaoKey.AppSecret);
            string str     = string.Format($"q={HttpUtility.UrlEncode(base64)}" +
                                           $"&structureType=idcard&appKey={YoudaoKey.AppKey}" +
                                           $"&salt={salt}&sign={sign}&docType=json&signType=v3&curtime={curTime}");
            string result = WebExt.Request(url, null, str);
            // 解析json数据
            JavaScriptSerializer js = new JavaScriptSerializer();
            string json_result      = GetDictResult(result);
            JsonId list             = js.Deserialize <JsonId>(json_result);

            return(string.Format($"姓名:{list.Name}\r\n性别:{list.Gender}\r\n" +
                                 $"民族:{list.Nation}\r\n出生:{list.Birthday}\r\n" +
                                 $"住址:{list.Address}\r\n身份证号码:{list.IDNumber}"));
        }