J2ME本身的API是没有提供这个方法的,但是我们通过CMWAP连接的时候,通过移动的网关来获取,当然,前提是移动的网关要提供这个功能。
如果网关支持这个功能的话,我们就可以通过服务器端来获得手机号码了,以下代码可以做为测试,看看你连接的移动网关是不是支持:
public
static
string
GetPhoneNumber(HttpRequest request)
{
string phone = "" ;
NameValueCollection coll = null ;
try
{
coll = request.ServerVariables ;
}
catch {}
try
{
if (phone == "" )
{
phone = coll[ " HTTP_X_UP_CALLING_LINE_ID " ].ToString() ;
}
}
catch {}
try
{
if (phone == "" )
{
phone = coll[ " MISC_MSISDN " ].ToString() ;
}
}
catch {}
try
{
if (phone == "" )
{
phone = coll[ " x-up-calling-line-id " ].ToString() ;
}
}
catch {}
try
{
if (phone == "" )
{
phone = coll[ " HTTP_X_NOKIA_MSISDN " ].ToString() ;
}
}
catch {}
try
{
if (phone.Length > 11 )
{
phone = phone.Substring( 2 ) ;
}
}
catch (Exception ex)
{
phone = ex.Message ;
}
return phone ;
}
{
string phone = "" ;
NameValueCollection coll = null ;
try
{
coll = request.ServerVariables ;
}
catch {}
try
{
if (phone == "" )
{
phone = coll[ " HTTP_X_UP_CALLING_LINE_ID " ].ToString() ;
}
}
catch {}
try
{
if (phone == "" )
{
phone = coll[ " MISC_MSISDN " ].ToString() ;
}
}
catch {}
try
{
if (phone == "" )
{
phone = coll[ " x-up-calling-line-id " ].ToString() ;
}
}
catch {}
try
{
if (phone == "" )
{
phone = coll[ " HTTP_X_NOKIA_MSISDN " ].ToString() ;
}
}
catch {}
try
{
if (phone.Length > 11 )
{
phone = phone.Substring( 2 ) ;
}
}
catch (Exception ex)
{
phone = ex.Message ;
}
return phone ;
}
客房端可以写个简单的测试程序。