查询手机归属地

前台页面文件:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="获取手机归属地.aspx.cs" Inherits="实例_获取手机归属地" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       请输入手机号码:<asp:TextBox ID="TextBox1"
            runat="server"></asp:TextBox><asp:Button ID="Button1" runat="server"
            Text="查  询" οnclick="Button1_Click" /><br />
           <div id="div1" runat="server"></div>
    </div>
    </form>
</body>
</html>
后台页面文件:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
public partial class 实例_获取手机归属地 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string phoneNumber = TextBox1.Text;
        if (phoneNumber != "")
        {
            div1.InnerHtml = "";
            foreach (string item in GetInfoByxml(" http://vip.showji.com/locating/?m={0}", phoneNumber.Trim()))
            {
                div1.InnerHtml += "<br/>" + item;
            }
        }
        else
        {
           //请输入手机号!
        }
    }

    /// <summary>
    /// 好123查询,符合下列规则也可使用
    /// 返回xml
    /// 需要顺序的节点:
    /// QueryResult(查询结果状态True,False)
    /// Province(所属省份)
    /// City(所属地区)
    /// Corp(服务商)
    /// Card(卡类型 GSM)
    /// AreaCode(区号)
    /// PostCode(邮编)
    /// </summary>
    /// <param name="url"></param>
    /// <param name="mobileNum"></param>
    /// <returns></returns>
    public static string[] GetInfoByxml(string url, string mobileNum)
    {
        try
        {
            XmlDocument xml = new XmlDocument();
            <?xml version='1.0' encoding='utf-8' ?>
            //<QueryResponse xmlns='http://api.showji.com/Locating/'>
            //<Mobile>15890636739</Mobile>
            //<QueryResult>True</QueryResult>
            //<Province>河南</Province>
            //<City>郑州</City>
            //<AreaCode>0371</AreaCode>
            //<PostCode>450000</PostCode>
            //<Corp>中国移动</Corp>
            //<Card>GSM</Card>
            //</QueryResponse>
            xml.Load(string.Format(url, mobileNum));
            XmlNamespaceManager xmlNm = new XmlNamespaceManager(xml.NameTable);
            xmlNm.AddNamespace("content", "http://api.showji.com/Locating/");
            XmlNodeList nodes = xml.SelectNodes("//content:QueryResult|//content:Mobile|//content:Province|//content:City|//content:Corp|//content:Card|//content:AreaCode|//content:PostCode", xmlNm);
            if (nodes.Count == 8)
            {
                if ("True".Equals(nodes[1].InnerText))
                {

                    return new string[] { "手机号码:" + nodes[0].InnerText, "省份:" + nodes[2].InnerText , "地区:" + nodes[3].InnerText,"服务商:"+ nodes[6].InnerText ,"卡类型:"+ nodes[7].InnerText, "区号:"+nodes[4].InnerText, "邮编:"+nodes[5].InnerText };
                }
            }
            return new string[] { "FALSE" };
        }
        catch
        {
            return new string[] { "FALSE" };
        }
    }
}

 此例使用IE9自带的开发人员工具查询hao123的手机号码归属地的问题。

可参考:http://www.cnblogs.com/sufei/archive/2011/04/29/2033036.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值