我的雲端生活網 - Life+

Showing posts with label msn bot. Show all posts
Showing posts with label msn bot. Show all posts

Thursday, March 19, 2009

msn機器人會打架

剛找到一個有趣的情況:

假設
機器人1: 會自動發訊息通知某事 且有 互動功能(且指令錯誤會回覆)
機器人2: 有互動功能(且指令錯誤會回覆)

且有一方必須是要能從 "非msn client" 加入機器人帳號為聯絡人加入;
另一方需要是可直接在 "msn client" 加入機器人帳號為聯絡人
=================================================
那麼;機器人彼此成為聯絡人時,會形成一個loop,彼此一直傳送訊息永不停止

將較之下 可直接在 "msn client" 加入機器人帳號為聯絡人 的程式,較容易
遭受病毒攻擊,反之;也無可避免

目前我沒有找到好的方法來避免,當然可以加入黑名單 使用發訊息的頻率來避
免大量的互相發訊,但我覺得這些都不是最好的方法,因為無法防範於事前

Monday, November 10, 2008

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

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



msnSDK訊息控制開發套件 同時支援MSN/Yahoo即時通 訊息雙向傳遞
ps.也請參考 msnSDK的使用流程
================================
public class clsMsnSDK {
public static void main(String[] args) throws Exception {
String UserName = "apiblogt3";
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;
System.out.println(SPID);
//註冊聯絡人
String Email = "xxxxx@hotmail.com"; //填入msn/yahoo聯絡人,勿使用這個預設值
String ret = Register(Email,SPID);
System.out.println(ret);
//發訊息
String strMsg = "Hello_World!"; //輸入訊息 (未做 Url EnCoded)
String MsgRet = SendMsg(Email,strMsg,SPID);
System.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;
}

}

其他更詳細的參數可以參考msnSDK訊息控制開發套件程式介面說明書

3分鐘學會使用程式發送msn訊息,dotNet C#篇(二)








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



msnSDK訊息控制開發套件 同時支援MSN/Yahoo即時通 訊息雙向傳遞

ps.也請參考 msnSDK的使用流程

================================



全域的物件及變數

WebClient wc = new WebClient();

string SPID = "";



步驟一:取得SPID(GETSPID)

private void button1_Click(object sender, EventArgs e)

{

string url="http://59.120.234.84:8082/msnSDK/msn_cgi-win32";

string method="POST";

string postdata = "FUNC=GETSPID&USERID=apiblogt2&PASSWD=msnsdkt";

byte[] postbyte=Encoding.UTF8.GetBytes(postdata);

byte[] resb = wc.UploadData(url, method, postbyte);

string resmsg = Encoding.UTF8.GetString(resb);

resmsg = resmsg.Replace("\n", "");

string[] arrstr = resmsg.Split('\t');

if (arrstr[0] == "1")

{

SPID = arrstr[1];

MessageBox.Show("取得SPID成功: SPID= " + SPID);

}

else

{

SPID = "";

MessageBox.Show("取得SPID失敗: " + resmsg);

}

}



步驟二:將帳號註冊為msn機器人的連絡人(REGISTER)

下述: txtmsnacc.Text 為msn/yahoo帳號



private void button2_Click(object sender, EventArgs e)

{

string url = "http://59.120.234.84:8082/msnSDK/msn_cgi-win32";

string method = "POST";

string postdata = "FUNC=REGISTER&uids=" + txtmsnacc.Text + "&session=" + SPID;

byte[] postbyte = Encoding.UTF8.GetBytes(postdata);

byte[] resb = wc.UploadData(url, method, postbyte);

string resmsg = Encoding.UTF8.GetString(resb);

resmsg = resmsg.Replace("\n", "");

string[] arrstr = resmsg.Split('\t');

if (arrstr[0] == "1")

{

MessageBox.Show("註冊成功: " + resmsg);

}

else

{

MessageBox.Show("註冊失敗: " + resmsg);

}

}



步驟三:發送訊息(SENDMSG)

private void button3_Click(object sender, EventArgs e)

{

string msg = "msnSDK測試訊息";

string url = "http://59.120.234.84:8082/msnSDK/msn_cgi-win32";

string method = "POST";

string postdata = "FUNC=SENDMSG&uids=" + txtmsnacc.Text + "&msg=" + msg + "&encoding=utf-8&flags=0&session=" + SPID;

byte[] postbyte = Encoding.UTF8.GetBytes(postdata);

byte[] resb = wc.UploadData(url, method, postbyte);

string resmsg = Encoding.UTF8.GetString(resb);

resmsg = resmsg.Replace("\n", "");

string[] arrstr = resmsg.Split('\t');

if (arrstr[0] == "1")

{

MessageBox.Show("發送訊息成功: " + resmsg);

}

else

{

MessageBox.Show("發送訊息失敗: " + resmsg);

}

}



其他更詳細的參數可以參考msnSDK訊息控制開發套件程式介面說明書

Tuesday, November 4, 2008

msnSDK 釋出支援YAHOO即時通的版本

msnSDK 經過適當的改寫後,已支援Yahoo 即時通

1.新增/刪除 聯絡人的處理
2.發送訊息
3.查詢暱稱
4.查詢個人資訊
5.傳送震動訊息
6.傳送離線訊息

Yahoo 再收送資訊的部份與既有MSN 使用不同的指令;但在msnSDK 裡,機器人會自動判斷發送的對象是使用哪種IM,所以使用同一個函式名稱不需變換

請參考其他相關文章
msnSDK文件下載
http://rd-program.blogspot.com/2008/10/msnsdk.html

Monday, October 20, 2008

msnSDK v1.0.2 文件釋出

msnSDK(http://tcmail.program.com.tw/image/msnSDKV1.0.2.pdf)主要的功能就是把一些常用的MSN 功能做成一些API,讓外部的程式可以簡單的應用它來開發相關應用程式

Wednesday, October 15, 2008

MSNP16 與MSNP15 的差異

MSNP16 與MSNP15 唯一的差異

USR 4 SSO S t=...&p=xxx {MACHINE_GUID}
其中 MACHINE_GUID 可以是任何 32bytes 的16進制亂數,這大概是為了要讓MSN 可以在不同位置重複登入所設計,就像是XMPP 中的(jid)uid@domain/resource類似

Sunday, October 12, 2008

msnSDK 文件

msnSDK(http://tcmail.program.com.tw/image/msnSDKV1.0.1.pdf)主要的功能就是把一些常用的MSN 功能做成一些API,讓外部的程式可以簡單的應用它來開發相關應用程式,目前;msnSDK支援4種程式介面, 1.SOAP 2.CGI 3.ADO (這三種API的功能相同) 4.CGI-Steam 這個介面主要是處理從msn client 到msnSDK 之間的訊息以及線上狀況的資訊傳遞,歡迎需要測試功能的人或是有應用需求的各行各業先進與我聯繫(sonet.all@gmail.com)

備註:msnSDK 本身有unix/linux/win32 版本


v1.0.2 已釋出:msnSDK v1.0.2 文件釋出
v1.0.3 已釋出:msnSDK v1.0.3 文件釋出
不分版本(最新):msnSDK 不分版本(最新)文件



Blog Archive