日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

飞信SDK内容【转载】

發布時間:2023/12/1 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 飞信SDK内容【转载】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用飛信SDK開發短信收發程序 2008-10-13 13:57
利用飛信的協議可以在線收發消息,或是向手機發送消息。由此,可以自己來完成一個IM工具。
本文即是對飛信SDK的使用方法,及如何開發作一個說明。

一、引用FetionSDK
飛信是采用C#開發的,所有的程序集均是.NET,因此我們也需要使用Delphi.NET/Chrome來進行相關的開發。在Chrome中,新建一個工程,并引入FetionSDK.dll,當然您也可以使用Delphi2007 for .NET,開發出來結果一樣。
其實我曾嘗試過把FetionSDK.dll變成一個COM+程序,但是不巧的是這個dll沒有strong name,無法轉換。
引用完SDK后,在主窗體的uses下添加NullStudio.Fetion_SDK。

二、準備工作
準備工作很簡單,在public區分符下,建立一個名為sdk的FetionSDK對象。然后為它創建一個實例。

三、用戶登錄
使用以下代碼來填入用戶名和密碼:
sdk.AccountManager.FillUserIdAndPassword(UserID,Password,true);
三個參數分別是用戶手機號,密碼,是否自動登錄,當選定了自動登錄為True時,可以使用
?????? sdk.AccountManager.LoginOrLogout();
來自動的判斷是登錄或是注銷,否則的話,就要使用
sdk.AccountManager.Login(); 來登錄。

四、狀態改變
用戶登錄或注銷,或是改變自己當前的狀態時,會觸發狀態改變的事件。如下:
procedure sdk_SDK_UserSatusChange(sender: Object; e:UserSatusChangedEventArgs);
其中參數e中來自命名空間Imps.Client.Core。
然后我們綁定這個事件:
sdk.SDK_UserSatusChange += new FetionSDK.SDK_UserSatusChangedEventHandler(sdk_SDK_UserSatusChange);
這樣SDK就能接收到狀態改變的事件了。另外,還能針對各個狀態,執行不同的指令,如下:
case e.NewStatus of
Imps.Client.UserAccountStatus.Disconnected: ;
Imps.Client.UserAccountStatus.Initialized: ;
Imps.Client.UserAccountStatus.Loginning: ;
Imps.Client.UserAccountStatus.Logon:
Imps.Client.UserAccountStatus.Logoff: ;
Imps.Client.UserAccountStatus.Logouting: ;
Imps.Client.UserAccountStatus.None: ;
Imps.Client.UserAccountStatus.OfflineLogon: ;
Imps.Client.UserAccountStatus.StandBy: ;
Imps.Client.UserAccountStatus.WaitReconnect: ;
else
end;

五、獲取好友列表
var
lst : List<Contact>;
i: Integer;
begin
lstFriendLst.Items.Clear();
lst := sdk.ContactControl.getAllContactList();
for i := 0 to lst.Count - 1 do
begin
lstFriendLst.Items.Add(
string.Format("{0} [Fetion: {1} Mobile: {2}]",
lst[i].DisplayName, lst[i].Uri.Id,
IfThen(lst[i].PersonalInfo.MobileNo = string.Empty, "Not Published", lst[i].PersonalInfo.MobileNo)));
end;

六、發送消息
調用SDK的發送消息指令,傳入的參數分別是對方手機號碼和短信的內容。
sdk.ContactControl.SendIM.SendIM(edtPhoneNo.Text, edtSendMsg.Text);

七、接收消息
接收到消息時,會解發SDK的收到消息事件,如下:
procedure sdk_SDK_ReceiveMessage(sender: Object; e:SDK_ReceiveMessageEventArgs);
實現此方法后,綁定這個事件。
sdk.SDK_ReceiveMessage += new FetionSDK.SDK_ReceiveMessageEventHandler(sdk_SDK_ReceiveMessage);

八、發送手機短信
與發送消息一樣,只不過使用的是另一個方法。
sdk.ContactControl.SendSMS.SendSMS(sdk.ContactControl.getMyself.Uri.Id,edtSendMsg.Text);
在這里需要注意SendIM與SendSMS的區別。
getMyself是SDK中的一個方法,用來獲取當前用戶的信息。

九、出錯事件
當SDK因為某種原因出錯后,會觸發出錯事件,如下:
procedure sdk_SDK_Error(sender: Object; e: SDK_ErrorEventArgs);
實現后綁定:
sdk.SDK_Error += new FetionSDK.SDK_ErrorEventHandler(sdk_SDK_Error);

