1 Star 0 Fork 0

丁小未 / GetPhoneNumberInfo

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or Download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

需求:

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

思路:

调用相关的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群

更多文章

Repository Comments ( 0 )

Sign in to post a comment

About

获得手机号的基本信息 expand collapse
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
C#
1
https://git.oschina.net/dingxiaowei/GetPhoneNumberInfo.git
git@git.oschina.net:dingxiaowei/GetPhoneNumberInfo.git
dingxiaowei
GetPhoneNumberInfo
GetPhoneNumberInfo
master

Search