WAP网页取得用户的手机号码
在WAP开发时,我们很想取到用户的手机号码,这样就可以确定用户的身份,免去用户的登录步骤,因为在手机上输入账号密码确实不是很容易。但是很不幸,现在大多数情况都会取不到,但是只要能取到,程序就得尽力去取。下面是一段比较实用的获取手机号码的代码:
// WAP网页取得用户的手机号码
// 如果通信运营商给送的话,一般在Http请求头的x-up-calling-line-id项里
String mobile = request.getHeader("x-up-calling-line-id"); // GPRS
if (mobile == null) {
mobile = request.getHeader("x-up-subno"); // CDMA
}
if (mobile == null) {
mobile = request.getHeader("x-network-info");
}
if (mobile == null) {
mobile = request.getHeader("deviceid");
}
if (mobile == null) {
// 有些wap门户站点跳转过来,手机号码由参数mobile传递过来
mobile = request.getParameter("mobile");
}
if (mobile != null) {
// 某些情况下,手机号码前面会加上中国国际区号86,需要去掉
if (mobile.length() == 13 && mobile.startsWith("86")) {
mobile = mobile.substring(2);
}
// TODO: 现在,程序可以认为用户身份(手机号码)已经确认,免登录(手机上输入账号密码不太容易)
} else {
// TODO: 无法取得手机号码的情况
}
下面的文章,很清楚的说明了WAP站点取得用户手机号码的情况。
wap获取手机号码 http://www.blogjava.net/phoebird/archive/2009/09/17/295499.html?opt=admin
http://www.blogjava.net/phoebird/archive/2009/09/17/295499.html?opt=admin 写道
原来获取用户手机号码很简单,关键是通信营运商给不给你送。如果给你送的话,手机号码是在Http请求头里获取,通常在x-up-calling-line-id项里,如果通过此项得不到的话。可采用循环读出所有的Http头里的信息,号码在哪一个头里就一目了然了。
String userPhone = request.getHeader("x-up-calling-line-id");一般通过这句就能获取到手机号码。
如果号码不在上面这条请求头里,采用下面方法读取看号码在哪一条请求头里。
Enumeration headers = request.getHeaderNames() ;
while(headers.hasMoreElements())
{
String head = (String)headers.nextElement();
out.println(head+":"+request.getHeader(head));
}
这样就可以将所有的信息打印出来,看到号码的位置了。注意获取号码的前提是跟营运商有合作或者跟他们申请。同意给你送,否则程序实现了也没有用。
下面的文章,提供了几种不同的获取用户手机号码的方式,跟运营商有关。
WAP 获取手机号码 http://www.elexcon.com/news/56455.html
http://www.elexcon.com/news/56455.html 写道
String Mobile_GPRS = request.getHeader("X-up-calling-line-id");
String Mobile_CDMA = request.getHeader("x-up-subno");
String Mobile_INFO = request.getHeader("x-network-info");
String Mobile_DEVI = request.getHeader("deviceid");
下面的文章,提供了更多的情况。实际情况,还得进行测试。
http://zhidao.baidu.com/question/155710398.html 写道
RE:我方法就是获得“浏览你WAP网站的那个手机的11位手机号码!!!”
补一下 我以前测试用的
a= request.ServerVariables("http_X_UP_subno")
b= request.ServerVariables("http_x-up-calling-line-id")
c= request.ServerVariables("http_user-agent")
d= request.ServerVariables("http_x_up_calling_line_id")
e= request.ServerVariables("deviceid")
f= request.ServerVariables("x_up_calling_line_id")
g= request.ServerVariables("x-up-calling-line-id")
h= request.ServerVariables("user_agent")
i= request.ServerVariables("user-agent")
j= request.ServerVariables("http_x_up_bear_type")
应该移动联通的手机就放在这么几个头里
全取出来测试下吧!