十、編譯,執行程序
現在可以編譯并執行程序了。

十一、程序源碼

namespace FetionDemo;

interface

uses
System.Windows.Forms,
System.Drawing,
Imps.Client.Core,
NullStudio.Fetion_SDK,
NullStudio.Fetion_SDK.Event,
System.Collections.Generic;

type
/// <summary>
/// Summary description for MainForm.
/// </summary>
MainForm = class(System.Windows.Forms.Form)
{$REGION Windows Form Designer generated fields}
private
??? btnSendSelf: System.Windows.Forms.Button;
??? edtPhoneNo: System.Windows.Forms.TextBox;
??? btnSend: System.Windows.Forms.Button;
??? edtSendMsg: System.Windows.Forms.TextBox;
??? sbMain: System.Windows.Forms.StatusStrip;
??? lblPassword: System.Windows.Forms.Label;
??? lblAccount: System.Windows.Forms.Label;
??? edtMsg: System.Windows.Forms.TextBox;
??? lblPhoneNo: System.Windows.Forms.Label;
??? gbMsg: System.Windows.Forms.GroupBox;
??? lstFriendLst: System.Windows.Forms.ListBox;
??? gbFriendLst: System.Windows.Forms.GroupBox;
??? edtPassword: System.Windows.Forms.TextBox;
??? edtUserID: System.Windows.Forms.TextBox;
??? lblError: System.Windows.Forms.ToolStripStatusLabel;
??? btnLogoff: System.Windows.Forms.Button;
??? btnLogin: System.Windows.Forms.Button;
??? lblStatus: System.Windows.Forms.ToolStripStatusLabel;
??? gbLogin: System.Windows.Forms.GroupBox;
??? components: System.ComponentModel.Container := nil;
??? method InitializeComponent;
{$ENDREGION}
private
????? method btnSendSelf_Click(sender: System.Object; e: System.EventArgs);
????? method btnSend_Click(sender: System.Object; e: System.EventArgs);
????? method btnLogoff_Click(sender: System.Object; e: System.EventArgs);
????? method btnLogin_Click(sender: System.Object; e: System.EventArgs);
????? method MainForm_Load(sender: System.Object; e: System.EventArgs);
protected
??? method Dispose(aDisposing: boolean); override;
??? function IfThen(ABool: Boolean; AStr1, AStr2: String): String;
public
??? sdk : FetionSDK;
??? bLogon: Boolean;
??? procedure sdk_SDK_UserSatusChange(sender: Object; e:UserSatusChangedEventArgs);
??? procedure sdk_SDK_Error(sender: Object; e: SDK_ErrorEventArgs);
??? procedure sdk_SDK_ReceiveMessage(sender: Object; e:SDK_ReceiveMessageEventArgs);
??? constructor;
end;

implementation

{$REGION Construction and Disposition}
constructor MainForm;
begin
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
end;

method MainForm.Dispose(aDisposing: boolean);
begin
if aDisposing then begin
??? if assigned(components) then
????? components.Dispose();

??? //
??? // TODO: Add custom disposition code here
??? //
end;
inherited Dispose(aDisposing);
end;
{$ENDREGION}

