VB.net 2010 视频教程 VB.net 2010 视频教程 VB.net 2010 视频教程
当前位置:
首页 > 编程开发 > c#教程 >
  • C#教程之API调用微信getWXACodeUnlimit()获取小程序码

  • 2019-03-14 21:32 来源:未知

微信文档地址: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);
        }
复制代码

 

微信调用成功返回的是图片二进制内容,这里做了处理,返回给前台的是byte数组

前台用Img标签显示:<img src='data:image/jpeg;base64,+result+'/>

相关教程
关于我们--广告服务--免责声明--本站帮助-友情链接--版权声明--联系我们       黑ICP备07002182号