Today, the company wants to develop an Apsara stack robot for the mobile branch to improve the activity of Apsara stack users. It is too troublesome to analyze the Protocol by myself. Some friends studied the Apsara stack protocol in the past few months, I believe there should also be a ready-made product on the Internet. Google it and find the desired materials.
The Apsara protocol can be used to send and receive messages online or send messages to mobile phones. Therefore, you can complete an im tool by yourself.
[Image]
This article describes how to use the Apsara stack SDK and how to develop it.
Fetionsdk download: http://sites.google.com/site/allwealthshare/software/FetionSDK.dll.rar? Attredirects = 0
Paste the core informationCode:
Private fetionsdk SDK = new fetionsdk (); // instantiate the Apsara stack SDK
SDK. sdk_receivemessage + = new fetionsdk. sdk_receivemessageeventhandler (sdk_sdk_receivemessage); // message receiving event
SDK. sdk_usersatuschange + = new fetionsdk. sdk_usersatuschangedeventhandler (sdk_sdk_usersatuschange); // user status event
SDK. sdk_error + = new fetionsdk. sdk_erroreventhandler (sdk_sdk_error); // SDK error event
///
// log on to Apsara stack
///
private bool fetionlogin (string username, string PWD)
{< br> SDK. accountmanager. filluseridandpassword (username, PWD, false); // The third parameter is whether to log on automatically
bool isok = SDK. accountmanager. login (); // login
return isok;
}
///
// send a message
///
private bool sendfetionmsg (string username, string MSG)
{< br> bool isok = false;
try
{< br> int state = SDK. contactcontrol. sendim. sendim (username, MSG);
}< br> catch {isok = false ;}< br> return isok;
}
/// <Summary>
/// Send a mobile message
/// </Summary>
Private bool sendfetionmobilemsg (string username, string MSG)
{
Bool isok = false;
Try
{
Int state = SDK. contactcontrol. sendsms. sendsms (username, MSG );
}
Catch {isok = false ;}
Return isok;
}
/// <Summary>
/// Load the friend list
/// </Summary>
/// <Param name = "pssdk"> Feixin SDK object </param>
/// <Returns> Returns a set of Apsara friends </returns>
Private list <fetionfriend> getfetionfriendlist (fetionsdk pssdk)
{
List <fetionfriend> fetionfriends = new list <fetionfriend> ();
Try
{
List <imps. Client. Core. Contact> List = pssdk. contactcontrol. getallcontactlist ();
For (INT I = 0; I <list. Count; I ++)
{
Try
{
Fetionfriend = new fetionfriend (); // you can customize the object information class of a user.
Fetionfriend. userid = int. parse (list [I]. Uri. ID );
Fetionfriend. Nickname = list [I]. displayname;
Fetionfriend. Mobile = list [I]. personalinfo. inclueno;
Fetionfriends. Add (fetionfriend );
}
Catch {}
}
}
Catch {fetionfriends = new list <fetionfriend> ();}
Return fetionfriends;
}
/// <Summary>
/// The Feixin SDK has an error.
/// </Summary>
Private void sdk_sdk_error (Object sender, nullstudio. fetion_sdk.event.sdk_erroreventargs Fe)
{
This.txt box. Text + = "error:" + Fe. message. Message + "\ r \ n ";
}
///
// current flight Signal Status
///
private void sdk_sdk_usersatuschange (Object sender, imps. client. core. usersatuschangedeventargs e)
{< br> switch (E. newstatus. tostring ()
{< br> case "disconnected": // The network is disconnected
fetionlogin (username, userpwd); // log on again
break;
case "initialized": // initialized
break;
case "loginning": // logging in
Break;
Case "Logon": // logged in
SDK. accountmanager. currentuser. presence. asyncchangemainpresence (imps. Common. mainpresence. Online, imps. Common. mainpresence. Online. tostring (); // set PC online
Break;
Case "logoff": // leave the network
Break;
Case "logouting": // canceling
Break;
Case "NONE": // stateless
Break;
Case "offlinelogon": // offline
Break;
Case "standby": // standby
Break;
Case "waitreconnect": // wait
Break;
}
This.txt box. Text + = "status" + E. newstatus. tostring () + "\ r \ n ";
}
/// <Summary>
/// Received message
/// </Summary>
Private void sdk_sdk_receivemessage (Object sender, nullstudio. fetion_sdk.event.sdk_receivemessageeventargs Fe)
{
This.txt box. text + = "" + String. format (Fe. message, Fe. contact. personalinfo. nickname + "(" + Fe. contact. uri. sid. tostring () + ")") + "\ r \ n ";
}
Note the following:
1. Why is the online status of SMS displayed after login?
SDK is required. accountmanager. currentuser. presence. asyncchangemainpresence (imps. common. mainpresence. online, imps. common. mainpresence. online. tostring (); Once activated, the PC is online and the user status is changed.
2. Why do I often lose lines?
Solution: Change the user status one time at a time to let the server know that I am still online.
/Files/angells/fetionsdk.rar