{$REGION Windows Form Designer generated code}
method MainForm.InitializeComponent;
begin
var resources: System.ComponentModel.ComponentResourceManager := new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
self.sbMain := new System.Windows.Forms.StatusStrip();
self.lblStatus := new System.Windows.Forms.ToolStripStatusLabel();
self.lblError := new System.Windows.Forms.ToolStripStatusLabel();
self.gbMsg := new System.Windows.Forms.GroupBox();
self.lblPhoneNo := new System.Windows.Forms.Label();
self.edtSendMsg := new System.Windows.Forms.TextBox();
self.btnSend := new System.Windows.Forms.Button();
self.edtPhoneNo := new System.Windows.Forms.TextBox();
self.edtMsg := new System.Windows.Forms.TextBox();
self.btnLogin := new System.Windows.Forms.Button();
self.edtUserID := new System.Windows.Forms.TextBox();
self.edtPassword := new System.Windows.Forms.TextBox();
self.lblAccount := new System.Windows.Forms.Label();
self.lblPassword := new System.Windows.Forms.Label();
self.gbLogin := new System.Windows.Forms.GroupBox();
self.btnLogoff := new System.Windows.Forms.Button();
self.gbFriendLst := new System.Windows.Forms.GroupBox();
self.lstFriendLst := new System.Windows.Forms.ListBox();
self.btnSendSelf := new System.Windows.Forms.Button();
self.sbMain.SuspendLayout();
self.gbMsg.SuspendLayout();
self.gbLogin.SuspendLayout();
self.gbFriendLst.SuspendLayout();
self.SuspendLayout();
//
// sbMain
//
self.sbMain.Items.AddRange(array of System.Windows.Forms.ToolStripItem([self.lblStatus,
????? self.lblError]));
self.sbMain.Location := new System.Drawing.Point(0, 466);
self.sbMain.Name := 'sbMain';
self.sbMain.Size := new System.Drawing.Size(358, 22);
self.sbMain.TabIndex := 9;
self.sbMain.Text := 'statusStrip1';
//
// lblStatus
//
self.lblStatus.Name := 'lblStatus';
self.lblStatus.Size := new System.Drawing.Size(41, 17);
self.lblStatus.Text := 'Logoff';
//
// lblError
//
self.lblError.Name := 'lblError';
self.lblError.Size := new System.Drawing.Size(53, 17);
self.lblError.Text := 'No Error';
//
// gbMsg
//
self.gbMsg.Controls.Add(self.lblPhoneNo);
self.gbMsg.Controls.Add(self.edtSendMsg);
self.gbMsg.Controls.Add(self.btnSend);
self.gbMsg.Controls.Add(self.edtPhoneNo);
self.gbMsg.Controls.Add(self.edtMsg);
self.gbMsg.Location := new System.Drawing.Point(12, 198);
self.gbMsg.Name := 'gbMsg';
self.gbMsg.Size := new System.Drawing.Size(337, 231);
self.gbMsg.TabIndex := 8;
self.gbMsg.TabStop := false;
self.gbMsg.Text := 'Message';
//
// lblPhoneNo
//
self.lblPhoneNo.AutoSize := true;
self.lblPhoneNo.Location := new System.Drawing.Point(11, 174);
self.lblPhoneNo.Name := 'lblPhoneNo';
self.lblPhoneNo.Size := new System.Drawing.Size(53, 12);
self.lblPhoneNo.TabIndex := 6;
self.lblPhoneNo.Text := 'Phone No';
//
// edtSendMsg
//
self.edtSendMsg.Location := new System.Drawing.Point(7, 198);
self.edtSendMsg.Name := 'edtSendMsg';
self.edtSendMsg.Size := new System.Drawing.Size(249, 21);
self.edtSendMsg.TabIndex := 5;
//
// btnSend
//
self.btnSend.Location := new System.Drawing.Point(262, 196);
self.btnSend.Name := 'btnSend';
self.btnSend.Size := new System.Drawing.Size(69, 23);
self.btnSend.TabIndex := 4;
self.btnSend.Text := 'Send';
self.btnSend.UseVisualStyleBackColor := true;
self.btnSend.Click += new System.EventHandler(@self.btnSend_Click);
//
// edtPhoneNo
//
self.edtPhoneNo.Location := new System.Drawing.Point(68, 171);
self.edtPhoneNo.Name := 'edtPhoneNo';
self.edtPhoneNo.Size := new System.Drawing.Size(145, 21);
self.edtPhoneNo.TabIndex := 3;
//
// edtMsg
//
self.edtMsg.Location := new System.Drawing.Point(5, 20);
self.edtMsg.Multiline := true;
self.edtMsg.Name := 'edtMsg';
self.edtMsg.ReadOnly := true;
self.edtMsg.ScrollBars := System.Windows.Forms.ScrollBars.Vertical;
self.edtMsg.Size := new System.Drawing.Size(326, 145);
self.edtMsg.TabIndex := 1;
//
// btnLogin
//
self.btnLogin.Location := new System.Drawing.Point(274, 12);
self.btnLogin.Name := 'btnLogin';
self.btnLogin.Size := new System.Drawing.Size(75, 23);
self.btnLogin.TabIndex := 6;
self.btnLogin.Text := 'Login';
self.btnLogin.UseVisualStyleBackColor := true;
self.btnLogin.Click += new System.EventHandler(@self.btnLogin_Click);
//
// edtUserID
//
self.edtUserID.Location := new System.Drawing.Point(69, 17);
self.edtUserID.Name := 'edtUserID';
self.edtUserID.Size := new System.Drawing.Size(180, 21);
self.edtUserID.TabIndex := 3;
//
// edtPassword
//
self.edtPassword.Location := new System.Drawing.Point(69, 44);
self.edtPassword.Name := 'edtPassword';
self.edtPassword.PasswordChar := '*';
self.edtPassword.Size := new System.Drawing.Size(180, 21);
self.edtPassword.TabIndex := 4;
//
// lblAccount
//
self.lblAccount.AutoSize := true;
self.lblAccount.Location := new System.Drawing.Point(6, 20);
self.lblAccount.Name := 'lblAccount';
self.lblAccount.Size := new System.Drawing.Size(47, 12);
self.lblAccount.TabIndex := 1;
self.lblAccount.Text := 'Accoumt';
//
// lblPassword
//
self.lblPassword.AutoSize := true;
self.lblPassword.Location := new System.Drawing.Point(6, 47);
self.lblPassword.Name := 'lblPassword';
self.lblPassword.Size := new System.Drawing.Size(53, 12);
self.lblPassword.TabIndex := 2;
self.lblPassword.Text := 'Password';
//
// gbLogin
//
self.gbLogin.Controls.Add(self.edtPassword);
self.gbLogin.Controls.Add(self.edtUserID);
self.gbLogin.Controls.Add(self.lblAccount);
self.gbLogin.Controls.Add(self.lblPassword);
self.gbLogin.Location := new System.Drawing.Point(11, 6);
self.gbLogin.Name := 'gbLogin';
self.gbLogin.Size := new System.Drawing.Size(255, 80);
self.gbLogin.TabIndex := 7;
self.gbLogin.TabStop := false;
self.gbLogin.Text := 'Login';
//
// btnLogoff
//
self.btnLogoff.Location := new System.Drawing.Point(274, 41);
self.btnLogoff.Name := 'btnLogoff';
self.btnLogoff.Size := new System.Drawing.Size(75, 23);
self.btnLogoff.TabIndex := 10;
self.btnLogoff.Text := 'Logoff';
self.btnLogoff.UseVisualStyleBackColor := true;
self.btnLogoff.Click += new System.EventHandler(@self.btnLogoff_Click);
//
// gbFriendLst
//
self.gbFriendLst.Controls.Add(self.lstFriendLst);
self.gbFriendLst.Location := new System.Drawing.Point(11, 92);
self.gbFriendLst.Name := 'gbFriendLst';
self.gbFriendLst.Size := new System.Drawing.Size(338, 100);
self.gbFriendLst.TabIndex := 11;
self.gbFriendLst.TabStop := false;
self.gbFriendLst.Text := 'Friend List';
//
// lstFriendLst
//
self.lstFriendLst.FormattingEnabled := true;
self.lstFriendLst.ItemHeight := 12;
self.lstFriendLst.Location := new System.Drawing.Point(8, 18);
self.lstFriendLst.Name := 'lstFriendLst';
self.lstFriendLst.Size := new System.Drawing.Size(324, 76);
self.lstFriendLst.TabIndex := 0;
//
// btnSendSelf
//
self.btnSendSelf.Location := new System.Drawing.Point(243, 435);
self.btnSendSelf.Name := 'btnSendSelf';
self.btnSendSelf.Size := new System.Drawing.Size(106, 23);
self.btnSendSelf.TabIndex := 12;
self.btnSendSelf.Text := 'Send To Self';
self.btnSendSelf.UseVisualStyleBackColor := true;
self.btnSendSelf.Click += new System.EventHandler(@self.btnSendSelf_Click);
//
// MainForm
//
self.ClientSize := new System.Drawing.Size(358, 488);
self.Controls.Add(self.btnSendSelf);
self.Controls.Add(self.gbFriendLst);
self.Controls.Add(self.btnLogoff);
self.Controls.Add(self.sbMain);
self.Controls.Add(self.gbMsg);
self.Controls.Add(self.btnLogin);
self.Controls.Add(self.gbLogin);
self.Icon := (resources.GetObject('$this.Icon') as System.Drawing.Icon);
self.Name := 'MainForm';
self.Text := 'Fetion';
self.Load += new System.EventHandler(@self.MainForm_Load);
self.sbMain.ResumeLayout(false);
self.sbMain.PerformLayout();
self.gbMsg.ResumeLayout(false);
self.gbMsg.PerformLayout();
self.gbLogin.ResumeLayout(false);
self.gbLogin.PerformLayout();
self.gbFriendLst.ResumeLayout(false);
self.ResumeLayout(false);
self.PerformLayout();
end;
{$ENDREGION}

