91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

使用C#如何實現調用騰訊即時通信功能

發布時間:2020-11-23 16:13:17 來源:億速云 閱讀:273 作者:Leah 欄目:開發技術

本篇文章為大家展示了使用C#如何實現調用騰訊即時通信功能,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。

IM SDK API 

/// <summary>
    /// IM SDK 初始化。
    /// </summary>
    /// <param name="sdk_app_id"></param>
    /// <param name="json_sdk_config"></param>
    /// <returns></returns>
    [DllImport(@"imsdk.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
    public extern static int TIMInit(long sdk_app_id, string json_sdk_config);
/// <summary>
    /// 登錄
    /// </summary>
    /// <param name="user_id">用戶id</param>
    /// <param name="user_sig">簽名</param>
    /// <param name="cb"></param>
    /// <returns></returns>
    [DllImport(@"imsdk.dll", CallingConvention = CallingConvention.Cdecl)]
    private extern static int TIMLogin(string user_id, string user_sig, TIMCommCallback cb);
/// <summary>
    /// 接收新消息回調
    /// </summary>
    /// <param name="cb"></param>
    [DllImport(@"imsdk.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
    private extern static void TIMAddRecvNewMsgCallback(delegateTIMRecvNewMsgCallback cb);
public void ImInit()
    {
      int sdk_app_id = 1400000000;
      var data = new { sdk_config_log_file_path = AppDomain.CurrentDomain.BaseDirectory, sdk_config_config_file_path = AppDomain.CurrentDomain.BaseDirectory };
      TIMInit(sdk_app_id, JsonConvert.SerializeObject(data));
      TIMAddRecvNewMsgCallback(TIMRecvNewMsgCallback);
      var tLSSig = new TLSSigAPIv2(sdk_app_id, "163250645178b565ffc0b22618d14a88d8a91d86f0e76813313197a5xxxxxxx");
      TIMLogin("用戶", tLSSig.GenSig("用戶"), CommCallback);

    }
    private delegate int TIMCommCallback(int code, string desc, string json_params);
    
    private int CommCallback(int code, string desc, string json_params)
    {
      return code;
    }
    public delegate void delegateTIMRecvNewMsgCallback([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string json_msg_array, IntPtr user_data);;
    private void TIMRecvNewMsgCallback(string json_msg_array, IntPtr user_data) {
      var b = Encoding.Default.GetBytes(json_msg_array);
      richTextBox1.AppendText(Encoding.UTF8.GetString(b));
    }
    private void Form1_Load(object sender, EventArgs e)
    {
     ImInit();
    }
public class Utf8Marshaler : ICustomMarshaler
    {
        public void CleanUpManagedData(object managedObj)
        {
        }
 
        public void CleanUpNativeData(IntPtr pNativeData)
        {
            Marshal.FreeHGlobal(pNativeData);
        }
 
        public int GetNativeDataSize()
        {
            return -1;
        }
 
        public IntPtr MarshalManagedToNative(object managedObj)
        {
            if (object.ReferenceEquals(managedObj, null))
                return IntPtr.Zero;
            if (!(managedObj is string))
                throw new InvalidOperationException();
 
            byte[] utf8Bytes = Encoding.UTF8.GetBytes((string)managedObj);
            IntPtr ptr = Marshal.AllocHGlobal(utf8Bytes.Length + 1);
            Marshal.Copy(utf8Bytes, 0, ptr, utf8Bytes.Length);
            Marshal.WriteByte(ptr, utf8Bytes.Length, 0);
            return ptr;
        }
 
        public object MarshalNativeToManaged(IntPtr pNativeData)
        {
            if (pNativeData == IntPtr.Zero)
                return null;
 
            List<byte> bytes = new List<byte>();
            for (int offset = 0; ; offset++)
            {
                byte b = Marshal.ReadByte(pNativeData, offset);
                if (b == 0)
                    break;
                else
                    bytes.Add(b);
            }
            return Encoding.UTF8.GetString(bytes.ToArray(), 0, bytes.Count);
        }
 
        private static readonly Utf8Marshaler Instance = new Utf8Marshaler();
        public static ICustomMarshaler GetInstance(string cookie)
        {
            return Instance;
        }
    }

上述內容就是使用C#如何實現調用騰訊即時通信功能,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

富阳市| 桃园县| 镇赉县| 连州市| 台中市| 石阡县| 巩义市| 全椒县| 巴塘县| 巍山| 开封县| 普格县| 宁安市| 祁阳县| 乌兰县| 武川县| 上饶县| 汶上县| 鹤山市| 绥德县| 类乌齐县| 航空| 留坝县| 保山市| 安阳县| 固始县| 长子县| 小金县| 固镇县| 博野县| 雷山县| 呼和浩特市| 府谷县| 孟州市| 富川| 福清市| 紫阳县| 蛟河市| 曲松县| 武陟县| 平塘县|