生成的小程序二维码图片无法打开?
最近发现通过小程序接口返回的二维码保存后,却无法打开。 前段时间还可以的,不知道是微信改了什么吗? 请帮忙看看。 下面是代码 [代码]public[代码] [代码]void[代码] [代码]CreateQrCode()[代码][代码]{[代码][代码] [代码][代码]var[代码] [代码]service = [代码][代码]new[代码] [代码]CommonService();[代码][代码] [代码][代码]var[代码] [代码]token = service.GetAccessToken();[代码][代码] [代码][代码]var[代码] [代码]url = $[代码][代码]"https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token={token}"[代码][代码];[代码][代码] [代码][代码]var[代码] [代码]qrcodeContent = Guid.NewGuid().ToString();[代码][代码] [代码][代码]var[代码] [代码]body = $[代码][代码]"{{\"path\":\"pages/xxx?q='{qrcodeContent}'\"}}"[代码][代码];[代码] [代码] [代码][代码]var[代码] [代码]results = HttpPost(url, body);[代码] [代码] [代码][代码]ToImage(results);[代码][代码]}[代码] [代码]public[代码] [代码]Stream HttpPost([代码][代码]string[代码] [代码]url, [代码][代码]string[代码] [代码]body)[代码][代码]{[代码][代码] [代码][代码]Encoding encoding = Encoding.UTF8;[代码][代码] [代码][代码]HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);[代码][代码] [代码][代码]request.Method = [代码][代码]"POST"[代码][代码];[代码][代码] [代码][代码]//request.ContentType = "application/json; charset=utf-8";[代码] [代码] [代码][代码]byte[代码][代码][] buffer = encoding.GetBytes(body);[代码][代码] [代码][代码]request.ContentLength = buffer.Length;[代码][代码] [代码][代码]var[代码] [代码]witer = request.GetRequestStream();[代码][代码] [代码][代码]witer.Write(buffer, 0, buffer.Length);[代码][代码] [代码][代码]witer.Close();[代码][代码] [代码][代码]HttpWebResponse response = (HttpWebResponse)request.GetResponse();[代码] [代码] [代码][代码]return[代码] [代码]response.GetResponseStream();[代码][代码]}[代码] [代码]private[代码] [代码]static[代码] [代码]void[代码] [代码]ToImage(Stream fileSteam)[代码][代码]{[代码][代码] [代码][代码]var[代码] [代码]path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),[代码][代码] [代码][代码]"test2.jpg"[代码][代码]);[代码] [代码] [代码][代码]byte[代码][代码][] bytes;[代码][代码] [代码][代码]using[代码] [代码](MemoryStream ms = [代码][代码]new[代码] [代码]MemoryStream())[代码][代码] [代码][代码]{[代码][代码] [代码][代码]fileSteam.CopyTo(ms);[代码][代码] [代码][代码]bytes = ms.ToArray();[代码][代码] [代码][代码]}[代码][代码] [代码][代码]using[代码] [代码]([代码][代码]var[代码] [代码]fs = File.OpenWrite(path))[代码][代码] [代码][代码]{[代码][代码] [代码][代码]fs.Write(bytes, 0, bytes.Length);[代码][代码] [代码][代码]}[代码] [代码] [代码][代码]Process.Start(path);[代码][代码]}[代码]