Skip to content
This repository has been archived by the owner on Aug 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #103 from Jie2GG/Test
Browse files Browse the repository at this point in the history
同步官方SDK接口及事件
  • Loading branch information
Jie2GG authored Oct 14, 2019
2 parents 6e52cac + 5fd0a69 commit 094d726
Show file tree
Hide file tree
Showing 17 changed files with 573 additions and 202 deletions.
17 changes: 15 additions & 2 deletions Native.Csharp.Sdk/Cqp/Core/CQP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ internal static class CQP
*
* V9 应用机制内的变动(即 V9.x 内的变动)通常**不会**影响已发布的应用,但有可能需要开发者在更新旧版本应用时,对代码进行细微调整。
*
* V9.25 (2019-10-8)
* -----------------
* 新增 取群信息 Api
* * 支持获取群当前人数与人数上限。如果您此前使用其他方式获取,建议迁移至本接口。
*
* 新增 群禁言事件
*
* V9.23 (2019-9-3)
* ----------------
* 新增 扩展 Cookies 适用范围
Expand Down Expand Up @@ -142,6 +149,12 @@ internal static class CQP

[DllImport (DllName, EntryPoint = "CQ_getImage")]
public static extern string CQ_getImage (int authCode, string file);
#endregion
}

[DllImport(DllName, EntryPoint = "CQ_getGroupInfo")]
public static extern string CQ_getGroupInfo(int authCode, long groupId, bool notCache);

