3分鐘學會使用程式發送msn訊息, Java篇(三) (MSN機器人)

<div?class="post?hentry"><a?name="1942913001923108412"><h3?class="post-title?entry-title"><a?href="http: rd-program.blogspot.com="" 2008="" 11="" 3msn-java.html"="">3分鐘學會使用程式發送msn訊息,?Java篇(三)<div?class="post-header-line-1"> <div?class="post-body?entry-content">

<a?href="http: www.program.com.tw="" newpage="" msnsdk.htm"=""><font?color="#6699cc">msnSDK訊息控制開發套件?同時支援MSN/Yahoo即時通?訊息雙向傳遞<br?>ps.也請參考?<a?href="http: rd-program.blogspot.com="" 2008="" 11="" msnsdk.html"=""><font?color="#666699">msnSDK的使用流程?<br?>================================<br?>public?class?clsMsnSDK?{<br?>public?static?void?main(String[]?args)?throws?Exception?{<br?>String?UserName?=?"apiblogt3";<br?>String?Password?=?"msnsdkt";<br?>//取得SPID<br?>String?strRet?=?GETSPID(UserName,Password);?<br?>String[]tmp?=?strRet.split("1\t");<br?>String?strValue?=?tmp[1].replace('\n','?').trim();<br?><br?>String?SPID?=?strValue;<br?>System.out.println(SPID);<br?>//註冊聯絡人<br?>String?Email?=?"[email protected]";?//填入msn/yahoo聯絡人,勿使用這個預設值<br?>String?ret?=?Register(Email,SPID);<br?>System.out.println(ret);<br?>//發訊息<br?>String?strMsg?=?"Hello_World!";?//輸入訊息?(未做?Url?EnCoded)<br?>String?MsgRet?=?SendMsg(Email,strMsg,SPID);<br?>System.out.println(MsgRet);<br?>}<br?><br?><br?>//取得SPID<br?>public?static?String?GETSPID(String?UserName,String?Password)?throws?Exception?{<br?><br?>String?strUrl?=?"http://59.120.234.84:8082/msnSDK/msn_cgi-win32";<br?>String?strValue?="?FUNC=GETSPID&USERID="?+?UserName?+?"&PASSWD="?+?Password;<br?>java.net.HttpURLConnection?urlConnection=?null;//定義一個HTTP連線?<br?>java.net.URL?url=?new?java.net.URL(strUrl?+?strValue);//定義一串URL?<br?>urlConnection=(java.net.HttpURLConnection)url.openConnection();//將URL餵給HttpURLConnection<br?>urlConnection.setRequestMethod("POST");//設定參數傳遞方式(GET?or?POST)<br?>urlConnection.setDoOutput(true);<br?>urlConnection.setDoInput(true);<br?>urlConnection.connect();//開啟連線<br?>java.io.InputStream?GetHTML=urlConnection.getInputStream();//內容儲存下來<br?>int?leng?=0;<br?>byte[]?Data?=?new?byte[100];<br?>byte[]?totalData?=?new?byte[0];<br?>int?totalLeg?=0;<br?>do{<br?>leng?=?GetHTML.read(Data);//(Data);?<br?>if(leng>0){<br?>totalLeg?+=?leng;<br?>byte[]?temp?=?new?byte[totalLeg];<br?>System.arraycopy(totalData,?0,?temp,?0,?totalData.length);<br?>System.arraycopy(Data,?0,?temp,?totalData.length,?leng);<br?>totalData?=?temp;?<br?>}<br?>}while(leng>0);<br?>String?tmp?=?new?String(totalData,"UTF-8");<br?>urlConnection.disconnect();<br?>return?tmp;?<br?>}<br?><br?>//註冊<br?>public?static?String?Register(String?UIDS,String?SPID)?throws?Exception{<br?>String?strUrl?=?"http://59.120.234.84:8082/msnSDK/msn_cgi-win32";<br?>String?strValue?=?"?FUNC=REGISTER&UIDS="?+?UIDS?+?"&SESSION="+?SPID;<br?>java.net.HttpURLConnection?urlConnection=?null;//定義一個HTTP連線?<br?>java.net.URL?url=?new?java.net.URL(strUrl?+?strValue);//定義一串URL?<br?>urlConnection=(java.net.HttpURLConnection)url.openConnection();//將URL餵給HttpURLConnection<br?>urlConnection.setRequestMethod("POST");//設定參數傳遞方式(GET?or?POST)<br?>urlConnection.setDoOutput(true);<br?>urlConnection.setDoInput(true);<br?>urlConnection.connect();//開啟連線<br?>java.io.InputStream?GetHTML=urlConnection.getInputStream();//內容儲存下來<br?>int?leng?=0;<br?>byte[]?Data?=?new?byte[100];<br?>byte[]?totalData?=?new?byte[0];<br?>int?totalLeg?=0;<br?>do{<br?>leng?=?GetHTML.read(Data);//(Data);?<br?>if(leng>0){<br?>totalLeg?+=?leng;<br?>byte[]?temp?=?new?byte[totalLeg];<br?>System.arraycopy(totalData,?0,?temp,?0,?totalData.length);<br?>System.arraycopy(Data,?0,?temp,?totalData.length,?leng);<br?>totalData?=?temp;?<br?>}<br?>}while(leng>0);<br?>String?tmp?=?new?String(totalData,"UTF-8");<br?>urlConnection.disconnect();<br?>return?tmp;<br?><br?>}<br?><br?>//傳送MSN?訊息<br?>public?static?String?SendMsg(String?UIDS,String?MSG,String?SPID)?throws?Exception{<br?>String?strUrl?=?"http://59.120.234.84:8082/msnSDK/msn_cgi-win32";<br?>String?strValue?="?FUNC=SENDMSG&UIDS="?+?UIDS?+?"&MSG="?+?MSG?+"&Encoding=BIG5&flag=0&Session="?+?SPID;<br?>java.net.HttpURLConnection?urlConnection=?null;//定義一個HTTP連線?<br?>java.net.URL?url=?new?java.net.URL(strUrl?+?strValue);//定義一串URL?<br?>urlConnection=(java.net.HttpURLConnection)url.openConnection();//將URL餵給HttpURLConnection<br?>urlConnection.setRequestMethod("POST");//設定參數傳遞方式(GET?or?POST)<br?>urlConnection.setDoOutput(true);<br?>urlConnection.setDoInput(true);<br?>urlConnection.connect();//開啟連線<br?>java.io.InputStream?GetHTML=urlConnection.getInputStream();//內容儲存下來<br?>int?leng?=0;<br?>byte[]?Data?=?new?byte[100];<br?>byte[]?totalData?=?new?byte[0];<br?>int?totalLeg?=0;<br?>do{<br?>leng?=?GetHTML.read(Data);//(Data);?<br?>if(leng>0){<br?>totalLeg?+=?leng;<br?>byte[]?temp?=?new?byte[totalLeg];<br?>System.arraycopy(totalData,?0,?temp,?0,?totalData.length);<br?>System.arraycopy(Data,?0,?temp,?totalData.length,?leng);<br?>totalData?=?temp;?<br?>}<br?>}while(leng>0);<br?><br?>String?tmp?=?new?String(totalData,"UTF-8");?<br?>urlConnection.disconnect();<br?>return?tmp;<br?>}<br?><br?>}<br?><br?>其他更詳細的參數可以參考<a?href="http: tcmail.program.com.tw="" image="" msnsdk.pdf"=""><font?color="#666699">msnSDK訊息控制開發套件程式介面說明書

<div?style="clear:?both"> <div?class="post-footer"><p?class="post-footer-line?post-footer-line-1"><span?class="post-labels">標籤:?<a?href="http: rd-program.blogspot.com="" search="" label="" 3%e5%88%86%e9%90%98%e5%ad%b8%e6%9c%83%e4%bd%bf%e7%94%a8%e7%a8%8b%e5%bc%8f%e7%99%bc%e9%80%81msn%e8%a8%8a%e6%81%af"?rel="tag"><font?color="#666699">3分鐘學會使用程式發送msn訊息,?<a?href="http: rd-program.blogspot.com="" search="" label="" javamsn"?rel="tag"><font?color="#6699cc">javamsn,?<a?href="http: rd-program.blogspot.com="" search="" label="" jmsn"?rel="tag"><font?color="#6699cc">jmsn,?<a?href="http: rd-program.blogspot.com="" search="" label="" msn%20bot"?rel="tag"><font?color="#6699cc">msn?bot,?<a?href="http: rd-program.blogspot.com="" search="" label="" msn%20messenger%20sdk"?rel="tag"><font?color="#6699cc">msn?messenger?SDK,?<a?href="http: rd-program.blogspot.com="" search="" label="" msnlib"?rel="tag"><font?color="#6699cc">msnlib,?<a?href="http: rd-program.blogspot.com="" search="" label="" msnp15"?rel="tag"><font?color="#6699cc">MSNP15,?<a?href="http: rd-program.blogspot.com="" search="" label="" msnsdk"?rel="tag"><font?color="#6699cc">msnSDK,?<a?href="http: rd-program.blogspot.com="" search="" label="" msnsdk%e8%a8%8a%e6%81%af%e6%8e%a7%e5%88%b6%e9%96%8b%e7%99%bc%e5%a5%97%e4%bb%b6"?rel="tag"><font?color="#6699cc">msnSDK訊息控制開發套件,?<a?href="http: rd-program.blogspot.com="" search="" label="" msn%e6%a9%9f%e5%99%a8%e4%ba%ba"?rel="tag"><font?color="#666699">msn機器人,?<a?href="http: rd-program.blogspot.com="" search="" label="" msn%e9%96%8b%e7%99%bc%e5%a5%97%e4%bb%b6"?rel="tag"><font?color="#6699cc">msn開發套件

<p?class="post-footer-line?post-footer-line-2"> 

<p?class="post-footer-line?post-footer-line-3"> 

你可能感兴趣的:(java,.net,Yahoo,cgi)