基于.Net平台C#的微信网页版API
时间:2017-12-01 13:33:59
收藏:0
阅读:268
git上有很多类似的项目,但大多都是python和js的,为了便于.Net windows平台的使用,我重构了一个.Net版本的,已整理开源
https://github.com/leestar54/WebWeChatAPI.Net
WebWeChat.Net
基于.Net平台C#的微信网页版API
近期更新
- 实现API基础功能
开发运行环境
vs2015+.net4.0 framework
依赖项
json.net 4.0
Feature
- 最小依赖,使用简单
- 支持同步、基于事件回调的异步方法
- 对象间隔离,可以实例化无数客户端
简单使用
具体内容见源码,此处仅简单说明
static void Main(string[] args) { Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; client = new Client(); qrForm = new QrCodeForm(); client.ExceptionCatched += Client_ExceptionCatched; ; client.GetLoginQrCodeComplete += Client_GetLoginQrCodeComplete; ; client.CheckScanComplete += Client_CheckScanComplete; ; client.LoginComplete += Client_LoginComplete; ; client.BatchGetContactComplete += Client_BatchGetContactComplete; ; client.GetContactComplete += Client_GetContactComplete; ; client.MPSubscribeMsgListComplete += Client_MPSubscribeMsgListComplete; ; client.LogoutComplete += Client_LogoutComplete; ; client.ReceiveMsg += Client_ReceiveMsg; ; client.DelContactListComplete += Client_DelContactListComplete; ; client.ModContactListComplete += Client_ModContactListComplete; Console.WriteLine("小助手启动"); client.Start(); qrForm.ShowDialog(); Console.ReadLine(); client.Close(); Console.ReadLine(); client.Logout(); }
方法说明
/// <summary> /// 异步发送文字消息 /// </summary> /// <param name="msg">消息</param> /// <param name="toUserName">发送人UserName</param> public void SendMsgAsync(string msg, string toUserName) /// <summary> /// 同步发送文字消息 /// </summary> /// <param name="msg">文字</param> /// <param name="toUserName">发送人UserName</param> /// <returns></returns> public SendMsgResponse SendMsg(string msg, string toUserName) /// <summary> /// 异步发送文件 /// </summary> /// <param name="fileInfo">文件信息</param> /// <param name="toUserName">发送人UserName</param> public void SendMsgAsync(FileInfo fileInfo, string toUserName) /// <summary> /// 同步发送文件,自动分块上传,文件较大可能会卡住进程,建议异步发送 /// </summary> /// <param name="fileInfo">文件信息</param> /// <param name="toUserName">发送人UserName</param> /// <returns></returns> public SendMsgResponse SendMsg(FileInfo fileInfo, string toUserName) /// <summary> /// 获取头像,因为请求的时候需要带Cookie等相关参数,所以直接用新的http请求不行,务必使用客户端API来获取 /// </summary> /// <param name="url">头像地址,例如/cgi-bin/mmwebwx-bin/webwxgeticon?seq=0&username=filehelper&skey=@crypt_372b266_540d016177e861740ee84fec697a3b01 </param> /// <param name="action">委托Action</param> /// <returns></returns> public void GetIconAsync(string url, Action<Image> action) /// <summary> /// 同步上传文件 /// </summary> /// <param name="fileInfo">文件信息</param> /// <returns></returns> public UploadMediaResponse UploadFile(FileInfo fileInfo) /// <summary> /// 同步修改备注 /// 注意:多次调用该接口会被封 /// </summary> /// <param name="remarkName">需要修改的备注名</param> /// <param name="userName">需要修改的联系人UserName</param> /// <returns></returns> public SimpleResponse RemarkName(string remarkName, string userName) /// <summary> /// 同步通过好友认证 /// </summary> /// <param name="info">sync中获得的申请信息</param> /// <returns></returns> public SimpleResponse VerifyUser(RecommendInfo info) /// <summary> /// 同步顶置聊天 /// 注意:多次调用该接口会被封 /// </summary> /// <param name="remarkName">备注名,官方接口同时附带这个参数,我们也带上吧</param> /// <param name="userName">需要修改的联系人UserName</param> /// <returns></returns> public SimpleResponse TopContact(string remarkName, string userName) /// <summary> /// 同步取消顶置消息 /// </summary> /// <param name="remarkName">备注名,官方接口同时附带这个参数,我们也带上吧</param> /// <param name="userName">需要修改的联系人UserName</param> /// <returns></returns> public SimpleResponse UnTopContact(string remarkName, string userName) /// <summary> /// 群里移除用户,用IsOwner判断自己是不是群主,否则没有权限 /// </summary> /// <param name="roomName"></param> /// <param name="delName">用户UserName,英文,分割</param> /// <returns></returns> public UpdateChatRoomResponse RemoveChatRoomMember(string roomName, List<string> delNameList) /// <summary> /// 添加用户到群聊 /// </summary> /// <param name="roomName">群UserName</param> /// <param name="addName">用户UserName,英文,分割</param> /// <returns></returns> public UpdateChatRoomResponse AddChatRoomMember(string roomName, List<string> addNameList) /// <summary> /// 创建群,调用完成,可以用返回的信息,通过GetBatchGetContact去获取群信息 /// </summary> /// <param name="memberList">UserName的list</param> /// <returns></returns> public CreateChatRoomResponse CreateChatRoom(List<MemberItem> memberList)
参考
评论(0)