zoukankan      html  css  js  c++  java
  • C# 调用腾讯即时通信 IM《转发》

    IM SDK API 概述 https://cloud.tencent.com/document/product/269/33543

            /// <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;
            }
            private delegate void delegateTIMRecvNewMsgCallback(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();
            }
  • 相关阅读:
    软件工程第四次作业-题目2
    oracle数据库本地网络服务名配置常见问题
    2020软件工程第三次作业
    2020软件工程第二次作业
    2020软件工程第一次作业
    20145208 蔡野 《网络攻防》 后门原理与实践
    20145208蔡野 《网络对抗》逆向及BOF基础实践
    密码分析学学习总结
    20145208 《信息安全系统设计基础》课程总结
    20145208 《信息安全系统设计基础》第十四周学习总结
  • 原文地址:https://www.cnblogs.com/yuanye0918/p/14652422.html
Copyright © 2011-2022 走看看