zoukankan      html  css  js  c++  java
  • 小程序生成小程序码

    getUnlimited 获取小程序码,适用于需要的码数量极多的业务场景。通过该接口生成的小程序码,永久有效,数量暂无限制。

    小程序官方文档 wxacode.getUnlimited

            /// <summary>
            /// 获取小店小程序码
            /// </summary>
            /// <returns>返回的图片 Buffer</returns>
            public object GetWxacode(string pagePath, int width, string Id)
            {
                var accessToken = "";//获取小程序全局唯一后台接口调用凭据(access_token
                var data = "{"scene":"" + Id + "","path":"" + HttpUtility.UrlDecode(pagePath) + "","width":" + width + "}";
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + accessToken);  //创建url
                request.Method = "POST";
                request.ContentType = "application/json;charset=UTF-8";
                byte[] load = Encoding.UTF8.GetBytes(data);
                request.ContentLength = load.Length;
                Stream writer = request.GetRequestStream();
                writer.Write(load, 0, load.Length);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Stream s = response.GetResponseStream();
                byte[] mg = StreamToBytes(s);
                MemoryStream ms = new MemoryStream(mg);
                string qrCodeImagePath = string.Empty;
                qrCodeImagePath = "data:image/gif;base64," + Convert.ToBase64String(ms.ToArray());
                ms.Dispose();
                var QrCodeImagePath = qrCodeImagePath;            
                return QrCodeImagePath;
            }
            private static byte[] StreamToBytes(Stream stream)
            {
    
                List<byte> bytes = new List<byte>();
                int temp = stream.ReadByte();
                while (temp != -1)
                {
                    bytes.Add((byte)temp);
                    temp = stream.ReadByte();
                }
                return bytes.ToArray();
    
            }

     

  • 相关阅读:
    链家新房爬虫
    豆瓣电影爬虫
    电影天堂爬虫
    数组、数组和集合的区别
    Profile小试
    SQL中的case when使用小例
    使用AVAudioPlayer播放网络音乐
    播放器
    全排列问题
    由while(scanf("%d",&n)!=EOF)引出的小问题
  • 原文地址:https://www.cnblogs.com/smileZeng/p/11725575.html
Copyright © 2011-2022 走看看