当前位置: 移动技术网 > IT编程>开发语言>.net > API调用微信getWXACodeUnlimit()获取小程序码

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

2018年10月25日  | 移动技术网IT编程  | 我要评论

鞍山千山晚报电子版,美少女战士国语版全集,八分休止符

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

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网