借助IP138网站来实现本地系统的IP,身份证号,手机号码查询功能

来源:互联网 发布:电池修复软件 编辑:程序博客网 时间:2024/04/30 09:09

公司内部的CRM系统和呼叫中心系统,客服人员经常会用到电话归属地查询,原来一直用Iframe嵌套IP138的查询页面,但总感觉有些不爽,公司还不愿意花钱去买手机号段库,因此决定通过程序将其解决;

 

通过此方式,公司内部呼叫中心系统即可实现,来电号码所属地区的提示,外呼时,系统也可判定手机号码前是否应该加0,比较多的问题都可解决,页面代码刻录如下: 

 

C#语言: crm
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;

public partial class test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            GetMobilePhoneInfo();
    }

    private void GetMobilePhoneInfo()
    {
        WebClient wb = new WebClient();
        NameValueCollection myNameValueCollection = new NameValueCollection();

        myNameValueCollection.Add("mobile", "13651259785");
        myNameValueCollection.Add("action", "mobile");
        byte[] pagedata = wb.UploadValues(new Uri("http://www.ip138.com:8080/search.asp"), myNameValueCollection);
        string result = Encoding.Default.GetString(pagedata);
        string pat = "tdc2>([^<]*)</TD>";
        Regex r = new Regex(pat, RegexOptions.IgnoreCase);
        Match m = r.Match(result);
        string[] strInfo = new string[4] { "", "", "", "" };
        int i = 0;
        while (m.Success)
        {
            if (i < strInfo.Length)
            {
                int end = m.ToString().IndexOf("<");
                strInfo[i] = m.ToString().Substring(5,end-5);
            }
            m = m.NextMatch();
            i++;
        }
        string mobilephone = strInfo[0].ToString();
        string provinceCity = strInfo[1].ToString();
        string type = strInfo[2].ToString();
        string areaCode = strInfo[3].ToString();
        Response.Write(mobilephone + "<br>");
        Response.Write(provinceCity + "<br>");
        Response.Write(type + "<br>");
        Response.Write(areaCode + "<br>");
    }
}