1 Star 0 Fork 0

丁小未 / GetPhoneNumberInfo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
README.md 2.48 KB
一键复制 编辑 原始数据 按行查看 历史
丁小未 提交于 2016-11-28 12:42 . 修改

需求:

用户输入根据手机号,获得手机号所在的省市信息

思路:

调用相关的API进行分析

效果

这里写图片描述

代码

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using LitJson;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
	public class PhoneInfo
	{

		/// <summary>
		/// </summary>
		public PhoneInfo()
		{

		}
		public string Mobile;

		public string QueryResult;

		public string TO;

		/// <summary>
		/// 中国联通
		/// </summary>
		public string Corp;

		public string Province;

		public string City;

		/// <summary>
		/// 区域编号
		/// </summary>
		public string AreaCode;

		public string PostCode;

		public string VNO;

		public string Card;

		public override string ToString()
		{
			return string.Format("手机号:{0} 运营商:{1} 省:{2} 市:{3} 区号:{4}", Mobile, Corp, Province, City, AreaCode);
		}
	}
	class Program
	{
		static void Main(string[] args)
		{
			Regex rx = new Regex(@"^[1][358][0-9]{9}$");
			var phoneNum = "13262983383";
			if (rx.IsMatch(phoneNum))
			{
				var Url = @"http://v.showji.com/Locating/showji.com2016234999234.aspx?m=13262983386&output=json&callback=querycallback&timestamp=1480066397101";
				HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
				request.Method = "GET";
				request.ContentType = "text/html;charset=UTF-8";

				HttpWebResponse response = (HttpWebResponse)request.GetResponse();
				Stream myResponseStream = response.GetResponseStream();
				StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
				string retString = myStreamReader.ReadToEnd();
				//字符串截取
				var trueValue = retString.Substring(14, retString.Length - 16);
				try
				{
					var phone = JsonMapper.ToObject<PhoneInfo>(trueValue);
					Console.WriteLine(phone);
				}
				catch(Exception ex)
				{
					Console.WriteLine(ex.ToString());
				}
				
				Console.Read();
			}
		}
	}
}

unity交流群

QQ群

更多文章

C#
1
https://gitee.com/dingxiaowei/GetPhoneNumberInfo.git
git@gitee.com:dingxiaowei/GetPhoneNumberInfo.git
dingxiaowei
GetPhoneNumberInfo
GetPhoneNumberInfo
master

搜索帮助