FetionSDK.dll 说明 BY SYSU_LXIONGH
前言 :
这篇文章是基于 Fetionsdk.dll 飞信端程序开发而写的 , 里面的代码是我通过 Reflector 反编译中国移动开发的飞信 2008 中的 fetionFx.exe 研究的结果 .Fetionsdk.dll 的下载地址 :
http://sites.google.com/site/allwealthshare/software/FetionSDK.dll.rar?attredirects=0
移动的飞信客户端是用 C# 语言开发的 , 所以我们在利用 fetionsdk.dll 来开发自己的飞信客户端的时候也应采用 C# 语言来开发 ( 我不清楚能不能用其他语言来开发 , 如 C++). 有一点需要说明的是 , 这个 fetionsdk.dll 是位能人反编绎而来的 , 难免会有些 bug. 例如 : 如果好友没有在分组里 , 则无法向其发送短信 , 也无法加载他的信息 ( 解决方法 : 用移动的飞信登录后将其加入分组里 ).
(The way to contact: SYSU_短号:611449,QQ:464050924)
能实现的功能 :
1. 登录飞信 , 注销飞信 , 设置飞信登录状态 .
2. 加载好友列表 .
3. 得到好友列表的分组 .
4. 加载飞信群成员列表 .
5. 加载飞信好友图像 (Portrait).
6. 加载任意飞信号图像 (Portrait).
7. 发送即时信息 , 发送手机短信 .
8. 接收飞信好友信息 .
9. 添加飞信好友 .
(there will be more...)
If you get some funtions different and you can realize it.
I will be very happy if you can share with me through the
QQ,Email or other contact way.
具体实现 :
在引用里加入下面几个命名空间的引用 :
Using NullStudio.Fetion_SDK;
Using Imps.Core;
( 当然还可能有其他的命名空间 , 这里就不一一写出 )
几个重要的事件 ( 这些应该在全局作用域内 )
sdk.SDK_ReceiveMessage += new FetionSDK.SDK_ReceiveMessageEventHandler(sdk_SDK_ReceiveMessage);
sdk.SDK_UserSatusChange += new FetionSDK.SDK_UserSatusChangedEventHandler(sdk_SDK_UserSatusChange);
sdk.SDK_Error += new FetionSDK.SDK_ErrorEventHandler(sdk_SDK_Error);
声明一个全局范围内的变量 : Fetionsdk sdk ( 这是一个飞信控制的总类 , 作用于整个程序 )
功能 1( 登录飞信 , 注销飞信 , 设置飞信登录状态 ) :
//Fill 手机号及密码 .
sdk.AccountManager.FillUserIdandPassword(string id,string password,bool autoLoginOrout)
// 自动判断是登录还是注销
sdk.AccountManager.LoginOrout();
// 设置飞信登录状态 , 这里设置为在线
( 前提 : 飞信已经登录 , 可以在飞信登录状态为 Logon 时调用此方法 )
sdk.AccountManager.CurrentUser.Presence.AsyncChangeMainPresence(Imps.Common.MainPresence.Online,Imps.Common.MainPresence.Online.ToString());
功能 2( 加载好友列表 ):
sdk.ContactControl.getAllContactList(); // 返回一个类型为 contact 的列表 List<Imps.Core.contact>
功能 3( 加载好友分组 ):
List<ContactGroup> cotactGroups = sdk.ContactControl.getContactGroup();
// 可以在 contactGroup 中加载属于该组的好友列表
List<Contact> contacts = contactGroup.Contacts.ListContacts.
功能 4( 加载群成员列表 ):
GroupBase groupBase = new GroupBase(sdk);
List<PersonalGroup> personalGroups = groupBase.getPersonalGroupList();
// 下面的代码很重要 , 如若缺少 , 则 personalGroups 里只是一些基本信息 , 成员信息没有 .
foreach (PersonalGroup personalGroup in personalGroups)
{
AsyncBizOperation op = new AsyncBizOperation();
lock (op)
{
sdk.AccountManager.CurrentUser.PersonalGroupManager.GetGroupMemberList(group, op);
}
}
功能 5,6( 加载图像 ):
首先要得到一个有效的 Contact 实例
其次增加 Contact.ContactInfo. PropertiesChanged 事件
最后在事件代码里完成图片的下载
基本代码如下 :
IicUri uri = Uri.CreatUri(string MobileNo);
Contact contact = sdk.AccountManager.CurrentUser.ContactList.FindFindContactByMsisdnEx(uri.MobileNo);
If(contact==null)
{
AsyncBizOperation op = new AsyncBizOperation();
contact = sdk.AccountManager.CurrentUser.ContactList.FindOrCreateContact(uri.Raw, op);
}
// 添加事件
contact.PersonalInfo.PropertiesChanged += new EventHandler<PropertiesChangedEventArgs>(PersonalInfo_PropertiesChanged);
void PersonalInfo_PropertiesChanged(object sender, PropertiesChangedEventArgs e)
{
// 返回为 True 时表示图像下载完毕
if (!e.ContainsAnyOfProperties(new string[] { "nickname", "Provision", "Portrait" }))
{
pictureBox1.Image = ((ContactInfo)sender).Portrait;
}
}
功能 7( 发送消息 )
sdk.ContactControl.SendSMS.SendSMS(friendPhone, msg); // 发送手机短信
sdk.ContactControl.SendIM.SendIM(friendPhone, msg); // 进行即时通信
( 注 : 通过 contact.Presence.MainPresence 在属性值确定用户状态 , 如 :
Imps.Common.MainPresence.OfflineLogin,
Imps.Common.MainPresence.Offline);
功能 8 ( 接收好友信息 )
接收信息前需要添加事件 sdk.SDK_ReceiveMessage
然后在事件中接收消息
功能 9( 添加飞信好友 )
// 声明变量
bool isByMobileNo = false; // 是否以手机号码加飞信
string id = string.Empty; //userId
string domain = string.Empty; // 域
Nullable<int> targetGroupId = null; // 添加到哪一组中 ( 每个 contactGroup 能有一个 ID 属性 )
string localName = string.Empty; // 本地备注
ContactList.AddBuddyExtraData extraData = new ContactList.AddBuddyExtraData();
bool sendRequestAgain = false;
bool copyWhenExist = false;
Nullable<bool> invite = null;
AsyncBizOperation op = new AsyncBizOperation();
// 赋值
IicUri uri = IicUri.CreateTelUri(friendNo);
id = uri.MobileNo;
isByMobileNo = true;
domain = "fetion";
targetGroupId = targetId;
localName = “// 本地备注名 ”
extraData = new ContactList.AddBuddyExtraData();
extraData.WhoAmI = “// 我是谁 ?”
sendRequestAgain = true;
copyWhenExist = false;
invite = null;
// 执行加入好友
op.ImpsError += new EventHandler<ImpsErrorEventArgs>(op_ImpsError);
op.Successed += new EventHandler(op_Successed);
sdk.AccountManager.CurrentUser.ContactList.AsyncAddBuddy(isByMobileNo, id, domain, targetGroupId, localName, extraData, sendRequestAgain, copyWhenExist, invite, op);