method MainForm.MainForm_Load(sender: System.Object; e: System.EventArgs);
begin
sdk := new FetionSDK;
bLogon := false;
sdk.SDK_UserSatusChange += new FetionSDK.SDK_UserSatusChangedEventHandler(sdk_SDK_UserSatusChange);
sdk.SDK_ReceiveMessage += new FetionSDK.SDK_ReceiveMessageEventHandler(sdk_SDK_ReceiveMessage);
sdk.SDK_Error += new FetionSDK.SDK_ErrorEventHandler(sdk_SDK_Error);
end;


procedure MainForm.sdk_SDK_UserSatusChange(sender: Object; e:UserSatusChangedEventArgs);
var
??? currStat: string;
??? i: Integer;
??? lst : List<Contact>;
begin
??? currStat := e.NewStatus.ToString();
??? lblStatus.Text := currStat;
???

??? case e.NewStatus of
??????? Imps.Client.UserAccountStatus.Logon:
??????? begin
??????????? bLogon := true;
??????????? lstFriendLst.Items.Clear();
??????????? lst := sdk.ContactControl.getAllContactList();
??????????? for i := 0 to lst.Count - 1 do
??????????? begin
??????????????? lstFriendLst.Items.Add(
??????????????????? string.Format("{0} [Fetion: {1} Mobile: {2}]",
??????????????????? lst[i].DisplayName, lst[i].Uri.Id,
??????????????????? IfThen(lst[i].PersonalInfo.MobileNo = string.Empty, "Not Published", lst[i].PersonalInfo.MobileNo)));
??????????? end;
??????? end;
??? else
??????? begin
??????????? bLogon := false;
??????????? lstFriendLst.Items.Clear();
??????? end;
??? {
??????? Imps.Client.UserAccountStatus.Disconnected: ;
??????? Imps.Client.UserAccountStatus.Initialized: ;
??????? Imps.Client.UserAccountStatus.Loginning: ;
???????
??????? Imps.Client.UserAccountStatus.Logoff: ;
??????? Imps.Client.UserAccountStatus.Logouting: ;
??????? Imps.Client.UserAccountStatus.None: ;
??????? Imps.Client.UserAccountStatus.OfflineLogon: ;
??????? Imps.Client.UserAccountStatus.StandBy: ;
??????? Imps.Client.UserAccountStatus.WaitReconnect: ;
??? }
??? end;
???
end;

