|
作者:w568273102,来自原文地址 微信小程序获取小程序页面二维码API接口,通过后台post网址,获取access_token方式,参数{"path": "pages/index/index?query=1", "width": 260},可以获得图片二进制流,直接打印二进制流为乱码 该二进制流直接保存成png图片,一下为本人所写的部分核心代码,需要引用using system.net /// url 网址 || param 参数 public static string PostMoths(string url, string param) {string strURL = url;System.Net.HttpWebRequest request;request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);request.Method = "POST";request.ContentType = "application/json;charset=UTF-8";string paraUrlCoded = param;byte[] payload;payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);request.ContentLength = payload.Length;Stream writer = request.GetRequestStream();writer.Write(payload, 0, payload.Length);writer.Close();System.Net.HttpWebResponse response;response = (System.Net.HttpWebResponse)request.GetResponse();System.IO.Stream s;s = response.GetResponseStream();string StrDate = "";string strValue = "";byte[] tt = StreamToBytes(s);//将流保存在c盘test.png文件下System.IO.File.WriteAllBytes(@"c:\test.png", tt);}///将数据流转为byte[]public static byte[] StreamToBytes(Stream stream){List bytes = new List();int temp = stream.ReadByte();while (temp != -1){bytes.Add((byte)temp);temp = stream.ReadByte();} return bytes.ToArray(); }
生成的带参数二维码
|