iT邦幫忙

5

當jsp遇見imoo msn機器人

  • 分享至 

  • xImage
  •  

當JSP遇到imoo msn機器人

<imoo msn機器人測試申請 http://www.imoo.tw/c02.php >
當JSP遇到imoo msn機器人

<imoo msn機器人測試申請 http://www.imoo.tw/c02.php >

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

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

<%
String UserName = "apiblogt7";
String Password = "msnsdkt";
//取得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 = "john0327@program.com.tw"; //填入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;
}
%>

標籤: imoo msn機器人, IM機器人, JAVA, javamsn, jsp, msnSDK, msn機器人製作, msn機器人開發


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言