/// <summary> /// 发送文本消息 /// </summary> /// <param name="account"></param> /// <param name="toUserNameId"></param> /// <param name="text"></param> /// <returns></returns> /// https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg /// ?lang=zh_CN /// &pass_ticket=4eHHuCPjQTzJL8d25%252FYZlo%252BzC%252FtbrmnGPwyNWPJTS8pqc%252FDZ%252FhdLzBJISu6rUn4E public static HttpTaskParams GetSendTextMsg(string host, WxAccount account, string toUserNameId, string text) { string url = string.Format("{0}?fun=async&lang=zh_CN&pass_ticket={1}", WxHttpApi.GetCommonUrl(host, WxHttpApi.URL_WX_SEND_MSG), encoding(account.PassTicket)); HttpTaskParams htp = HttpTaskParams.NewPost(url); htp.ContentType = "application/json;charset=UTF-8"; WxSendMsgReq req = new WxSendMsgReq(); req.BaseRequest = WxReqUtil.GetIdentifyReq(account); req.Scene = 0; WxSendMsg msg = new WxSendMsg(); msg.Type = 1; msg.Content = text; msg.FromUserName = account.UserName; msg.ToUserName = toUserNameId; string msgId = TimeUtil.CurrentTimeMillis() + TextUtil.RandomNumber(4); msg.LocalID = msgId; msg.ClientMsgId = msgId; req.Msg = msg; htp.CustomStringContentBody = JsonConvert.SerializeObject(req); return(htp); }
public override bool SendMessage(string word) { long time = Time.Now(); string url = WxApi.SendMessageUrl + "?sid=" + CurrentUser.WxSid + "&skey=" + CurrentUser.Skey + "&pass_ticket=" + CurrentUser.PassTicket + "&r=" + time; JObject jsonObj = new JObject(); jsonObj.Add("BaseRequest", JObject.FromObject(CurrentUser.BaseRequest)); SendMsg msg = new SendMsg(); msg.FromUserName = CurrentUser.Me.UserName; msg.ToUserName = user.UserName; msg.Type = 1; msg.Content = word; msg.ClientMsgId = time; msg.LocalID = time; TB_SendBox.Clear(); jsonObj.Add("Msg", JObject.FromObject(msg)); WxSendMsg wxsendmsg = HttpRequest.PostJsonSync <WxSendMsg>(url, jsonObj); TB_Receive.Text += "我:\n" + msg.Content + "\n"; return(true); }