Exemple #1
0
 /// <summary>
 /// 发送私聊消息
 /// </summary>
 /// <param name="qqId">目标QQ</param>
 /// <param name="message">消息内容</param>
 /// <returns>失败返回负值, 成功返回消息 Id</returns>
 public int SendPrivateMessage(long qqId, string message)
 {
     GCHandle handle = message.GetStringGCHandle(_defaultEncoding);
     int msgId = CQP.CQ_sendPrivateMsg(_authCode, qqId, handle.AddrOfPinnedObject());
     handle.Free();
     return msgId;
 }
Exemple #2
0
        /// <summary>
        /// 发送私聊消息
        /// </summary>
        /// <param name="qqId">目标QQ</param>
        /// <param name="message">消息内容</param>
        /// <param name="anonymous">是否匿名</param>
        /// <param name="ignore">为 true 时,代表不强制使用匿名,如果匿名失败将转为普通消息发送。为 false 或 ignore 参数被忽略时,代表强制使用匿名,如果匿名失败将取消该消息的发送。</param>
        /// <returns>失败返回负值, 成功返回0</returns>
        public string SendPrivateMessage(long qqId, string message, bool anonymous = false, bool ignore = false)
        {
            if (anonymous)
            {
                if (ignore)
                {
                    message = "[CQ:anonymous,ignore=true]" + message;
                }
                else
                {
                    message = "[CQ:anonymous,ignore=false]" + message;
                }
            }
            GCHandle handle = message.GetStringGCHandle(_defaultEncoding);
            string   c      = CQP.CQ_sendPrivateMsg(_authCode, qqId, handle.AddrOfPinnedObject()).ToString(_defaultEncoding);

            handle.Free();
            return(c);
        }
Exemple #3
0
        /// <summary>
        /// 发送私聊消息
        /// </summary>
        /// <param name="qqId">目标QQ号码</param>
        /// <param name="message">用于发送消息对象数组. (获取字符串将优先调用 <see cref="IToSendString.ToSendString"/> 接口, 若不存在该接口则调用 <see cref="Object.ToString"/>)</param>
        /// <exception cref="ArgumentOutOfRangeException">参数: qqId 超出范围</exception>
        /// <exception cref="ArgumentNullException">参数: message 中有 null 元素</exception>
        /// <returns>描述已发送消息的 <see cref="QQMessage"/> 对象</returns>
        public QQMessage SendPrivateMessage(long qqId, params object[] message)
        {
            if (qqId < QQ.MinValue)
            {
                throw new ArgumentOutOfRangeException("qqId");
            }

            string   sendMsg   = message.ToSendString();
            GCHandle msgHandle = sendMsg.GetStringGCHandle(CQApi.DefaultEncoding);

            try
            {
                int msgId = CQP.CQ_sendPrivateMsg(this.AppInfo.AuthCode, qqId, msgHandle.AddrOfPinnedObject());
                return(new QQMessage(this, msgId, sendMsg, false));
            }
            finally
            {
                msgHandle.Free();
            }
        }
Exemple #4
0
 /// <summary>
 /// 发送私聊消息
 /// </summary>
 /// <param name="qqId">目标QQ</param>
 /// <param name="message">消息内容</param>
 /// <returns></returns>
 public int SendPrivateMessage(long qqId, string message)
 {
     return(CQP.CQ_sendPrivateMsg(_authCode, qqId, message.ToIntPtr(_defaultEncoding)));
 }
Exemple #5
0
 /// <summary>
 /// 发送私聊消息
 /// </summary>
 /// <param name="qqId">目标QQ</param>
 /// <param name="message">消息内容</param>
 /// <returns></returns>
 public int SendPrivateMessage(long qqId, string message)
 {
     return(CQP.CQ_sendPrivateMsg(_authCode, qqId, NativeConvert.ToStringPtr(message, Encoding.GetEncoding("GB18030"))));
 }