API調用微信getWXACodeUnlimit()獲取小程序碼


微信文檔地址:https://developers.weixin.qq.com/miniprogram/dev/api/open-api/qr-code/getWXACodeUnlimit.html?client=tim&ADUIN=2312459330&ADSESSION=1540344656&ADTAG=CLIENT.QQ.5585_.0&ADPUBNO=26849

代碼:

public JsonR MiniAppCode(string scene, string page, int width, bool auto_color, object line_color, bool is_hyaline)
        {
            var accessToken = WX.GetAccessToken("appid*************", "appSecret******************************");//獲取接口AccessToken
            var url = string.Format("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={0}", accessToken);
            var postData = new
            {
                scene,
                page,
                width,
                auto_color,
                line_color,
                is_hyaline,
            }.ToJson();
            System.Net.HttpWebRequest request;
            request = (System.Net.HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/json;charset=UTF-8";
            byte[] payload;
            payload = System.Text.Encoding.UTF8.GetBytes(postData);
            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 stream;
            stream = response.GetResponseStream();
            List<byte> bytes = new List<byte>();
            int temp = stream.ReadByte();
            while (temp != -1)
            {
                bytes.Add((byte)temp);
                temp = stream.ReadByte();
            }
            byte[] result = bytes.ToArray();
            return ComEnum.Code.A_操作成功.JsonR(result);
        }
View Code

 

微信調用成功返回的是圖片二進制內容,這里做了處理,返回給前台的是byte數組

前台用Img標簽顯示:<img src='data:image/jpeg;base64,+result+'/>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM