Exemple #1
0
        public static IDCardInfo GetIDCardInfoByIDCard(string idCard)
        {
            var idCardInfo = new IDCardInfo();

            if (!string.IsNullOrWhiteSpace(idCard))
            {
                try
                {
                    var       apiUrl      = "http://apistore.baidu.com/microservice/icardinfo?id=" + idCard;
                    WebClient wc          = new WebClient();
                    byte[]    bResponse   = wc.DownloadData(apiUrl);
                    string    strResponse = Encoding.ASCII.GetString(bResponse);

                    var apiRR = JsonConvert.DeserializeObject <IDCardAPIRequestResult>(strResponse);
                    if (apiRR != null && apiRR.retData != null)
                    {
                        idCardInfo = apiRR.retData;
                        switch (idCardInfo.sex)
                        {
                        case "M":
                            idCardInfo.sex = "男";
                            break;

                        case "F":
                            idCardInfo.sex = "女";
                            break;

                        case "N":
                            idCardInfo.sex = "未知";
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                }
            }

            return(idCardInfo);
        }
Exemple #2
0
        public static IDCardInfo GetIDCardInfoByIDCard(string idCard)
        {
            var idCardInfo = new IDCardInfo();
            if (!string.IsNullOrWhiteSpace(idCard))
            {
                try
                {
                    var apiUrl = "http://apistore.baidu.com/microservice/icardinfo?id=" + idCard;
                    WebClient wc = new WebClient();
                    byte[] bResponse = wc.DownloadData(apiUrl);
                    string strResponse = Encoding.ASCII.GetString(bResponse);

                    var apiRR = JsonConvert.DeserializeObject<IDCardAPIRequestResult>(strResponse);
                    if (apiRR != null && apiRR.retData != null)
                    {
                        idCardInfo = apiRR.retData;
                        switch (idCardInfo.sex)
                        {
                            case "M":
                                idCardInfo.sex = "男";
                                break;
                            case "F":
                                idCardInfo.sex = "女";
                                break;
                            case "N":
                                idCardInfo.sex = "未知";
                                break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                }
            }

            return idCardInfo;
        }