开源微信Http协议Sdk【实现登录/获取好友列表/修改备注/发送消息】
基于微信Http协议封装的一个Sdk,目前实现了以下功能:、
1:扫码登录(检测二维码扫描状态)
2:获取最近联系人、群组、所有联系人
3:修改好友备注
4:给好友发送消息
暂且这么多,也没多余的时间去增加了,大家有需要的可以下载源码自己扩展下
项目结构如下
如何使用
HttpWeChat类封装了所有和微信相关的功能,对外暴露了以下事件,在实例化HttpWeChat实例的时候就可以订阅相关事件,并做相对应操作
/// <summary>
/// 二维码发生变化事件
/// </summary>
public event EventHandler<QrCodeChangEventArgs> QRCodeChangeEvent;
/// <summary>
/// 二维码状态发生改变事件
/// </summary>
public event EventHandler<QrCodeStatusChangEventArgs> QRCodeStatusChangeEvent;
/// <summary>
/// 初始化数据之前
/// </summary>
public event EventHandler<EventArgs> InitDatabeforeEvent;
/// <summary>
/// 初始化数据完成
/// </summary>
public event EventHandler<EventArgs> InitDatacompleteEvent;
/// <summary>
/// 消息检查事件
/// </summary>
public event EventHandler<SyncCheckEventArgs> SyncCheckEvent;
/// <summary>
/// 收到新消息事件
/// </summary>
public event EventHandler<WebwxsyncEventArgs> WebwxsyncEvent;
发送消息
var result = httpWeChat.SendMessage(new Model.SendMessage
{
ClientMsgId = DateTime.Now.ToUnix().ToString(),
Content = "测试一下",
ToUserName = httpWeChat.WeChatData.AllMember.FirstOrDefault(c => c.NickName == haoyouliebiao.Text)?.UserName,
FromUserName = httpWeChat.WeChatData.CurrentLoginMemberInfo.UserName
});
if (result.Status)
{
MessageBox.Show("消息发送成功!消息Id是:" + result.MsgId);
}
else {
MessageBox.Show("消息发送失败,错误消息是:"+result.ErrorMsg);
}
修改备注
httpWeChat.UpdateRemarke(new Model.UpdateRemarke {
UserName = httpWeChat.WeChatData.AllMember.FirstOrDefault(c => c.NickName == haoyouliebiao.Text)?.UserName,
RemarkName = httpWeChat.WeChatData.AllMember.FirstOrDefault(c => c.NickName == haoyouliebiao.Text).RemarkName + "Sdk修改测试"
});
MessageBox.Show("修改成功!");
项目地址
https://github.com/dazhuangtage/Diego.WxHttpSdk/tree/master