From f7b0d48c2862bdf21a0d0b6c7769a9457cfefc10 Mon Sep 17 00:00:00 2001 From: limqhz Date: Tue, 20 Oct 2020 21:39:58 +0800 Subject: [PATCH] init project --- .gitignore | 33 ++ bootstrap/pom.xml | 57 +++ .../src/main/java/com/qn/DemoApplication.java | 13 + .../src/main/resources/application.properties | 23 + common/pom.xml | 22 + .../src/main/java/com/qn/utils/HTTPUtils.java | 154 +++++++ .../src/main/java/com/qn/utils/SignUtils.java | 75 ++++ .../src/main/java/model/wx/TextMessage.java | 63 +++ dal/pom.xml | 52 +++ dal/src/main/java/com/qn/entity/User.java | 54 +++ .../main/java/com/qn/entity/UserExample.java | 410 ++++++++++++++++++ .../main/java/com/qn/mapper/UserMapper.java | 36 ++ dal/src/main/resources/generatorConfig.xml | 101 +++++ .../resources/mybatis/mapper/UserMapper.xml | 241 ++++++++++ .../main/resources/mybatis/mybatis-config.xml | 24 + docker/Dockerfile | 8 + docker/run.sh | 1 + pom.xml | 83 ++++ web/pom.xml | 52 +++ .../com/qn/controller/HomeController.java | 29 ++ .../com/qn/controller/TestController.java | 33 ++ .../com/qn/controller/WXTokenController.java | 75 ++++ .../com/qn/controller/utils/MessageUtils.java | 69 +++ 23 files changed, 1708 insertions(+) create mode 100644 .gitignore create mode 100644 bootstrap/pom.xml create mode 100644 bootstrap/src/main/java/com/qn/DemoApplication.java create mode 100644 bootstrap/src/main/resources/application.properties create mode 100644 common/pom.xml create mode 100644 common/src/main/java/com/qn/utils/HTTPUtils.java create mode 100644 common/src/main/java/com/qn/utils/SignUtils.java create mode 100644 common/src/main/java/model/wx/TextMessage.java create mode 100644 dal/pom.xml create mode 100644 dal/src/main/java/com/qn/entity/User.java create mode 100644 dal/src/main/java/com/qn/entity/UserExample.java create mode 100644 dal/src/main/java/com/qn/mapper/UserMapper.java create mode 100644 dal/src/main/resources/generatorConfig.xml create mode 100644 dal/src/main/resources/mybatis/mapper/UserMapper.xml create mode 100644 dal/src/main/resources/mybatis/mybatis-config.xml create mode 100644 docker/Dockerfile create mode 100644 docker/run.sh create mode 100644 pom.xml create mode 100644 web/pom.xml create mode 100644 web/src/main/java/com/qn/controller/HomeController.java create mode 100644 web/src/main/java/com/qn/controller/TestController.java create mode 100644 web/src/main/java/com/qn/controller/WXTokenController.java create mode 100644 web/src/main/java/com/qn/controller/utils/MessageUtils.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml new file mode 100644 index 0000000..c563ea1 --- /dev/null +++ b/bootstrap/pom.xml @@ -0,0 +1,57 @@ + + + + forever + com.love.qn + 1.0.0 + + 4.0.0 + + bootstrap + + + + com.love.qn + web + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + ../target/boot + executable + + + + + repackage + + + + + + + + \ No newline at end of file diff --git a/bootstrap/src/main/java/com/qn/DemoApplication.java b/bootstrap/src/main/java/com/qn/DemoApplication.java new file mode 100644 index 0000000..ece70be --- /dev/null +++ b/bootstrap/src/main/java/com/qn/DemoApplication.java @@ -0,0 +1,13 @@ +package com.qn; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DemoApplication { + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } + +} diff --git a/bootstrap/src/main/resources/application.properties b/bootstrap/src/main/resources/application.properties new file mode 100644 index 0000000..891c56b --- /dev/null +++ b/bootstrap/src/main/resources/application.properties @@ -0,0 +1,23 @@ +server.port=8088 + + +mybatis.config-locations=classpath:mybatis/mybatis-config.xml +mybatis.mapper-locations=classpath:mybatis/mapper/*.xml + +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.datasource.druid.filters=stat +spring.datasource.druid.initialSize=1 +spring.datasource.druid.minIdle=1 +spring.datasource.druid.maxActive=40 +spring.datasource.druid.maxWait=600000 +spring.datasource.druid.timeBetweenEvictionRunsMillis=60000 +spring.datasource.druid.minEvictableIdleTimeMillis=300000 +spring.datasource.druid.testWhileIdle=true +spring.datasource.druid.testOnBorrow=false +spring.datasource.druid.testOnReturn=false +spring.datasource.druid.poolPreparedStatements=true +spring.datasource.druid.maxPoolPreparedStatementPerConnectionSize=20 + +spring.datasource.url=jdbc:mysql://127.0.0.1:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true&useSSL=false +spring.datasource.username=root +spring.datasource.password=123456 \ No newline at end of file diff --git a/common/pom.xml b/common/pom.xml new file mode 100644 index 0000000..d4f9194 --- /dev/null +++ b/common/pom.xml @@ -0,0 +1,22 @@ + + + + forever + com.love.qn + 1.0.0 + ../pom.xml + + 4.0.0 + ${version} + common + + + + org.apache.httpcomponents + httpclient + + + + \ No newline at end of file diff --git a/common/src/main/java/com/qn/utils/HTTPUtils.java b/common/src/main/java/com/qn/utils/HTTPUtils.java new file mode 100644 index 0000000..d0bf490 --- /dev/null +++ b/common/src/main/java/com/qn/utils/HTTPUtils.java @@ -0,0 +1,154 @@ +package com.qn.utils; + +import org.apache.http.NameValuePair; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.util.EntityUtils; +import java.io.IOException; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class HTTPUtils { + + public static String doGet(String url, Map param) { + // 创建Httpclient对象 + CloseableHttpClient httpclient = HttpClients.createDefault(); + String resultString = ""; + CloseableHttpResponse response = null; + try { + // 创建uri + URIBuilder builder = new URIBuilder(url); + if (param != null) { + for (String key : param.keySet()) { + builder.addParameter(key, param.get(key)); + } + } + URI uri = builder.build(); + // 创建http GET请求 + HttpGet httpGet = new HttpGet(uri); + // 执行请求 + response = httpclient.execute(httpGet); + // 判断返回状态是否为200 + if (response.getStatusLine().getStatusCode() == 200) { + resultString = EntityUtils.toString(response.getEntity(), "UTF-8"); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (response != null) { + response.close(); + } + httpclient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return resultString; + } + + public static String doGet(String url) { + return doGet(url, null); + } + + public static String doPost(String url, Map param) { + // 创建Httpclient对象 + CloseableHttpClient httpClient = HttpClients.createDefault(); + CloseableHttpResponse response = null; + String resultString = ""; + try { + // 创建Http Post请求 + HttpPost httpPost = new HttpPost(url); + // 创建参数列表 + if (param != null) { + List paramList = new ArrayList<>(); + for (String key : param.keySet()) { + paramList.add(new BasicNameValuePair(key, param.get(key))); + } + // 模拟表单 + UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList,"utf-8"); + httpPost.setEntity(entity); + } + // 执行http请求 + response = httpClient.execute(httpPost); + resultString = EntityUtils.toString(response.getEntity(), "utf-8"); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + response.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return resultString; + } + + public static String doPost(String url) { + return doPost(url, null); + } + + public static String doPostJson(String url, String json) { + // 创建Httpclient对象 + CloseableHttpClient httpClient = HttpClients.createDefault(); + CloseableHttpResponse response = null; + String resultString = ""; + try { + // 创建Http Post请求 + HttpPost httpPost = new HttpPost(url); + // 创建请求内容 + StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON); + httpPost.setEntity(entity); + // 执行http请求 + response = httpClient.execute(httpPost); + resultString = EntityUtils.toString(response.getEntity(), "utf-8"); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + response.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + return resultString; + } + + public static String doPostXml(String url, String json) { + // 创建Httpclient对象 + CloseableHttpClient httpClient = HttpClients.createDefault(); + CloseableHttpResponse response = null; + String resultString = ""; + try { + // 创建Http Post请求 + HttpPost httpPost = new HttpPost(url); + // 创建请求内容 + StringEntity entity = new StringEntity(json, ContentType.APPLICATION_XML); + httpPost.setEntity(entity); + // 执行http请求 + response = httpClient.execute(httpPost); + resultString = EntityUtils.toString(response.getEntity(), "utf-8"); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + response.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return resultString; + } + +} diff --git a/common/src/main/java/com/qn/utils/SignUtils.java b/common/src/main/java/com/qn/utils/SignUtils.java new file mode 100644 index 0000000..e9030e2 --- /dev/null +++ b/common/src/main/java/com/qn/utils/SignUtils.java @@ -0,0 +1,75 @@ +package com.qn.utils; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; + +public class SignUtils { + + private static String token = "wxTokenfromqnforever";//这里是自定义的token,需和你提交的token一致 + + /** + * 校验签名 + * + * @param signature + * 签名 + * @param timestamp + * 时间戳 + * @param nonce + * 随机数 + * @return 布尔值 + */ + public static boolean checkSignature(String signature, String timestamp, String nonce) { + String checktext = null; + if (null != signature) { + // 对ToKen,timestamp,nonce 按字典排序 + String[] paramArr = new String[] { token, timestamp, nonce }; + Arrays.sort(paramArr); + // 将排序后的结果拼成一个字符串 + String content = paramArr[0].concat(paramArr[1]).concat(paramArr[2]); + + try { + MessageDigest md = MessageDigest.getInstance("SHA-1"); + // 对接后的字符串进行sha1加密 + byte[] digest = md.digest(content.toString().getBytes()); + checktext = byteToStr(digest); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + } + // 将加密后的字符串与signature进行对比 + return checktext != null ? checktext.equals(signature.toUpperCase()) : false; + } + + /** + * 将字节数组转化为16进制字符串 + * + * @param byteArrays + * 字符数组 + * @return 字符串 + */ + private static String byteToStr(byte[] byteArrays) { + String str = ""; + for (int i = 0; i < byteArrays.length; i++) { + str += byteToHexStr(byteArrays[i]); + } + return str; + } + + /** + * 将字节转化为十六进制字符串 + * + * @param myByte + * 字节 + * @return 字符串 + */ + private static String byteToHexStr(byte myByte) { + char[] Digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + char[] tampArr = new char[2]; + tampArr[0] = Digit[(myByte >>> 4) & 0X0F]; + tampArr[1] = Digit[myByte & 0X0F]; + String str = new String(tampArr); + return str; + } + +} \ No newline at end of file diff --git a/common/src/main/java/model/wx/TextMessage.java b/common/src/main/java/model/wx/TextMessage.java new file mode 100644 index 0000000..96f298b --- /dev/null +++ b/common/src/main/java/model/wx/TextMessage.java @@ -0,0 +1,63 @@ +package model.wx; + +import java.io.Serializable; + +public class TextMessage implements Serializable { + private String ToUserName; + + private String FromUserName; + + private Long CreateTime; + + private String MsgType; + private String Content; + private String MsgId; + + public String getToUserName() { + return ToUserName; + } + + public void setToUserName(String toUserName) { + ToUserName = toUserName; + } + + public String getFromUserName() { + return FromUserName; + } + + public void setFromUserName(String fromUserName) { + FromUserName = fromUserName; + } + + public Long getCreateTime() { + return CreateTime; + } + + public void setCreateTime(Long createTime) { + CreateTime = createTime; + } + + public String getMsgType() { + return MsgType; + } + + public void setMsgType(String msgType) { + MsgType = msgType; + } + + public String getContent() { + return Content; + } + + public void setContent(String content) { + Content = content; + } + + public String getMsgId() { + return MsgId; + } + + public void setMsgId(String msgId) { + MsgId = msgId; + } +} diff --git a/dal/pom.xml b/dal/pom.xml new file mode 100644 index 0000000..e9ffd77 --- /dev/null +++ b/dal/pom.xml @@ -0,0 +1,52 @@ + + + + forever + com.love.qn + 1.0.0 + + 4.0.0 + dal + ${version} + + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 1.3.2 + + + mysql + mysql-connector-java + 5.1.41 + + + + + + + org.mybatis.generator + mybatis-generator-maven-plugin + 1.3.2 + + true + true + src/main/resources/generatorConfig.xml + + + + + mysql + mysql-connector-java + 5.1.41 + runtime + + + + + + + \ No newline at end of file diff --git a/dal/src/main/java/com/qn/entity/User.java b/dal/src/main/java/com/qn/entity/User.java new file mode 100644 index 0000000..93f0781 --- /dev/null +++ b/dal/src/main/java/com/qn/entity/User.java @@ -0,0 +1,54 @@ +package com.qn.entity; + +public class User { + private String openid; + + private String username; + + private String phone; + + private String avatarUrl; + + public User(String openid, String username, String phone, String avatarUrl) { + this.openid = openid; + this.username = username; + this.phone = phone; + this.avatarUrl = avatarUrl; + } + + public User() { + super(); + } + + public String getOpenid() { + return openid; + } + + public void setOpenid(String openid) { + this.openid = openid == null ? null : openid.trim(); + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username == null ? null : username.trim(); + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone == null ? null : phone.trim(); + } + + public String getAvatarUrl() { + return avatarUrl; + } + + public void setAvatarUrl(String avatarUrl) { + this.avatarUrl = avatarUrl == null ? null : avatarUrl.trim(); + } +} \ No newline at end of file diff --git a/dal/src/main/java/com/qn/entity/UserExample.java b/dal/src/main/java/com/qn/entity/UserExample.java new file mode 100644 index 0000000..7a83900 --- /dev/null +++ b/dal/src/main/java/com/qn/entity/UserExample.java @@ -0,0 +1,410 @@ +package com.qn.entity; + +import java.util.ArrayList; +import java.util.List; + +public class UserExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + public UserExample() { + oredCriteria = new ArrayList(); + } + + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + public String getOrderByClause() { + return orderByClause; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + public boolean isDistinct() { + return distinct; + } + + public List getOredCriteria() { + return oredCriteria; + } + + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + protected abstract static class GeneratedCriteria { + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andOpenidIsNull() { + addCriterion("openid is null"); + return (Criteria) this; + } + + public Criteria andOpenidIsNotNull() { + addCriterion("openid is not null"); + return (Criteria) this; + } + + public Criteria andOpenidEqualTo(String value) { + addCriterion("openid =", value, "openid"); + return (Criteria) this; + } + + public Criteria andOpenidNotEqualTo(String value) { + addCriterion("openid <>", value, "openid"); + return (Criteria) this; + } + + public Criteria andOpenidGreaterThan(String value) { + addCriterion("openid >", value, "openid"); + return (Criteria) this; + } + + public Criteria andOpenidGreaterThanOrEqualTo(String value) { + addCriterion("openid >=", value, "openid"); + return (Criteria) this; + } + + public Criteria andOpenidLessThan(String value) { + addCriterion("openid <", value, "openid"); + return (Criteria) this; + } + + public Criteria andOpenidLessThanOrEqualTo(String value) { + addCriterion("openid <=", value, "openid"); + return (Criteria) this; + } + + public Criteria andOpenidLike(String value) { + addCriterion("openid like", value, "openid"); + return (Criteria) this; + } + + public Criteria andOpenidNotLike(String value) { + addCriterion("openid not like", value, "openid"); + return (Criteria) this; + } + + public Criteria andOpenidIn(List values) { + addCriterion("openid in", values, "openid"); + return (Criteria) this; + } + + public Criteria andOpenidNotIn(List values) { + addCriterion("openid not in", values, "openid"); + return (Criteria) this; + } + + public Criteria andOpenidBetween(String value1, String value2) { + addCriterion("openid between", value1, value2, "openid"); + return (Criteria) this; + } + + public Criteria andOpenidNotBetween(String value1, String value2) { + addCriterion("openid not between", value1, value2, "openid"); + return (Criteria) this; + } + + public Criteria andUsernameIsNull() { + addCriterion("username is null"); + return (Criteria) this; + } + + public Criteria andUsernameIsNotNull() { + addCriterion("username is not null"); + return (Criteria) this; + } + + public Criteria andUsernameEqualTo(String value) { + addCriterion("username =", value, "username"); + return (Criteria) this; + } + + public Criteria andUsernameNotEqualTo(String value) { + addCriterion("username <>", value, "username"); + return (Criteria) this; + } + + public Criteria andUsernameGreaterThan(String value) { + addCriterion("username >", value, "username"); + return (Criteria) this; + } + + public Criteria andUsernameGreaterThanOrEqualTo(String value) { + addCriterion("username >=", value, "username"); + return (Criteria) this; + } + + public Criteria andUsernameLessThan(String value) { + addCriterion("username <", value, "username"); + return (Criteria) this; + } + + public Criteria andUsernameLessThanOrEqualTo(String value) { + addCriterion("username <=", value, "username"); + return (Criteria) this; + } + + public Criteria andUsernameLike(String value) { + addCriterion("username like", value, "username"); + return (Criteria) this; + } + + public Criteria andUsernameNotLike(String value) { + addCriterion("username not like", value, "username"); + return (Criteria) this; + } + + public Criteria andUsernameIn(List values) { + addCriterion("username in", values, "username"); + return (Criteria) this; + } + + public Criteria andUsernameNotIn(List values) { + addCriterion("username not in", values, "username"); + return (Criteria) this; + } + + public Criteria andUsernameBetween(String value1, String value2) { + addCriterion("username between", value1, value2, "username"); + return (Criteria) this; + } + + public Criteria andUsernameNotBetween(String value1, String value2) { + addCriterion("username not between", value1, value2, "username"); + return (Criteria) this; + } + + public Criteria andPhoneIsNull() { + addCriterion("phone is null"); + return (Criteria) this; + } + + public Criteria andPhoneIsNotNull() { + addCriterion("phone is not null"); + return (Criteria) this; + } + + public Criteria andPhoneEqualTo(String value) { + addCriterion("phone =", value, "phone"); + return (Criteria) this; + } + + public Criteria andPhoneNotEqualTo(String value) { + addCriterion("phone <>", value, "phone"); + return (Criteria) this; + } + + public Criteria andPhoneGreaterThan(String value) { + addCriterion("phone >", value, "phone"); + return (Criteria) this; + } + + public Criteria andPhoneGreaterThanOrEqualTo(String value) { + addCriterion("phone >=", value, "phone"); + return (Criteria) this; + } + + public Criteria andPhoneLessThan(String value) { + addCriterion("phone <", value, "phone"); + return (Criteria) this; + } + + public Criteria andPhoneLessThanOrEqualTo(String value) { + addCriterion("phone <=", value, "phone"); + return (Criteria) this; + } + + public Criteria andPhoneLike(String value) { + addCriterion("phone like", value, "phone"); + return (Criteria) this; + } + + public Criteria andPhoneNotLike(String value) { + addCriterion("phone not like", value, "phone"); + return (Criteria) this; + } + + public Criteria andPhoneIn(List values) { + addCriterion("phone in", values, "phone"); + return (Criteria) this; + } + + public Criteria andPhoneNotIn(List values) { + addCriterion("phone not in", values, "phone"); + return (Criteria) this; + } + + public Criteria andPhoneBetween(String value1, String value2) { + addCriterion("phone between", value1, value2, "phone"); + return (Criteria) this; + } + + public Criteria andPhoneNotBetween(String value1, String value2) { + addCriterion("phone not between", value1, value2, "phone"); + return (Criteria) this; + } + } + + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} \ No newline at end of file diff --git a/dal/src/main/java/com/qn/mapper/UserMapper.java b/dal/src/main/java/com/qn/mapper/UserMapper.java new file mode 100644 index 0000000..fb71837 --- /dev/null +++ b/dal/src/main/java/com/qn/mapper/UserMapper.java @@ -0,0 +1,36 @@ +package com.qn.mapper; + +import com.qn.entity.User; +import com.qn.entity.UserExample; +import java.util.List; +import org.apache.ibatis.annotations.Param; + +public interface UserMapper { + int countByExample(UserExample example); + + int deleteByExample(UserExample example); + + int deleteByPrimaryKey(String openid); + + int insert(User record); + + int insertSelective(User record); + + List selectByExampleWithBLOBs(UserExample example); + + List selectByExample(UserExample example); + + User selectByPrimaryKey(String openid); + + int updateByExampleSelective(@Param("record") User record, @Param("example") UserExample example); + + int updateByExampleWithBLOBs(@Param("record") User record, @Param("example") UserExample example); + + int updateByExample(@Param("record") User record, @Param("example") UserExample example); + + int updateByPrimaryKeySelective(User record); + + int updateByPrimaryKeyWithBLOBs(User record); + + int updateByPrimaryKey(User record); +} \ No newline at end of file diff --git a/dal/src/main/resources/generatorConfig.xml b/dal/src/main/resources/generatorConfig.xml new file mode 100644 index 0000000..c46c053 --- /dev/null +++ b/dal/src/main/resources/generatorConfig.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
\ No newline at end of file diff --git a/dal/src/main/resources/mybatis/mapper/UserMapper.xml b/dal/src/main/resources/mybatis/mapper/UserMapper.xml new file mode 100644 index 0000000..39ddc62 --- /dev/null +++ b/dal/src/main/resources/mybatis/mapper/UserMapper.xml @@ -0,0 +1,241 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + openid, username, phone + + + avatar_url + + + + + + delete from tb_gw_user + where openid = #{openid,jdbcType=VARCHAR} + + + delete from tb_gw_user + + + + + + insert into tb_gw_user (openid, username, phone, + avatar_url) + values (#{openid,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, + #{avatarUrl,jdbcType=LONGVARCHAR}) + + + insert into tb_gw_user + + + openid, + + + username, + + + phone, + + + avatar_url, + + + + + #{openid,jdbcType=VARCHAR}, + + + #{username,jdbcType=VARCHAR}, + + + #{phone,jdbcType=VARCHAR}, + + + #{avatarUrl,jdbcType=LONGVARCHAR}, + + + + + + update tb_gw_user + + + openid = #{record.openid,jdbcType=VARCHAR}, + + + username = #{record.username,jdbcType=VARCHAR}, + + + phone = #{record.phone,jdbcType=VARCHAR}, + + + avatar_url = #{record.avatarUrl,jdbcType=LONGVARCHAR}, + + + + + + + + update tb_gw_user + set openid = #{record.openid,jdbcType=VARCHAR}, + username = #{record.username,jdbcType=VARCHAR}, + phone = #{record.phone,jdbcType=VARCHAR}, + avatar_url = #{record.avatarUrl,jdbcType=LONGVARCHAR} + + + + + + update tb_gw_user + set openid = #{record.openid,jdbcType=VARCHAR}, + username = #{record.username,jdbcType=VARCHAR}, + phone = #{record.phone,jdbcType=VARCHAR} + + + + + + update tb_gw_user + + + username = #{username,jdbcType=VARCHAR}, + + + phone = #{phone,jdbcType=VARCHAR}, + + + avatar_url = #{avatarUrl,jdbcType=LONGVARCHAR}, + + + where openid = #{openid,jdbcType=VARCHAR} + + + update tb_gw_user + set username = #{username,jdbcType=VARCHAR}, + phone = #{phone,jdbcType=VARCHAR}, + avatar_url = #{avatarUrl,jdbcType=LONGVARCHAR} + where openid = #{openid,jdbcType=VARCHAR} + + + update tb_gw_user + set username = #{username,jdbcType=VARCHAR}, + phone = #{phone,jdbcType=VARCHAR} + where openid = #{openid,jdbcType=VARCHAR} + + \ No newline at end of file diff --git a/dal/src/main/resources/mybatis/mybatis-config.xml b/dal/src/main/resources/mybatis/mybatis-config.xml new file mode 100644 index 0000000..3eda75e --- /dev/null +++ b/dal/src/main/resources/mybatis/mybatis-config.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..e07be2f --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,8 @@ +FROM java:8 + +ADD ../target/boot/bootstrap-1.0.0-executable.jar /home +ADD run.sh /home + +EXPOSE 8088 + +ENTRYPOINT [ "sh", "/home/run.sh" ] \ No newline at end of file diff --git a/docker/run.sh b/docker/run.sh new file mode 100644 index 0000000..9ca6d65 --- /dev/null +++ b/docker/run.sh @@ -0,0 +1 @@ +java -jar /home/web-1.0.0.jar \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..b365dd4 --- /dev/null +++ b/pom.xml @@ -0,0 +1,83 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.3.3.RELEASE + + com.love.qn + forever + 1.0.0 + pom + + + 1.8 + 1.0.0 + + + + + + com.love.qn + web + ${version} + + + com.love.qn + common + ${version} + + + com.love.qn + dal + ${version} + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${java.version} + ${java.version} + + 3.3 + + + org.apache.maven.plugins + maven-surefire-plugin + 2.20 + + true + 1 + + **/*Tests.java + **/*Test.java + + + **/Abstract*.java + + + + + org.apache.maven.plugins + maven-eclipse-plugin + 2.6 + + + + + + web + common + dal + bootstrap + + + diff --git a/web/pom.xml b/web/pom.xml new file mode 100644 index 0000000..fe68744 --- /dev/null +++ b/web/pom.xml @@ -0,0 +1,52 @@ + + + + forever + com.love.qn + 1.0.0 + ../pom.xml + + 4.0.0 + web + ${version} + + + + + org.springframework.boot + spring-boot-starter-web + + + + com.love.qn + common + + + com.love.qn + dal + 1.0.0 + + + + dom4j + dom4j + 1.6.1 + + + com.thoughtworks.xstream + xstream + 1.4.4 + + + + com.github.binarywang + weixin-java-mp + 3.9.0 + provided + + + + + \ No newline at end of file diff --git a/web/src/main/java/com/qn/controller/HomeController.java b/web/src/main/java/com/qn/controller/HomeController.java new file mode 100644 index 0000000..516c4ca --- /dev/null +++ b/web/src/main/java/com/qn/controller/HomeController.java @@ -0,0 +1,29 @@ +package com.qn.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@Controller +public class HomeController { + /** + * 表白 + */ + @RequestMapping(value = "/", method = RequestMethod.GET) + public void enter(HttpServletResponse response) throws IOException { + StringBuilder sb = new StringBuilder(); + sb.append(""); + sb.append("

欢迎光临QN恋爱中!

"); + sb.append("

此网站没有网页,只为【惊喜女友的微信小程序】提供必要的后台支持,该网页为备案号专用网页。

"); + // 设置备案号 + sb.append("浙ICP备2020031991号"); + sb.append(""); + response.setStatus(200); + response.setCharacterEncoding("UTF-8"); + response.getWriter().write(sb.toString()); + response.flushBuffer(); + } +} diff --git a/web/src/main/java/com/qn/controller/TestController.java b/web/src/main/java/com/qn/controller/TestController.java new file mode 100644 index 0000000..aad78a6 --- /dev/null +++ b/web/src/main/java/com/qn/controller/TestController.java @@ -0,0 +1,33 @@ +package com.qn.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@Controller +public class TestController { + + /** + * 表白 + */ + @RequestMapping(value = "/to/{name}", method = RequestMethod.GET) + public void enter(@PathVariable("name") String name, HttpServletResponse response) throws IOException { + StringBuilder sb = new StringBuilder(); + sb.append(""); + sb.append("

"); + if (name==null || "".equals(name)){ + name = "王娜"; + } + sb.append(name); + sb.append(",I love you!!!

"); + response.setStatus(200); + response.setCharacterEncoding("UTF-8"); + response.getWriter().write(sb.toString()); + response.flushBuffer(); + } + +} diff --git a/web/src/main/java/com/qn/controller/WXTokenController.java b/web/src/main/java/com/qn/controller/WXTokenController.java new file mode 100644 index 0000000..78156a0 --- /dev/null +++ b/web/src/main/java/com/qn/controller/WXTokenController.java @@ -0,0 +1,75 @@ +package com.qn.controller; + +import com.qn.controller.utils.MessageUtils; +import com.qn.utils.SignUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Map; + +@Controller +public class WXTokenController { + + private Logger logger = LoggerFactory.getLogger("WXTokenController"); + + /** + * 微信TokenCheck + */ + @RequestMapping(value = "/wx", method = RequestMethod.GET) + public void wxTokenCheck(HttpServletRequest request, HttpServletResponse response) throws IOException { + if (!StringUtils.isEmpty(request.getParameter("signature"))) { + String signature = request.getParameter("signature"); + String timestamp = request.getParameter("timestamp"); + String nonce = request.getParameter("nonce"); + String echostr = request.getParameter("echostr"); + logger.info("signature[{}], timestamp[{}], nonce[{}], echostr[{}]", signature, timestamp, nonce, echostr); + if (SignUtils.checkSignature(signature, timestamp, nonce)) { + logger.info("数据源为微信后台,将echostr[{}]返回!", echostr); + response.getOutputStream().println(echostr); + response.flushBuffer(); + } + }else { + logger.info("不是微信请求,不操作"); + } + + } + + /** + * 微信TokenCheck + */ + @RequestMapping(value = "/wx", method = RequestMethod.POST) + public void wxMessage(HttpServletRequest request, HttpServletResponse response) throws IOException { + Map map = MessageUtils.xmlToMap(request); + StringBuilder sb = new StringBuilder(); + map.forEach((x,y) -> + sb.append(x + "===" + y + ";")); + logger.info("此次微信请求的消息内容为:" + sb.toString()); + String toUserName = map.get("ToUserName"); + String fromUserName = map.get("FromUserName"); + String msgType = map.get("MsgType"); + String content = map.get("Content"); + String message = null; +// HTTPUtils.doPost() + if ("text".equals(msgType)){ + //回复文本信息触发的消息 + message = MessageUtils.initText(toUserName,fromUserName,"text",fromUserName + "您好!" + content); + }else if ("text".equals(msgType)){ + //关注时触发的消息 + String event = map.get("Event"); + if ("subscribe".equals(event)){ + message = MessageUtils.initText(toUserName,fromUserName,"text","Welcome lmq love nn"); + } + } + logger.info("返回微信的数据为" + message); + response.setContentType("text/xml;charset=utf-8"); + response.getWriter().write(message); + response.flushBuffer(); + } +} diff --git a/web/src/main/java/com/qn/controller/utils/MessageUtils.java b/web/src/main/java/com/qn/controller/utils/MessageUtils.java new file mode 100644 index 0000000..b587834 --- /dev/null +++ b/web/src/main/java/com/qn/controller/utils/MessageUtils.java @@ -0,0 +1,69 @@ +package com.qn.controller.utils; + +import com.thoughtworks.xstream.XStream; +import model.wx.TextMessage; +import org.dom4j.Document; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; + +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class MessageUtils { + /** + * xml转Map + * @param request + * @return + */ + public static Map xmlToMap(HttpServletRequest request) { + Map map = new HashMap<>(); + SAXReader reader = new SAXReader(); + ServletInputStream in = null; + try{ + in = request.getInputStream(); + Document doc = reader.read(in); + Element root = doc.getRootElement(); + List list = root.elements(); + for (Element e: list){ + map.put(e.getName(),e.getText()); + } + in.close(); + }catch (Exception e){ + + } + return map; + } + + /** + * 文本对象转换成xml + * @param message + * @return + */ + public static String textMessageToXml(Object message){ + XStream xStream = new XStream(); + xStream.alias("xml",message.getClass()); + return xStream.toXML(message); + } + + /** + * 初始化文本信息 + * @param toUserName + * @param fromUserName + * @param msgType + * @param content + * @return + */ + public static String initText(String toUserName,String fromUserName,String msgType,String content){ + TextMessage textMessage = new TextMessage(); + textMessage.setFromUserName(toUserName); + textMessage.setToUserName(fromUserName); + textMessage.setMsgType(msgType); + textMessage.setCreateTime(new Date().getTime()); + textMessage.setContent(content); + return MessageUtils.textMessageToXml(textMessage); + } +}