/// <summary> /// 发送视频消息 /// </summary> /// <param name="host"></param> /// <param name="account"></param> /// <param name="toUserNameId"></param> /// <param name="mediaId"></param> /// <returns></returns> /// https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsendvideomsg?fun=async&f=json&pass_ticket=%252FX8NCpFJfNmU%252Be%252FgE2dwRCN2D8Y8EBSKunfckAJmPfCeVD4YaubkaS2e767qiyAO /// https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsendvideomsg?fun=async&f=json&lang=zh_CN&pass_ticket=KwMEOlgC57Dc1AwBwr7oaHekXX0P8fJE%252Bl0cLVocIrxdWNr%252F9URPGCAEmf%252FzfjEK public static HttpTaskParams GetSendVideoMsg(string host, WxAccount account, string toUserNameId, string mediaId) { string url = string.Format("{0}?fun=async&f=json&lang=zh_CN&pass_ticket={1}", WxHttpApi.GetCommonUrl(host, WxHttpApi.URL_WX_SEND_VIDEO_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; WxSendMediaMsg msg = new WxSendMediaMsg(); msg.Type = 43;//视频 msg.MediaId = mediaId; msg.FromUserName = account.UserName; msg.ToUserName = toUserNameId; string msgId = TimeUtil.CurrentTimeMillis() + TextUtil.RandomNumber(4); msg.LocalID = msgId; msg.ClientMsgId = msgId; msg.Content = string.Empty; req.Msg = msg; htp.CustomStringContentBody = JsonConvert.SerializeObject(req); return(htp); }
/// <summary> /// 登出 /// </summary> /// <returns></returns> /// https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxlogout?redirect=1&type=1&skey=%40crypt_55085584_86ecfa5dcc8c6c64484e0014d33882de public static HttpTaskParams GetLogout(string host, string skey, string uin, string sid) { string url = string.Format("{0}?redirect={1}type={2}&skey={3}&uin={4}&sid={5}", WxHttpApi.GetCommonUrl(host, WxHttpApi.URL_WX_LOGOUT), "1", "1", encoding(skey), encoding(uin), encoding(sid)); return(HttpTaskParams.NewPost(url)); }
/// <summary> /// 获取微信状态通知 /// </summary> /// <param name="result"></param> /// <returns></returns> /// https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxstatusnotify /// ?lang=zh_CN /// &pass_ticket=zXbwZhRifdRRNcPjsjxyemYskxzSRQOxZF6T3HJuTpsdgPENMSMXylIlmsnrEZ5s public static HttpTaskParams GetStatusNotify(string host, WxAccount wxAccount) { string url = string.Format("{0}?lang={1}&pass_ticket={2}", WxHttpApi.GetCommonUrl(host, WxHttpApi.URL_WX_STATUS_NOTIFY), "zh_CN", encoding(wxAccount.PassTicket)); HttpTaskParams htp = HttpTaskParams.NewPost(url); htp.ContentType = "application/json;charset=utf-8"; htp.CustomStringContentBody = JsonConvert.SerializeObject(WxReqUtil.GetStatusNotifyReq(wxAccount)); return(htp); }
/// <summary> /// 群踢人 /// </summary> /// <param name="account"></param> /// <param name="userNameId"></param> /// <param name="groupUserNameId"></param> /// <returns></returns> public static HttpTaskParams GetGroupContactDelMember(string host, WxAccount account, string userNameId, string groupUserNameId) { string url = string.Format("{0}?fun=delmember&lang=zh_CN&pass_ticket={1}", WxHttpApi.GetCommonUrl(host, WxHttpApi.URL_WX_GROUP_DEL_MEMBER), encoding(account.PassTicket)); HttpTaskParams htp = HttpTaskParams.NewPost(url); htp.ContentType = "application/json;charset=UTF-8"; WxGroupMemberReq req = new WxGroupMemberReq(); req.BaseRequest = WxReqUtil.GetIdentifyReq(account); req.DelMemberList = userNameId; req.ChatRoomName = groupUserNameId; htp.CustomStringContentBody = JsonConvert.SerializeObject(req); return(htp); }
/// <summary> /// 获取微信登录初始化接口 /// </summary> /// <param name="result"></param> /// <returns></returns> /// demo:https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit /// ?r=665841145 /// &lang=zh_CN /// &pass_ticket=zXbwZhRifdRRNcPjsjxyemYskxzSRQOxZF6T3HJuTpsdgPENMSMXylIlmsnrEZ5s public static HttpTaskParams GetLoginInitParams(string host, WxLoginIdsResult result, string deviceId) { //r时间戳取反 string url = string.Format("{0}?r={1}&lang={2}&pass_ticket={3}", WxHttpApi.GetCommonUrl(host, WxHttpApi.URL_WX_INIT), (TimeUtil.CurrentTimeMillis() / 1000), "zh_CN", encoding(result.PassTicket)); HttpTaskParams htp = HttpTaskParams.NewPost(url); htp.ContentType = "application/json;charset=utf-8"; htp.CustomStringContentBody = JsonConvert.SerializeObject(WxReqUtil.GetBaseReq(result, deviceId)); #if Debug Console.WriteLine("init content body = " + htp.CustomStringContentBody); #endif return(htp); }
public static HttpTaskParams GetUploadImage(string host, WxAccount account, string toUserNameId, string imagePath) { string url = string.Format("{0}?f=json", WxHttpApi.GetFileUploadUrl(host, WxHttpApi.URL_WX_FILE_UPLOAD)); HttpTaskParams htp = HttpTaskParams.NewPost(url); FileInfo info = new FileInfo(imagePath); htp.AddStringParam("id", "WU_FILE_" + fileCount); htp.AddStringParam("name", info.Name); htp.AddStringParam("type", "image/jpeg"); htp.AddStringParam("lastModifiedDate", info.LastWriteTime.ToString("r", DateTimeFormatInfo.InvariantInfo)); htp.AddStringParam("size", info.Length.ToString()); htp.AddStringParam("mediatype", "pic"); htp.AddStringParam("webwx_data_ticket", account.DataTicket); htp.AddStringParam("pass_ticket", account.PassTicket); htp.AddFileParam("filename", imagePath, WxReqUtil.GetImageMimeType(info)); htp.AddStringParam("uploadmediarequest", WxReqUtil.GetUploadMediaRequestBody(account, toUserNameId, info, imagePath)); return(htp); }
/// <summary> /// 批量获取联系人,包含个人和组 /// </summary> /// <param name="wxAccount"></param> /// <param name="groupUserNames"></param> /// <returns></returns> /// //https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxbatchgetcontact /// ?type=ex /// &r=1498291861743 /// &lang=zh_CN /// &pass_ticket=ga8bxGb9YQJLWhU6RA6FMamJy0wqnD7QuWP9k%252F9tlTb8O1uUkgcZ7YbjNg3bEkYH public static HttpTaskParams GetBatchContactParams(string host, WxAccount wxAccount, List <string> groupUserNameIds) { string url = string.Format("{0}?type=ex&r={1}&lang=zh_CN&pass_ticket={2}", WxHttpApi.GetCommonUrl(host, WxHttpApi.URL_WX_CONTACT_BATCH), TimeUtil.CurrentTimeMillis(), encoding(wxAccount.PassTicket)); HttpTaskParams htp = HttpTaskParams.NewPost(url); htp.ContentType = "application/json;charset=utf-8"; WxBatchContactReq req = new WxBatchContactReq(); req.BaseRequest = WxReqUtil.GetIdentifyReq(wxAccount); req.Count = CollectionUtil.Size(groupUserNameIds); req.List = WxReqUtil.GetBatchContactItemList(groupUserNameIds); htp.CustomStringContentBody = JsonConvert.SerializeObject(req); return(htp); }
/// <summary> /// 同步获取更新消息 /// </summary> /// <param name="account"></param> /// <param name="syncKey"></param> /// <returns></returns> /// https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsync /// ?sid=XbUcBWzGt6NPu5jO /// &skey=@crypt_55085584_cf738edf865a9c101021022d1c732ae6 /// &lang=zh_CN /// &pass_ticket=lBIvUtbeb5e%252BMIDHLr5QVehuJDPbW3NEgMSh87ILAOv3ue1HdLtSV%252B8AK0ULznEL public static HttpTaskParams GetSyncMsgParams(string host, WxAccount account, WxSyncKey syncKey) { string url = string.Format("{0}?sid={1}&skey={2}&pass_ticket={3}&lang={4}", WxHttpApi.GetCommonUrl(host, WxHttpApi.URL_WX_MSG_PULL), encoding(account.Sid), encoding(account.Skey), encoding(account.PassTicket), "zh_CN"); HttpTaskParams htp = HttpTaskParams.NewPost(url); htp.ContentType = "application/json;charset=UTF-8"; WxWebSyncReq req = new WxWebSyncReq(); req.BaseRequest = WxReqUtil.GetIdentifyReq(account); req.SyncKey = syncKey; req.rr = (~(TimeUtil.CurrentTimeMillis() / 1000)).ToString();//时间戳取反 htp.CustomStringContentBody = JsonConvert.SerializeObject(req); return(htp); }
/// <summary> /// 上传视频文件 /// </summary> /// <param name="host"></param> /// <param name="account"></param> /// <param name="toUserNameId"></param> /// <param name="videoPath"></param> /// <returns></returns> /// https://file.wx.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json public static HttpTaskParams GetUploadVideo(string host, WxAccount account, string toUserNameId, string videoPath) { string url = string.Format("{0}?f=json", WxHttpApi.GetFileUploadUrl(host, WxHttpApi.URL_WX_FILE_UPLOAD)); HttpTaskParams htp = HttpTaskParams.NewPost(url); FileInfo info = new FileInfo(videoPath); htp.AddStringParam("id", "WU_FILE_" + fileCount); htp.AddStringParam("name", info.Name); htp.AddStringParam("type", WxReqUtil.GetVideoMimeType(info));//"video/mp4" htp.AddStringParam("lastModifiedDate", info.LastWriteTime.ToString("r", DateTimeFormatInfo.InvariantInfo)); htp.AddStringParam("size", info.Length.ToString()); htp.AddStringParam("chunks", "1"); //分段数,这里一次上传,不分段 htp.AddStringParam("chunk", "0"); //第几段 htp.AddStringParam("mediatype", "video"); htp.AddStringParam("uploadmediarequest", WxReqUtil.GetUploadMediaRequestBody(account, toUserNameId, info, videoPath)); htp.AddStringParam("webwx_data_ticket", account.DataTicket); htp.AddStringParam("pass_ticket", account.PassTicket); htp.AddFileParam("filename", videoPath); return(htp); }