相關業務/技術合作 行銷/經銷/代理;可洽 service@imoo.tw
星期二, 十一月 11, 2008
3分鐘學會使用程式發送msn訊息,dotNet C#篇(二)

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

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

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)
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訊息控制開發套件程式介面說明書

More... funp HemiDemi MyShare del.icio.us technorati Google Bookmarks Digg
XUE 發表於 9:56 AM | 標籤列表: , , , , ,

迴響留言
尚無迴響

張貼迴響:
名稱
電子郵件
網址



請輸入你在圖片中看到的文字
引用列表
本篇文章引用網址: http://yblog.org/api/trackback/?id=9407
沒有引用

Collablog Portal enabled