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();
    
            }

     

  • 相关阅读:
    十大排序
    算法11----判断是否为回文词(双端队列判断)
    算法10-----分糖果
    算法9-----输出全排列(递归)---移除K个数,剩下最小数。
    算法8-----罗马字转整数(分治法)
    Python数据结构2-----队列和堆
    Python数据结构1-----基本数据结构和collections系列
    Python笔记22-----高阶函数
    10、TV UI
    9、创建向后兼容的用
  • 原文地址:https://www.cnblogs.com/smileZeng/p/11725575.html
Copyright © 2011-2022 走看看