码迷,mamicode.com
首页 > 微信 > 详细

小程序生成小程序码

时间:2019-10-23 14:05:07      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:场景   程序   adb   add   web   ESS   app   enc   temp   

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

        }

 

 

小程序生成小程序码

标签:场景   程序   adb   add   web   ESS   app   enc   temp   

原文地址:https://www.cnblogs.com/smileZeng/p/11725575.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!