using Chat.Framework.PCRobotSDK;
using Chat.Framework.WXSdk.Events;
using Chat.Framework.WXSdk.IPAD;
using Google.Protobuf;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WechatProto;
namespace Chat.Framework.WXSdk.Implement
{
///
/// 朋友圈评论类型
///
public enum CircleCommentType : int
{
评论 = 2,
点赞 = 1
}
///
/// 微信类型
///
public enum WeixinType
{
Grpc微信 = 1,
Hook微信 = 2,
QYHook微信 = 3
}
///
/// 协议类型
///
public enum LoginDeviceType : int
{
未知 = 0,
Ipad = 1,
Mac = 3,
Windows = 5,
QQBrowser = 7
}
///
/// 协议操作类型
///
public enum EditContactsType
{
保存通讯录 = 2051,
取消保存通讯录 = 2,
星标 = 71,
取消星标 = 7,
备注 = 7,
拉黑 = 15,
取消拉黑 = 7,
置顶 = 2055,
取消置顶 = 7
}
///
/// 标签
///
public class Lable
{
///
/// 标签名称
///
public string LabelName { get; set; }
///
/// 标签ID
///
public string LabelID { get; set; }
}
///
/// 微信基础用户
///
public class WeixinBaseUser
{
///
/// 机器人登录时间
///
public DateTime LoginTime { get; private set; }
private long _uin;
private string _nick;
private string _username;
///
/// Uin
///
public long Uin
{
get
{
if (this.User != null) return this.User.Uin;
else return _uin;
}
}
///
/// 机器人昵称
///
public string Nick
{
get
{
if (this.User != null) return Encoding.UTF8.GetString(this.User.Nickname.ToArray());
else return _nick;
}
}
///
/// 机器人微信id
///
public string Username
{
get
{
if (this.User != null) return this.User.Userame;
else return _username;
}
}
public string Data
{
get
{
var _data = this.User.ToByteArray();
return Util.HexToStr(_data);
}
}
internal User User { get; set; }
public WeixinBaseUser()
{
this.LoginTime = DateTime.Now;
}
public WeixinBaseUser(User user)
{
this.User = user;
this.LoginTime = DateTime.Now;
}
public WeixinBaseUser(string data)
{
var temp = Util.StrToHex(data);
this.User = new User();
this.User.MergeFrom(temp);
this.LoginTime = DateTime.Now;
}
public WeixinBaseUser(string username, string nick, long uin = -1)
{
this._username = username;
this._uin = uin;
this._nick = nick;
}
}
///
/// 微信基类
///
public class WeixinBase : IDisposable
{
///
/// 好友列表
///
public Dictionary Friends { get; internal set; }
///
/// 用户
///
public WeixinBaseUser User { get; set; }
///
/// 微信类型
///
public WeixinType WeixinType { get; set; }
///
/// 微信号
///
public string WeixinHao { get; internal set; }
///
/// 启动微信
///
public virtual void ShowLogin() { }
///
/// 退出微信
///
public virtual void LoginOut() { }
///
/// 退出微信
///
/// 退出说明
public virtual void LoginOut(string message) { }
///
/// 微信状态
///
public WxStatus Status { get; set; }
///
/// 微信状态改变
///
/// 状态
/// 微信修改状态事件,可为空
/// 无用
public virtual void ChangeStatus(WxStatus status, WXChangeStatus e = null, bool is_next = true)
{
if (this.Status == status) return;
this.Status = status;
if (e == null)
{
ChatClient.Events.OnEvent(new WXChangeStatus(this));
}
else
{
e.Status = status;
ChatClient.Events.OnEvent(e);
}
if (this.Status == WxStatus.在线)
{
LogHelper.GetSingleObj().Debug("", $"微信状态改变:{this.User.Nick}({this.WeixinHao})");
ChatClient.UpdateWXClient(this);
}
}
///
/// 重新连接微信
///
/// 连接数次
public virtual void ResetConnection(int next = 3) { }
///
/// 获得联系人信息
///
/// 用户账号
/// 时候刷新
///
public virtual Friend GetContact(string wxid, bool refresh = false) { return null; }
///
/// 发送消息
///
/// 接收者账号
/// 发送的消息
/// 艾特用户
public virtual Task SendMessage(string username, string message, string atUsername = "") { return null; }
///
/// 发送小程序
///
/// 发送给谁
/// 小程序ID
/// 所有者wxid
/// 小程序名称
/// 小程序分享的标题
/// 入口点
/// 小程序图标
/// 缩略图key1
/// 缩略图key2
/// 缩略图key3
/// 缩略图大小
public virtual void SendProgramMessage(string username, string ghid, string wxid, string name, string title, string enterpoint, string headimg, string image_key1, string image_key2, string image_key3, string image_size) { throw new Exception("本协议暂时不支持该方法"); }
///
/// 刷新通讯录信息(获取好友列表)
///
public virtual void RefreshContact(Action method = null) { }
///
/// 同意添加我为好友
///
/// 收到添加好友信息token信息
///
public virtual string AgreeAddMe(string token) { return string.Empty; }
///
/// 发送图片
///
/// 图片byte[]
/// 接收者账号
public virtual void SendImage(byte[] img, string username) { throw new Exception("本协议暂时不支持该方法"); }
///
/// 分析事件
///
///
public virtual void Receive(object obj) { throw new Exception("本协议暂时不支持该方法"); }
///
/// 发送卡片消息
///
/// 接收者账号
/// 卡片用户账号
public virtual void SendCard(string username, string friendwxid) { throw new Exception("本协议暂时不支持该方法"); }
///
/// 获取群成员,不支持pc
///
/// 群id
/// 是否刷新
///
public virtual GroupMember[] GetMembers(string groupid, bool flag = false) { throw new Exception("本协议暂时不支持该方法"); }
///
/// 获取群用户信息
///
/// 群
/// 用户账号
///
public virtual GroupMember GetMember(string groupid, string wxid) { throw new Exception("本协议暂时不支持该方法"); }
///
/// 获取群用户信息带刷新
///
/// 群
/// 用户账号
/// 刷新
///
public virtual GroupMember GetMember(string groupid, string wxid, bool flush = false) { throw new Exception("本协议暂时不支持该方法"); }
///
/// 发送图片
///
/// 接收者账号
/// 图片地址
public virtual void SendImage(string username, string address) { throw new Exception("本协议暂时不支持该方法"); }
///
/// 搜索关键词
///
/// 关键词
///
public virtual Dictionary SerchKeyword(string keyword) { throw new Exception("本协议暂时不支持该方法"); }
///
/// 关注公众号
///
/// 公众号账号
///
public virtual bool FocusWechat(string username) { throw new Exception("本协议暂时不支持该方法"); }
///
/// 发送语音
///
/// 接收者账号
/// 连接
public virtual void SendVoice(string username, string url) { throw new Exception("本协议暂时不支持该方法"); }
///
/// 获得联系人二维码
///
/// 刷新
///
public virtual Bitmap GetRobotQRcode(bool Refresh = false) { return null; }
///
/// 验证支付
///
/// code
/// isHongbao
/// reqKey
/// bank
/// token
/// pass
///
public virtual void SnsVerify(string code, bool isHongbao, string reqKey, BankCar bank, string token, string pass) { throw new Exception("本协议暂时不支持该方法"); }
///
/// 下载图片
///
/// 消息id
/// 账号
/// 长度
///
public virtual string DownlowdImage(int msgid, string fromUsername, int datatotalength) { return string.Empty; }
///
/// 秒发CDN消息
///
/// 接收者账号
/// cdnurl
/// aeskey
/// type
public virtual void SendCDNInfo(string tousername, string cdnurl, string aeskey, CDNType type) { }
///
/// 发送CDN图片
///
/// 接收者账号
/// 图片cdn
public virtual void SendCDNImage(string tousername, string data) { }
///
/// 发送CDN视频
///
/// 接收者账号
/// cdnurl
/// aeskey
public virtual void SendCDNVideo(string tousername, string cdnurl, string aeskey) { }
///
/// 发送红包
///
/// 接收者账号
/// content
/// TotalAmount
/// password
/// count
/// type
/// bank
/// param
///
public virtual string SendPay(string toUsername, string content, int TotalAmount, string password, int count, PayType type, BankCar bank = null, Dictionary param = null) { return string.Empty; }
///
/// 获得好友列表
///
///
///
public virtual List FindFriends()
{
return null;
}
///
/// 获取朋友圈
///
///
public virtual List> FindCircles() { throw new Exception("此协议不支持,FindCircles!"); }
///
/// 获取群列表(不包含群成员)
///
///
public virtual List GetGroupsNotInMember() { return null; }
///
/// 检测URL在微信中是否有效
///
/// url
/// 0可以访问, -x 负值代表不能访问
public virtual bool CheckUrl(string url) { throw new Exception("此协议不支持,CheckUrl!"); }
///
/// 打开内置浏览器
///
/// url
///
public virtual void OpenUrl(string url) { throw new Exception("此协议不支持,OpenUrl!"); }
///
/// 清理历史聊天记录
///
///
public virtual void ClearChatHistoryMsg() { throw new Exception("此协议不支持,ClearChatHistoryMsg!"); }
///
/// 设置会话已读
///
public virtual void SetSessionReadedMsg(string wxid) { throw new Exception("此协议不支持,SetSessionReadedMsg!"); }
///
/// 修改群聊名称
///
/// 新的群名
/// 群id
public virtual void SetRoomName(string new_name, string groupId) { throw new Exception("此协议不支持,SetRoomName!"); }
///
/// 修改群公告(可用于@全体)
///
/// 新公告
/// 群聊wxid
public virtual void SetRoomNotice(string notice, string groupId) { throw new Exception("此协议不支持,SetRoomNotice!"); }
///
/// 设置自己在群中昵称
///
/// 要设置的昵称
/// 需要设置的群id
public virtual void ModRoomMyName(string nickname, string groupId) { throw new Exception("此协议不支持,ModRoomMyName!"); }
///
/// 设置是否显示群成员昵称
///
/// true为开启
/// 要显示得到群
public virtual void SetRoomShowMemeberName(bool status, string groupId) { throw new Exception("此协议不支持,SetRoomShowMemeberName!"); }
///
/// 修改群聊名称
///
/// 新名称
/// 群号
public virtual void ModRoomName(string newnick, string groupId) { throw new Exception("此协议不支持,ModRoomName!"); }
///
/// 是否消息免打扰
///
/// true为开启
/// wxid
public virtual void SetRecvNotify(bool status, string wxid) { throw new Exception("此协议不支持,SetRecvNotify!"); }
///
/// 创建群聊
///
/// 用户账号用英文逗号分隔
public virtual string CreateChatRoom(string members) { throw new Exception("此协议不支持,CreateChatRoom!"); }
///
/// 创建群
///
/// 用户账号3个或者以上
public virtual string CreateChatRoom(string[] wxids) { throw new Exception("此协议不支持,CreateChatRoom!"); }
///
/// 添加群用户
///
/// 群号
/// 用户wxid多个用户逗号分隔
public virtual void AddChatRoomMember(string groupid, string members) { throw new Exception("此协议不支持,AddChatRoomMember!"); }
///
/// 添加群用户_40人以下
///
/// 群id
/// 用户账号多个用英文逗号分隔
public virtual void AddChatRoomMember_40Down(string groupid, string members) { throw new Exception("此协议不支持,AddChatRoomMember!"); }
///
/// 关注公众号
///
/// 公众号wxid
public virtual void AddPublicUser(string wxid) { throw new Exception("此协议不支持,AddPublicUser!"); }
///
/// 开启/关闭防撤回功能
///
/// 1是开启防撤回,0是关闭
public virtual void SetDisableRevoke(bool status) { throw new Exception("此协议不支持,SetDisableRevoke!"); }
///
/// 发表朋友圈
///
/// 内容-需要携带至少一张图片,例如:[图片=路径]
///
public virtual string SendCircle(string msg) { throw new Exception("此协议不支持,SendCircle!"); }
///
/// 发表评论
///
/// 发送的微信ID
/// 朋友圈的ID
/// 发送的内容
///
public virtual void SendCircleComment(string username, string circleId, string content) { throw new Exception("此协议不支持,SendCircleComment!"); }
///
/// 点赞
///
/// 账号
/// 朋友圈id
public virtual void SendCirclePraise(string username, string circleId) { throw new Exception("此协议不支持,SendCirclePraise!"); }
///
/// 获取朋友圈
///
/// 微信ID
/// 页码
/// 页码ID
///
public virtual List> FindCircle(string username, string firstPageMd5 = "", long MaxId = 0) { throw new Exception("此协议不支持,FindCircle!"); }
///
/// 自动授权登录小程序
///
/// appid
public virtual string AutoAuthMiniAPPLogin(string appid) { throw new Exception("此协议不支持,AutoAuthMiniAPPLogin!"); }
private static LogHelper log = new LogHelper();
///
/// 写出日志
///
/// 内容
/// 是否为debug
public void WriteLog(string msg, bool debug = false)
{
ChatClient.Events.OnEvent(new WXWriteLog(this) { IsDebug = debug, Message = msg });
}
///
/// 编辑用户信息
///
/// 操作用户
/// 操作类型
/// 如果Type=备注,为空表示取消备注,不为空表示备注所填写内容
public virtual void EditContacts(string username, EditContactsType type, string remark = "") { }
///
/// 删除朋友
///
/// 用户wxid
///
public virtual string DeleteFriend(string username) { return null; }
///
/// 邀请入群
///
/// 用户wxid
/// 群id
///
public virtual string InviteIntoGroup(string username, string groupId) { return null; }
///
/// 删除群用户
///
/// 用户账号
/// 群id
///
public virtual string DeleteGroupMember(string username, string groupId) { return null; }
public void Dispose()
{
}
public virtual Dictionary GetBalance() { return null; }
///
/// 领取转账
///
/// 收到转账中的Invalidtime
/// 收到转账中的Transferid
/// 收到转账中的FromUsername
///
public virtual int TenPayTransferConfirm(string Invalidtime, string Transferid, string FromUsername) { return -1; }
///
/// 获取标签组
///
/// 是否刷新标签组
///
public virtual List GetLabelList(bool refresh = false) { throw new Exception("此协议不支持,GetTagList!"); }
///
/// 添加标签
///
/// 标签名称
///
public virtual bool AddLabel(string TagName) { throw new Exception("此协议不支持,AddTag!"); }
///
/// 批量修改标签
///
/// 用户信息
/// 标签组
///
public virtual bool EditUserLabel(string[] Users, List Lable) { throw new Exception("此协议不支持,ModifyUserTag!"); }
/////
///// 获取PC微信登录二维码
/////
/////
//public virtual RemoteLoginCode GetLoginCode() { throw new Exception("此协议不支持,GetLoginCode!"); }
}
}