功能:1.读取Excel的内容,将地址和序号生成带参数的微信小程序码
packagetest;importjava.io.BufferedInputStream;importjava.io.BufferedReader;importjava.io.DataOutputStream;importjava.io.File;importjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.InputStream;importjava.io.InputStreamReader;importjava.io.OutputStream;importjava.io.PrintWriter;importjava.net.HttpURLConnection;importjava.net.URL;importjava.net.URLConnection;importjava.util.ArrayList;importjava.util.List;importorg.apache.poi.hssf.usermodel.HSSFWorkbook;importorg.apache.poi.ss.usermodel.Cell;importorg.apache.poi.ss.usermodel.Row;importorg.apache.poi.ss.usermodel.Sheet;importorg.apache.poi.ss.usermodel.Workbook;importorg.apache.poi.ss.usermodel.WorkbookFactory;importorg.apache.poi.xssf.usermodel.XSSFWorkbook;importcom.alibaba.fastjson.JSONObject;publicclasswxma{publicstaticvoidmain(String[]args)throwsException{//excel文件路径StringexcelPath"C:/Users/Administrator/Desktop/wxCodes.xlsx";Stringtokenwxma.postToken();ListStringlistswxma.getCode(excelPath);if(lists!null){for(Stringitem:lists){wxma.getminiqrQr(item,token,"C:/Users/Administrator/Desktop/code/"+item+".png");System.out.print(item+"");}}else{System.out.println("是空没事干");}}publicstaticListgetCode(StringexcelPath){ListStringdatanewArrayListString();InputStreamisnull;Workbookwbnull;try{//excel文件路径FileexcelnewFile(excelPath);if(excel.isFile()excel.exists()){//判断文件是否存在String[]splitexcel.getName().split("\.");//.是特殊字符,需要转义!!!!!//根据文件后缀(xls/xlsx)进行判断if("xls".equals(split[1])){isnewFileInputStream(excelPath);wbWorkbookFactory.create(is);}elseif("xlsx".equals(split[1])){isnewFileInputStream(excelPath);wbWorkbookFactory.create(is);}else{System.out.println("文件类型错误!");returnnull;}//开始解析Sheetsheetwb.getSheetAt(1);//读取sheet0intfirstRowIndexsheet.getFirstRowNum()+1;//第一行是列名,所以不读intlastRowIndexsheet.getLastRowNum();for(intrIndexfirstRowIndex;rIndexlastRowIndex;rIndex++){//遍历行Rowrowsheet.getRow(rIndex);if(row!null){intfirstCellIndexrow.getFirstCellNum();intlastCellIndexrow.getLastCellNum();Stringterminal"";for(intcIndexfirstCellIndex;cIndexlastCellIndex;cIndex++){//遍历列Cellcellrow.getCell(cIndex);if(cell!null){if(cIndex0){terminalcell.toString();}if(cIndex1){data.add(terminal+cell.toString());}}}}}}else{System.out.println("找不到指定的文件");}}catch(Exceptione){e.printStackTrace();}returndata;}/***用于获取access_token*@paramparams*@paramAPIKEY小程序id*@paramSECRETKEY小程序密钥*@returnaccess_token*@throwsException*/publicstaticStringpostToken()throwsException{StringAPIKEY"";//小程序idStringSECRETKEY"";//小程序密钥StringrequestUrl"https://api.weixin.qq.com/cgi-bin/token?grant_typeclient_credentialappid"+APIKEY+"secret"+SECRETKEY;URLurlnewURL(requestUrl);//打开和URL之间的连接HttpURLConnectionconnection(HttpURLConnection)url.openConnection();connection.setRequestMethod("POST");//设置通用的请求属性connection.setRequestProperty("Content-Type","application/json");connection.setRequestProperty("Connection","Keep-Alive");connection.setUseCaches(false);connection.setDoOutput(true);connection.setDoInput(true);//得到请求的输出流对象DataOutputStreamoutnewDataOutputStream(connection.getOutputStream());out.writeBytes("");out.flush();out.close();//建立实际的连接connection.connect();//定义BufferedReader输入流来读取URL的响应BufferedReaderinnull;if(requestUrl.contains("nlp"))innewBufferedReader(newInputStreamReader(connection.getInputStream(),"GBK"));elseinnewBufferedReader(newInputStreamReader(connection.getInputStream(),"UTF-8"));Stringresult"";StringgetLine;while((getLinein.readLine())!null){result+getLine;}in.close();JSONObjectjsonObjectJSONObject.parseObject(result);StringaccesstokenjsonObject.getString("access_token");returnaccesstoken;}/***生成带参小程序二维码*@paramsceneStr参数*@paramaccessTokentoken*@paramfilePath文件路径*/publicstaticvoidgetminiqrQr(StringsceneStr,StringaccessToken,StringfilePath){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("d","123");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);**/System.out.println(paramJson.toString());printWriter.write(paramJson.toString());//flush输出流的缓冲printWriter.flush();//开始获取数据BufferedInputStreambisnewBufferedInputStream(httpURLConnection.getInputStream());OutputStreamosnewFileOutputStream(newFile(filePath));intlen;byte[]arrnewbyte[1024];while((lenbis.read(arr))!-1){os.write(arr,0,len);os.flush();}os.close();}catch(Exceptione){e.printStackTrace();}}}2.生成的微信小程序码:
使用Excel批量生成微信小程序码-如何将excel转成微信小程序-微信小程序生成器
浏览量:6155
时间:
来源:改天
版权声明
即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

最新资讯
-
抖音再现本地生活服务,咫尺同城圈商业变现新通道
短视频成为本地生活探店网红营销变现引流的新阵地,每一位网红都渴望在短视频内“一夜爆红”。即速应用团队对多商家小程序进行升级,打造了咫尺同城圈:“同城探店营销助手”,不仅完善商家营销技巧,还助力探店网红玩转本地生活服务。 -
抖音再现本地生活服务,咫尺同城圈商业变现新通道
短视频成为本地生活探店网红营销变现引流的新阵地,每一位网红都渴望在短视频内“一夜爆红”。即速应用团队对多商家小程序进行升级,打造了咫尺同城圈:“同城探店营销助手”,不仅完善商家营销技巧,还助力探店网红玩转本地生活服务。 -
阿坝小程序代理
阿坝藏族羌族小程序代理公司有哪些?阿坝藏族羌族小程序代理平台哪个好?阿坝藏族羌族小程序代理商怎么收费,代理政策如何?下面就让即速应用产品经理jisuapp.cn来告诉你吧!