This commit is contained in:
LingZhaoHui 2020-10-08 21:06:48 +08:00
parent df67bbd1d3
commit eb6157c48f
12 changed files with 102 additions and 43 deletions

32
.classpath Normal file
View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

23
.project Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>blog-weixin</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,5 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8

View File

@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@ -2,5 +2,5 @@
# 项目编译启动脚本
mvn clean
mvn install -Dmaven.test.skip=true
mvn install -e -Dmaven.test.skip=true

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.zeekling</groupId>
<artifactId>solo-weixin</artifactId>
<artifactId>blog-weixin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

View File

@ -4,12 +4,12 @@ import com.zeekling.solo.wechat.conf.WeChatConfigure;
import com.zeekling.solo.wechat.entity.Validate;
import com.zeekling.solo.wechat.service.WeChatMenuService;
import com.zeekling.solo.wechat.verify.SHA1;
import me.chanjar.weixin.mp.api.WxMpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
/**
@ -21,7 +21,7 @@ import javax.annotation.Resource;
@RestController
public class WeXinController {
private Logger logger = LoggerFactory.getLogger(getClass());
private static Logger logger = LoggerFactory.getLogger(WeXinController.class);
@Resource
private WeChatConfigure weChatConfigure;
@ -29,6 +29,13 @@ public class WeXinController {
@Resource
private WeChatMenuService weChatMenuService;
@PostConstruct
public void init() {
logger.info("开始初始化菜单");
this.createMenu();
logger.info("初始化菜单成功");
}
@RequestMapping(value = "/validate")
public String validate(Validate validate) {
String token = weChatConfigure.getToken();

View File

@ -2,8 +2,6 @@ package com.zeekling.solo.wechat.service;
import com.zeekling.solo.wechat.conf.WeChatConfigure;
import com.zeekling.solo.wechat.util.FileUtils;
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.bean.menu.WxMenuButton;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.json.JSONArray;
@ -12,12 +10,8 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
@ -55,7 +49,8 @@ public class WeChatMenuServiceImpl implements WeChatMenuService {
JSONArray buttonArray = menuInfo.getJSONArray("button");
if (buttonArray == null || buttonArray.length() == 0){
return "{}";
}
}
System.out.println(menuInfo);
return this.wxMpService.getMenuService().menuCreate(menuInfo.toString());
} catch (JSONException | WxErrorException e) {
LOG.warn("error in create menu, error:{}", e);

View File

@ -27,7 +27,8 @@ public final class FileUtils {
* @param filePath 文件地址
* @return 文件内容
*/
public static String readFile(String filePath) {
@SuppressWarnings("resource")
public static String readFile(String filePath) {
StrBuilder sb = new StrBuilder();
byte[] buffer = new byte[1024];
try {

View File

@ -1,10 +1,9 @@
server.port=9090
logging.file=/home/zeek/project/solo-weixin/logs/weixin.log
# 公众号配置(必填)
wx.mp.appId=wxa1de154d148ffc9e
wx.mp.secret=3b988f265ea9d5056657b5f5fc3ad566
wx.mp.token=zeekling
wx.mp.aesKey=MhHpsysI44QIZkEPTiIvTf96XbEJY3QAGUHyxF1Vp9W
menu.file_path = /home/zeek/project/solo-weixin/src/main/resources/menu.json
menu.file_path = /home/zeek/project/blog-weixin/src/main/resources/menu.json

View File

@ -10,14 +10,23 @@
},
{
"type":"view",
"name":"搜索",
"url":"https://www.zeekling.cn/search"
"name":"机器学习算法",
"url":"https://www.zeekling.cn/category/ml"
},
{
"type":"view",
"name":"登录",
"url":"https://www.zeekling.cn/start"
"name":"读书+追剧",
"url":"https://www.zeekling.cn/category/read"
},
{
"type":"view",
"name":"大数据",
"url":"https://www.zeekling.cn/category/big_data"
},
{
"type":"view",
"name":"搜索",
"url":"https://www.zeekling.cn/search"
}
]
@ -30,30 +39,6 @@
"url":"https://git.zeekling.cn/zeekling"
}
]
},{
"name":"私人图床",
"sub_button":[
{
"name":"二次元",
"type":"view",
"url":"https://img.zeekling.cn/album/18g"
},
{
"name":"厦门",
"type":"view",
"url":"https://img.zeekling.cn/album/kt6"
},
{
"name":"我的图片",
"type":"view",
"url":"https://img.zeekling.cn/album/bCG"
},
{
"name":"壁纸",
"type":"view",
"url":"https://img.zeekling.cn/album/p7Z"
}
]
}
]
}