自己解决了,这接口传递的时间是utc时间,而我传递的是local的时间所以没取到;结贴
微信获取客服接口一直返回空数据?如下为官方文档 https://developers.weixin.qq.com/doc/offiaccount/Customer_Service/Obtain_chat_transcript.html 我参考官方文档,但是接口调用成功后recordlist一直是空 我尝试了用两个appid,wxbb23a029883b991d和wx260a67855553e9c2,都是空。
2020-12-14使用HttpWebRequest 发送请求成功,代码如下 HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; CookieContainer cookieContainer = new CookieContainer(); request.CookieContainer = cookieContainer; request.AllowAutoRedirect = true; request.Method = "POST"; string boundary = DateTime.Now.Ticks.ToString("X"); request.ContentType = "multipart/form-data;charset=utf-8;boundary=" + boundary; byte[] itemBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "\r\n"); byte[] endBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "--\r\n"); int pos = path.LastIndexOf("\\"); string fileName = path.Substring(pos + 1); StringBuilder sbHeader = new StringBuilder(string.Format("Content-Disposition:form-data;name=\"" + formName + "\";filename=\"{0}\"\r\nContent-Type:application/octet-stream\r\n\r\n", fileName)); byte[] postHeaderBytes = Encoding.UTF8.GetBytes(sbHeader.ToString()); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); byte[] bArr = new byte[fs.Length]; fs.Read(bArr, 0, bArr.Length); fs.Close(); Stream postStream = request.GetRequestStream(); postStream.Write(itemBoundaryBytes, 0, itemBoundaryBytes.Length); postStream.Write(postHeaderBytes, 0, postHeaderBytes.Length); postStream.Write(bArr, 0, bArr.Length); byte[] bSplit = Encoding.UTF8.GetBytes("--" + boundary + "\r\n"); postStream.Write(bSplit, 0, bSplit.Length); if (!string.IsNullOrEmpty(additionInfo)) { byte[] additionBytes = Encoding.UTF8.GetBytes("Content-Disposition: form-data; name=\"description\";\r\n\r\n"); postStream.Write(additionBytes, 0, additionBytes.Length); byte[] additionContentBytes = Encoding.UTF8.GetBytes(additionInfo); postStream.Write(additionContentBytes, 0, additionContentBytes.Length); postStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length); } postStream.Close(); HttpWebResponse response = request.GetResponse() as HttpWebResponse; Stream instream = response.GetResponseStream(); StreamReader sr = new StreamReader(instream, Encoding.UTF8); content = sr.ReadToEnd(); 但是使用HttpClient就一直提示41005,代码如下 using (var client = _clientFactory.CreateClient()) { var file = new FileInfo(filePath); byte[] buffur = File.ReadAllBytes(filePath); using (var formData = new MultipartFormDataContent()) { ByteArrayContent fileContent = new ByteArrayContent(buffur); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") { Name = formName, FileName = file.Name }; formData.Add(fileContent); var response = await client.PostAsync(url, formData); if (response.IsSuccessStatusCode) { var result = await response.Content.ReadAsStringAsync(); return result; } else { throw new BadHttpResponseException(url, response.StatusCode); } } } 对比了一下貌似区别在换行符上"\r\n",但是封装好的HttpClient又不知道如何添加相应的换行符。 不知道这个是不是根本原因。
上传素材的接口总是41005?在调用https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token={0}接口时候出现下面的提示 {"errcode":41005,"errmsg":"media data missing hint: [A5xKlA00450022] rid: 5fa26845-61692912-4f6634a1"} 我用的是C#,能帮我查一下什么原因吗?
2020-11-04