开发接口
MyMobileTrack支持第三方程序通过开放接口提交数据,轻轻松松就可以给你的程序加上基站定位,GPS定位,轨迹查询等功能。注意:本文档面向对象为程序开发者,如果您只是MobileTrack软件的使用者,则无需关注此文档。
当前版本:1.3
文档更新时间:2010.11.1
前提条件:
1.必须拥有本站的帐户;2.客户端能通过网络访问本网站接口;程序接口:
GET http://www.mymobiletrack.com/mobile/interface/location.php?username=xxx&password=xxx&mcc=xxx&mnc=xxx&lac=xxx&cellid=xxx&lat=xxx&lon=xxx&time=xxx&imei=xxx&imsi=xxx&ver=xxx
其中各参数含义如下:
username | mymobiletrack.com的用户名 |
password | mymobiletrack.com的密码,32位MD5加密格式 |
mcc | 基站mcc信息 |
mnc | 基站mnc信息 |
lac | 基站LAC信息 |
cellid | 基站Cellid信息 |
lat | GPS纬度(可为空) |
lon | GPS经度(可为空) |
time | 数据采集的时间,时间戳格式 |
imei | 手机串号(可为空) |
imsi | 手机卡号(可为空) |
ver | 开发者的程序名称 |
返回结果:
1.解析正常时返回格式:
(1)普通用户
"Error:0"
(2)授权用户 (
如需授权,请联系ant: anttna123@gmail.com )
"纬度,经度,详细地址" 示例:"22.559517,114.134659,广东省;深圳市;罗湖区;深圳电视台东南20米;中国银行景贝支行西北150米;电视广播大院停车场东南20米;"
2.解析错误时返回格式:
"Error:错误代码"
错误代码:
1 | 提交参数不足 |
2 | 非法参数 |
3 | 服务器出错 |
4 | 服务器出错 |
5 | 用户名不存在 |
6 | 用户名密码错误 |
7 | 服务器出错 |
提交数据后,使用蚁足网的用户名和密码登录网站,即可看到提交的轨迹点,也可进行查询历史轨迹,统计轨迹里程等操作。
提交数据示例
假设获取当前手机的基站为1234-5678-460,用户在MyMobileTrack的用户名为test,密码为test。可以用下面的代码将数据提交到MyMobileTrackC#代码(PPC):
...Other Code...
...
username="test";
password="098f6bcd4621d373cade4e832627b4f6";//32位md5密码
lac="5678";
cellid="1234";
lat="";
lon="";
time=getTimeStamp();
imes="";
imsi="";
ver="MyProgram";
url = "http://www.mymobiletrack.com/mobile/interface/location.php?username="+username+"&password="+password+"&lac="+lac+"&cellid="+cellid+"&lat="+lat+"&lon="+lon+"&time="+time+"&imes="+imes+"&imsi="+imsi+"&ver="+ver;
try
{
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
req.Method = "GET";
WebResponse wr = req.GetResponse();
Stream webstream = wr.GetResponseStream();
StreamReader sr = new StreamReader(webstream);
br = sr.ReadToEnd();
sr.Close();
wr.Close();
if (isSuccess(br))
{
//发送成功
printFunc("更新数据成功");
}
else
{
//不成功,可根据具体错误代码判断出错原因
printFunc("发送数据失败");
}
}
catch (Exception ex)
{
printFunc("发送数据时发生异常,网络是否已连接?");
}
...
如何获取基站
在PPC上可以用RIL获取基站信息(注:测试发现在少数机型上用RIL获取不了基站)C#代码(PPC): 把 ril.cs 加入到你的workspace中
string info = CellId.RIL.GetCellTowerInfo();
printFunc("基站是:"+info);//xxxx-xxxx-0
C++代码(Symbian):
在Symbian S60v3系统上可以用CTelephony获取基站信息 详见: http://wiki.forum.nokia.com/index.php/Cell_ID_with_CTelephony
如何得到时间戳
C#代码(PPC):DateTime timeStamp = new DateTime(1970, 1, 1); //得到1970年的时间戳
long stime = (DateTime.Now.Ticks - timeStamp.Ticks) / 10000000;
printFunc("当前时间戳是:"+stime);
C++代码(Symbian):
TTime currentTime;
currentTime.HomeTime();
TTime baseTime( _L("19700000:000000.000000"));
TInt64 interval;
interval=currentTime.Int64()-baseTime.Int64();
interval/=1000000; //interval即是当前的时间戳
MD5加密示例
C#代码(PPC):protected string UserMd5(string Sourcein)
{
MD5CryptoServiceProvider MD5CSP = new MD5CryptoServiceProvider();
byte[] MD5Source = System.Text.Encoding.UTF8.GetBytes(Sourcein);
byte[] MD5Out = MD5CSP.ComputeHash(MD5Source);
string pwd = "";
for (int i = 0; i < MD5Out.Length; i++)
{
pwd = pwd + MD5Out[i].ToString("x2");
}
return pwd;
}
C++代码(Symbian):
HBufC8* Preference::Md5HexDigestLC(const TDes8& aString )
{
CMD5* md5 = CMD5::NewL();
CleanupStack::PushL(md5);
TPtrC8 hashedSig(md5->Hash(aString));
HBufC8* buf = HBufC8::NewL(hashedSig.Length() * 2);
TPtr8 bufPtr = buf->Des();
for(TInt i=0; i< hashedSig.Length(); i++)
{
bufPtr.AppendFormat(_L8("%+02x"),hashedSig[i]);
}
CleanupStack::PopAndDestroy(md5);
CleanupStack::PushL(buf);
return buf;
}