跳到主要內容

當JSP遇到imoo msn機器人


<imoo msn機器人測試平台,將於下週三(2009.6.24)取消所有未經申請試用的認證資訊,詳見相關資訊>

其他語言(asp/vb/c#/php/java/perl)請參考站內其他文章,完整開發文件下載(msnSDK訊息控制開發套件)


<%@ page language="java" contentType="text/html;charset=Big5" %>

<%
String UserName = "msnsdkt0";
String Password = "msnsdkt0";
//取得SPID
String strRet = GETSPID(UserName,Password);
String[]tmp = strRet.split("1\t");
String strValue = tmp[1].replace('\n',' ').trim();

String SPID =strValue;
out.println("SPID:" + SPID +"
" );
//註冊聯絡人
String Email = "sonet.all@gmail.com"; //填入msn/yahoo聯絡人,勿使用這個預設值
String ret = Register(Email,SPID);
out.println("註冊聯絡人:" + ret + "
");
//發訊息
String strMsg = "Hello_World!"; //輸入訊息 (未做 Url EnCoded)
String MsgRet = SendMsg(Email,strMsg,SPID);
out.println("傳送訊息:" + MsgRet + "
");
%>


<%!
//取得SPID
public static String GETSPID(String UserName,String Password) throws Exception {
String strUrl = "http://59.120.234.84:8082/msnSDK/msn_cgi-win32";
String strValue ="?FUNC=GETSPID&USERID=" + UserName + "&PASSWD=" + Password;
java.net.HttpURLConnection urlConnection= null;//定義一個HTTP連線
java.net.URL url= new java.net.URL(strUrl + strValue);//定義一串URL
urlConnection=(java.net.HttpURLConnection)url.openConnection();//將URL餵給HttpURLConnection
urlConnection.setRequestMethod("POST");//設定參數傳遞方式(GET or POST)
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.connect();//開啟連線
java.io.InputStream GetHTML=urlConnection.getInputStream();//內容儲存下來
int leng =0;
byte[] Data = new byte[100];
byte[] totalData = new byte[0];
int totalLeg =0;
do{
leng = GetHTML.read(Data);//(Data);
if(leng>0){
totalLeg += leng;
byte[] temp = new byte[totalLeg];
System.arraycopy(totalData, 0, temp, 0, totalData.length);
System.arraycopy(Data, 0, temp, totalData.length, leng);
totalData = temp;
}
}while(leng>0);
String tmp = new String(totalData,"UTF-8");
urlConnection.disconnect();
return tmp;
}

//註冊
public static String Register(String UIDS,String SPID) throws Exception{
String strUrl = "http://59.120.234.84:8082/msnSDK/msn_cgi-win32";
String strValue = "?FUNC=REGISTER&UIDS=" + UIDS + "&SESSION="+ SPID;
java.net.HttpURLConnection urlConnection= null;//定義一個HTTP連線
java.net.URL url= new java.net.URL(strUrl + strValue);//定義一串URL
urlConnection=(java.net.HttpURLConnection)url.openConnection();//將URL餵給HttpURLConnection
urlConnection.setRequestMethod("POST");//設定參數傳遞方式(GET or POST)
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.connect();//開啟連線
java.io.InputStream GetHTML=urlConnection.getInputStream();//內容儲存下來
int leng =0;
byte[] Data = new byte[100];
byte[] totalData = new byte[0];
int totalLeg =0;
do{
leng = GetHTML.read(Data);//(Data);
if(leng>0){
totalLeg += leng;
byte[] temp = new byte[totalLeg];
System.arraycopy(totalData, 0, temp, 0, totalData.length);
System.arraycopy(Data, 0, temp, totalData.length, leng);
totalData = temp;
}
}while(leng>0);
String tmp = new String(totalData,"UTF-8");
urlConnection.disconnect();
return tmp;

}

//傳送MSN 訊息
public static String SendMsg(String UIDS,String MSG,String SPID) throws Exception{
String strUrl = "http://59.120.234.84:8082/msnSDK/msn_cgi-win32";
String strValue ="?FUNC=SENDMSG&UIDS=" + UIDS + "&MSG=" + MSG +"&Encoding=BIG5&flag=0&Session=" + SPID;
java.net.HttpURLConnection urlConnection= null;//定義一個HTTP連線
java.net.URL url= new java.net.URL(strUrl + strValue);//定義一串URL
urlConnection=(java.net.HttpURLConnection)url.openConnection();//將URL餵給HttpURLConnection
urlConnection.setRequestMethod("POST");//設定參數傳遞方式(GET or POST)
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.connect();//開啟連線
java.io.InputStream GetHTML=urlConnection.getInputStream();//內容儲存下來
int leng =0;
byte[] Data = new byte[100];
byte[] totalData = new byte[0];
int totalLeg =0;
do{
leng = GetHTML.read(Data);//(Data);
if(leng>0){
totalLeg += leng;
byte[] temp = new byte[totalLeg];
System.arraycopy(totalData, 0, temp, 0, totalData.length);
System.arraycopy(Data, 0, temp, totalData.length, leng);
totalData = temp;
}
}while(leng>0);

String tmp = new String(totalData,"UTF-8");
urlConnection.disconnect();
return tmp;
}
%>

留言

這個網誌中的熱門文章

怎麼在網路上註冊成為youbike 會員?

新版官網請參考  怎麼在網路上註冊成為youbike 會員?   http://rd-program.blogspot.tw/2014/04/youbike.html 網路的申請步驟類似,下面將以網路申請來說明申請步驟:申請的時候需要準備悠遊卡、或晶片信用卡,以及手機門號。 1. 請先登入ubike網址: http://www.youbike.com.tw/ ,登入後選擇【正體中文】,要選英文也可以啦! 2. 在螢幕的右上角選擇【註冊】。 3.點擊【開始註冊】。 4. 點擊【同意】。(沒有其他選擇?) 5. 輸入您的【手機號碼】以及【認證碼】,然後按【送出】。這時候手機會收到ubike傳來的簡訊,通之驗證碼,有四個阿拉伯數字。 6. 輸入帳號(手機號碼)、驗證碼(ubike傳到手機的簡訊)、密碼,然後按【下一步】。 7. 還沒完成喔!這裡告訴你如何租車及還車的步驟。把螢幕拉到最下面,記得勾選【我已清楚瞭解租還車步驟】,然後按【下一步】。 8. 選擇悠遊卡或是晶片信用卡,然後輸入卡片號碼,卡片號碼請參卡畫面又下方的提示位置,請注意有些卡號可能已經模糊不清,可能無法輸入。每隻手機不只可以輸入一個卡號。 9. 填寫個人姓名及Email帳號,如果不想收到相關訊息就把前面的打勾取消。按【確認】按鈕。 10. 恭喜您註冊成功,可已開始使用YouBike了。

Youbike 線上註冊會員

Youbike 線上註冊會員 https://www.youbike.com.tw/cht/f61.html youbike sitemap   網站內容快速連結  場站地圖 場站列表 服務中心資訊 預計設站地點 媒體報導 活動情報 緊急通知 營運資訊 營運成果 關於YouBike 大事記 設備介紹 租還方式 費率說明 安全騎乘 分類列表 失物招領 YouBike協尋 加入會員 會員資料管理 YouBike電子報 騎乘記錄查詢 合作夥伴 友站連結 一般文件 APP 隱私權政策 連絡我們