当前位置: 首页 > news >正文

微信公众号开发学习

申请测试号

地址

  • 通过F12抓取体验接口权限表的HTML
    在这里插入图片描述

解析HTML

引入pom

		<dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-extra</artifactId><version>5.8.21</version></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-core</artifactId><version>5.8.21</version></dependency><dependency><groupId>io.github.biezhi</groupId><artifactId>TinyPinyin</artifactId><version>2.0.3.RELEASE</version></dependency><dependency><groupId>org.jsoup</groupId><artifactId>jsoup</artifactId><version>1.16.1</version></dependency>

代码

CellDTO

import lombok.Builder;
import lombok.Data;@Data
@Builder
public class CellDTO {private String namePY;private String nameZW;private String url;
}

HeadDTO

import lombok.Builder;
import lombok.Data;@Data
@Builder
public class HeadDTO {private String namePY;private String nameZW;
}

核心逻辑

        private static  CellDTO[][] gen(String html){Document document = Jsoup.parse(html);List<HeadDTO> headDTOList =new ArrayList<>();for (Element theadELe : document.select("thead th")) {List<String> resultFindAll = ReUtil.findAll("[\\u4e00-\\u9fa5]+", theadELe.html(), 0, new ArrayList<>());String zw=String.join("",resultFindAll);String pinyin= PinyinUtil.getFirstLetter(zw,"");headDTOList.add(HeadDTO.builder().namePY(pinyin).nameZW(zw).build());}int columnSize = headDTOList.size();Map<Integer,Integer> tdCount =new HashMap<>();Elements trs = document.select(".table_special > tbody > tr");int trTotal = trs.size();CellDTO[][] table = new CellDTO[trTotal][columnSize-2];int tdNowFixNum =0;int tdTotalFixNum =0;for (int trIndex = 0; trIndex < trs.size(); trIndex++) {Elements tds = trs.get(trIndex).select("> td ");int tdSize = tds.size();int nowTrIndex=trIndex;for (int tdIndex = 0; tdIndex < tdSize-2; tdIndex++) {if(0==tdIndex){for (Map.Entry<Integer,Integer> entry : tdCount.entrySet()) {Integer key=entry.getKey();        //获取键Integer value=entry.getValue();value=value-1;if(0==value){tdTotalFixNum--;}tdCount.put(key,value);}tdNowFixNum=tdTotalFixNum;}Element td =tds.get(tdIndex);int nowTdIndex = columnSize==tdSize?tdIndex:(tdIndex+tdTotalFixNum );String tdValue;Elements a = td.select("a");String url="";if(!a.isEmpty()){tdValue=a.html();url=a.attr("href");}  else {tdValue= td.html();}List<String> resultFindAll = ReUtil.findAll("[\\u4e00-\\u9fa5]+", tdValue, 0, new ArrayList<>());String zw=String.join("",resultFindAll);String pinyin= PinyinUtil.getFirstLetter(zw,"");CellDTO cell = CellDTO.builder().url(url).nameZW(zw).namePY(PinyinUtil.getFirstLetter(pinyin, "")).build();
//                System.out.println("> "+(trIndex+1)+" "+ (tdIndex+1)+" || "+nowTrIndex+" "+ nowTdIndex +" > "+tdNowFixNum +" : "+tdTotalFixNum + " >>  "+tdValue);if (td.hasAttr("rowspan")) {Integer trAddNum = Integer.valueOf(td.attr("rowspan"));for (int fillTrNum = nowTrIndex; fillTrNum < nowTrIndex+trAddNum; fillTrNum++) {table[fillTrNum][nowTdIndex]=cell;}tdCount.put(nowTdIndex,trAddNum);tdNowFixNum++;}else {table[nowTrIndex][nowTdIndex]=cell;}}tdTotalFixNum =tdNowFixNum;}return table;}

vm模板代码生成

wx-java-mp-spring-boot-starter

引入pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.5.15</version><relativePath/></parent><groupId>com.binarywang</groupId><artifactId>wx-java-mp-demo</artifactId><version>0.0.1-SNAPSHOT</version><name>wx mp demo</name><description>Demo project for wx mp with spring boot</description><properties><java.version>1.8</java.version><swagger.version>3.0.0</swagger.version></properties><dependencies><dependency><groupId>org.apache.velocity</groupId><artifactId>velocity-engine-core</artifactId><version>2.3</version></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-core</artifactId><version>5.8.21</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-extra</artifactId><version>5.8.21</version></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-core</artifactId><version>5.8.21</version></dependency><dependency><groupId>io.github.biezhi</groupId><artifactId>TinyPinyin</artifactId><version>2.0.3.RELEASE</version></dependency><!-- https://mvnrepository.com/artifact/org.jsoup/jsoup --><dependency><groupId>org.jsoup</groupId><artifactId>jsoup</artifactId><version>1.16.1</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>com.github.binarywang</groupId><artifactId>wx-java-mp-spring-boot-starter</artifactId><version>4.5.3.B</version></dependency><dependency><groupId>com.github.jedis-lock</groupId><artifactId>jedis-lock</artifactId><version>1.0.0</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><!-- Swagger3依赖 --><dependency><groupId>io.springfox</groupId><artifactId>springfox-boot-starter</artifactId><version>${swagger.version}</version><exclusions><exclusion><groupId>io.swagger</groupId><artifactId>swagger-models</artifactId></exclusion></exclusions></dependency><!-- 防止进入swagger页面报类型转换错误,排除3.0.0中的引用,手动增加1.6.2版本 --><dependency><groupId>io.swagger</groupId><artifactId>swagger-models</artifactId><version>1.6.2</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

配置模板

文件路径:src/main/resources/templates/Controller.java.vm

package com.binarywang.demo.wx.mp.controller;import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/${requestMapping}")
@Api(value = "${apiValue}", tags = {"${apiValue}"})
public class ${requestMappingUF}Controller {@Autowiredprivate WxMpService wxMpService;
#foreach ($data in $datas)@ApiOperation("${data.nameZW}")@GetMapping("/${data.namePY}")public Object ${data.namePY}ListFn() throws WxErrorException {return  null;}#end
}

核心代码

html 是F12抓取的页面代码 , 需要替换中文 文件目录

CellDTO[][] gen = HtmlUtils.gen(html);String key =null;List<CellDTO> data =null;TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("templates", TemplateConfig.ResourceMode.CLASSPATH));Template template = engine.getTemplate("Controller.java.vm");for (int i = 0; i <gen.length ; i++) {CellDTO cell= gen[i][1];if (key == null) {key=cell.getNamePY();data =new ArrayList<>();}if(key.equals(cell.getNamePY() ) ){data.add( gen[i][2]);}else {CODE_WRITE(gen,i,data,template);key=cell.getNamePY();data =new ArrayList<>();data.add( gen[i][2]);}}CODE_WRITE(gen,gen.length,data,template);}public static void CODE_WRITE(CellDTO[][] gen, int i , List<CellDTO> data, Template template){String py= gen[i-1][1].getNamePY();String apiValue =gen[i-1][0].getNameZW()+" - "+gen[i-1][1].getNameZW();Map<String,Object> map = new HashMap<>();map.put("datas",data);map.put("requestMapping",py);String requestMappingUF=StrUtil.upperFirst(py);map.put("requestMappingUF",requestMappingUF );map.put("apiValue",apiValue);String fileName= requestMappingUF+"Controller.java";String result = template.render(map);String filePath="文件目录\\main\\java\\com\\binarywang\\demo\\wx\\mp\\controller\\"+fileName;FileUtil.writeUtf8String(result,new File(filePath));System.out.println(result);System.out.println("  ");}
http://www.lryc.cn/news/105022.html

相关文章:

  • 【LeetCode】221.最大正方形
  • 生成模型相关算法:EM算法步骤和公式推导
  • Compose手势
  • 【雕爷学编程】Arduino动手做(177)---ESP-32 掌控板2
  • Ubuntu-文件和目录相关命令
  • 显式接口实现(C# 编程指南)
  • element-ui 图片上传 及 quillEditor富文本(图片视频上传)
  • 前端技术Vue学习笔记--002
  • 【RabbitMQ(day4)】SpringBoot整合RabbitMQ与MQ应用场景说明
  • 想了解好用的翻译pdf的软件吗?
  • docker安装nginx并配置SSL
  • 【LeetCode 算法】Reorder List 重排链表
  • MQ面试题3
  • 【Linux命令200例】patch 用于将补丁文件应用到源码中
  • 一起来学算法(邻接矩阵)
  • hadoop与HDFS交互
  • MYSQL 分区如何指定不同存储路径(多块磁盘)
  • 安全加固服务器
  • Linux 命令学习:
  • 牛客网Verilog刷题——VL54
  • 学习系统编程No.34【线程同步之信号量】
  • SolidUI社区-Snakemq 通信源码分析
  • 【大数据之Flume】四、Flume进阶之复制和多路复用、负载均衡和故障转移、聚合案例
  • 前端学习--vue2--插槽
  • 使用 Docker Compose 部署 Redis Cluster 集群,轻松搭建高可用分布式缓存
  • 在Spring Boot框架中集成 Spring Security
  • 登月再进一步:Apollo自动驾驶的里程碑
  • 嵌入式一开始该怎么学?学习单片机
  • Spring事件监听器ApplicationListener
  • 安全学习DAY10_HTTP数据包