欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

API调用微信getWXACodeUnlimit()获取小程序码

程序员文章站 2022-10-17 10:13:21
微信文档地址:https://developers.weixin.qq.com/miniprogram/dev/api/open-api/qr-code/getWXACodeUnlimit.html?client=tim&ADUIN=2312459330&ADSESSION=1540344656&A ......

微信文档地址: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

代码:

API调用微信getWXACodeUnlimit()获取小程序码
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+'/>

 

上一篇: 猫和老虎

下一篇: 两只癞蛤蟆