我的雲端生活網 - Life+

Thursday, November 13, 2008

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

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



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

perl 的範例我們使用soap 介面來處理,其他語言也可以這樣做,可參考文件(文末提供下載處)
wsdl位置:http://59.120.234.84:8082/msnSDK/genwsdl-win32

ps.也請參考 msnSDK的使用流程
================================
#!/usr/bin/perl
use SOAP::Lite;

#取得使用api 的權限
sub setspid
{
my $session_ret=SOAP::Lite->uri('http://59.120.234.84:8082/MSN')
->proxy('http://59.120.234.84:8082/msnSDK/msn_soap-win32')
->GETSPID('apiblogt4','msnsdkt')->result;
my ($code,$session)=split("\t",$session_ret);
$session=~tr/\r\n //d;
return $session;
}

#註冊聯絡人
sub register
{
my $sret= setspid();
my $session_ret=SOAP::Lite->uri('http://59.120.234.84:8082/MSN')
->proxy('http://59.120.234.84:8082/msnSDK/msn_soap-win32')
->REGISTER('要加入聯絡人的msn/yahoo帳號',$sret)->result;
print $session_ret;
}

#傳送訊息
sub sendmsg
{
my $sret= setspid();
my $msg_ret = SOAP::Lite->uri('http://59.120.234.84:8082/MSN')->
proxy('http://59.120.234.84:8082/msnSDK/msn_soap-win32')->
SENDMSG( '要傳送訊息聯絡人的msn/yahoo帳號', '欲傳送的訊息', 'utf-8','1',$sret)->result;
print $msg_ret;
}

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

Wednesday, November 12, 2008

ALE middleware 架構布局


目前正在思考 Application Level Events 介面 [1,2] 如何整併入系統中。我的構想如右圖。 Middleware 為 ALE 介面的實作,處理讀寫命令呼叫及程序觸發與控制,可能是獨立 server 、或是 DLL 、 local services 或 Web services 形式。一件 middleware server 可以管理許多台 readers 。 Middleware 對應用系統提供介面做讀取 (pooling) 。

Middleware 對 readers 以低層 reader 協定 (LLRP) 溝通,對應用系統則以 SOAP (簡單物件存取協定) 溝通。 Readers 的設定表可能離線備份在 middleware ,使上下二端讀取設定比較簡單。每一台 reader 只和少數一件 middleware(或二件,包含備援機)溝通,不同步的問題會比較少。應用系統的開發人員則呼叫 middleware 的 ALE 介面,傳 SOAP 參數或訊息,讓程式比較好寫。不過,少數的 middleware 會是效能關卡,這方面還要思考解決方案。


Middleware 做成獨立模組,內涵物可以有許多故事。例如 [4] 的處理方式。

SOAP 效能問題則可以參考 [3] 的處理方式(參左圖):應用系統送出訊息(由路線 2 )都由 client 代理,處理每一串 SOAP 訊息都先找 cache 有沒有舊的相同資料(由路線 3 ),若有則發送舊的訊息(由路線 5 ),或者若沒有則發送新訊息(由路線 5 )。

參考資料

[1] EPCglobal Inc. The EPCglobal architecture framework, EPCglobal final version 1.2 approved 10 September 2007. http://www.epcglobalinc.org/standards/architecture/architecture_1_2-framework-20070910.pdf , Sep. 10, 2007 (referred at August 2008).

[2] EPCglobal Inc. The Application Level Events (ALE) specification, version 1.1: Part I: Core specification. http://www.epcglobalinc.org/standards/ale/ale_1_1-standard-core-20080227.pdf , Feb. 27, 2008 (referred at September 2008).

