微信小程序生成小程序码的方法-小程序转换成小程序码-小程序码在线生成
生成小程序码,刚做这个功能,看了官方的文档,也看了好多别人写的,都感觉代码累赘,需要二进制流,或者生成在去保存,太麻烦了。后来找到一个简单并且使用的,此博客以此记录。也方便其他人看到学习(在此注明一点,正在审核或者审核未通过的,生成的小程序码无效)
2.原版地址https://blog.csdn.net/qq_36466653/article/details/80106903
3.publicstaticvoidgetminiqrQr(StringsceneStr,StringaccessToken){try{URLurlnewURL("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token"+accessToken);HttpURLConnectionhttpURLConnection(HttpURLConnection)url.openConnection();httpURLConnection.setRequestMethod("POST");//提交模式//conn.setConnectTimeout(10000);//连接超时单位毫秒//conn.setReadTimeout(2000);//读取超时单位毫秒//发送POST请求必须设置如下两行httpURLConnection.setDoOutput(true);httpURLConnection.setDoInput(true);//获取URLConnection对象对应的输出流PrintWriterprintWriternewPrintWriter(httpURLConnection.getOutputStream());//发送请求参数JSONObjectparamJsonnewJSONObject();paramJson.put("scene",sceneStr);paramJson.put("page","pages/index/index");paramJson.put("width",430);paramJson.put("auto_color",true);/***line_color生效*paramJson.put("auto_color",false);*JSONObjectlineColornewJSONObject();*lineColor.put("r",0);*lineColor.put("g",0);*lineColor.put("b",0);*paramJson.put("line_color",lineColor);**/
4.printWriter.write(paramJson.toString());//flush输出流的缓冲printWriter.flush();//开始获取数据BufferedInputStreambisnewBufferedInputStream(httpURLConnection.getInputStream());OutputStreamosnewFileOutputStream(newFile("F:/qrcode/2.png"));intlen;byte[]arrnewbyte[1024];while((lenbis.read(arr))!-1){os.write(arr,0,len);os.flush();}os.close();}catch(Exceptione){e.printStackTrace();}
5.publicstaticvoidmain(String[]args){getminiqrQr("1","xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");//第一个为参数第二个为token}}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

