private async Task SendMessage(string content, string to) { var url = $"{_baseUri}/webwxsendmsg?lang=zh_CN&pass_ticket={_loginXml.PassTicket}"; var time = Common.ConvertDateTimeToInt(DateTime.Now); var obj = new { BaseRequest = _loginXml.GetBaseRequest(), Msg = new { ClientMsgId = time, Content = content, FromUserName = _me.UserName, LocalID = time, ToUserName = to, Type = 1 }, Scene = 0 };//1 文字消息,3 图片消息(先把图片上传得到MediaId再调用webwxsendmsg发送),其他消息类型没试 var data = JsonConvert.SerializeObject(obj); var result = await WechatHttp.Post(url, data); }
private async Task <bool> StatusNotify() { var url = $"{_baseUri}/webwxstatusnotify?lang=zh_CN&pass_ticket={_loginXml.PassTicket}"; var obj = new { BaseRequest = _loginXml.GetBaseRequest(), Code = 3, FromUserName = _me.UserName, ToUserName = _me.UserName, ClientMsgId = Common.ConvertDateTimeToInt(DateTime.Now) }; var data = JsonConvert.SerializeObject(obj); var result = await WechatHttp.Post(url, data); var response = JsonConvert.DeserializeObject <StatusNotifyResponse>(result); return(response.BaseResponse.Ret == 0); }
private async Task GetContact() { var url = $"{_baseUri}/webwxgetcontact?pass_ticket={_loginXml.PassTicket}&skey={_loginXml.Skey}&r={Common.ConvertDateTimeToInt(DateTime.Now)}"; var result = await WechatHttp.Post(url, "{}"); var response = JsonConvert.DeserializeObject <GetContactResponse>(result); if (response.MemberCount > 0) { _contactList = response.MemberList; } }
private async Task <SyncResponse> Sync() { var url = $"{_baseUri}/webwxsync?sid={_loginXml.Sid}&lang=zh_CN&skey={_loginXml.Skey}&pass_ticket={_loginXml.PassTicket}"; var data = _loginXml.CreateSycnRequestData(_syncKey); var result = await WechatHttp.Post(url, data); var response = JsonConvert.DeserializeObject <SyncResponse>(result); if (response.SyncKey.Count > 0) { _syncKey = response.SyncKey; } return(response); }
/// <summary> /// 初始化 /// </summary> /// <returns></returns> private async Task <bool> Init() { var url = $"{_baseUri}/webwxinit?r={Common.ConvertDateTimeToInt(DateTime.Now)}&lang=en_US&pass_ticket={_loginXml.PassTicket}"; var data = _loginXml.CreateBaseRequestData(); var returnValue = await WechatHttp.Post(url, data); var result = JsonConvert.DeserializeObject <InitResponse>(returnValue); _syncKey = result.SyncKey; _me = result.User; if (result.Count > 0) { _contactList = result.ContactList; } return(result?.BaseResponse?.Ret == 0); }