method MainForm.btnLogin_Click(sender: System.Object; e: System.EventArgs);
begin
??? if not bLogon then
??? begin
??????? sdk.AccountManager.FillUserIdAndPassword(edtUserID.Text,edtPassword.Text,false);
??????? sdk.AccountManager.LoginOrLogout();
??? end;
end;

procedure MainForm.sdk_SDK_Error(sender: Object; e: SDK_ErrorEventArgs);
begin
??? lblError.Text := e.Message.Message;
end;

method MainForm.btnLogoff_Click(sender: System.Object; e: System.EventArgs);
begin
??? if bLogon then
?????? sdk.AccountManager.LoginOrLogout();
end;

function MainForm.IfThen(ABool: Boolean; AStr1, AStr2: String): String;
begin
??? if ABool then
??????? result := AStr1
??? else
??????? result := AStr2;
end;

method MainForm.btnSend_Click(sender: System.Object; e: System.EventArgs);
begin
??? sdk.ContactControl.SendIM.SendIM(edtPhoneNo.Text, edtSendMsg.Text);
??? edtMsg.Text := edtMsg.Text + 'Self: ' + edtSendMsg.Text + '\r\n';???
end;

procedure MainForm.sdk_SDK_ReceiveMessage(sender: Object; e:SDK_ReceiveMessageEventArgs);
begin
??? edtMsg.Text := edtMsg.Text + e.Contact.DisplayName + ': '+e.Message;
end;

method MainForm.btnSendSelf_Click(sender: System.Object; e: System.EventArgs);
begin
??? sdk.ContactControl.SendSMS.SendSMS(sdk.ContactControl.getMyself.Uri.Id,edtSendMsg.Text);
end;

end.

轉載于:https://www.cnblogs.com/ddlzq/archive/2009/10/24/1589271.html

總結

以上是生活随笔為你收集整理的飞信SDK内容【转载】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。