[DllImport (DllName, EntryPoint = "CQ_getFriendList")]
public static extern string CQ_getFriendList (int authCode, bool reserved);
#endregion
}
}
85 changes: 83 additions & 2 deletions Native.Csharp.Sdk/Cqp/CqApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ public List<GroupMemberInfo> GetMemberList (long groupId)
/// <summary>
/// 获取发送语音支持
/// </summary>
/// <returns></returns>
/// <returns>获取成功则返回 <code>true</code>, 否则返回 <code>false</code></returns>
public bool GetSendRecordSupport ()
{
return CQP.CQ_canSendRecord (_authCode) > 0;
Expand All @@ -604,11 +604,92 @@ public bool GetSendRecordSupport ()
/// <summary>
/// 获取发送图片支持
/// </summary>
/// <returns></returns>
/// <returns>获取成功则返回 <code>true</code>, 否则返回 <code>false</code></returns>
public bool GetSendImageSupport ()
{
return CQP.CQ_canSendImage (_authCode) > 0;
}

/// <summary>
/// 获取群信息
/// </summary>
/// <param name="groupId">群号码</param>
/// <param name="notCache">不使用缓存, 通常为 <code>false</code>, 仅在必要时使用</param>
/// <returns>如果成功返回 <see cref="GroupInfo"/>, 若失败返回 null</returns>
public GroupInfo GetGroupInfo (long groupId, bool notCache = false)
{
string result = CQP.CQ_getGroupInfo (_authCode, groupId, false);
if (string.IsNullOrEmpty (result))
{
return null;
}
#region --其他_转换_文本到群信息--
using (BinaryReader reader = new BinaryReader (new MemoryStream (Convert.FromBase64String (result))))
{
if (reader.Length () < 18)
{
return null;
}

GroupInfo info = new GroupInfo ();
info.Id = reader.ReadInt64_Ex ();
info.Name = reader.ReadString_Ex (_defaultEncoding);
info.CurrentNumber = reader.ReadInt32_Ex ();
info.MaximumNumber = reader.ReadInt32_Ex ();
return info;
}
#endregion
}

/// <summary>
/// 获取好友列表
/// </summary>
/// <returns>获取成功返回 <see cref="List{FriendInfo}"/>, 否则返回 null</returns>
public List<FriendInfo> GetFriendList ()
{
string result = CQP.CQ_getFriendList (_authCode, false);
if (string.IsNullOrEmpty (result))
{
return null;
}

#region --其他_转换_文本到好友列表信息a--
using (BinaryReader reader = new BinaryReader (new MemoryStream (Convert.FromBase64String (result))))
{
if (reader.Length () < 4)
{
return null;
}

List<FriendInfo> friends = new List<FriendInfo> ();
for (int i = 0, len = reader.ReadInt32_Ex (); i < len; i++)
{
FriendInfo temp = new FriendInfo ();
if (reader.Length () <= 0)
{
return null;
}

#region --其他_转换_ansihex到好友信息--
using (BinaryReader tempReader = new BinaryReader (new MemoryStream (reader.ReadToken_Ex ())))
{
if (tempReader.Length () < 12)
{
return null;
}

temp.Id = tempReader.ReadInt64_Ex ();
temp.Nick = tempReader.ReadString_Ex (_defaultEncoding);
temp.Note = tempReader.ReadString_Ex (_defaultEncoding);
}
#endregion

friends.Add (temp);
}
return friends;
}
#endregion
}
#endregion

#region --日志--
Expand Down
70 changes: 70 additions & 0 deletions Native.Csharp.Sdk/Cqp/EventArgs/CqGroupBanEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Native.Csharp.Sdk.Cqp.EventArgs
{
/// <summary>
/// 表示群禁言事件参数的类
/// </summary>
public class CqGroupBanEventArgs : CqEventArgsBase
{
/// <summary>
/// 表示当前事件的类型
/// </summary>
public override int Type { get { return 104; } }

/// <summary>
/// 获取当前事件触发时间
/// </summary>
public DateTime SendTime { get; private set; }

/// <summary>
/// 获取当前消息的来源群组号
/// </summary>
public long FromGroup { get; private set; }

/// <summary>
/// 操作者QQ
/// </summary>
public long FromQQ { get; private set; }

/// <summary>
/// 获取当前事件触发时的目标QQ
/// </summary>
public long BeingOperateQQ { get; private set; }

/// <summary>
/// 禁言时长
/// </summary>
public TimeSpan Duration { get; private set; }

/// <summary>
/// 获取或设置一个值, 指示当前是否处理过此事件. 若此值为 True 将停止处理后续事件
/// </summary>
public bool Handler { get; set; }

/// <summary>
/// 初始化 <see cref="CqGroupBanEventArgs"/> 类的新实例
/// </summary>
/// <param name="id"></param>
/// <param name="name"></param>
/// <param name="sendTime"></param>
/// <param name="fromGroup"></param>
/// <param name="fromQQ"></param>
/// <param name="beingOperateQQ"></param>
/// <param name="duration"></param>
public CqGroupBanEventArgs (int id, string name, DateTime sendTime, long fromGroup, long fromQQ, long beingOperateQQ, TimeSpan duration)
{
this.Id = id;
this.Name = name;
this.SendTime = sendTime;
this.FromGroup = fromGroup;
this.FromQQ = fromQQ;
this.BeingOperateQQ = beingOperateQQ;
this.Duration = duration;
}
}
}
22 changes: 22 additions & 0 deletions Native.Csharp.Sdk/Cqp/Interface/IReceiveRemoveGroupBan.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Native.Csharp.Sdk.Cqp.EventArgs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Native.Csharp.Sdk.Cqp.Interface
{
/// <summary>
/// Type=104 群解除禁言事件接口
/// </summary>
public interface IReceiveRemoveGroupBan
{
/// <summary>
/// 当在派生类中重写时, 处理收到的群解除禁言
/// </summary>
/// <param name="sender">事件的触发对象</param>
/// <param name="e">事件的附加参数</param>
void ReceiveRemoveGroupBan (object sender, CqGroupBanEventArgs e);
}
}
22 changes: 22 additions & 0 deletions Native.Csharp.Sdk/Cqp/Interface/IReceiveSetGroupBan.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Native.Csharp.Sdk.Cqp.EventArgs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Native.Csharp.Sdk.Cqp.Interface
{
/// <summary>
/// Type=104 群禁言事件接口
/// </summary>
public interface IReceiveSetGroupBan
{
/// <summary>
/// 当在派生类中重写时, 处理收到的群禁言
/// </summary>
/// <param name="sender">事件的触发对象</param>
/// <param name="e">事件的附加参数</param>
void ReceiveSetGroupBan (object sender, CqGroupBanEventArgs e);
}
}
29 changes: 29 additions & 0 deletions Native.Csharp.Sdk/Cqp/Model/FriendInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Native.Csharp.Sdk.Cqp.Model
{
/// <summary>
/// 描述 QQ 好友信息的类
/// </summary>
public class FriendInfo
{
/// <summary>
/// QQ帐号
/// </summary>
public long Id { get; set; }

/// <summary>
/// QQ昵称
/// </summary>
public string Nick { get; set; }

/// <summary>
/// 备注信息
/// </summary>
public string Note { get; set; }
}
}
10 changes: 9 additions & 1 deletion Native.Csharp.Sdk/Cqp/Model/GroupInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,13 @@ public class GroupInfo
/// 群名字
/// </summary>
public string Name { get; set; }
}
/// <summary>
/// 当前成员数量, 由 <see cref="CqApi.GetGroupInfo"/> 方法获取
/// </summary>
public int CurrentNumber { get; set; }
/// <summary>
/// 获取最大成员数量, 由 <see cref="CqApi.GetGroupInfo"/> 方法获取
/// </summary>
public int MaximumNumber { get; set; }
}
}
4 changes: 4 additions & 0 deletions Native.Csharp.Sdk/Native.Csharp.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<Compile Include="Cqp\EventArgs\CqEventArgsBase.cs" />
<Compile Include="Cqp\EventArgs\CqExitEventArgs.cs" />
<Compile Include="Cqp\EventArgs\CqFriendIncreaseEventArgs.cs" />
<Compile Include="Cqp\EventArgs\CqGroupBanEventArgs.cs" />
<Compile Include="Cqp\EventArgs\CqGroupFileUploadEventArgs.cs" />
<Compile Include="Cqp\EventArgs\CqGroupManageChangeEventArgs.cs" />
<Compile Include="Cqp\EventArgs\CqGroupMemberDecreaseEventArgs.cs" />
Expand Down Expand Up @@ -100,8 +101,11 @@
<Compile Include="Cqp\Interface\IReceiveGroupMessage.cs" />
<Compile Include="Cqp\Interface\IReceiveGroupPrivateMessage.cs" />
<Compile Include="Cqp\Interface\IReceiveOnlineStatusMessage.cs" />
<Compile Include="Cqp\Interface\IReceiveRemoveGroupBan.cs" />
<Compile Include="Cqp\Interface\IReceiveSetGroupBan.cs" />
<Compile Include="Cqp\Model\CqCode.cs" />
<Compile Include="Cqp\Model\FloatWindow.cs" />
<Compile Include="Cqp\Model\FriendInfo.cs" />
<Compile Include="Cqp\Model\GroupAnonymous.cs" />
<Compile Include="Cqp\Model\GroupFile.cs" />
<Compile Include="Cqp\Model\GroupInfo.cs" />
Expand Down
4 changes: 2 additions & 2 deletions Native.Csharp.Sdk/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion ("2.5.1.0906")]
[assembly: AssemblyFileVersion ("2.5.1.0906")]
[assembly: AssemblyVersion ("2.6.0.1013")]
[assembly: AssemblyFileVersion ("2.6.0.1013")]
Loading

0 comments on commit 094d726

Please sign in to comment.