Пример #1
0
        private void InitControls()
        {
            PubApi apiProcess = new PubApi();

            comKd.Properties.Items.Clear();
            foreach (PubApi.ApiExpressType item in Enum.GetValues(typeof(PubApi.ApiExpressType)))
            {
                comKd.Properties.Items.Add(new ComboxItem()
                {
                    Value = item.ToString(), Text = apiProcess.GetEnumDescription(item)
                });
            }
        }
Пример #2
0
        public bool ApiData_GetMobileInfo(string appkey, string mobileNum)
        {
            //手机归属地查询
            string url           = "http://apis.juhe.cn/mobile/get";
            var    parametersGet = new Dictionary <string, string>();

            parametersGet.Add("phone", mobileNum.Substring(0, 7)); //需要查询的手机号码或手机号码前7位
            parametersGet.Add("key", appkey);                      //你申请的key
            parametersGet.Add("dtype", "");                        //返回数据的格式,xml或json,默认json

            PubApi apiProcess = new PubApi();
            string resultGet  = apiProcess.sendPost(url, parametersGet, "get");

            apiDataObject.MobileInfoObj mobileInfos = JsonConvert.DeserializeObject <apiDataObject.MobileInfoObj>(resultGet);

            //JsonObject newObjGet = new JsonObject(resultGet);
            //string errorCode = newObjGet["error_code"].Value;
            if (mobileInfos != null)
            {
                if (mobileInfos.error_code == 0)
                {
                    string sNr = string.Empty;
                    sNr += "您查询的手机号信息为:" + "\r\n";
                    sNr += "省份:" + mobileInfos.result.province + "\r\n";
                    sNr += "城市:" + mobileInfos.result.city + "\r\n";
                    sNr += "区号:" + mobileInfos.result.areacode + "\r\n";
                    sNr += "邮编:" + mobileInfos.result.zip + "\r\n";
                    sNr += "运营商:" + mobileInfos.result.company;
                    System.Windows.Forms.MessageBox.Show(sNr);
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show(mobileInfos.resultcode.ToString() + ":" + mobileInfos.reason);
                }
            }
            return(true);
        }