[3] K. Devaram and D. Andresen. SOAP optimization via client-side caching. Proceedings of the First International Conference on Web Services (ICWS'03), pp. 520-524, Las Vegas, NV, June 24-27, 2003.

[4] J. Song, T. Kim, S. Lee, and H. Kim. Security enhanced RFID middleware system. Procedings of World Academy of Science, Engineering and Technology, v.10, pp.79-82, Dec. 10, 2005.

msnSDK的使用流程說明

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



3分鐘學會使用程式發送系列文章所使用的流程

STEP1:
取得SPID: GETSPID請參考各種語言所使用的帳號/密碼(每篇文章的程式碼內有),取得SPID以取得使用API 的權力

STEP2:
註冊聯絡人: 要發訊息給別人,需要先讓他成為聯絡人,因此這必須要是合法聯絡人(msn/yahoo帳號),而此時這個帳號會收到邀請通知(請見下圖)

STEP3:
傳送MSN/YAHOO訊息: SENDMSG(uids傳遞訊息的目的MSN/YAHOO帳號,msg欲傳遞的訊息內容,encoding傳遞的訊息中文編碼(utf-8/big5/gbk/gb2312),flags 0 對方離線則不送訊息 1對方離線則訊息是否傳送由系統決定,session GETSPIS得到的session值)

msnSDK擁有非常多的FUNCTION,也包含互動式的機器人選單,其他功能可參考msnSDK訊息控制開發套件程式介面說明書

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

Sunday, November 9, 2008

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

---電子發票整合方案 http://rd-program.blogspot.com/2012/03/blog-post.html ---




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



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



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

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



步驟一:取得api 使用的權限(GETSPID)



$file="http://59.120.234.84:8082/msnSDK/msn_cgi-win32?FUNC=GETSPID&USERID=apiblogt1&PASSWD=msnsdkt" ;

$myArray='';

$mySession='';

$myResult='';

$getline='';



if (!($fp = fopen($file, "r"))) {

die("could not open XML input");

}

while ($getline = fgets($fp, 4096)) {

$myArray=explode("\t",$getline);

$myResult=$myArray[0];

$mySession= $myArray[1];

}

fclose($fp);

if ($myResult=="0")

{

echo "get session fail...

";

exit();

}

else

{

//$_SESSION["mySession"]= $mySession;

echo "get session=".$mySession."

";

}

echo "<a href='REGISTER.php?uids=".$_GET["uids"]."&session=".$mySession."'>go register page</a>";

?>



步驟二: 邀請聯絡人(REGISTER)



$myArray='';

$mySession='';

$myResult='';

$getline='';

//register:

$file="http://59.120.234.84:8082/msnSDK/msn_cgi-win32?FUNC=REGISTER&uids=".$_GET["uids"]."&session=".$_GET["session"] ;

echo $file."

";



if (!($fp = fopen($file, "r"))) {

die("could not open XML input");

}

while ($getline = fgets($fp, 4096)) {

$myArray=explode("\t",$getline);

$myResult=$myArray[0];

}

fclose($fp);



if ($myResult=="0")

{

echo "register fail... ".$myArray[1]."

";

//exit();

}

else

{

echo "register ok. account=".$myArray[2]."

";

}

echo "<a href='SENDMSG.php?uids=".$_GET["uids"]."&msg=hello&encoding=utf-8&flags=0&session=".$_GET["session"]."'>go SENDMSG page</a>";

?>



步驟三:發送訊息(SENDMSG)



$myArray='';

$mySession='';

$myResult='';

$getline='';



//send message:

$file="http://59.120.234.84:8082/msnSDK/msn_cgi-win32?FUNC=SENDMSG&uids=".$_GET["uids"]."&msg=".$_GET["msg"]."&encoding=utf-8&flags=0&session=".$_GET["session"] ;

if (!($fp = fopen($file, "r"))) {

die("could not open XML input");

}

while ($getline = fgets($fp, 4096)) {

$myArray=explode("\t",$getline);

$myResult=$myArray[0];

}

fclose($fp);

if ($myResult=="0")

{

echo "send message fail... ".$myArray[1]."

";

exit();

}

else

{

echo "send message ok. message=".$myArray[2]."

";

}

?>



其他更詳細的參數可以參考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

Blog Archive