mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-29 16:14:16 +08:00
Compare commits
69 Commits
test403
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
029e74d407 | ||
|
|
af2fbfd3bf | ||
|
|
ee608c63fc | ||
|
|
f987ce0ef6 | ||
|
|
d94e524236 | ||
|
|
a6d7918ffe | ||
|
|
485260d12a | ||
|
|
b3ac50e327 | ||
|
|
5e6708fca8 | ||
|
|
11f5cca1a2 | ||
|
|
ecf741007f | ||
|
|
5009d64f5a | ||
|
|
008a1f5c5e | ||
|
|
97e5319e0f | ||
|
|
427c713e50 | ||
|
|
9d59b2d1d3 | ||
|
|
c8dd0d6306 | ||
|
|
4f3fbc2c91 | ||
|
|
0de1ce63d9 | ||
|
|
9ccd27d9d9 | ||
|
|
2cbc843227 | ||
|
|
0bdcf031b5 | ||
|
|
529b36d9e3 | ||
|
|
4737957043 | ||
|
|
c97faf5994 | ||
|
|
8d7d7d22e4 | ||
|
|
abe2e1a125 | ||
|
|
6f11c7f965 | ||
|
|
c32a938dc7 | ||
|
|
f1e73b8945 | ||
|
|
91ba67514f | ||
|
|
179c28e31c | ||
|
|
82d61269cd | ||
|
|
3736d66e74 | ||
|
|
287d44d80c | ||
|
|
c431340294 | ||
|
|
94340aae2f | ||
|
|
595dfc8ae0 | ||
|
|
f6e8152b0f | ||
|
|
5128ce4b6f | ||
|
|
715c285a91 | ||
|
|
402dc2985e | ||
|
|
abb6b34aeb | ||
|
|
5e2ef15bac | ||
|
|
a8aef40ccc | ||
|
|
fa5e5ff6a9 | ||
|
|
3d4de0e52e | ||
|
|
06d4d115d3 | ||
|
|
b5ccd18a59 | ||
|
|
e834fdfb7b | ||
|
|
6150e5dcc1 | ||
|
|
a43ebe24c4 | ||
|
|
bd8e78b196 | ||
|
|
1e18bc3179 | ||
|
|
81a52327fe | ||
|
|
6737dc0e7a | ||
|
|
4f6b13c0df | ||
|
|
2493153bdf | ||
|
|
83c68f7fed | ||
|
|
7624dd84c6 | ||
|
|
a4dea5a21c | ||
|
|
850e45a2d8 | ||
|
|
035d07e7b4 | ||
|
|
496827b152 | ||
|
|
9e77961666 | ||
|
|
e929c69fdb | ||
|
|
b4065be9e1 | ||
|
|
89f3c5cbca | ||
|
|
05ea96bd9b |
15
.editorconfig
Normal file
15
.editorconfig
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
[*]
|
||||||
|
charset=utf-8
|
||||||
|
end_of_line=lf
|
||||||
|
trim_trailing_whitespace=true
|
||||||
|
insert_final_newline=true
|
||||||
|
indent_style=space
|
||||||
|
indent_size=4
|
||||||
|
|
||||||
|
[*.json]
|
||||||
|
indent_style=space
|
||||||
|
indent_size=2
|
||||||
|
|
||||||
|
[{*.ddl,*.sql}]
|
||||||
|
indent_style=space
|
||||||
|
indent_size=2
|
||||||
9
.gitignore
vendored
9
.gitignore
vendored
@@ -1,13 +1,4 @@
|
|||||||
/buildNumber.properties
|
|
||||||
/docs
|
/docs
|
||||||
.idea/
|
.idea/
|
||||||
out/
|
|
||||||
/.metadata/
|
|
||||||
/web/META-INF/context.xml
|
|
||||||
*.iml
|
*.iml
|
||||||
~*
|
|
||||||
.DS_Store
|
|
||||||
.classpath
|
|
||||||
/target
|
/target
|
||||||
/src/main/webapp/META-INF/context.xml
|
|
||||||
.project
|
|
||||||
165
LICENSE
Normal file
165
LICENSE
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
|
||||||
|
This version of the GNU Lesser General Public License incorporates
|
||||||
|
the terms and conditions of version 3 of the GNU General Public
|
||||||
|
License, supplemented by the additional permissions listed below.
|
||||||
|
|
||||||
|
0. Additional Definitions.
|
||||||
|
|
||||||
|
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||||
|
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||||
|
General Public License.
|
||||||
|
|
||||||
|
"The Library" refers to a covered work governed by this License,
|
||||||
|
other than an Application or a Combined Work as defined below.
|
||||||
|
|
||||||
|
An "Application" is any work that makes use of an interface provided
|
||||||
|
by the Library, but which is not otherwise based on the Library.
|
||||||
|
Defining a subclass of a class defined by the Library is deemed a mode
|
||||||
|
of using an interface provided by the Library.
|
||||||
|
|
||||||
|
A "Combined Work" is a work produced by combining or linking an
|
||||||
|
Application with the Library. The particular version of the Library
|
||||||
|
with which the Combined Work was made is also called the "Linked
|
||||||
|
Version".
|
||||||
|
|
||||||
|
The "Minimal Corresponding Source" for a Combined Work means the
|
||||||
|
Corresponding Source for the Combined Work, excluding any source code
|
||||||
|
for portions of the Combined Work that, considered in isolation, are
|
||||||
|
based on the Application, and not on the Linked Version.
|
||||||
|
|
||||||
|
The "Corresponding Application Code" for a Combined Work means the
|
||||||
|
object code and/or source code for the Application, including any data
|
||||||
|
and utility programs needed for reproducing the Combined Work from the
|
||||||
|
Application, but excluding the System Libraries of the Combined Work.
|
||||||
|
|
||||||
|
1. Exception to Section 3 of the GNU GPL.
|
||||||
|
|
||||||
|
You may convey a covered work under sections 3 and 4 of this License
|
||||||
|
without being bound by section 3 of the GNU GPL.
|
||||||
|
|
||||||
|
2. Conveying Modified Versions.
|
||||||
|
|
||||||
|
If you modify a copy of the Library, and, in your modifications, a
|
||||||
|
facility refers to a function or data to be supplied by an Application
|
||||||
|
that uses the facility (other than as an argument passed when the
|
||||||
|
facility is invoked), then you may convey a copy of the modified
|
||||||
|
version:
|
||||||
|
|
||||||
|
a) under this License, provided that you make a good faith effort to
|
||||||
|
ensure that, in the event an Application does not supply the
|
||||||
|
function or data, the facility still operates, and performs
|
||||||
|
whatever part of its purpose remains meaningful, or
|
||||||
|
|
||||||
|
b) under the GNU GPL, with none of the additional permissions of
|
||||||
|
this License applicable to that copy.
|
||||||
|
|
||||||
|
3. Object Code Incorporating Material from Library Header Files.
|
||||||
|
|
||||||
|
The object code form of an Application may incorporate material from
|
||||||
|
a header file that is part of the Library. You may convey such object
|
||||||
|
code under terms of your choice, provided that, if the incorporated
|
||||||
|
material is not limited to numerical parameters, data structure
|
||||||
|
layouts and accessors, or small macros, inline functions and templates
|
||||||
|
(ten or fewer lines in length), you do both of the following:
|
||||||
|
|
||||||
|
a) Give prominent notice with each copy of the object code that the
|
||||||
|
Library is used in it and that the Library and its use are
|
||||||
|
covered by this License.
|
||||||
|
|
||||||
|
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||||
|
document.
|
||||||
|
|
||||||
|
4. Combined Works.
|
||||||
|
|
||||||
|
You may convey a Combined Work under terms of your choice that,
|
||||||
|
taken together, effectively do not restrict modification of the
|
||||||
|
portions of the Library contained in the Combined Work and reverse
|
||||||
|
engineering for debugging such modifications, if you also do each of
|
||||||
|
the following:
|
||||||
|
|
||||||
|
a) Give prominent notice with each copy of the Combined Work that
|
||||||
|
the Library is used in it and that the Library and its use are
|
||||||
|
covered by this License.
|
||||||
|
|
||||||
|
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||||
|
document.
|
||||||
|
|
||||||
|
c) For a Combined Work that displays copyright notices during
|
||||||
|
execution, include the copyright notice for the Library among
|
||||||
|
these notices, as well as a reference directing the user to the
|
||||||
|
copies of the GNU GPL and this license document.
|
||||||
|
|
||||||
|
d) Do one of the following:
|
||||||
|
|
||||||
|
0) Convey the Minimal Corresponding Source under the terms of this
|
||||||
|
License, and the Corresponding Application Code in a form
|
||||||
|
suitable for, and under terms that permit, the user to
|
||||||
|
recombine or relink the Application with a modified version of
|
||||||
|
the Linked Version to produce a modified Combined Work, in the
|
||||||
|
manner specified by section 6 of the GNU GPL for conveying
|
||||||
|
Corresponding Source.
|
||||||
|
|
||||||
|
1) Use a suitable shared library mechanism for linking with the
|
||||||
|
Library. A suitable mechanism is one that (a) uses at run time
|
||||||
|
a copy of the Library already present on the user's computer
|
||||||
|
system, and (b) will operate properly with a modified version
|
||||||
|
of the Library that is interface-compatible with the Linked
|
||||||
|
Version.
|
||||||
|
|
||||||
|
e) Provide Installation Information, but only if you would otherwise
|
||||||
|
be required to provide such information under section 6 of the
|
||||||
|
GNU GPL, and only to the extent that such information is
|
||||||
|
necessary to install and execute a modified version of the
|
||||||
|
Combined Work produced by recombining or relinking the
|
||||||
|
Application with a modified version of the Linked Version. (If
|
||||||
|
you use option 4d0, the Installation Information must accompany
|
||||||
|
the Minimal Corresponding Source and Corresponding Application
|
||||||
|
Code. If you use option 4d1, you must provide the Installation
|
||||||
|
Information in the manner specified by section 6 of the GNU GPL
|
||||||
|
for conveying Corresponding Source.)
|
||||||
|
|
||||||
|
5. Combined Libraries.
|
||||||
|
|
||||||
|
You may place library facilities that are a work based on the
|
||||||
|
Library side by side in a single library together with other library
|
||||||
|
facilities that are not Applications and are not covered by this
|
||||||
|
License, and convey such a combined library under terms of your
|
||||||
|
choice, if you do both of the following:
|
||||||
|
|
||||||
|
a) Accompany the combined library with a copy of the same work based
|
||||||
|
on the Library, uncombined with any other library facilities,
|
||||||
|
conveyed under the terms of this License.
|
||||||
|
|
||||||
|
b) Give prominent notice with the combined library that part of it
|
||||||
|
is a work based on the Library, and explaining where to find the
|
||||||
|
accompanying uncombined form of the same work.
|
||||||
|
|
||||||
|
6. Revised Versions of the GNU Lesser General Public License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the GNU Lesser General Public License from time to time. Such new
|
||||||
|
versions will be similar in spirit to the present version, but may
|
||||||
|
differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Library as you received it specifies that a certain numbered version
|
||||||
|
of the GNU Lesser General Public License "or any later version"
|
||||||
|
applies to it, you have the option of following the terms and
|
||||||
|
conditions either of that published version or of any later version
|
||||||
|
published by the Free Software Foundation. If the Library as you
|
||||||
|
received it does not specify a version number of the GNU Lesser
|
||||||
|
General Public License, you may choose any version of the GNU Lesser
|
||||||
|
General Public License ever published by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Library as you received it specifies that a proxy can decide
|
||||||
|
whether future versions of the GNU Lesser General Public License shall
|
||||||
|
apply, that proxy's public statement of acceptance of any version is
|
||||||
|
permanent authorization for you to choose that version for the
|
||||||
|
Library.
|
||||||
29
README.md
Normal file
29
README.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# WechatTicketSystem
|
||||||
|
WechatTicketSystem is a basic ticket system for network maintaining, based on Wechat.
|
||||||
|
|
||||||
|
## Build
|
||||||
|
### Requirements
|
||||||
|
- [Apache Maven](https://maven.apache.org/) (latest version recommended)
|
||||||
|
|
||||||
|
### Steps
|
||||||
|
1. Clone the git repository `git clone https://github.com/ZSCNetSupportDept/WechatTicketSystem.git`
|
||||||
|
2. Change dir to project root (where the `pom.xml` is)
|
||||||
|
3. Build with Maven `mvn clean package`
|
||||||
|
4. The out file will be in `target/` folder
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
### Code Style
|
||||||
|
The code style configuration is [here](http://stash.sola.love/projects/PSS/repos/ide_configuration/browse/intellij%20idea/Code_Style_Use_Tab.xml).
|
||||||
|
|
||||||
|
In Intellij IDEA, you can import the configuration by Settings-\>Editor-\>Code Style-\>Manage(at right side)-\>Import..
|
||||||
|
### Pull Request
|
||||||
|
Please notice that the pull requests should compare with `develop` branch instead of `master`,
|
||||||
|
submit pull requests to `master` branch will be ignored.
|
||||||
|
## TroubleShooting
|
||||||
|
- Before you report a bug, please [search the issue tracker](https://github.com/ZSCNetSupportDept/WechatTicketSystem/issues) to see if someone has already reported the problem.
|
||||||
|
- If the issue doesn’t already exist, [create a new issue](https://github.com/ZSCNetSupportDept/WechatTicketSystem/issues/new).
|
||||||
|
- Please provide as much information as possible with the issue report, we like to know the version you are using, as well as your Operating System and JVM version.
|
||||||
|
- If you need to paste code, or include a stack trace use Markdown ```` ``` ```` escapes before and after your text.
|
||||||
|
|
||||||
|
## License
|
||||||
|
WechatTicketSystem is distributed under the GNU Lesser General Public License v3.0 (LGPLv3).
|
||||||
286
pom.xml
286
pom.xml
@@ -1,162 +1,142 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
<modelVersion>4.0.0</modelVersion>
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<name>WechatTicketSystem</name>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>love.sola.netsupport</groupId>
|
<name>WechatTicketSystem</name>
|
||||||
<artifactId>WechatTicketSystem</artifactId>
|
<groupId>love.sola.netsupport</groupId>
|
||||||
<version>1.4-SNAPSHOT</version>
|
<artifactId>WechatTicketSystem</artifactId>
|
||||||
<packaging>war</packaging>
|
<version>2.2-SNAPSHOT</version>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<source>1.8</source>
|
<source>1.8</source>
|
||||||
<target>1.8</target>
|
<target>1.8</target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<scm>
|
<build>
|
||||||
<connection>scm:svn:http://127.0.0.1/dummy</connection>
|
<plugins>
|
||||||
<developerConnection>scm:svn:https://127.0.0.1/dummy</developerConnection>
|
<plugin>
|
||||||
<tag>HEAD</tag>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<url>http://127.0.0.1/dummy</url>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
</scm>
|
<version>3.3</version>
|
||||||
|
<configuration>
|
||||||
<build>
|
<source>1.8</source>
|
||||||
<plugins>
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.tomcat.maven</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>tomcat7-maven-plugin</artifactId>
|
||||||
<version>3.3</version>
|
<version>2.2</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.8</source>
|
<url>http://localhost:8080/manager/text</url>
|
||||||
<target>1.8</target>
|
<server>wwbx</server>
|
||||||
|
<path>/WechatTicketSystem</path>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
</plugins>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
</build>
|
||||||
<artifactId>buildnumber-maven-plugin</artifactId>
|
|
||||||
<version>1.4</version>
|
|
||||||
<configuration>
|
|
||||||
<format>{0,number,0000}</format>
|
|
||||||
<items>
|
|
||||||
<item>buildNumber0</item>
|
|
||||||
</items>
|
|
||||||
<doCheck>false</doCheck>
|
|
||||||
<doUpdate>false</doUpdate>
|
|
||||||
<revisionOnScmFailure>unknown</revisionOnScmFailure>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>validate</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>create</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
<finalName>${project.artifactId}##${buildNumber}</finalName>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.1.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>1.16.6</version>
|
<version>4.12</version>
|
||||||
<scope>provided</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>slf4j-simple</artifactId>
|
||||||
<version>4.12</version>
|
<version>1.7.12</version>
|
||||||
<scope>test</scope>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>com.google.guava</groupId>
|
||||||
<groupId>org.slf4j</groupId>
|
<artifactId>guava</artifactId>
|
||||||
<artifactId>slf4j-simple</artifactId>
|
<version>19.0-rc2</version>
|
||||||
<version>1.7.12</version>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>com.google.code.gson</groupId>
|
||||||
<groupId>com.google.guava</groupId>
|
<artifactId>gson</artifactId>
|
||||||
<artifactId>guava</artifactId>
|
<version>2.4</version>
|
||||||
<version>19.0-rc2</version>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.apache.commons</groupId>
|
||||||
<groupId>com.google.code.gson</groupId>
|
<artifactId>commons-io</artifactId>
|
||||||
<artifactId>gson</artifactId>
|
<version>1.3.2</version>
|
||||||
<version>2.4</version>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.apache.commons</groupId>
|
||||||
<groupId>org.apache.commons</groupId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<artifactId>commons-io</artifactId>
|
<version>3.4</version>
|
||||||
<version>1.3.2</version>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>commons-net</groupId>
|
||||||
<groupId>org.apache.commons</groupId>
|
<artifactId>commons-net</artifactId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<version>3.3</version>
|
||||||
<version>3.4</version>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>me.chanjar</groupId>
|
||||||
<groupId>commons-net</groupId>
|
<artifactId>weixin-java-mp</artifactId>
|
||||||
<artifactId>commons-net</artifactId>
|
<version>1.3.3</version>
|
||||||
<version>3.3</version>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>com.mchange</groupId>
|
||||||
<groupId>me.chanjar</groupId>
|
<artifactId>c3p0</artifactId>
|
||||||
<artifactId>weixin-java-mp</artifactId>
|
<version>0.9.5.4</version>
|
||||||
<version>1.3.3</version>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>mysql</groupId>
|
||||||
<groupId>com.mchange</groupId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
<artifactId>c3p0</artifactId>
|
<version>5.1.37</version>
|
||||||
<version>0.9.5.1</version>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.hibernate</groupId>
|
||||||
<groupId>mysql</groupId>
|
<artifactId>hibernate-core</artifactId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<version>5.0.3.Final</version>
|
||||||
<version>5.1.37</version>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.hibernate</groupId>
|
||||||
<groupId>org.hibernate</groupId>
|
<artifactId>hibernate-entitymanager</artifactId>
|
||||||
<artifactId>hibernate-core</artifactId>
|
<version>5.0.3.Final</version>
|
||||||
<version>5.0.3.Final</version>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.hibernate</groupId>
|
||||||
<groupId>org.hibernate</groupId>
|
<artifactId>hibernate-c3p0</artifactId>
|
||||||
<artifactId>hibernate-entitymanager</artifactId>
|
<version>5.0.3.Final</version>
|
||||||
<version>5.0.3.Final</version>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.hibernate.javax.persistence</groupId>
|
||||||
<groupId>org.hibernate</groupId>
|
<artifactId>hibernate-jpa-2.1-api</artifactId>
|
||||||
<artifactId>hibernate-c3p0</artifactId>
|
<version>1.0.0.Final</version>
|
||||||
<version>5.0.3.Final</version>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.hibernate</groupId>
|
||||||
<groupId>org.hibernate.javax.persistence</groupId>
|
<artifactId>hibernate-envers</artifactId>
|
||||||
<artifactId>hibernate-jpa-2.1-api</artifactId>
|
<version>5.0.3.Final</version>
|
||||||
<version>1.0.0.Final</version>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>de.svenkubiak</groupId>
|
||||||
<groupId>org.hibernate</groupId>
|
<artifactId>jBCrypt</artifactId>
|
||||||
<artifactId>hibernate-envers</artifactId>
|
<version>0.4</version>
|
||||||
<version>5.0.3.Final</version>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.yaml</groupId>
|
||||||
<groupId>de.svenkubiak</groupId>
|
<artifactId>snakeyaml</artifactId>
|
||||||
<artifactId>jBCrypt</artifactId>
|
<version>1.32</version>
|
||||||
<version>0.4</version>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.reflections</groupId>
|
||||||
<groupId>org.yaml</groupId>
|
<artifactId>reflections</artifactId>
|
||||||
<artifactId>snakeyaml</artifactId>
|
<version>0.9.10</version>
|
||||||
<version>1.16</version>
|
</dependency>
|
||||||
</dependency>
|
</dependencies>
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,37 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport;
|
package love.sola.netsupport;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.annotation.WebServlet;
|
import javax.servlet.annotation.WebServlet;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2014/8/4.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
@WebServlet(name = "Index",urlPatterns = "/index",loadOnStartup = 1)
|
@WebServlet(name = "Index", urlPatterns = "/index", loadOnStartup = 1)
|
||||||
public class Index extends HttpServlet {
|
public class Index extends HttpServlet {
|
||||||
|
|
||||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
doGet(request, response);
|
doGet(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
request.setCharacterEncoding("utf-8");
|
request.setCharacterEncoding("utf-8");
|
||||||
response.addHeader("Content-type", "text/plain;charset=utf-8");
|
response.addHeader("Content-type", "text/plain;charset=utf-8");
|
||||||
response.setCharacterEncoding("utf-8");
|
response.setCharacterEncoding("utf-8");
|
||||||
PrintWriter out = response.getWriter();
|
PrintWriter out = response.getWriter();
|
||||||
out.println("Wechat Ticket System (WTS) 0.1 Copyright 2015-2016 Sola & LiuYue all rights reserved. | Commercial license for ZSC Network Support Department (ZSCNSD).");
|
out.println("Wechat Ticket System (WTS) 0.1 Copyright 2015-2016 Sola & LiuYue all rights reserved. | Commercial license for ZSC Network Support Department (ZSCNSD).");
|
||||||
out.println("For any problem, Please contact loli@sola.love.");
|
out.println("For any problem, Please contact loli@sola.love.");
|
||||||
if (response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
|
if (response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
|
||||||
out.println("\nError 404: Page not found.");
|
out.println("\nError 404: Page not found.");
|
||||||
}
|
}
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,62 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.api;
|
package love.sola.netsupport.api;
|
||||||
|
|
||||||
import love.sola.netsupport.api.manager.GetUser;
|
import org.apache.commons.lang3.time.DateUtils;
|
||||||
import love.sola.netsupport.api.manager.TicketPush;
|
|
||||||
import love.sola.netsupport.api.root.DashBoard;
|
import java.util.Calendar;
|
||||||
import love.sola.netsupport.api.root.FlushCache;
|
import java.util.Date;
|
||||||
import love.sola.netsupport.api.root.SetPassword;
|
|
||||||
import love.sola.netsupport.api.stuff.TicketLog;
|
|
||||||
import love.sola.netsupport.api.stuff.TicketLookup;
|
|
||||||
import love.sola.netsupport.api.stuff.TicketTrack;
|
|
||||||
import love.sola.netsupport.api.stuff.TicketUpdate;
|
|
||||||
import love.sola.netsupport.api.user.ProfileModify;
|
|
||||||
import love.sola.netsupport.api.user.Register;
|
|
||||||
import love.sola.netsupport.api.user.TicketQuery;
|
|
||||||
import love.sola.netsupport.api.user.TicketSubmit;
|
|
||||||
import love.sola.netsupport.enums.Access;
|
|
||||||
import love.sola.netsupport.wechat.Command;
|
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import love.sola.netsupport.enums.Access;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
|
import love.sola.netsupport.wechat.Command;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2016/2/27.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public abstract class API {
|
public abstract class API {
|
||||||
|
|
||||||
public String url = null; //url
|
public String url = null; //url
|
||||||
public int access = Access.GOD_MODE; //operator's permission
|
public int access = Access.GOD_MODE; //operator's permission
|
||||||
public Command authorize = null; //session check
|
public Command authorize = null; //session check
|
||||||
|
|
||||||
protected abstract Object process(HttpServletRequest req, WxSession session) throws Exception;
|
protected abstract Object process(HttpServletRequest req, WxSession session) throws Exception;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getClass().getSimpleName() + "{" +
|
return getClass().getSimpleName() + "{" +
|
||||||
"url='" + url + '\'' +
|
"url='" + url + '\'' +
|
||||||
", access=" + Access.inverseMap.get(access) +
|
", access=" + Access.inverseMap.get(access) +
|
||||||
", authorize=" + authorize +
|
", authorize=" + authorize +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Class[] LIST = new Class[]{
|
public static String getParameterWithDefault(String obj, String def) {
|
||||||
GetUser.class,
|
return obj == null ? def : obj;
|
||||||
TicketPush.class,
|
}
|
||||||
DashBoard.class,
|
|
||||||
FlushCache.class,
|
public static Date getParameterAsDate(String obj, Date def) {
|
||||||
SetPassword.class,
|
return obj == null ? def : new Date(Long.valueOf(obj));
|
||||||
TicketLog.class,
|
}
|
||||||
TicketLookup.class,
|
|
||||||
TicketTrack.class,
|
public static Date getToday() {
|
||||||
TicketUpdate.class,
|
return DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH);
|
||||||
ProfileModify.class,
|
}
|
||||||
Register.class,
|
|
||||||
TicketQuery.class,
|
public static Date getDay(Date date) {
|
||||||
TicketSubmit.class,
|
return DateUtils.truncate(date, Calendar.DAY_OF_MONTH);
|
||||||
CheckSession.class
|
}
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,127 +1,155 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.api;
|
package love.sola.netsupport.api;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import love.sola.netsupport.enums.Access;
|
|
||||||
import love.sola.netsupport.enums.Attribute;
|
|
||||||
import love.sola.netsupport.pojo.Operator;
|
|
||||||
import love.sola.netsupport.pojo.User;
|
|
||||||
import love.sola.netsupport.sql.SQLCore;
|
|
||||||
import love.sola.netsupport.wechat.WechatSession;
|
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
|
import org.reflections.Reflections;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.annotation.WebServlet;
|
import javax.servlet.annotation.WebServlet;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.PrintWriter;
|
import love.sola.netsupport.enums.Access;
|
||||||
import java.text.ParseException;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import java.util.HashMap;
|
import love.sola.netsupport.pojo.Operator;
|
||||||
import java.util.Map;
|
import love.sola.netsupport.pojo.User;
|
||||||
|
import love.sola.netsupport.session.WechatSession;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
|
import love.sola.netsupport.sql.SQLCore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2016/2/27.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
@WebServlet(name = "APIRouter", urlPatterns = "/api/*", loadOnStartup = 11)
|
@WebServlet(name = "APIRouter", urlPatterns = "/api/*", loadOnStartup = 11)
|
||||||
public class APIRouter extends HttpServlet {
|
public class APIRouter extends HttpServlet {
|
||||||
|
|
||||||
protected static Gson gson = SQLCore.gson;
|
protected static Gson gson = SQLCore.gson;
|
||||||
private Map<String, API> nodes = new HashMap<>();
|
private Map<String, API> nodes = new HashMap<>();
|
||||||
|
|
||||||
public APIRouter() {
|
@Override
|
||||||
try {
|
public void init() throws ServletException {
|
||||||
// ClassPath path = ClassPath.from(getServletContext().getClassLoader());
|
super.init();
|
||||||
// Set<ClassPath.ClassInfo> classes = path.getTopLevelClasses();
|
try {
|
||||||
// for (ClassPath.ClassInfo info : classes) {
|
Reflections reflections = new Reflections(getClass().getPackage().getName());
|
||||||
for (Class<?> clz : API.LIST) {
|
Set<Class<? extends API>> set = reflections.getSubTypesOf(API.class);
|
||||||
// Class<?> clz = info.load();
|
for (Class<? extends API> clz : set) {
|
||||||
if (!API.class.equals(clz) && API.class.isAssignableFrom(clz)) {
|
try {
|
||||||
try {
|
System.out.println("Loading API: " + clz.getName());
|
||||||
System.out.print("Loading API: " + clz.getName());
|
API obj = clz.newInstance();
|
||||||
API obj = (API) clz.newInstance();
|
System.out.println("Registered API: " + obj);
|
||||||
System.out.println("Registered API: " + obj);
|
nodes.put(obj.url, obj);
|
||||||
nodes.put(obj.url, obj);
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
} catch (InstantiationException | IllegalAccessException e) {
|
e.printStackTrace();
|
||||||
e.printStackTrace();
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
} catch (Exception e) {
|
}
|
||||||
e.printStackTrace();
|
System.out.println("Total " + nodes.size() + " API(s) loaded.");
|
||||||
}
|
}
|
||||||
System.out.println("Total " + nodes.size() + " API(s) loaded.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
req.setCharacterEncoding("utf-8");
|
req.setCharacterEncoding("utf-8");
|
||||||
resp.setCharacterEncoding("utf-8");
|
resp.setCharacterEncoding("utf-8");
|
||||||
resp.addHeader("Content-type", "application/json;charset=utf-8");
|
resp.addHeader("Content-type", "application/json;charset=utf-8");
|
||||||
resp.addHeader("Access-Control-Allow-Origin", "*");
|
resp.addHeader("Access-Control-Allow-Origin", "*");
|
||||||
Object obj = null;
|
Object obj = null;
|
||||||
try {
|
try {
|
||||||
API api = nodes.get(req.getPathInfo());
|
API api = nodes.get(req.getPathInfo());
|
||||||
if (api == null) {
|
if (api == null) {
|
||||||
resp.sendError(HttpServletResponse.SC_FORBIDDEN);
|
resp.sendError(HttpServletResponse.SC_FORBIDDEN);
|
||||||
// obj = req.getPathInfo();
|
return;
|
||||||
return;
|
}
|
||||||
}
|
WxSession session = getSession(req);
|
||||||
WxSession session = getSession(req);
|
if (session == null) {
|
||||||
if (session == null) {
|
obj = Error.UNAUTHORIZED;
|
||||||
obj = Error.UNAUTHORIZED;
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if (api.authorize != null) {
|
||||||
if (api.authorize != null) {
|
if (session.getAttribute(Attribute.AUTHORIZED) != api.authorize) {
|
||||||
if (session.getAttribute(Attribute.AUTHORIZED) != api.authorize) {
|
obj = Error.UNAUTHORIZED;
|
||||||
obj = Error.UNAUTHORIZED;
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if (api.access == Access.USER) {
|
||||||
if (api.access == Access.USER) {
|
User u = session.getAttribute(Attribute.USER);
|
||||||
User u = (User) session.getAttribute(Attribute.USER);
|
if (u == null) {
|
||||||
if (u == null) {
|
obj = Error.UNAUTHORIZED;
|
||||||
obj = Error.UNAUTHORIZED;
|
return;
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
}
|
if (api.access < Access.USER) {
|
||||||
if (api.access < Access.USER) {
|
Operator op = session.getAttribute(Attribute.OPERATOR);
|
||||||
Operator op = (Operator) session.getAttribute(Attribute.OPERATOR);
|
if (op == null) {
|
||||||
if (op == null) {
|
obj = Error.UNAUTHORIZED;
|
||||||
obj = Error.UNAUTHORIZED;
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if (op.getAccess() > api.access) {
|
||||||
if (op.getAccess() > api.access) {
|
obj = Error.PERMISSION_DENIED;
|
||||||
obj = Error.PERMISSION_DENIED;
|
return;
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
obj = api.process(req, session);
|
||||||
obj = api.process(req, session);
|
} catch (ParseException | NumberFormatException e) {
|
||||||
} catch (ParseException | NumberFormatException e) {
|
obj = Error.ILLEGAL_PARAMETER;
|
||||||
obj = Error.ILLEGAL_PARAMETER;
|
} catch (HibernateException e) {
|
||||||
} catch (HibernateException e) {
|
e.printStackTrace();
|
||||||
e.printStackTrace();
|
obj = Error.DATABASE_ERROR;
|
||||||
obj = Error.DATABASE_ERROR;
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
e.printStackTrace();
|
||||||
e.printStackTrace();
|
obj = Error.INTERNAL_ERROR;
|
||||||
obj = Error.INTERNAL_ERROR;
|
} finally {
|
||||||
} finally {
|
if (!resp.isCommitted()) {
|
||||||
if (!resp.isCommitted()) {
|
try (PrintWriter out = resp.getWriter()) {
|
||||||
try (PrintWriter out = resp.getWriter()) {
|
out.println(gson.toJson(obj));
|
||||||
out.println(gson.toJson(obj));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static WxSession getSession(HttpServletRequest req) {
|
@Override
|
||||||
String t = req.getParameter("token");
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
if (t == null || t.isEmpty()) return null;
|
doGet(req, resp);
|
||||||
return WechatSession.get(t, false);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
resp.addHeader("Access-Control-Allow-Method", "POST, GET, OPTIONS");
|
||||||
|
resp.addHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static WxSession getSession(HttpServletRequest req) {
|
||||||
|
String t = req.getParameter("token");
|
||||||
|
if (t == null || t.isEmpty()) return null;
|
||||||
|
return WechatSession.get(t);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,41 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.api;
|
package love.sola.netsupport.api;
|
||||||
|
|
||||||
import love.sola.netsupport.enums.Access;
|
|
||||||
import love.sola.netsupport.enums.Attribute;
|
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import love.sola.netsupport.enums.Access;
|
||||||
|
import love.sola.netsupport.enums.Attribute;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/21.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class CheckSession extends API {
|
public class CheckSession extends API {
|
||||||
|
|
||||||
public CheckSession() {
|
public CheckSession() {
|
||||||
url = "/checksession";
|
url = "/checksession";
|
||||||
access = Access.GUEST;
|
access = Access.GUEST;
|
||||||
authorize = null;
|
authorize = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||||
String more = req.getParameter("more");
|
String more = req.getParameter("more");
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
result.put(Attribute.AUTHORIZED, session.getAttribute(Attribute.AUTHORIZED));
|
result.put(Attribute.AUTHORIZED, session.getAttribute(Attribute.AUTHORIZED));
|
||||||
if (more != null) {
|
if (more != null) {
|
||||||
switch (more) {
|
switch (more) {
|
||||||
case "1":
|
case "1":
|
||||||
result.put(Attribute.USER, session.getAttribute(Attribute.USER));
|
result.put(Attribute.USER, session.getAttribute(Attribute.USER));
|
||||||
result.put(Attribute.OPERATOR, session.getAttribute(Attribute.OPERATOR));
|
result.put(Attribute.OPERATOR, session.getAttribute(Attribute.OPERATOR));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.api;
|
package love.sola.netsupport.api;
|
||||||
|
|
||||||
import static love.sola.netsupport.config.Lang.lang;
|
import static love.sola.netsupport.config.Lang.lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/11/5.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class Error {
|
public class Error {
|
||||||
|
|
||||||
public static final Error ALREADY_SUBMITTED = new Error(1);
|
public static final Error ALREADY_SUBMITTED = new Error(1);
|
||||||
public static final Object OK = new Object();
|
public static final Object OK = new Object();
|
||||||
public static final Error PARAMETER_REQUIRED = new Error(-1);
|
public static final Error PARAMETER_REQUIRED = new Error(-1);
|
||||||
public static final Error ILLEGAL_PARAMETER = new Error(-2);
|
public static final Error ILLEGAL_PARAMETER = new Error(-2);
|
||||||
// public static final Error REQUEST_FAILED = new Error(-3); REMOVED
|
// public static final Error REQUEST_FAILED = new Error(-3); REMOVED
|
||||||
public static final Error LENGTH_LIMIT_EXCEEDED = new Error(-4);
|
public static final Error LENGTH_LIMIT_EXCEEDED = new Error(-4);
|
||||||
public static final Error INVALID_PARAMETER = new Error(-5);
|
public static final Error INVALID_PARAMETER = new Error(-5);
|
||||||
public static final Error USER_NOT_FOUND = new Error(-11);
|
public static final Error USER_NOT_FOUND = new Error(-11);
|
||||||
public static final Error TICKET_NOT_FOUND = new Error(-12);
|
public static final Error TICKET_NOT_FOUND = new Error(-12);
|
||||||
public static final Error OPERATOR_NOT_FOUND = new Error(-13);
|
public static final Error OPERATOR_NOT_FOUND = new Error(-13);
|
||||||
public static final Error UNAUTHORIZED = new Error(-20);
|
public static final Error UNAUTHORIZED = new Error(-20);
|
||||||
public static final Error WRONG_PASSWORD = new Error(-22);
|
public static final Error WRONG_PASSWORD = new Error(-22);
|
||||||
public static final Error PERMISSION_DENIED = new Error(-24);
|
public static final Error PERMISSION_DENIED = new Error(-24);
|
||||||
public static final Error INTERNAL_ERROR = new Error(-90);
|
public static final Error INTERNAL_ERROR = new Error(-90);
|
||||||
public static final Error DATABASE_ERROR = new Error(-91);
|
public static final Error DATABASE_ERROR = new Error(-91);
|
||||||
|
|
||||||
public int errCode;
|
public int errCode;
|
||||||
public String errMsg;
|
public String errMsg;
|
||||||
|
|
||||||
private Error(int code) {
|
private Error(int code) {
|
||||||
this(code, lang("ERR_" + code));
|
this(code, lang("ERR_" + code));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Error(int errCode, String errMsg) {
|
public Error(int errCode, String errMsg) {
|
||||||
this.errCode = errCode;
|
this.errCode = errCode;
|
||||||
this.errMsg = errMsg;
|
this.errMsg = errMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Error withMsg(String msg) {
|
public Error withMsg(String msg) {
|
||||||
return new Error(errCode, msg);
|
return new Error(errCode, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,93 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.api;
|
package love.sola.netsupport.api;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import love.sola.netsupport.enums.Access;
|
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import java.io.IOException;
|
||||||
import love.sola.netsupport.pojo.Operator;
|
import java.io.PrintWriter;
|
||||||
import love.sola.netsupport.pojo.User;
|
|
||||||
import love.sola.netsupport.sql.SQLCore;
|
|
||||||
import love.sola.netsupport.sql.TableOperator;
|
|
||||||
import love.sola.netsupport.sql.TableUser;
|
|
||||||
import love.sola.netsupport.util.Crypto;
|
|
||||||
import love.sola.netsupport.util.ParseUtil;
|
|
||||||
import love.sola.netsupport.util.RSAUtil;
|
|
||||||
import love.sola.netsupport.wechat.Command;
|
|
||||||
import love.sola.netsupport.wechat.WechatSession;
|
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.annotation.WebServlet;
|
import javax.servlet.annotation.WebServlet;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.PrintWriter;
|
import love.sola.netsupport.enums.Access;
|
||||||
|
import love.sola.netsupport.enums.Attribute;
|
||||||
|
import love.sola.netsupport.pojo.Operator;
|
||||||
|
import love.sola.netsupport.pojo.User;
|
||||||
|
import love.sola.netsupport.session.WechatSession;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
|
import love.sola.netsupport.sql.SQLCore;
|
||||||
|
import love.sola.netsupport.sql.TableOperator;
|
||||||
|
import love.sola.netsupport.sql.TableUser;
|
||||||
|
import love.sola.netsupport.util.Crypto;
|
||||||
|
import love.sola.netsupport.wechat.Command;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/12.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@WebServlet(name = "Login", urlPatterns = "/api/admin/login", loadOnStartup = 12)
|
@WebServlet(name = "Login", urlPatterns = "/api/admin/login", loadOnStartup = 12)
|
||||||
public class Login extends HttpServlet {
|
public class Login extends HttpServlet {
|
||||||
|
|
||||||
private Gson gson = SQLCore.gson;
|
private Gson gson = SQLCore.gson;
|
||||||
|
|
||||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
doGet(request, response);
|
doGet(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
request.setCharacterEncoding("utf-8");
|
request.setCharacterEncoding("utf-8");
|
||||||
response.setCharacterEncoding("utf-8");
|
response.setCharacterEncoding("utf-8");
|
||||||
response.addHeader("Content-type", "application/json;charset=utf-8");
|
response.addHeader("Content-type", "application/json;charset=utf-8");
|
||||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||||
PrintWriter out = response.getWriter();
|
PrintWriter out = response.getWriter();
|
||||||
String json = gson.toJson(login(request));
|
out.println(gson.toJson(login(request)));
|
||||||
out.println(ParseUtil.parseJsonP(request, json));
|
out.close();
|
||||||
out.close();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private Object login(HttpServletRequest request) {
|
private Object login(HttpServletRequest request) {
|
||||||
try {
|
try {
|
||||||
int oid = Integer.parseInt(request.getParameter("id"));
|
int oid = Integer.parseInt(request.getParameter("id"));
|
||||||
String password = request.getParameter("pass");
|
String password = request.getParameter("pass");
|
||||||
boolean bypass = request.getParameter("bypass") != null;
|
boolean bypass = request.getParameter("bypass") != null;
|
||||||
Operator op = TableOperator.get(oid);
|
Operator op = TableOperator.get(oid);
|
||||||
if (op == null)
|
if (op == null)
|
||||||
return Error.OPERATOR_NOT_FOUND;
|
return Error.OPERATOR_NOT_FOUND;
|
||||||
else if (op.getAccess() >= Access.NO_LOGIN)
|
else if (op.getAccess() >= Access.NO_LOGIN)
|
||||||
return Error.PERMISSION_DENIED;
|
return Error.PERMISSION_DENIED;
|
||||||
|
|
||||||
if (!Crypto.check(bypass ? password : RSAUtil.decrypt(password), op.getPassword())) {
|
if (!Crypto.check(password, op.getPassword())) {
|
||||||
return Error.WRONG_PASSWORD;
|
return Error.WRONG_PASSWORD;
|
||||||
}
|
}
|
||||||
|
|
||||||
String sid = WechatSession.genId();
|
WxSession session = WechatSession.create();
|
||||||
WxSession session = WechatSession.get(sid, true);
|
if (bypass) {
|
||||||
if (bypass) {
|
session.setAttribute(Attribute.AUTHORIZED, Command.fromId(Integer.parseInt(request.getParameter("bypass"))));
|
||||||
session.setAttribute(Attribute.AUTHORIZED, Command.fromId(Integer.parseInt(request.getParameter("bypass"))));
|
} else {
|
||||||
} else {
|
session.setAttribute(Attribute.AUTHORIZED, Command.LOGIN);
|
||||||
session.setAttribute(Attribute.AUTHORIZED, Command.LOGIN);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
session.setAttribute(Attribute.WECHAT, op.getWechat());
|
session.setAttribute(Attribute.WECHAT, op.getWechat());
|
||||||
session.setAttribute(Attribute.OPERATOR, op);
|
session.setAttribute(Attribute.OPERATOR, op);
|
||||||
|
|
||||||
if (request.getParameter("bypassuser") != null) {
|
if (request.getParameter("bypassuser") != null) {
|
||||||
User u = TableUser.getById(Long.parseLong(request.getParameter("bypassuser")));
|
User u = TableUser.getById(Long.parseLong(request.getParameter("bypassuser")));
|
||||||
session.setAttribute(Attribute.USER, u);
|
session.setAttribute(Attribute.USER, u);
|
||||||
session.setAttribute(Attribute.WECHAT, u.getWechatId());
|
session.setAttribute(Attribute.WECHAT, u.getWechatId());
|
||||||
}
|
}
|
||||||
if (request.getParameter("bypasswechat") != null) {
|
if (request.getParameter("bypasswechat") != null) {
|
||||||
session.setAttribute(Attribute.WECHAT, request.getParameter("bypasswechat"));
|
session.setAttribute(Attribute.WECHAT, request.getParameter("bypasswechat"));
|
||||||
}
|
}
|
||||||
return sid;
|
return session.getId();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return Error.INTERNAL_ERROR;
|
return Error.INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,53 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.api.manager;
|
package love.sola.netsupport.api.manager;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import love.sola.netsupport.api.API;
|
import love.sola.netsupport.api.API;
|
||||||
import love.sola.netsupport.api.Error;
|
import love.sola.netsupport.api.Error;
|
||||||
import love.sola.netsupport.enums.Access;
|
import love.sola.netsupport.enums.Access;
|
||||||
import love.sola.netsupport.pojo.User;
|
import love.sola.netsupport.pojo.User;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
import love.sola.netsupport.sql.TableUser;
|
import love.sola.netsupport.sql.TableUser;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2014/8/20.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class GetUser extends API {
|
public class GetUser extends API {
|
||||||
|
|
||||||
public GetUser() {
|
public GetUser() {
|
||||||
url = "/admin/getuser";
|
url = "/admin/getuser";
|
||||||
access = Access.LEADER;
|
access = Access.LEADER;
|
||||||
authorize = Command.LOGIN;
|
authorize = Command.LOGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||||
String id = req.getParameter("id");
|
String id = req.getParameter("id");
|
||||||
String name = req.getParameter("name");
|
String name = req.getParameter("name");
|
||||||
if ((id == null || id.isEmpty()) && (name == null || name.isEmpty())) {
|
if ((id == null || id.isEmpty()) && (name == null || name.isEmpty())) {
|
||||||
return Error.PARAMETER_REQUIRED;
|
return Error.PARAMETER_REQUIRED;
|
||||||
}
|
}
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
try {
|
try {
|
||||||
User u = TableUser.getById(Long.parseLong(id));
|
User u = TableUser.getById(Long.parseLong(id));
|
||||||
if (u == null)
|
if (u == null)
|
||||||
return Error.USER_NOT_FOUND;
|
return Error.USER_NOT_FOUND;
|
||||||
else
|
else
|
||||||
return u;
|
return u;
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
return Error.ILLEGAL_PARAMETER;
|
return Error.ILLEGAL_PARAMETER;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
User u = TableUser.getByName(name);
|
User u = TableUser.getByName(name);
|
||||||
if (u == null)
|
if (u == null)
|
||||||
return Error.USER_NOT_FOUND;
|
return Error.USER_NOT_FOUND;
|
||||||
else
|
else
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.api.manager;
|
package love.sola.netsupport.api.manager;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import love.sola.netsupport.api.API;
|
import love.sola.netsupport.api.API;
|
||||||
import love.sola.netsupport.api.Error;
|
import love.sola.netsupport.api.Error;
|
||||||
import love.sola.netsupport.config.Settings;
|
import love.sola.netsupport.config.Settings;
|
||||||
@@ -9,50 +30,44 @@ import love.sola.netsupport.enums.Status;
|
|||||||
import love.sola.netsupport.pojo.Operator;
|
import love.sola.netsupport.pojo.Operator;
|
||||||
import love.sola.netsupport.pojo.Ticket;
|
import love.sola.netsupport.pojo.Ticket;
|
||||||
import love.sola.netsupport.pojo.User;
|
import love.sola.netsupport.pojo.User;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
import love.sola.netsupport.sql.SQLCore;
|
import love.sola.netsupport.sql.SQLCore;
|
||||||
import love.sola.netsupport.util.Checker;
|
import love.sola.netsupport.util.Checker;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
import org.hibernate.Session;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/22.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class TicketPush extends API {
|
public class TicketPush extends API {
|
||||||
|
|
||||||
public TicketPush() {
|
public TicketPush() {
|
||||||
url = "/admin/ticketpush";
|
url = "/admin/ticketpush";
|
||||||
access = Access.LEADER;
|
access = Access.LEADER;
|
||||||
authorize = Command.LOGIN;
|
authorize = Command.LOGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||||
String uid = req.getParameter("uid");
|
String uid = req.getParameter("uid");
|
||||||
String desc = req.getParameter("desc");
|
String desc = req.getParameter("desc");
|
||||||
if (Checker.hasNull(uid, desc)) {
|
if (Checker.hasNull(uid, desc)) {
|
||||||
return Error.PARAMETER_REQUIRED;
|
return Error.PARAMETER_REQUIRED;
|
||||||
}
|
}
|
||||||
if (desc.length() > Settings.MAX_DESC_LENGTH) {
|
if (desc.length() > Settings.MAX_DESC_LENGTH) {
|
||||||
return Error.LENGTH_LIMIT_EXCEEDED;
|
return Error.LENGTH_LIMIT_EXCEEDED;
|
||||||
}
|
}
|
||||||
Operator op = (Operator) session.getAttribute(Attribute.OPERATOR);
|
Operator op = session.getAttribute(Attribute.OPERATOR);
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
User u = s.get(User.class, Long.parseLong(uid));
|
User u = s.get(User.class, Long.parseLong(uid));
|
||||||
if (u == null) {
|
if (u == null) {
|
||||||
return Error.USER_NOT_FOUND;
|
return Error.USER_NOT_FOUND;
|
||||||
}
|
}
|
||||||
Ticket t = new Ticket(null, u, desc, null, "Pushed By Admin", null, op, Status.UNCHECKED);
|
Ticket t = new Ticket(u, desc, null, "Pushed By Admin", null, op, Status.UNCHECKED);
|
||||||
s.save(t);
|
s.save(t);
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,42 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.api.root;
|
package love.sola.netsupport.api.root;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import love.sola.netsupport.api.API;
|
import love.sola.netsupport.api.API;
|
||||||
import love.sola.netsupport.enums.Access;
|
import love.sola.netsupport.enums.Access;
|
||||||
|
import love.sola.netsupport.session.WechatSession;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import love.sola.netsupport.wechat.WechatSession;
|
|
||||||
import me.chanjar.weixin.common.session.InternalSession;
|
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/15.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class DashBoard extends API {
|
public class DashBoard extends API {
|
||||||
|
|
||||||
public DashBoard() {
|
public DashBoard() {
|
||||||
url = "/root/dashboard";
|
url = "/root/dashboard";
|
||||||
access = Access.ROOT;
|
access = Access.ROOT;
|
||||||
authorize = Command.LOGIN;
|
authorize = Command.LOGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (InternalSession s : WechatSession.list()) {
|
for (love.sola.netsupport.session.WxSession ws : WechatSession.list()) {
|
||||||
sb.append("=====").append(s.getIdInternal()).append("=====\n");
|
sb.append("=====").append(ws.getId()).append("=====\n");
|
||||||
WxSession ws = s.getSession();
|
Set<String> e = ws.getAttributeNames();
|
||||||
Enumeration<String> e = ws.getAttributeNames();
|
for (String key : e) {
|
||||||
while (e.hasMoreElements()) {
|
sb.append(key).append(": ").append(ws.getAttribute(key).toString()).append("\n");
|
||||||
String key = e.nextElement();
|
}
|
||||||
sb.append(key).append(": ").append(ws.getAttribute(key)).append("\n");
|
}
|
||||||
}
|
return sb.toString();
|
||||||
}
|
}
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.api.root;
|
package love.sola.netsupport.api.root;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import love.sola.netsupport.api.API;
|
import love.sola.netsupport.api.API;
|
||||||
import love.sola.netsupport.api.Error;
|
import love.sola.netsupport.api.Error;
|
||||||
import love.sola.netsupport.enums.Access;
|
import love.sola.netsupport.enums.Access;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
import love.sola.netsupport.sql.TableUser;
|
import love.sola.netsupport.sql.TableUser;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/15.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class FlushCache extends API {
|
public class FlushCache extends API {
|
||||||
|
|
||||||
public FlushCache() {
|
public FlushCache() {
|
||||||
url = "/root/flushcache";
|
url = "/root/flushcache";
|
||||||
access = Access.ROOT;
|
access = Access.ROOT;
|
||||||
authorize = Command.LOGIN;
|
authorize = Command.LOGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||||
TableUser.flushCache();
|
TableUser.flushCache();
|
||||||
return Error.OK;
|
return Error.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.api.root;
|
package love.sola.netsupport.api.root;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import love.sola.netsupport.api.API;
|
import love.sola.netsupport.api.API;
|
||||||
import love.sola.netsupport.api.Error;
|
import love.sola.netsupport.api.Error;
|
||||||
import love.sola.netsupport.enums.Access;
|
import love.sola.netsupport.enums.Access;
|
||||||
import love.sola.netsupport.pojo.Operator;
|
import love.sola.netsupport.pojo.Operator;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
import love.sola.netsupport.sql.SQLCore;
|
import love.sola.netsupport.sql.SQLCore;
|
||||||
import love.sola.netsupport.util.Crypto;
|
import love.sola.netsupport.util.Crypto;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
import org.hibernate.Session;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/20.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class SetPassword extends API {
|
public class SetPassword extends API {
|
||||||
|
|
||||||
public SetPassword() {
|
public SetPassword() {
|
||||||
url = "/root/setpass";
|
url = "/root/setpass";
|
||||||
access = Access.ROOT;
|
access = Access.ROOT;
|
||||||
authorize = Command.LOGIN;
|
authorize = Command.LOGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||||
String id = req.getParameter("id");
|
String id = req.getParameter("id");
|
||||||
String pass = req.getParameter("pass");
|
String pass = req.getParameter("pass");
|
||||||
if (pass == null || pass.length() < 8) {
|
if (pass == null || pass.length() < 8) {
|
||||||
return Error.INVALID_PARAMETER;
|
return Error.INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
Operator op = s.get(Operator.class, Integer.parseInt(id));
|
Operator op = s.get(Operator.class, Integer.parseInt(id));
|
||||||
if (op == null) {
|
if (op == null) {
|
||||||
return Error.OPERATOR_NOT_FOUND;
|
return Error.OPERATOR_NOT_FOUND;
|
||||||
}
|
}
|
||||||
op.setPassword(Crypto.hash(pass));
|
op.setPassword(Crypto.hash(pass));
|
||||||
s.update(op);
|
s.update(op);
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
return Error.OK;
|
return Error.OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,63 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.api.stuff;
|
package love.sola.netsupport.api.stuff;
|
||||||
|
|
||||||
import love.sola.netsupport.api.API;
|
import love.sola.netsupport.api.API;
|
||||||
import love.sola.netsupport.enums.Access;
|
import love.sola.netsupport.enums.Access;
|
||||||
import love.sola.netsupport.pojo.Ticket;
|
import love.sola.netsupport.pojo.Ticket;
|
||||||
|
import love.sola.netsupport.pojo.User;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
import love.sola.netsupport.sql.SQLCore;
|
import love.sola.netsupport.sql.SQLCore;
|
||||||
import love.sola.netsupport.sql.TableTicket;
|
import love.sola.netsupport.sql.TableTicket;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
import org.apache.commons.lang3.time.DateUtils;
|
import org.apache.commons.lang3.time.DateUtils;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.envers.AuditReader;
|
import org.hibernate.envers.AuditReader;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
import org.hibernate.envers.query.AuditEntity;
|
||||||
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/18.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class TicketLog extends API {
|
public class TicketLog extends API {
|
||||||
|
|
||||||
public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||||
|
|
||||||
public TicketLog() {
|
public TicketLog() {
|
||||||
url = "/admin/ticketlog";
|
url = "/admin/ticketlog";
|
||||||
access = Access.MEMBER;
|
access = Access.MEMBER;
|
||||||
authorize = Command.LOGIN;
|
authorize = Command.LOGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@SuppressWarnings("unchecked")
|
||||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
@Override
|
||||||
int first;
|
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||||
int limit;
|
int first;
|
||||||
Date start;
|
int limit;
|
||||||
Date end;
|
Date start;
|
||||||
first = req.getParameter("first") == null ? 0 : Integer.parseInt(req.getParameter("first"));
|
Date end;
|
||||||
limit = req.getParameter("limit") == null ? 20 : Integer.parseInt(req.getParameter("limit"));
|
first = req.getParameter("first") == null ? 0 : Integer.parseInt(req.getParameter("first"));
|
||||||
start = req.getParameter("start") == null ? getToday() : dateFormat.parse(req.getParameter("start"));
|
limit = req.getParameter("limit") == null ? 20 : Integer.parseInt(req.getParameter("limit"));
|
||||||
end = req.getParameter("end") == null ? getToday() : dateFormat.parse(req.getParameter("end"));
|
start = req.getParameter("start") == null ? getToday() : dateFormat.parse(req.getParameter("start"));
|
||||||
end = DateUtils.addDays(end, 1);
|
end = req.getParameter("end") == null ? getToday() : dateFormat.parse(req.getParameter("end"));
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
end = DateUtils.addDays(end, 1);
|
||||||
AuditReader reader = TableTicket.getAuditReader(s);
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
return reader.createQuery()
|
AuditReader reader = TableTicket.getAuditReader(s);
|
||||||
.forRevisionsOfEntity(Ticket.class, false, true)
|
List<Object[]> resultList = reader.createQuery()
|
||||||
.addOrder(AuditEntity.revisionNumber().desc())
|
.forRevisionsOfEntity(Ticket.class, false, true)
|
||||||
.add(AuditEntity.revisionProperty("timestamp").between(start.getTime(), end.getTime()))
|
.addOrder(AuditEntity.revisionNumber().desc())
|
||||||
.setFirstResult(first)
|
.add(AuditEntity.revisionProperty("timestamp").between(start.getTime(), end.getTime()))
|
||||||
.setMaxResults(limit)
|
.setFirstResult(first)
|
||||||
.getResultList();
|
.setMaxResults(limit)
|
||||||
}
|
.getResultList();
|
||||||
}
|
return TableTicket.initializeTickets(resultList);
|
||||||
|
}
|
||||||
private static Date getToday() {
|
}
|
||||||
return DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.api.stuff;
|
package love.sola.netsupport.api.stuff;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import love.sola.netsupport.api.API;
|
import love.sola.netsupport.api.API;
|
||||||
import love.sola.netsupport.enums.Access;
|
import love.sola.netsupport.enums.Access;
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.pojo.Operator;
|
import love.sola.netsupport.pojo.Operator;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
import love.sola.netsupport.sql.TableTicket;
|
import love.sola.netsupport.sql.TableTicket;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/13.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class TicketLookup extends API {
|
public class TicketLookup extends API {
|
||||||
|
|
||||||
public TicketLookup() {
|
public TicketLookup() {
|
||||||
url = "/admin/ticketlookup";
|
url = "/admin/ticketlookup";
|
||||||
access = Access.MEMBER;
|
access = Access.MEMBER;
|
||||||
authorize = Command.LOGIN;
|
authorize = Command.LOGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||||
Operator op = (Operator) session.getAttribute(Attribute.OPERATOR);
|
Operator op = session.getAttribute(Attribute.OPERATOR);
|
||||||
int block;
|
int block;
|
||||||
if (req.getParameter("block") != null) {
|
if (req.getParameter("block") != null) {
|
||||||
block = Integer.parseInt(req.getParameter("block"));
|
block = Integer.parseInt(req.getParameter("block"));
|
||||||
} else {
|
} else {
|
||||||
block = op.getBlock();
|
block = op.getBlock();
|
||||||
}
|
}
|
||||||
return TableTicket.unsolvedByBlock(block);
|
return TableTicket.unsolvedByBlock(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.api.stuff;
|
package love.sola.netsupport.api.stuff;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import love.sola.netsupport.api.API;
|
import love.sola.netsupport.api.API;
|
||||||
import love.sola.netsupport.api.Error;
|
import love.sola.netsupport.api.Error;
|
||||||
import love.sola.netsupport.enums.Access;
|
import love.sola.netsupport.enums.Access;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
import love.sola.netsupport.sql.TableTicket;
|
import love.sola.netsupport.sql.TableTicket;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/18.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class TicketTrack extends API {
|
public class TicketTrack extends API {
|
||||||
|
|
||||||
public TicketTrack() {
|
public TicketTrack() {
|
||||||
url = "/admin/tickettrack";
|
url = "/admin/tickettrack";
|
||||||
access = Access.MEMBER;
|
access = Access.MEMBER;
|
||||||
authorize = Command.LOGIN;
|
authorize = Command.LOGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||||
String tid = req.getParameter("id");
|
String tid = req.getParameter("id");
|
||||||
if (tid == null) {
|
if (tid == null) {
|
||||||
return Error.PARAMETER_REQUIRED;
|
return Error.PARAMETER_REQUIRED;
|
||||||
}
|
}
|
||||||
return TableTicket.track(Integer.parseInt(tid));
|
return TableTicket.track(Integer.parseInt(tid));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,54 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.api.stuff;
|
package love.sola.netsupport.api.stuff;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import love.sola.netsupport.api.API;
|
import love.sola.netsupport.api.API;
|
||||||
import love.sola.netsupport.api.Error;
|
import love.sola.netsupport.api.Error;
|
||||||
import love.sola.netsupport.enums.Access;
|
import love.sola.netsupport.enums.Access;
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.pojo.Operator;
|
import love.sola.netsupport.pojo.Operator;
|
||||||
import love.sola.netsupport.pojo.Ticket;
|
import love.sola.netsupport.pojo.Ticket;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
import love.sola.netsupport.sql.SQLCore;
|
import love.sola.netsupport.sql.SQLCore;
|
||||||
import love.sola.netsupport.util.Checker;
|
import love.sola.netsupport.util.Checker;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
import org.hibernate.Session;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/13.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class TicketUpdate extends API {
|
public class TicketUpdate extends API {
|
||||||
|
|
||||||
public TicketUpdate() {
|
public TicketUpdate() {
|
||||||
url = "/admin/ticketupdate";
|
url = "/admin/ticketupdate";
|
||||||
access = Access.MEMBER;
|
access = Access.MEMBER;
|
||||||
authorize = Command.LOGIN;
|
authorize = Command.LOGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||||
String ticket = req.getParameter("ticket");
|
String ticket = req.getParameter("ticket");
|
||||||
String remark = req.getParameter("remark");
|
String remark = req.getParameter("remark");
|
||||||
String status = req.getParameter("status");
|
String status = req.getParameter("status");
|
||||||
if (Checker.hasNull(ticket, remark, status)) return Error.PARAMETER_REQUIRED;
|
if (Checker.hasNull(ticket, remark, status)) return Error.PARAMETER_REQUIRED;
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
Operator op = (Operator) session.getAttribute(Attribute.OPERATOR);
|
Operator op = session.getAttribute(Attribute.OPERATOR);
|
||||||
Ticket t = s.get(Ticket.class, Integer.parseInt(ticket));
|
Ticket t = s.get(Ticket.class, Integer.parseInt(ticket));
|
||||||
if (t == null) {
|
if (t == null) {
|
||||||
return Error.TICKET_NOT_FOUND;
|
return Error.TICKET_NOT_FOUND;
|
||||||
}
|
}
|
||||||
t.setOperator(op);
|
t.setOperator(op);
|
||||||
t.setRemark(remark);
|
t.setRemark(remark);
|
||||||
t.setStatus(Integer.parseInt(status));
|
t.setStatus(Integer.parseInt(status));
|
||||||
t.setUpdateTime(new Date());
|
t.setUpdateTime(new Date());
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
s.update(t);
|
s.update(t);
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
104
src/main/java/love/sola/netsupport/api/stuff/ToolsCheck.java
Normal file
104
src/main/java/love/sola/netsupport/api/stuff/ToolsCheck.java
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package love.sola.netsupport.api.stuff;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.commons.lang3.time.DateUtils;
|
||||||
|
import org.hibernate.Criteria;
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.criterion.Restrictions;
|
||||||
|
import org.hibernate.type.IntegerType;
|
||||||
|
import org.hibernate.type.Type;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import love.sola.netsupport.api.API;
|
||||||
|
import love.sola.netsupport.api.Error;
|
||||||
|
import love.sola.netsupport.enums.Access;
|
||||||
|
import love.sola.netsupport.enums.Attribute;
|
||||||
|
import love.sola.netsupport.pojo.Operator;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
|
import love.sola.netsupport.sql.SQLCore;
|
||||||
|
import love.sola.netsupport.wechat.Command;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sola
|
||||||
|
*/
|
||||||
|
public class ToolsCheck extends API {
|
||||||
|
|
||||||
|
public ToolsCheck() {
|
||||||
|
url = "/admin/toolscheck";
|
||||||
|
access = Access.MEMBER;
|
||||||
|
authorize = Command.LOGIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||||
|
if (req.getMethod().equals("GET")) {
|
||||||
|
return query(req, session);
|
||||||
|
} else if (req.getMethod().equals("POST")) {
|
||||||
|
return submit(req, session);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object submit(HttpServletRequest req, WxSession session) {
|
||||||
|
Operator op = session.getAttribute(Attribute.OPERATOR);
|
||||||
|
int status = Integer.valueOf(getParameterWithDefault(req.getParameter("status"), "0"));
|
||||||
|
String remark = req.getParameter("remark");
|
||||||
|
if (status != 0 && StringUtils.isBlank(remark)) {
|
||||||
|
return Error.PARAMETER_REQUIRED;
|
||||||
|
}
|
||||||
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
|
s.beginTransaction();
|
||||||
|
s.save(new love.sola.netsupport.pojo.ToolsCheck(
|
||||||
|
op,
|
||||||
|
op.getBlock(),
|
||||||
|
new Date(),
|
||||||
|
status,
|
||||||
|
remark
|
||||||
|
));
|
||||||
|
s.getTransaction().commit();
|
||||||
|
return Error.OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object query(HttpServletRequest req, WxSession session) {
|
||||||
|
int status = Integer.valueOf(getParameterWithDefault(req.getParameter("status"), "0"));
|
||||||
|
Date after = getDay(getParameterAsDate(req.getParameter("after"), getToday()));
|
||||||
|
Date before = getDay(getParameterAsDate(req.getParameter("before"), getToday()));
|
||||||
|
before = DateUtils.addDays(before, 1);
|
||||||
|
int block = Integer.valueOf(getParameterWithDefault(req.getParameter("block"), "0"));
|
||||||
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
|
Criteria query = s.createCriteria(love.sola.netsupport.pojo.ToolsCheck.class);
|
||||||
|
query.add(
|
||||||
|
Restrictions.sqlRestriction(
|
||||||
|
"{alias}.status & ? = ?",
|
||||||
|
new Object[]{status, status},
|
||||||
|
new Type[]{IntegerType.INSTANCE, IntegerType.INSTANCE}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
query.add(Restrictions.between("checkTime", after, before));
|
||||||
|
if (block != 0) query.add(Restrictions.eq("block", block));
|
||||||
|
return query.list();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,61 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.api.user;
|
package love.sola.netsupport.api.user;
|
||||||
|
|
||||||
|
import org.hibernate.exception.ConstraintViolationException;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import love.sola.netsupport.api.API;
|
import love.sola.netsupport.api.API;
|
||||||
import love.sola.netsupport.api.Error;
|
import love.sola.netsupport.api.Error;
|
||||||
import love.sola.netsupport.enums.Access;
|
import love.sola.netsupport.enums.Access;
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.enums.ISP;
|
import love.sola.netsupport.enums.ISP;
|
||||||
import love.sola.netsupport.pojo.User;
|
import love.sola.netsupport.pojo.User;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
import love.sola.netsupport.sql.TableUser;
|
import love.sola.netsupport.sql.TableUser;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
import org.hibernate.exception.ConstraintViolationException;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import static love.sola.netsupport.util.Checker.checkBlock;
|
||||||
|
import static love.sola.netsupport.util.Checker.checkISP;
|
||||||
import static love.sola.netsupport.util.Checker.*;
|
import static love.sola.netsupport.util.Checker.checkNetAccount;
|
||||||
|
import static love.sola.netsupport.util.Checker.checkPhoneNumber;
|
||||||
|
import static love.sola.netsupport.util.Checker.checkRoom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/15.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class ProfileModify extends API {
|
public class ProfileModify extends API {
|
||||||
|
|
||||||
public ProfileModify() {
|
public ProfileModify() {
|
||||||
url = "/profilemodify";
|
url = "/profilemodify";
|
||||||
access = Access.USER;
|
access = Access.USER;
|
||||||
authorize = Command.PROFILE;
|
authorize = Command.PROFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||||
User u = (User) session.getAttribute(Attribute.USER);
|
User u = session.getAttribute(Attribute.USER);
|
||||||
ISP isp = checkISP(req.getParameter("isp"));
|
ISP isp = checkISP(req.getParameter("isp"));
|
||||||
String netAccount = checkNetAccount(req.getParameter("username"), isp);
|
String netAccount = checkNetAccount(req.getParameter("username"), isp);
|
||||||
int block = checkBlock(req.getParameter("block"));
|
int block = checkBlock(req.getParameter("block"));
|
||||||
int room = checkRoom(req.getParameter("room"), block);
|
int room = checkRoom(req.getParameter("room"), block);
|
||||||
long phone = checkPhoneNumber(req.getParameter("phone"));
|
long phone = checkPhoneNumber(req.getParameter("phone"));
|
||||||
if (room == -1)
|
if (room == -1)
|
||||||
return Error.INVALID_PARAMETER.withMsg("Invalid_Room");
|
return Error.INVALID_PARAMETER.withMsg("Invalid_Room");
|
||||||
if (phone == -1)
|
if (phone == -1)
|
||||||
return Error.INVALID_PARAMETER.withMsg("Invalid_Phone_Number");
|
return Error.INVALID_PARAMETER.withMsg("Invalid_Phone_Number");
|
||||||
if (netAccount == null)
|
if (netAccount == null)
|
||||||
return Error.INVALID_PARAMETER.withMsg("Invalid_Account");
|
return Error.INVALID_PARAMETER.withMsg("Invalid_Account");
|
||||||
|
|
||||||
u.setIsp(isp);
|
u.setIsp(isp);
|
||||||
u.setNetAccount(netAccount);
|
u.setNetAccount(netAccount);
|
||||||
u.setBlock(block);
|
u.setBlock(block);
|
||||||
u.setRoom(room);
|
u.setRoom(room);
|
||||||
u.setPhone(phone);
|
u.setPhone(phone);
|
||||||
try {
|
try {
|
||||||
TableUser.update(u);
|
TableUser.update(u);
|
||||||
} catch (ConstraintViolationException e) {
|
} catch (ConstraintViolationException e) {
|
||||||
String dupKey = e.getConstraintName();
|
String dupKey = e.getConstraintName();
|
||||||
return Error.INVALID_PARAMETER.withMsg("Duplicated_" + dupKey.toUpperCase());
|
return Error.INVALID_PARAMETER.withMsg("Duplicated_" + dupKey.toUpperCase());
|
||||||
}
|
}
|
||||||
session.invalidate();
|
session.invalidate();
|
||||||
return Error.OK;
|
return Error.OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,127 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.api.user;
|
package love.sola.netsupport.api.user;
|
||||||
|
|
||||||
|
import org.hibernate.exception.ConstraintViolationException;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import love.sola.netsupport.api.API;
|
import love.sola.netsupport.api.API;
|
||||||
import love.sola.netsupport.api.Error;
|
import love.sola.netsupport.api.Error;
|
||||||
import love.sola.netsupport.enums.Access;
|
import love.sola.netsupport.enums.Access;
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.enums.ISP;
|
import love.sola.netsupport.enums.ISP;
|
||||||
import love.sola.netsupport.pojo.User;
|
import love.sola.netsupport.pojo.User;
|
||||||
import love.sola.netsupport.sql.SQLCore;
|
import love.sola.netsupport.session.WxSession;
|
||||||
import love.sola.netsupport.sql.TableUser;
|
import love.sola.netsupport.sql.TableUser;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import love.sola.netsupport.wechat.WxMpServlet;
|
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
|
|
||||||
import org.hibernate.exception.ConstraintViolationException;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import static love.sola.netsupport.util.Checker.checkBlock;
|
||||||
import java.sql.Connection;
|
import static love.sola.netsupport.util.Checker.checkISP;
|
||||||
import java.sql.PreparedStatement;
|
import static love.sola.netsupport.util.Checker.checkNetAccount;
|
||||||
import java.sql.ResultSet;
|
import static love.sola.netsupport.util.Checker.checkPhoneNumber;
|
||||||
import java.sql.SQLException;
|
import static love.sola.netsupport.util.Checker.checkRoom;
|
||||||
|
import static love.sola.netsupport.util.Checker.checkStudentId;
|
||||||
import static love.sola.netsupport.util.Checker.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/11/29.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class Register extends API {
|
public class Register extends API {
|
||||||
|
|
||||||
public Register() {
|
public Register() {
|
||||||
url = "/register";
|
url = "/register";
|
||||||
access = Access.GUEST;
|
access = Access.GUEST;
|
||||||
authorize = Command.REGISTER;
|
authorize = Command.REGISTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||||
String wechat = (String) session.getAttribute(Attribute.WECHAT);
|
String wechat = session.getAttribute(Attribute.WECHAT);
|
||||||
if (wechat == null) {
|
if (wechat == null) {
|
||||||
return Error.UNAUTHORIZED;
|
return Error.UNAUTHORIZED;
|
||||||
}
|
}
|
||||||
ISP isp = checkISP(req.getParameter("isp"));
|
ISP isp = checkISP(req.getParameter("isp"));
|
||||||
int block = checkBlock(req.getParameter("block"));
|
int block = checkBlock(req.getParameter("block"));
|
||||||
return register(
|
return register(
|
||||||
checkStudentId(req.getParameter("sid")),
|
checkStudentId(req.getParameter("sid")),
|
||||||
req.getParameter("name"),
|
req.getParameter("name"),
|
||||||
isp,
|
isp,
|
||||||
checkNetAccount(req.getParameter("username"), isp),
|
checkNetAccount(req.getParameter("username"), isp),
|
||||||
block,
|
block,
|
||||||
checkRoom(req.getParameter("room"), block),
|
checkRoom(req.getParameter("room"), block),
|
||||||
checkPhoneNumber(req.getParameter("phone")),
|
checkPhoneNumber(req.getParameter("phone")),
|
||||||
wechat);
|
wechat);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object register(long sid, String name, ISP isp, String netAccount, int block, int room, long phone, String wechat) {
|
private Object register(long sid, String name, ISP isp, String netAccount, int block, int room, long phone, String wechat) {
|
||||||
if (sid == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Student_Id");
|
if (sid == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Student_Id");
|
||||||
if (name == null) return Error.INVALID_PARAMETER.withMsg("Invalid_Name");
|
if (name == null) return Error.INVALID_PARAMETER.withMsg("Invalid_Name");
|
||||||
if (isp == null) return Error.INVALID_PARAMETER.withMsg("Invalid_ISP");
|
if (isp == null) return Error.INVALID_PARAMETER.withMsg("Invalid_ISP");
|
||||||
if (netAccount == null) return Error.INVALID_PARAMETER.withMsg("Invalid_Account");
|
if (netAccount == null) return Error.INVALID_PARAMETER.withMsg("Invalid_Account");
|
||||||
if (block == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Block");
|
if (block == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Block");
|
||||||
if (room == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Room");
|
if (room == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Room");
|
||||||
if (phone == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Phone_Number");
|
if (phone == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Phone_Number");
|
||||||
User user = TableUser.getById(sid);
|
User user = TableUser.getById(sid);
|
||||||
if (user == null) return Error.INVALID_PARAMETER.withMsg("Invalid_Student_Id");
|
if (user == null) return Error.INVALID_PARAMETER.withMsg("Invalid_Student_Id");
|
||||||
if (!user.getName().equals(name)) return Error.INVALID_PARAMETER.withMsg("Invalid_Name");
|
if (!user.getName().equals(name)) return Error.INVALID_PARAMETER.withMsg("Invalid_Name");
|
||||||
if (user.getWechatId() != null) return Error.INVALID_PARAMETER.withMsg("User_Already_Registered");
|
if (user.getWechatId() != null)
|
||||||
user.setIsp(isp);
|
return Error.INVALID_PARAMETER.withMsg("User_Already_Registered");
|
||||||
user.setNetAccount(netAccount);
|
user.setIsp(isp);
|
||||||
user.setBlock(block);
|
user.setNetAccount(netAccount);
|
||||||
user.setRoom(room);
|
user.setBlock(block);
|
||||||
user.setPhone(phone);
|
user.setRoom(room);
|
||||||
user.setWechatId(wechat);
|
user.setPhone(phone);
|
||||||
try {
|
user.setWechatId(wechat);
|
||||||
TableUser.update(user);
|
try {
|
||||||
} catch (ConstraintViolationException e) {
|
TableUser.update(user);
|
||||||
String dupKey = e.getConstraintName();
|
} catch (ConstraintViolationException e) {
|
||||||
return Error.INVALID_PARAMETER.withMsg("Duplicated_" + dupKey.toUpperCase()); // PHONE ACCOUNT WECHAT
|
String dupKey = e.getConstraintName();
|
||||||
}
|
return Error.INVALID_PARAMETER.withMsg("Duplicated_" + dupKey.toUpperCase()); // PHONE ACCOUNT WECHAT
|
||||||
// FIXME: 2015/12/30 Temporary converter
|
}
|
||||||
converterWithRetry(user);
|
return Error.OK;
|
||||||
return Error.OK;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static void converterWithRetry(User u) {
|
|
||||||
Throwable last = null;
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
try {
|
|
||||||
converter(u);
|
|
||||||
return;
|
|
||||||
} catch (WxErrorException | SQLException e) {
|
|
||||||
last = e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
last.printStackTrace();
|
|
||||||
try {
|
|
||||||
WxMpServlet.instance.wxMpService.customMessageSend(WxMpCustomMessage.TEXT().toUser(u.getWechatId()).content("数据转换失败").build());
|
|
||||||
} catch (WxErrorException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void converter(User u) throws WxErrorException, SQLException {
|
|
||||||
try (Connection conn = SQLCore.ds.getConnection()) {
|
|
||||||
PreparedStatement ps = conn.prepareStatement("SELECT wechat FROM `convert` WHERE id=?");
|
|
||||||
ps.setLong(1, u.getId());
|
|
||||||
ResultSet rs = ps.executeQuery();
|
|
||||||
if (rs.next()) {
|
|
||||||
WxMpServlet.instance.wxMpService
|
|
||||||
.userUpdateGroup(u.getWechatId(), 100L);
|
|
||||||
String old = rs.getString(1);
|
|
||||||
ps = conn.prepareStatement("UPDATE `operators` SET wechat=? WHERE wechat=?");
|
|
||||||
ps.setString(1, u.getWechatId());
|
|
||||||
ps.setString(2, old);
|
|
||||||
if (ps.executeUpdate() == 1) {
|
|
||||||
WxMpServlet.instance.wxMpService.customMessageSend(WxMpCustomMessage.TEXT().toUser(u.getWechatId()).content("数据转换成功").build());
|
|
||||||
} else {
|
|
||||||
WxMpServlet.instance.wxMpService.customMessageSend(WxMpCustomMessage.TEXT().toUser(u.getWechatId()).content("已进行过数据转换").build());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.api.user;
|
package love.sola.netsupport.api.user;
|
||||||
|
|
||||||
import love.sola.netsupport.api.API;
|
|
||||||
import love.sola.netsupport.enums.Access;
|
|
||||||
import love.sola.netsupport.enums.Attribute;
|
|
||||||
import love.sola.netsupport.pojo.Ticket;
|
|
||||||
import love.sola.netsupport.pojo.User;
|
|
||||||
import love.sola.netsupport.sql.SQLCore;
|
|
||||||
import love.sola.netsupport.wechat.Command;
|
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.criterion.Order;
|
import org.hibernate.criterion.Order;
|
||||||
@@ -15,41 +24,47 @@ import org.hibernate.criterion.Restrictions;
|
|||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import love.sola.netsupport.api.API;
|
||||||
|
import love.sola.netsupport.enums.Access;
|
||||||
|
import love.sola.netsupport.enums.Attribute;
|
||||||
|
import love.sola.netsupport.pojo.Ticket;
|
||||||
|
import love.sola.netsupport.pojo.User;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
|
import love.sola.netsupport.sql.SQLCore;
|
||||||
|
import love.sola.netsupport.wechat.Command;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/4.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class TicketQuery extends API {
|
public class TicketQuery extends API {
|
||||||
|
|
||||||
public TicketQuery() {
|
public TicketQuery() {
|
||||||
url = "/ticketquery";
|
url = "/ticketquery";
|
||||||
access = Access.USER;
|
access = Access.USER;
|
||||||
authorize = Command.QUERY;
|
authorize = Command.QUERY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
User u = (User) session.getAttribute(Attribute.USER);
|
User u = session.getAttribute(Attribute.USER);
|
||||||
Criteria c = s.createCriteria(Ticket.class);
|
Criteria c = s.createCriteria(Ticket.class);
|
||||||
int first = req.getParameter("offset") == null ? 0 : Integer.parseInt(req.getParameter("offset"));
|
int first = req.getParameter("offset") == null ? 0 : Integer.parseInt(req.getParameter("offset"));
|
||||||
int limit = req.getParameter("limit") == null ? 5 : Integer.parseInt(req.getParameter("limit"));
|
int limit = req.getParameter("limit") == null ? 5 : Integer.parseInt(req.getParameter("limit"));
|
||||||
c.setFirstResult(first);
|
c.setFirstResult(first);
|
||||||
c.setMaxResults(limit);
|
c.setMaxResults(limit);
|
||||||
c.addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME));
|
c.addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME));
|
||||||
c.add(Restrictions.eq(Ticket.PROPERTY_USER, u));
|
c.add(Restrictions.eq(Ticket.PROPERTY_USER, u));
|
||||||
if (req.getParameter("status") != null) {
|
if (req.getParameter("status") != null) {
|
||||||
c.add(Restrictions.eq(Ticket.PROPERTY_STATUS, Integer.parseInt(req.getParameter("status"))));
|
c.add(Restrictions.eq(Ticket.PROPERTY_STATUS, Integer.parseInt(req.getParameter("status"))));
|
||||||
} else if (req.getParameter("statusl") != null && req.getParameter("statush") != null) {
|
} else if (req.getParameter("statusl") != null && req.getParameter("statush") != null) {
|
||||||
c.add(Restrictions.between(Ticket.PROPERTY_STATUS,
|
c.add(Restrictions.between(Ticket.PROPERTY_STATUS,
|
||||||
Integer.parseInt(req.getParameter("statusl")),
|
Integer.parseInt(req.getParameter("statusl")),
|
||||||
Integer.parseInt(req.getParameter("statush"))
|
Integer.parseInt(req.getParameter("statush"))
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return c.list();
|
return c.list();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.api.user;
|
package love.sola.netsupport.api.user;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import love.sola.netsupport.api.API;
|
import love.sola.netsupport.api.API;
|
||||||
import love.sola.netsupport.api.Error;
|
import love.sola.netsupport.api.Error;
|
||||||
import love.sola.netsupport.config.Settings;
|
import love.sola.netsupport.config.Settings;
|
||||||
@@ -7,53 +28,47 @@ import love.sola.netsupport.enums.Access;
|
|||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.pojo.Ticket;
|
import love.sola.netsupport.pojo.Ticket;
|
||||||
import love.sola.netsupport.pojo.User;
|
import love.sola.netsupport.pojo.User;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
import love.sola.netsupport.sql.SQLCore;
|
import love.sola.netsupport.sql.SQLCore;
|
||||||
import love.sola.netsupport.sql.TableTicket;
|
import love.sola.netsupport.sql.TableTicket;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
import org.hibernate.Session;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/6.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class TicketSubmit extends API {
|
public class TicketSubmit extends API {
|
||||||
|
|
||||||
public TicketSubmit() {
|
public TicketSubmit() {
|
||||||
url = "/ticketsubmit";
|
url = "/ticketsubmit";
|
||||||
access = Access.USER;
|
access = Access.USER;
|
||||||
authorize = Command.SUBMIT;
|
authorize = Command.SUBMIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||||
String desc = req.getParameter("desc");
|
String desc = req.getParameter("desc");
|
||||||
if (desc == null || desc.isEmpty()) {
|
if (desc == null || desc.isEmpty()) {
|
||||||
return Error.PARAMETER_REQUIRED;
|
return Error.PARAMETER_REQUIRED;
|
||||||
}
|
}
|
||||||
if (desc.length() > Settings.MAX_DESC_LENGTH) {
|
if (desc.length() > Settings.MAX_DESC_LENGTH) {
|
||||||
return Error.LENGTH_LIMIT_EXCEEDED;
|
return Error.LENGTH_LIMIT_EXCEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
User u = (User) session.getAttribute(Attribute.USER);
|
User u = session.getAttribute(Attribute.USER);
|
||||||
if (TableTicket.hasOpen(u)) {
|
if (TableTicket.hasOpen(u)) {
|
||||||
session.invalidate();
|
session.invalidate();
|
||||||
return Error.ALREADY_SUBMITTED;
|
return Error.ALREADY_SUBMITTED;
|
||||||
}
|
}
|
||||||
Ticket t = new Ticket();
|
Ticket t = new Ticket();
|
||||||
t.setUser(u);
|
t.setUser(u);
|
||||||
t.setDescription(desc);
|
t.setDescription(desc);
|
||||||
t.setStatus(0);
|
t.setStatus(0);
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
s.save(t);
|
s.save(t);
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
session.invalidate();
|
session.invalidate();
|
||||||
return Error.OK;
|
return Error.OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.auth;
|
package love.sola.netsupport.auth;
|
||||||
|
|
||||||
import love.sola.netsupport.util.Checker;
|
import java.io.IOException;
|
||||||
import love.sola.netsupport.wechat.WechatSession;
|
import java.util.HashMap;
|
||||||
import love.sola.netsupport.wechat.WxMpServlet;
|
import java.util.Map;
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
import me.chanjar.weixin.mp.api.WxMpService;
|
|
||||||
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
|
|
||||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
|
||||||
|
|
||||||
import javax.servlet.AsyncContext;
|
import javax.servlet.AsyncContext;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
@@ -14,38 +27,59 @@ import javax.servlet.annotation.WebServlet;
|
|||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
|
||||||
|
import love.sola.netsupport.session.WechatSession;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
|
import love.sola.netsupport.util.Checker;
|
||||||
|
import love.sola.netsupport.wechat.WxMpServlet;
|
||||||
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
|
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2014/8/20.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
@WebServlet(name = "OAuth2", urlPatterns = "/oauth2/callback", loadOnStartup = 21)
|
@WebServlet(name = "OAuth2", urlPatterns = "/oauth2/callback", loadOnStartup = 21, asyncSupported = true)
|
||||||
public class OAuth2 extends HttpServlet {
|
public class OAuth2 extends HttpServlet {
|
||||||
|
|
||||||
@Override
|
private static Map<String, OAuth2Handler> oAuth2HandlerMap = new HashMap<>();
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
|
||||||
AsyncContext acxt = req.startAsync();
|
|
||||||
String code = req.getParameter("code");
|
|
||||||
String state = req.getParameter("state");
|
|
||||||
if (Checker.hasNull(code, state)) {
|
|
||||||
resp.sendError(HttpServletResponse.SC_FORBIDDEN);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
acxt.start(() -> {
|
|
||||||
try {
|
|
||||||
WxMpService wxMpService = WxMpServlet.instance.wxMpService;
|
|
||||||
WxMpOAuth2AccessToken token = wxMpService.oauth2getAccessToken(code);
|
|
||||||
WxMpUser wxUser = wxMpService.oauth2getUserInfo(token, "zh_CN");
|
|
||||||
String sid = WechatSession.genId();
|
|
||||||
WxSession session = WechatSession.get(sid, true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* for {@link love.sola.netsupport.wechat.WxMpServlet#registerCommands}
|
||||||
|
*
|
||||||
|
* @param state the state key from open platform callback.
|
||||||
|
* @param handler handler
|
||||||
|
*/
|
||||||
|
public static void registerOAuth2Handler(String state, OAuth2Handler handler) {
|
||||||
|
oAuth2HandlerMap.put(state, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
AsyncContext actx = req.startAsync();
|
||||||
|
String code = req.getParameter("code");
|
||||||
|
String state = req.getParameter("state");
|
||||||
|
if (Checker.hasNull(code, state)) {
|
||||||
|
resp.sendError(HttpServletResponse.SC_FORBIDDEN);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
OAuth2Handler handler = oAuth2HandlerMap.get(state);
|
||||||
|
if (handler == null) {
|
||||||
|
resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
actx.start(() -> {
|
||||||
|
try {
|
||||||
|
WxMpService wxMpService = WxMpServlet.instance.wxMpService;
|
||||||
|
WxMpOAuth2AccessToken token = wxMpService.oauth2getAccessToken(code);
|
||||||
|
String wechat = token.getOpenId();
|
||||||
|
WxSession session = WechatSession.create();
|
||||||
|
handler.onOAuth2(actx, (HttpServletResponse) actx.getResponse(), wechat, session);
|
||||||
|
actx.complete();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
32
src/main/java/love/sola/netsupport/auth/OAuth2Handler.java
Normal file
32
src/main/java/love/sola/netsupport/auth/OAuth2Handler.java
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package love.sola.netsupport.auth;
|
||||||
|
|
||||||
|
import javax.servlet.AsyncContext;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
|
*/
|
||||||
|
public interface OAuth2Handler {
|
||||||
|
|
||||||
|
void onOAuth2(AsyncContext actx, HttpServletResponse resp, String user, WxSession session);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package love.sola.netsupport.config;
|
|
||||||
|
|
||||||
import org.yaml.snakeyaml.Yaml;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ***********************************************
|
|
||||||
* Created by Sola on 2015/12/29.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
|
||||||
public class Cortana {
|
|
||||||
|
|
||||||
|
|
||||||
public static List<Compiled> entries;
|
|
||||||
|
|
||||||
public static void load() {
|
|
||||||
InputStream in = Lang.class.getClassLoader().getResourceAsStream("cortana.yml");
|
|
||||||
Map<String, Object> root = (Map<String, Object>) new Yaml().load(in);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static class Compiled {
|
|
||||||
Pattern[] patterns;
|
|
||||||
String[] replies;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.config;
|
package love.sola.netsupport.config;
|
||||||
|
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
@@ -8,36 +25,33 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/11/30.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class Lang {
|
public class Lang {
|
||||||
|
|
||||||
public static Map<String, String> messages;
|
public static Map<String, String> messages;
|
||||||
public static Map<String, MessageFormat> format_cache = new HashMap<>(32);
|
public static Map<String, MessageFormat> format_cache = new HashMap<>(32);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
InputStream in = Lang.class.getClassLoader().getResourceAsStream("lang.yml");
|
InputStream in = Lang.class.getClassLoader().getResourceAsStream("lang.yml");
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
messages = new Yaml().loadAs(in, Map.class);
|
messages = new Yaml().loadAs(in, Map.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String lang(String key) {
|
public static String lang(String key) {
|
||||||
String value = messages.get(key);
|
String value = messages.get(key);
|
||||||
return value == null ? "!!" + key + "!!" : value;
|
return value == null ? "!!" + key + "!!" : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String format(String key, Object... args) {
|
public static String format(String key, Object... args) {
|
||||||
MessageFormat cache = format_cache.get(key);
|
MessageFormat cache = format_cache.get(key);
|
||||||
if (cache != null) {
|
if (cache != null) {
|
||||||
return cache.format(args);
|
return cache.format(args);
|
||||||
} else {
|
} else {
|
||||||
cache = new MessageFormat(lang(key));
|
cache = new MessageFormat(lang(key));
|
||||||
format_cache.put(key, cache);
|
format_cache.put(key, cache);
|
||||||
return cache.format(args);
|
return cache.format(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,40 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.config;
|
package love.sola.netsupport.config;
|
||||||
|
|
||||||
import lombok.ToString;
|
|
||||||
import love.sola.netsupport.sql.TableConfig;
|
import love.sola.netsupport.sql.TableConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/11/23.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
@ToString
|
|
||||||
public class Settings {
|
public class Settings {
|
||||||
|
|
||||||
public static final int MAX_DESC_LENGTH = 255;
|
public static final int MAX_DESC_LENGTH = 255;
|
||||||
|
|
||||||
public static Settings I;
|
public static Settings I;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
I = TableConfig.getSettings();
|
I = TableConfig.getSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
public String Wechat_AppId;
|
||||||
// CONFIGURATIONS
|
public String Wechat_Secret;
|
||||||
// -------------------------------------------- //
|
public String Wechat_Token;
|
||||||
public String Wechat_AppId;
|
public String Wechat_AesKey;
|
||||||
public String Wechat_Secret;
|
|
||||||
public String Wechat_Token;
|
|
||||||
public String Wechat_AesKey;
|
|
||||||
|
|
||||||
public int Check_Spam_Cache_Expire_Time;
|
public int Check_Spam_Cache_Expire_Time;
|
||||||
public int Check_Spam_Interval;
|
public int Check_Spam_Interval;
|
||||||
|
|
||||||
public int User_Session_Max_Inactive;
|
public int User_Session_Max_Inactive;
|
||||||
public int User_Wechat_Cache_Expire_Time;
|
public int User_Wechat_Cache_Expire_Time;
|
||||||
|
|
||||||
//No arg constructor for Yaml.loadAs
|
//No arg constructor for Yaml.loadAs
|
||||||
public Settings() { I = this; }
|
public Settings() {
|
||||||
|
I = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Settings{" +
|
||||||
|
"Wechat_AppId='" + Wechat_AppId + '\'' +
|
||||||
|
", Wechat_Secret='" + Wechat_Secret + '\'' +
|
||||||
|
", Wechat_Token='" + Wechat_Token + '\'' +
|
||||||
|
", Wechat_AesKey='" + Wechat_AesKey + '\'' +
|
||||||
|
", Check_Spam_Cache_Expire_Time=" + Check_Spam_Cache_Expire_Time +
|
||||||
|
", Check_Spam_Interval=" + Check_Spam_Interval +
|
||||||
|
", User_Session_Max_Inactive=" + User_Session_Max_Inactive +
|
||||||
|
", User_Wechat_Cache_Expire_Time=" + User_Wechat_Cache_Expire_Time +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
package love.sola.netsupport.config;
|
|
||||||
|
|
||||||
import com.thoughtworks.xstream.XStream;
|
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|
||||||
import lombok.ToString;
|
|
||||||
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
|
|
||||||
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
@XStreamAlias("wechat-config")
|
|
||||||
@ToString
|
|
||||||
public class WxMpXmlInMemoryConfigStorage extends WxMpInMemoryConfigStorage {
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T> T fromXml(Class<T> clazz, InputStream is) {
|
|
||||||
XStream xstream = XStreamInitializer.getInstance();
|
|
||||||
xstream.alias("wechat-config", clazz);
|
|
||||||
xstream.processAnnotations(clazz);
|
|
||||||
return (T) xstream.fromXML(is);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.enums;
|
package love.sola.netsupport.enums;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@@ -7,47 +24,44 @@ import java.util.Map;
|
|||||||
import static love.sola.netsupport.config.Lang.lang;
|
import static love.sola.netsupport.config.Lang.lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/6.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class Access {
|
public class Access {
|
||||||
|
|
||||||
public static final int GOD_MODE = -1;
|
public static final int GOD_MODE = -1;
|
||||||
public static final int ROOT = 0;
|
public static final int ROOT = 0;
|
||||||
public static final int MANAGER = 1;
|
public static final int MANAGER = 1;
|
||||||
public static final int CO_MANAGER = 2;
|
public static final int CO_MANAGER = 2;
|
||||||
public static final int LEADER = 3;
|
public static final int LEADER = 3;
|
||||||
public static final int CO_LEADER = 4;
|
public static final int CO_LEADER = 4;
|
||||||
public static final int ELITE = 5;
|
public static final int ELITE = 5;
|
||||||
public static final int ELDER = 6;
|
public static final int ELDER = 6;
|
||||||
public static final int MEMBER = 7;
|
public static final int MEMBER = 7;
|
||||||
public static final int PRE_MEMBER = 8;
|
public static final int PRE_MEMBER = 8;
|
||||||
public static final int NO_LOGIN = 9;
|
public static final int NO_LOGIN = 9;
|
||||||
public static final int USER = 10;
|
public static final int USER = 10;
|
||||||
public static final int GUEST = 11;
|
public static final int GUEST = 11;
|
||||||
|
|
||||||
public static final Map<Integer, String> inverseMap = new HashMap<>();
|
public static final Map<Integer, String> inverseMap = new HashMap<>();
|
||||||
|
|
||||||
static{
|
static {
|
||||||
System.out.println("Loading Access...");
|
System.out.println("Loading Access...");
|
||||||
for (Field field : Access.class.getDeclaredFields()) {
|
for (Field field : Access.class.getDeclaredFields()) {
|
||||||
if (field.getType().isAssignableFrom(Integer.TYPE)) {
|
if (field.getType().isAssignableFrom(Integer.TYPE)) {
|
||||||
try {
|
try {
|
||||||
inverseMap.put((Integer) field.get(null), field.getName());
|
inverseMap.put((Integer) field.get(null), field.getName());
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLocalized(int access) {
|
public static String getLocalized(int access) {
|
||||||
if (inverseMap.containsKey(access)) {
|
if (inverseMap.containsKey(access)) {
|
||||||
return lang("ACCESS_" + inverseMap.get(access));
|
return lang("ACCESS_" + inverseMap.get(access));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.enums;
|
package love.sola.netsupport.enums;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/14.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class Attribute {
|
public class Attribute {
|
||||||
|
|
||||||
public static final String AUTHORIZED = "authorized";
|
public static final String AUTHORIZED = "authorized";
|
||||||
public static final String WECHAT = "wechat";
|
public static final String WECHAT = "wechat";
|
||||||
public static final String OPERATOR = "operator";
|
public static final String OPERATOR = "operator";
|
||||||
public static final String USER = "user";
|
public static final String USER = "user";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.enums;
|
package love.sola.netsupport.enums;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@@ -5,93 +22,114 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/11/30.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class Block {
|
public class Block {
|
||||||
|
|
||||||
public static final int QT_18 = 10;
|
public static final int QT_18 = 10;
|
||||||
public static final int QT_19 = 11;
|
public static final int QT_19 = 11;
|
||||||
public static final int QT_16 = 12;
|
public static final int QT_16 = 12;
|
||||||
public static final int QT_17 = 13;
|
public static final int QT_17 = 13;
|
||||||
public static final int BM_7 = 20;
|
public static final int BM_7 = 20;
|
||||||
public static final int BM_8 = 21;
|
public static final int BM_8 = 21;
|
||||||
public static final int BM_9 = 22;
|
public static final int BM_9 = 22;
|
||||||
public static final int BM_10 = 23;
|
public static final int BM_10 = 23;
|
||||||
public static final int BM_11 = 24;
|
public static final int BM_11 = 24;
|
||||||
public static final int DM_12 = 30;
|
public static final int DM_12 = 30;
|
||||||
public static final int DM_13 = 31;
|
public static final int DM_13 = 31;
|
||||||
public static final int DM_14 = 32;
|
public static final int DM_14 = 32;
|
||||||
public static final int DM_15 = 33;
|
public static final int DM_15 = 33;
|
||||||
public static final int DM_20 = 34;
|
public static final int DM_20 = 34;
|
||||||
public static final int DM_21 = 35;
|
public static final int DM_21 = 35;
|
||||||
public static final int XH_A = 40;
|
public static final int XH_A = 40;
|
||||||
public static final int XH_B = 41;
|
public static final int XH_B = 41;
|
||||||
public static final int XH_C = 42;
|
public static final int XH_C = 42;
|
||||||
public static final int XH_D = 43;
|
public static final int XH_D = 43;
|
||||||
public static final int FX_1 = 50;
|
public static final int FX_1 = 50;
|
||||||
public static final int FX_2 = 51;
|
public static final int FX_2 = 51;
|
||||||
public static final int FX_3 = 52;
|
public static final int FX_3 = 52;
|
||||||
public static final int FX_4 = 53;
|
public static final int FX_4 = 53;
|
||||||
public static final int FX_5 = 54;
|
public static final int FX_5 = 54;
|
||||||
public static final int FX_6 = 55;
|
public static final int FX_6 = 55;
|
||||||
|
public static final int BS_1 = 60;
|
||||||
|
public static final int BS_2 = 61;
|
||||||
|
public static final int BS_3 = 62;
|
||||||
|
public static final int BS_4 = 63;
|
||||||
|
public static final int BS_5 = 64;
|
||||||
|
public static final int BS_6 = 65;
|
||||||
|
public static final int BS_7 = 66;
|
||||||
|
public static final int BS_8 = 67;
|
||||||
|
public static final int BS_9 = 68;
|
||||||
|
public static final int ZH = 80;
|
||||||
|
|
||||||
public static final Map<Integer, String> inverseMap = new HashMap<>();
|
public static final Map<Integer, String> inverseMap = new HashMap<>();
|
||||||
|
|
||||||
static{
|
static {
|
||||||
System.out.println("Loading Blocks...");
|
System.out.println("Loading Blocks...");
|
||||||
for (Field field : Block.class.getDeclaredFields()) {
|
for (Field field : Block.class.getDeclaredFields()) {
|
||||||
if (field.getType().isAssignableFrom(Integer.TYPE)) {
|
if (field.getType().isAssignableFrom(Integer.TYPE)) {
|
||||||
try {
|
try {
|
||||||
inverseMap.put((Integer) field.get(null), field.getName());
|
inverseMap.put((Integer) field.get(null), field.getName());
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int[][] AVAILABLE = new int[62][0];
|
private static final int[][] AVAILABLE = new int[100][0];
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
// @formatter:off
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// THANKS DATA PROVIDED BY Lai Juncheng
|
// THANKS DATA PROVIDED BY Lai Juncheng
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
AVAILABLE[FX_1] = new int[]{108, 208, 308, 408, 508};
|
// UPDATE 2018:BS was destroyed.Update by HTroy
|
||||||
AVAILABLE[FX_2] = new int[]{110, 210, 310, 410, 510, 610};
|
// -------------------------------------------- //
|
||||||
AVAILABLE[FX_3] = new int[]{110, 210, 310, 410, 510, 610};
|
AVAILABLE[FX_1] = new int[]{108, 208, 308, 408, 508};
|
||||||
AVAILABLE[FX_4] = new int[]{110, 210, 310, 410, 510, 610, 710};
|
AVAILABLE[FX_2] = new int[]{110, 210, 310, 410, 510, 610};
|
||||||
AVAILABLE[FX_5] = new int[]{108, 208, 308, 408, 508, 608, 708};
|
AVAILABLE[FX_3] = new int[]{110, 210, 310, 410, 510, 610};
|
||||||
AVAILABLE[BM_7] = new int[]{100, 216, 317, 417, 517, 617, 717};
|
AVAILABLE[FX_4] = new int[]{110, 210, 310, 410, 510, 610, 710};
|
||||||
AVAILABLE[BM_8] = new int[]{100, 221, 321, 421, 521, 621, 721};
|
AVAILABLE[FX_5] = new int[]{108, 208, 308, 408, 508, 608, 708};
|
||||||
AVAILABLE[BM_9] = new int[]{100, 221, 321, 421, 521, 621};
|
AVAILABLE[BM_7] = new int[]{100, 216, 317, 417, 517, 617, 717};
|
||||||
AVAILABLE[BM_10] = new int[]{111, 239, 354, 454, 564, 664, 764, 864};
|
AVAILABLE[BM_8] = new int[]{100, 221, 321, 421, 521, 621, 721};
|
||||||
AVAILABLE[BM_11] = new int[]{100, 213, 321, 421, 521, 621, 721, 821};
|
AVAILABLE[BM_9] = new int[]{100, 221, 321, 421, 521, 621};
|
||||||
AVAILABLE[DM_12] = new int[]{119, 221, 321, 421, 521, 621, 720};
|
AVAILABLE[BM_10] = new int[]{111, 239, 354, 454, 564, 664, 764, 864};
|
||||||
AVAILABLE[DM_13] = new int[]{120, 222, 322, 422, 522, 622, 722};
|
AVAILABLE[BM_11] = new int[]{100, 213, 321, 421, 521, 621, 721, 821};
|
||||||
AVAILABLE[DM_14] = new int[]{100, 230, 330, 430, 530, 630, 730};
|
AVAILABLE[DM_12] = new int[]{119, 221, 321, 421, 521, 621, 720};
|
||||||
AVAILABLE[DM_15] = new int[]{119, 219, 319, 419, 519, 619};
|
AVAILABLE[DM_13] = new int[]{120, 222, 322, 422, 522, 622, 722};
|
||||||
AVAILABLE[QT_16] = new int[]{154, 257, 357, 457, 557, 657, 757};
|
AVAILABLE[DM_14] = new int[]{100, 230, 330, 430, 530, 630, 730};
|
||||||
AVAILABLE[QT_17] = new int[]{154, 257, 357, 457, 557, 657, 757};
|
AVAILABLE[DM_15] = new int[]{119, 219, 319, 419, 519, 619};
|
||||||
AVAILABLE[QT_18] = new int[]{139, 239, 339, 439, 539, 639, 739};
|
AVAILABLE[QT_16] = new int[]{154, 257, 357, 457, 557, 657, 757};
|
||||||
AVAILABLE[QT_19] = new int[]{100, 200, 332, 432, 532, 632, 732};
|
AVAILABLE[QT_17] = new int[]{154, 257, 357, 457, 557, 657, 757};
|
||||||
AVAILABLE[DM_20] = new int[]{109, 209, 309, 409, 509, 609, 709};
|
AVAILABLE[QT_18] = new int[]{139, 239, 339, 439, 539, 639, 739};
|
||||||
AVAILABLE[DM_21] = new int[]{109, 209, 309, 409, 509, 609, 709};
|
AVAILABLE[QT_19] = new int[]{100, 200, 332, 432, 532, 632, 732};
|
||||||
AVAILABLE[XH_A] = new int[]{129, 231, 331, 431, 531, 631, 731, 831, 931, 1031, 1131, 1231};
|
AVAILABLE[DM_20] = new int[]{109, 209, 309, 409, 509, 609, 709};
|
||||||
AVAILABLE[XH_B] = new int[]{129, 229, 329, 429, 529, 629, 729, 829, 929, 1029, 1129, 1229};
|
AVAILABLE[DM_21] = new int[]{109, 209, 309, 409, 509, 609, 709};
|
||||||
AVAILABLE[XH_C] = new int[]{126, 226, 326, 426, 526, 626, 726, 826, 926, 1026, 1126, 1226};
|
AVAILABLE[XH_A] = new int[]{129, 231, 331, 431, 531, 631, 731, 831, 931, 1031, 1131, 1231};
|
||||||
AVAILABLE[XH_D] = new int[]{128, 228, 328, 428, 528, 628, 728, 828, 928, 1028, 1128, 1228};
|
AVAILABLE[XH_B] = new int[]{129, 229, 329, 429, 529, 629, 729, 829, 929, 1029, 1129, 1229};
|
||||||
AVAILABLE[FX_6] = new int[0];
|
AVAILABLE[XH_C] = new int[]{126, 226, 326, 426, 526, 626, 726, 826, 926, 1026, 1126, 1226};
|
||||||
}
|
AVAILABLE[XH_D] = new int[]{128, 228, 328, 428, 528, 628, 728, 828, 928, 1028, 1128, 1228};
|
||||||
|
AVAILABLE[FX_6] = new int[0];
|
||||||
|
AVAILABLE[BS_1] = new int[0];
|
||||||
|
AVAILABLE[BS_2] = new int[0];
|
||||||
|
AVAILABLE[BS_3] = new int[0];
|
||||||
|
AVAILABLE[BS_4] = new int[0];
|
||||||
|
AVAILABLE[BS_5] = new int[0];
|
||||||
|
AVAILABLE[BS_6] = new int[0];
|
||||||
|
AVAILABLE[BS_7] = new int[0];
|
||||||
|
AVAILABLE[BS_8] = new int[0];
|
||||||
|
AVAILABLE[BS_9] = new int[0];
|
||||||
|
AVAILABLE[ZH] = new int[]{199, 299, 399, 499, 599, 699, 799, 899, 999, 1099, 1199, 1299, 1399, 1499};
|
||||||
|
// @formatter:on
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean checkRoom(int block, int room) {
|
public static boolean checkRoom(int block, int room) {
|
||||||
int floor = room / 100;
|
int floor = room / 100;
|
||||||
if (floor == 0 || room % 100 == 0) return false;
|
if (floor == 0 || room % 100 == 0) return false;
|
||||||
if (block < 0 || block >= AVAILABLE.length) return false;
|
if (block < 0 || block >= AVAILABLE.length) return false;
|
||||||
if (AVAILABLE[block].length < floor) return false;
|
if (AVAILABLE[block].length < floor) return false;
|
||||||
return room <= AVAILABLE[block][floor - 1];
|
return room <= AVAILABLE[block][floor - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.enums;
|
package love.sola.netsupport.enums;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -6,55 +23,54 @@ import java.util.Map;
|
|||||||
import static love.sola.netsupport.config.Lang.lang;
|
import static love.sola.netsupport.config.Lang.lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2014/8/20.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public enum ISP {
|
public enum ISP {
|
||||||
|
|
||||||
TELECOM(1, "^1[3|4|5|7|8][0-9]{9}$"),
|
TELECOM(1, "^1[3|4|5|6|7|8|9][0-9]{9}$"),
|
||||||
UNICOM(2, "ZSZJLAN[0-9]{10}@16900\\.gd"),
|
UNICOM(2, "^\\w+([-+.]\\w+)*@16900\\.gd"),
|
||||||
CHINAMOBILE(3, "^1[3|4|5|7|8][0-9]{9}@139\\.gd$"),
|
CHINAMOBILE(3, "^1[3|4|5|6|7|8|9][0-9]{9}@139\\.gd$"),
|
||||||
OTHER(4, ".*"),
|
OTHER(4, ".*"),
|
||||||
;
|
;
|
||||||
|
|
||||||
private static final Map<String, ISP> NAME_MAP = new HashMap<>();
|
private static final Map<String, ISP> NAME_MAP = new HashMap<>();
|
||||||
private static final Map<Integer, ISP> ID_MAP = new HashMap<>();
|
private static final Map<Integer, ISP> ID_MAP = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for (ISP type : values()) {
|
for (ISP type : values()) {
|
||||||
if (type.name != null) {
|
if (type.name != null) {
|
||||||
NAME_MAP.put(type.name.toLowerCase(), type);
|
NAME_MAP.put(type.name.toLowerCase(), type);
|
||||||
}
|
}
|
||||||
if (type.id > 0) {
|
if (type.id > 0) {
|
||||||
ID_MAP.put(type.id, type);
|
ID_MAP.put(type.id, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int id;
|
public final int id;
|
||||||
public final String name;
|
public final String name;
|
||||||
public final String accountRegex;
|
public final String accountRegex;
|
||||||
|
|
||||||
ISP(int id, String accountRegex) {
|
ISP(int id, String accountRegex) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = lang("ISP_" + name());
|
this.name = lang("ISP_" + name());
|
||||||
this.accountRegex = accountRegex;
|
this.accountRegex = accountRegex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ISP fromName(String name) {
|
public static ISP fromName(String name) {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return NAME_MAP.get(name.toLowerCase());
|
return NAME_MAP.get(name.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ISP fromId(int id) {
|
public static ISP fromId(int id) {
|
||||||
return ID_MAP.get(id);
|
return ID_MAP.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() { return name; }
|
public String toString() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.enums;
|
package love.sola.netsupport.enums;
|
||||||
|
|
||||||
import javax.persistence.AttributeConverter;
|
import javax.persistence.AttributeConverter;
|
||||||
import javax.persistence.Converter;
|
import javax.persistence.Converter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
|
*/
|
||||||
@Converter
|
@Converter
|
||||||
public class ISPConverter implements AttributeConverter<ISP, Integer> {
|
public class ISPConverter implements AttributeConverter<ISP, Integer> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer convertToDatabaseColumn(ISP attribute) {
|
public Integer convertToDatabaseColumn(ISP attribute) {
|
||||||
if (attribute == null) {
|
if (attribute == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return attribute.id;
|
return attribute.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ISP convertToEntityAttribute(Integer dbData) {
|
public ISP convertToEntityAttribute(Integer dbData) {
|
||||||
if (dbData == null) {
|
if (dbData == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return ISP.fromId(dbData);
|
return ISP.fromId(dbData);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.enums;
|
package love.sola.netsupport.enums;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@@ -7,40 +24,37 @@ import java.util.Map;
|
|||||||
import static love.sola.netsupport.config.Lang.lang;
|
import static love.sola.netsupport.config.Lang.lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/6.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class Status {
|
public class Status {
|
||||||
|
|
||||||
public static final int UNCHECKED = 0;
|
public static final int UNCHECKED = 0;
|
||||||
public static final int ARRANGED = 1;
|
public static final int ARRANGED = 1;
|
||||||
public static final int PUTOFF = 2;
|
public static final int PUTOFF = 2;
|
||||||
public static final int REPORTED = 4;
|
public static final int REPORTED = 4;
|
||||||
public static final int ISP_HANDLED = 7;
|
public static final int ISP_HANDLED = 7;
|
||||||
public static final int SOLVED = 9;
|
public static final int SOLVED = 9;
|
||||||
|
|
||||||
public static final Map<Integer, String> inverseMap = new HashMap<>();
|
public static final Map<Integer, String> inverseMap = new HashMap<>();
|
||||||
|
|
||||||
static{
|
static {
|
||||||
System.out.println("Loading Status...");
|
System.out.println("Loading Status...");
|
||||||
for (Field field : Status.class.getDeclaredFields()) {
|
for (Field field : Status.class.getDeclaredFields()) {
|
||||||
if (field.getType().isAssignableFrom(Integer.TYPE)) {
|
if (field.getType().isAssignableFrom(Integer.TYPE)) {
|
||||||
try {
|
try {
|
||||||
inverseMap.put((Integer) field.get(null), field.getName());
|
inverseMap.put((Integer) field.get(null), field.getName());
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLocalized(int status) {
|
public static String getLocalized(int status) {
|
||||||
if (inverseMap.containsKey(status)) {
|
if (inverseMap.containsKey(status)) {
|
||||||
return lang("STATUS_" + inverseMap.get(status));
|
return lang("STATUS_" + inverseMap.get(status));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.pojo;
|
package love.sola.netsupport.pojo;
|
||||||
|
|
||||||
import com.google.gson.annotations.Expose;
|
import com.google.gson.annotations.Expose;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.ToString;
|
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
@@ -12,40 +25,111 @@ import javax.persistence.Id;
|
|||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/6.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Data
|
|
||||||
@ToString(exclude = "password")
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "operators")
|
@Table(name = "operators")
|
||||||
public class Operator {
|
public class Operator {
|
||||||
|
|
||||||
public static final String PROPERTY_WECHAT = "wechat";
|
public static final String PROPERTY_WECHAT = "wechat";
|
||||||
|
|
||||||
@Id
|
//System Accounts
|
||||||
@Column(name = "id", nullable = false, insertable = false, updatable = false)
|
public static Operator USER_SELF;
|
||||||
private Integer id;
|
public static Operator ADMIN;
|
||||||
@Column(name = "name", nullable = false, insertable = false, updatable = false)
|
|
||||||
private String name;
|
|
||||||
@Column(name = "access", nullable = false, insertable = false, updatable = false)
|
|
||||||
private Integer access;
|
|
||||||
@Column(name = "wechat", insertable = false, updatable = false)
|
|
||||||
@Expose(serialize = false)
|
|
||||||
private String wechat;
|
|
||||||
private Integer block;
|
|
||||||
private Integer week;
|
|
||||||
@Expose(serialize = false)
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "id", nullable = false, insertable = false, updatable = false)
|
||||||
|
private Integer id;
|
||||||
|
@Column(name = "name", nullable = false, insertable = false, updatable = false)
|
||||||
|
private String name;
|
||||||
|
@Column(name = "access", nullable = false, insertable = false, updatable = false)
|
||||||
|
private Integer access;
|
||||||
|
@Column(name = "wechat", insertable = false, updatable = false)
|
||||||
|
@Expose(serialize = false)
|
||||||
|
private String wechat;
|
||||||
|
private Integer block;
|
||||||
|
private Integer week;
|
||||||
|
@Expose(serialize = false)
|
||||||
|
private String password;
|
||||||
|
|
||||||
//System Accounts
|
public Operator(Integer id, String name, Integer access, String wechat, Integer block, Integer week, String password) {
|
||||||
public static Operator USER_SELF;
|
this.id = id;
|
||||||
public static Operator ADMIN;
|
this.name = name;
|
||||||
|
this.access = access;
|
||||||
|
this.wechat = wechat;
|
||||||
|
this.block = block;
|
||||||
|
this.week = week;
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Operator() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getAccess() {
|
||||||
|
return access;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccess(Integer access) {
|
||||||
|
this.access = access;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWechat() {
|
||||||
|
return wechat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWechat(String wechat) {
|
||||||
|
this.wechat = wechat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getBlock() {
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlock(Integer block) {
|
||||||
|
this.block = block;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getWeek() {
|
||||||
|
return week;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeek(Integer week) {
|
||||||
|
this.week = week;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Operator{" +
|
||||||
|
"id=" + id +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
", access=" + access +
|
||||||
|
", wechat='" + wechat + '\'' +
|
||||||
|
", block=" + block +
|
||||||
|
", week=" + week +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +1,154 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.pojo;
|
package love.sola.netsupport.pojo;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import love.sola.netsupport.sql.TableTicket;
|
|
||||||
import org.hibernate.envers.Audited;
|
import org.hibernate.envers.Audited;
|
||||||
import org.hibernate.envers.RelationTargetAuditMode;
|
import org.hibernate.envers.RelationTargetAuditMode;
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.ManyToOne;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import love.sola.netsupport.sql.TableTicket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/2.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "tickets")
|
@Table(name = "tickets")
|
||||||
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
|
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
|
||||||
public class Ticket {
|
public class Ticket {
|
||||||
|
|
||||||
public static final String PROPERTY_USER = "user";
|
public static final String PROPERTY_USER = "user";
|
||||||
public static final String PROPERTY_STATUS = "status";
|
public static final String PROPERTY_STATUS = "status";
|
||||||
public static final String PROPERTY_SUBMIT_TIME = "submitTime";
|
public static final String PROPERTY_SUBMIT_TIME = "submitTime";
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Integer id;
|
private Integer id;
|
||||||
@ManyToOne(optional = false)
|
@ManyToOne(optional = false)
|
||||||
@JoinColumn(name = TableTicket.COLUMN_SID)
|
@JoinColumn(name = TableTicket.COLUMN_SID)
|
||||||
private User user;
|
private User user;
|
||||||
private String description;
|
private String description;
|
||||||
@Column(name = TableTicket.COLUMN_SUBMIT_TIME, insertable = false, updatable = false)
|
@Column(name = TableTicket.COLUMN_SUBMIT_TIME, insertable = false, updatable = false)
|
||||||
private Date submitTime;
|
private Date submitTime;
|
||||||
private String remark;
|
private String remark;
|
||||||
private Date updateTime;
|
private Date updateTime;
|
||||||
@ManyToOne(optional = true)
|
@ManyToOne
|
||||||
@JoinColumn(name = TableTicket.COLUMN_OPSID)
|
@JoinColumn(name = TableTicket.COLUMN_OPSID)
|
||||||
private Operator operator;
|
private Operator operator;
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
|
public Ticket() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Ticket(User user, String description, Date submitTime, String remark, Date updateTime, Operator operator, Integer status) {
|
||||||
|
this.user = user;
|
||||||
|
this.description = description;
|
||||||
|
this.submitTime = submitTime;
|
||||||
|
this.remark = remark;
|
||||||
|
this.updateTime = updateTime;
|
||||||
|
this.operator = operator;
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getSubmitTime() {
|
||||||
|
return submitTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubmitTime(Date submitTime) {
|
||||||
|
this.submitTime = submitTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRemark() {
|
||||||
|
return remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemark(String remark) {
|
||||||
|
this.remark = remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getUpdateTime() {
|
||||||
|
return updateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdateTime(Date updateTime) {
|
||||||
|
this.updateTime = updateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Operator getOperator() {
|
||||||
|
return operator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOperator(Operator operator) {
|
||||||
|
this.operator = operator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Integer status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Ticket{" +
|
||||||
|
"id=" + id +
|
||||||
|
", user=" + user +
|
||||||
|
", description='" + description + '\'' +
|
||||||
|
", submitTime=" + submitTime +
|
||||||
|
", remark='" + remark + '\'' +
|
||||||
|
", updateTime=" + updateTime +
|
||||||
|
", operator=" + operator +
|
||||||
|
", status=" + status +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
114
src/main/java/love/sola/netsupport/pojo/ToolsCheck.java
Normal file
114
src/main/java/love/sola/netsupport/pojo/ToolsCheck.java
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
package love.sola.netsupport.pojo;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
import org.hibernate.annotations.DynamicInsert;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Index;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.ManyToOne;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "toolschk", indexes = {
|
||||||
|
@Index(columnList = "block,chktime,status"),
|
||||||
|
@Index(columnList = "chktime,status")
|
||||||
|
})
|
||||||
|
@DynamicInsert
|
||||||
|
public class ToolsCheck {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
@ManyToOne(optional = false)
|
||||||
|
@JoinColumn(name = "opsid", nullable = false)
|
||||||
|
private Operator operator;
|
||||||
|
@Column(nullable = false)
|
||||||
|
private Integer block;
|
||||||
|
@Column(name = "chktime", nullable = false)
|
||||||
|
private Date checkTime = new Date();
|
||||||
|
@ColumnDefault("0")
|
||||||
|
private Integer status = 0;
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
|
||||||
|
public ToolsCheck() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ToolsCheck(Operator operator, Integer block, Date checkTime, Integer status, String remark) {
|
||||||
|
this.operator = operator;
|
||||||
|
this.block = block;
|
||||||
|
this.checkTime = checkTime;
|
||||||
|
this.status = status;
|
||||||
|
this.remark = remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Operator getOperator() {
|
||||||
|
return operator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOperator(Operator operator) {
|
||||||
|
this.operator = operator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getBlock() {
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlock(Integer block) {
|
||||||
|
this.block = block;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCheckTime() {
|
||||||
|
return checkTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCheckTime(Date checkTime) {
|
||||||
|
this.checkTime = checkTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Integer status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRemark() {
|
||||||
|
return remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemark(String remark) {
|
||||||
|
this.remark = remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ToolsCheck{" +
|
||||||
|
"id=" + id +
|
||||||
|
", operator=" + operator +
|
||||||
|
", block=" + block +
|
||||||
|
", checkTime=" + checkTime +
|
||||||
|
", status=" + status +
|
||||||
|
", remark='" + remark + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,51 +1,154 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.pojo;
|
package love.sola.netsupport.pojo;
|
||||||
|
|
||||||
import com.google.gson.annotations.Expose;
|
import com.google.gson.annotations.Expose;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
import javax.persistence.Column;
|
||||||
import lombok.NoArgsConstructor;
|
import javax.persistence.Convert;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import love.sola.netsupport.enums.ISP;
|
import love.sola.netsupport.enums.ISP;
|
||||||
import love.sola.netsupport.enums.ISPConverter;
|
import love.sola.netsupport.enums.ISPConverter;
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2014/8/20.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "users")
|
@Table(name = "users")
|
||||||
public class User {
|
public class User {
|
||||||
|
|
||||||
public static final String PROPERTY_NAME = "name";
|
//System Accounts
|
||||||
public static final String PROPERTY_WECHAT = "wechatId";
|
public static User OFFICIAL_CHINA_UNICOM_XH;
|
||||||
public static final String PROPERTY_BLOCK = "block";
|
public static User OFFICIAL_CHINA_MOBILE_XH;
|
||||||
|
public static User OFFICIAL_CHINA_MOBILE_FX;
|
||||||
|
|
||||||
@Id
|
public static final String PROPERTY_NAME = "name";
|
||||||
@Column(name = "id", updatable = false, nullable = false)
|
public static final String PROPERTY_WECHAT = "wechatId";
|
||||||
private Long id;
|
public static final String PROPERTY_BLOCK = "block";
|
||||||
@Column(name = "name", updatable = false, nullable = false)
|
|
||||||
private String name;
|
|
||||||
@Convert(converter = ISPConverter.class)
|
|
||||||
private ISP isp;
|
|
||||||
@Column(name = "netaccount")
|
|
||||||
private String netAccount;
|
|
||||||
@Expose(serialize = false)
|
|
||||||
@Column(name = "wechat")
|
|
||||||
private String wechatId;
|
|
||||||
private Integer block;
|
|
||||||
private Integer room;
|
|
||||||
private Long phone;
|
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "id", updatable = false, nullable = false)
|
||||||
|
private Long id;
|
||||||
|
@Column(name = "name", updatable = false, nullable = false)
|
||||||
|
private String name;
|
||||||
|
@Convert(converter = ISPConverter.class)
|
||||||
|
private ISP isp;
|
||||||
|
@Column(name = "netaccount")
|
||||||
|
private String netAccount;
|
||||||
|
@Expose(serialize = false)
|
||||||
|
@Column(name = "wechat")
|
||||||
|
private String wechatId;
|
||||||
|
private Integer block;
|
||||||
|
private Integer room;
|
||||||
|
private Long phone;
|
||||||
|
|
||||||
//System Accounts
|
public User() {
|
||||||
public static User OFFICIAL_CHINA_UNICOM_XH;
|
}
|
||||||
public static User OFFICIAL_CHINA_MOBILE_XH;
|
|
||||||
public static User OFFICIAL_CHINA_MOBILE_FX;
|
|
||||||
|
|
||||||
|
public User(Long id, String name, ISP isp, String netAccount, String wechatId, Integer block, Integer room, Long phone) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.isp = isp;
|
||||||
|
this.netAccount = netAccount;
|
||||||
|
this.wechatId = wechatId;
|
||||||
|
this.block = block;
|
||||||
|
this.room = room;
|
||||||
|
this.phone = phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ISP getIsp() {
|
||||||
|
return isp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsp(ISP isp) {
|
||||||
|
this.isp = isp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNetAccount() {
|
||||||
|
return netAccount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNetAccount(String netAccount) {
|
||||||
|
this.netAccount = netAccount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWechatId() {
|
||||||
|
return wechatId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWechatId(String wechatId) {
|
||||||
|
this.wechatId = wechatId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getBlock() {
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlock(Integer block) {
|
||||||
|
this.block = block;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getRoom() {
|
||||||
|
return room;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoom(Integer room) {
|
||||||
|
this.room = room;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getPhone() {
|
||||||
|
return phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPhone(Long phone) {
|
||||||
|
this.phone = phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "User{" +
|
||||||
|
"id=" + id +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
", isp=" + isp +
|
||||||
|
", netAccount='" + netAccount + '\'' +
|
||||||
|
", wechatId='" + wechatId + '\'' +
|
||||||
|
", block=" + block +
|
||||||
|
", room=" + room +
|
||||||
|
", phone=" + phone +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
130
src/main/java/love/sola/netsupport/session/MapSession.java
Normal file
130
src/main/java/love/sola/netsupport/session/MapSession.java
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2015 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
package love.sola.netsupport.session;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
|
*/
|
||||||
|
public final class MapSession implements WxSession, Serializable {
|
||||||
|
|
||||||
|
private final String id;
|
||||||
|
private Map<String, Object> sessionAttrs = new HashMap<String, Object>();
|
||||||
|
private long creationTime = System.currentTimeMillis();
|
||||||
|
private long lastAccessedTime = creationTime;
|
||||||
|
private boolean invalidated = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance with a secure randomly generated identifier.
|
||||||
|
*/
|
||||||
|
public MapSession() {
|
||||||
|
this(UUID.randomUUID().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance with the specified id. This is preferred to the
|
||||||
|
* default constructor when the id is known to prevent unnecessary consumption on
|
||||||
|
* entropy which can be slow.
|
||||||
|
*
|
||||||
|
* @param id the identifier to use
|
||||||
|
*/
|
||||||
|
public MapSession(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T> T getAttribute(String attributeName) {
|
||||||
|
return (T) sessionAttrs.get(attributeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getAttributeNames() {
|
||||||
|
return sessionAttrs.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAttribute(String attributeName, Object attributeValue) {
|
||||||
|
if (attributeValue == null) {
|
||||||
|
removeAttribute(attributeName);
|
||||||
|
} else {
|
||||||
|
sessionAttrs.put(attributeName, attributeValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeAttribute(String attributeName) {
|
||||||
|
sessionAttrs.remove(attributeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void invalidate() {
|
||||||
|
invalidated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLastAccessedTime() {
|
||||||
|
return lastAccessedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastAccessedTime(long lastAccessedTime) {
|
||||||
|
this.lastAccessedTime = lastAccessedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getId() {
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCreationTime() {
|
||||||
|
return creationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInvalidated() {
|
||||||
|
return invalidated;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof MapSession)) return false;
|
||||||
|
MapSession that = (MapSession) o;
|
||||||
|
return Objects.equals(id, that.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2015 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
package love.sola.netsupport.session;
|
||||||
|
|
||||||
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
import com.google.common.cache.CacheLoader;
|
||||||
|
import com.google.common.cache.LoadingCache;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.Validate;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import love.sola.netsupport.config.Settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
|
*/
|
||||||
|
public class MapSessionRepository {
|
||||||
|
|
||||||
|
private final LoadingCache<String, MapSession> sessions;
|
||||||
|
|
||||||
|
public MapSessionRepository() {
|
||||||
|
this(CacheBuilder.newBuilder()
|
||||||
|
.concurrencyLevel(4)
|
||||||
|
.maximumSize(65535)
|
||||||
|
.expireAfterAccess(Settings.I.User_Session_Max_Inactive, TimeUnit.SECONDS)
|
||||||
|
.build(new CacheLoader<String, MapSession>() {
|
||||||
|
@Override
|
||||||
|
public MapSession load(@Nonnull String key) throws Exception {
|
||||||
|
return new MapSession(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapSessionRepository(LoadingCache<String, MapSession> sessions) {
|
||||||
|
Validate.notNull(sessions);
|
||||||
|
this.sessions = sessions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save(MapSession session) {
|
||||||
|
sessions.put(session.getId(), session);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapSession getSession(String id) {
|
||||||
|
MapSession saved = sessions.getIfPresent(id);
|
||||||
|
if (saved == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (saved.isInvalidated()) {
|
||||||
|
delete(saved.getId());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return saved;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(String id) {
|
||||||
|
sessions.invalidate(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapSession createSession() {
|
||||||
|
MapSession session = new MapSession();
|
||||||
|
save(session);
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, MapSession> asMap() {
|
||||||
|
return sessions.asMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package love.sola.netsupport.session;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
|
*/
|
||||||
|
public class WechatSession {
|
||||||
|
|
||||||
|
private static MapSessionRepository repository;
|
||||||
|
|
||||||
|
static {
|
||||||
|
repository = new MapSessionRepository();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WxSession get(String id) {
|
||||||
|
return repository.getSession(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WxSession create() {
|
||||||
|
return repository.createSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends WxSession> list() {
|
||||||
|
return repository.asMap().values();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
39
src/main/java/love/sola/netsupport/session/WxSession.java
Normal file
39
src/main/java/love/sola/netsupport/session/WxSession.java
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package love.sola.netsupport.session;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
|
*/
|
||||||
|
public interface WxSession {
|
||||||
|
|
||||||
|
String getId();
|
||||||
|
|
||||||
|
<T> T getAttribute(String name);
|
||||||
|
|
||||||
|
Set<String> getAttributeNames();
|
||||||
|
|
||||||
|
void setAttribute(String name, Object value);
|
||||||
|
|
||||||
|
void removeAttribute(String name);
|
||||||
|
|
||||||
|
void invalidate();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,12 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.sql;
|
package love.sola.netsupport.sql;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.ExclusionStrategy;
|
||||||
|
import com.google.gson.FieldAttributes;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.JsonDeserializer;
|
||||||
|
import com.google.gson.JsonPrimitive;
|
||||||
|
import com.google.gson.JsonSerializer;
|
||||||
|
import com.google.gson.TypeAdapter;
|
||||||
|
import com.google.gson.TypeAdapterFactory;
|
||||||
import com.google.gson.annotations.Expose;
|
import com.google.gson.annotations.Expose;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
import love.sola.netsupport.enums.ISP;
|
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
||||||
import love.sola.netsupport.wechat.Command;
|
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
@@ -17,113 +42,126 @@ import org.hibernate.envers.AuditReaderFactory;
|
|||||||
import org.hibernate.proxy.HibernateProxy;
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
|
|
||||||
import javax.naming.InitialContext;
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.naming.InitialContext;
|
||||||
|
import javax.naming.NamingException;
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
import love.sola.netsupport.enums.ISP;
|
||||||
|
import love.sola.netsupport.wechat.Command;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2014/8/20.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class SQLCore {
|
public class SQLCore {
|
||||||
|
|
||||||
public static DataSource ds;
|
public static InitialContext ic;
|
||||||
public static Gson gson = new GsonBuilder()
|
public static DataSource ds;
|
||||||
.addSerializationExclusionStrategy(new ExclusionStrategy() {
|
public static SessionFactory sf;
|
||||||
@Override
|
public static ServiceRegistry sr;
|
||||||
public boolean shouldSkipField(FieldAttributes fieldAttributes) {
|
public static Gson gson = new GsonBuilder()
|
||||||
final Expose expose = fieldAttributes.getAnnotation(Expose.class);
|
.addSerializationExclusionStrategy(new ExclusionStrategy() {
|
||||||
return expose != null && !expose.serialize();
|
@Override
|
||||||
}
|
public boolean shouldSkipField(FieldAttributes fieldAttributes) {
|
||||||
|
final Expose expose = fieldAttributes.getAnnotation(Expose.class);
|
||||||
|
return expose != null && !expose.serialize();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldSkipClass(Class<?> aClass) {
|
public boolean shouldSkipClass(Class<?> aClass) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.addDeserializationExclusionStrategy(new ExclusionStrategy() {
|
.addDeserializationExclusionStrategy(new ExclusionStrategy() {
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldSkipField(FieldAttributes fieldAttributes) {
|
public boolean shouldSkipField(FieldAttributes fieldAttributes) {
|
||||||
final Expose expose = fieldAttributes.getAnnotation(Expose.class);
|
final Expose expose = fieldAttributes.getAnnotation(Expose.class);
|
||||||
return expose != null && !expose.deserialize();
|
return expose != null && !expose.deserialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldSkipClass(Class<?> aClass) {
|
public boolean shouldSkipClass(Class<?> aClass) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.registerTypeAdapter(Date.class, (JsonDeserializer<Date>) (json, typeOfT, context) -> new Date(json.getAsJsonPrimitive().getAsLong()))
|
.registerTypeAdapter(Date.class, (JsonDeserializer<Date>) (json, typeOfT, context) -> new Date(json.getAsJsonPrimitive().getAsLong()))
|
||||||
.registerTypeAdapter(Date.class, (JsonSerializer<Date>) (src, typeOfSrc, context) -> new JsonPrimitive(src.getTime()))
|
.registerTypeAdapter(Date.class, (JsonSerializer<Date>) (src, typeOfSrc, context) -> new JsonPrimitive(src.getTime()))
|
||||||
.registerTypeAdapter(ISP.class, (JsonDeserializer<ISP>) (json, typeOfT, context) -> ISP.fromId(json.getAsJsonPrimitive().getAsInt()))
|
.registerTypeAdapter(ISP.class, (JsonDeserializer<ISP>) (json, typeOfT, context) -> ISP.fromId(json.getAsJsonPrimitive().getAsInt()))
|
||||||
.registerTypeAdapter(ISP.class, (JsonSerializer<ISP>) (src, typeOfSrc, context) -> new JsonPrimitive(src.id))
|
.registerTypeAdapter(ISP.class, (JsonSerializer<ISP>) (src, typeOfSrc, context) -> new JsonPrimitive(src.id))
|
||||||
.registerTypeAdapter(Command.class, (JsonDeserializer<Command>) (json, typeOfT, context) -> Command.fromId(json.getAsJsonPrimitive().getAsInt()))
|
.registerTypeAdapter(Command.class, (JsonDeserializer<Command>) (json, typeOfT, context) -> Command.fromId(json.getAsJsonPrimitive().getAsInt()))
|
||||||
.registerTypeAdapter(Command.class, (JsonSerializer<Command>) (src, typeOfSrc, context) -> new JsonPrimitive(src.id))
|
.registerTypeAdapter(Command.class, (JsonSerializer<Command>) (src, typeOfSrc, context) -> new JsonPrimitive(src.id))
|
||||||
.registerTypeAdapterFactory(HibernateProxyTypeAdapter.FACTORY)
|
.registerTypeAdapterFactory(HibernateProxyTypeAdapter.FACTORY)
|
||||||
.create();
|
.create();
|
||||||
public static SessionFactory sf;
|
|
||||||
public static ServiceRegistry sr;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
InitialContext ic = new InitialContext();
|
ic = new InitialContext();
|
||||||
ds = (DataSource) ic.lookup("java:comp/env/jdbc/netsupport");
|
ds = (DataSource) ic.lookup("java:comp/env/jdbc/netsupport");
|
||||||
ds.setLoginTimeout(3);
|
ds.setLoginTimeout(3);
|
||||||
|
|
||||||
sr = new StandardServiceRegistryBuilder().configure().build();
|
sr = new StandardServiceRegistryBuilder().configure().build();
|
||||||
sf = new MetadataSources(sr).buildMetadata().buildSessionFactory();
|
sf = new MetadataSources(sr).buildMetadata().buildSessionFactory();
|
||||||
|
|
||||||
TableUser.init();
|
TableUser.init();
|
||||||
TableOperator.init();
|
TableOperator.init();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AuditReader getAuditReader(Session session) {
|
public static void destroy() {
|
||||||
return AuditReaderFactory.get(session);
|
try {
|
||||||
}
|
SQLCore.sf.close();
|
||||||
|
((ComboPooledDataSource) SQLCore.ds).close();
|
||||||
|
SQLCore.ic.close();
|
||||||
|
} catch (NamingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class HibernateProxyTypeAdapter extends TypeAdapter<HibernateProxy> {
|
public static AuditReader getAuditReader(Session session) {
|
||||||
|
return AuditReaderFactory.get(session);
|
||||||
|
}
|
||||||
|
|
||||||
public static final TypeAdapterFactory FACTORY = new TypeAdapterFactory() {
|
public static class HibernateProxyTypeAdapter extends TypeAdapter<HibernateProxy> {
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
|
|
||||||
return (HibernateProxy.class.isAssignableFrom(type.getRawType()) ? (TypeAdapter<T>) new HibernateProxyTypeAdapter(gson) : null);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
private final Gson context;
|
|
||||||
|
|
||||||
private HibernateProxyTypeAdapter(Gson context) {
|
public static final TypeAdapterFactory FACTORY = new TypeAdapterFactory() {
|
||||||
this.context = context;
|
@Override
|
||||||
}
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
|
||||||
|
return (HibernateProxy.class.isAssignableFrom(type.getRawType()) ? (TypeAdapter<T>) new HibernateProxyTypeAdapter(gson) : null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
private final Gson context;
|
||||||
|
|
||||||
@Override
|
private HibernateProxyTypeAdapter(Gson context) {
|
||||||
public HibernateProxy read(JsonReader in) throws IOException {
|
this.context = context;
|
||||||
throw new UnsupportedOperationException("Not supported");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
@Override
|
||||||
@Override
|
public HibernateProxy read(JsonReader in) throws IOException {
|
||||||
public void write(JsonWriter out, HibernateProxy value) throws IOException {
|
throw new UnsupportedOperationException("Not supported");
|
||||||
if (value == null) {
|
}
|
||||||
out.nullValue();
|
|
||||||
return;
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
}
|
@Override
|
||||||
// Retrieve the original (not proxy) class
|
public void write(JsonWriter out, HibernateProxy value) throws IOException {
|
||||||
Class<?> baseType = Hibernate.getClass(value);
|
if (value == null) {
|
||||||
// Get the TypeAdapter of the original class, to delegate the serialization
|
out.nullValue();
|
||||||
TypeAdapter delegate = context.getAdapter(TypeToken.get(baseType));
|
return;
|
||||||
// Get a filled instance of the original class
|
}
|
||||||
Object unproxiedValue = ((HibernateProxy) value).getHibernateLazyInitializer()
|
// Retrieve the original (not proxy) class
|
||||||
.getImplementation();
|
Class<?> baseType = Hibernate.getClass(value);
|
||||||
// Serialize the value
|
// Get the TypeAdapter of the original class, to delegate the serialization
|
||||||
delegate.write(out, unproxiedValue);
|
TypeAdapter delegate = context.getAdapter(TypeToken.get(baseType));
|
||||||
}
|
// Get a filled instance of the original class
|
||||||
}
|
Object unproxiedValue = value.getHibernateLazyInitializer()
|
||||||
|
.getImplementation();
|
||||||
|
// Serialize the value
|
||||||
|
delegate.write(out, unproxiedValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.sql;
|
package love.sola.netsupport.sql;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
|
||||||
import love.sola.netsupport.config.Settings;
|
import love.sola.netsupport.config.Settings;
|
||||||
|
|
||||||
import java.sql.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/11/10.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class TableConfig extends SQLCore{
|
public class TableConfig extends SQLCore {
|
||||||
|
|
||||||
public static final String KEY_SYS = "sys";
|
public static final String KEY_SYS = "sys";
|
||||||
|
|
||||||
public static Settings getSettings() {
|
public static Settings getSettings() {
|
||||||
try (Connection conn = ds.getConnection()) {
|
try (Connection conn = ds.getConnection()) {
|
||||||
Statement st = conn.createStatement();
|
Statement st = conn.createStatement();
|
||||||
ResultSet rs = st.executeQuery("SELECT * FROM settings WHERE type='" + KEY_SYS + "'");
|
ResultSet rs = st.executeQuery("SELECT * FROM settings WHERE type='" + KEY_SYS + "'");
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
return gson.fromJson(rs.getString("data"), Settings.class);
|
return gson.fromJson(rs.getString("data"), Settings.class);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) { }
|
} catch (SQLException e) {
|
||||||
return null;
|
}
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static int saveSettings(Settings obj) {
|
public static int saveSettings(Settings obj) {
|
||||||
try (Connection conn = ds.getConnection()) {
|
try (Connection conn = ds.getConnection()) {
|
||||||
PreparedStatement ps = conn.prepareStatement("UPDATE settings SET data=? WHERE type=?");
|
PreparedStatement ps = conn.prepareStatement("UPDATE settings SET data=? WHERE type=?");
|
||||||
ps.setString(1, gson.toJson(obj));
|
ps.setString(1, gson.toJson(obj));
|
||||||
ps.setString(2, KEY_SYS);
|
ps.setString(2, KEY_SYS);
|
||||||
return ps.executeUpdate();
|
return ps.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.sql;
|
package love.sola.netsupport.sql;
|
||||||
|
|
||||||
import love.sola.netsupport.pojo.Operator;
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.criterion.Projections;
|
import org.hibernate.criterion.Projections;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
|
|
||||||
|
import love.sola.netsupport.pojo.Operator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/12.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class TableOperator extends SQLCore {
|
public class TableOperator extends SQLCore {
|
||||||
|
|
||||||
public static boolean has(String wechat) {
|
public static boolean has(String wechat) {
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
return (long) s.createCriteria(Operator.class)
|
return (long) s.createCriteria(Operator.class)
|
||||||
.add(Restrictions.eq(Operator.PROPERTY_WECHAT, wechat))
|
.add(Restrictions.eq(Operator.PROPERTY_WECHAT, wechat))
|
||||||
.setProjection(Projections.rowCount())
|
.setProjection(Projections.rowCount())
|
||||||
.uniqueResult() > 0;
|
.uniqueResult() > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Operator get(String wechat) {
|
public static Operator get(String wechat) {
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
return (Operator) s.createCriteria(Operator.class)
|
return (Operator) s.createCriteria(Operator.class)
|
||||||
.add(Restrictions.eq(Operator.PROPERTY_WECHAT, wechat))
|
.add(Restrictions.eq(Operator.PROPERTY_WECHAT, wechat))
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Operator get(int id) {
|
public static Operator get(int id) {
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
return s.get(Operator.class, id);
|
return s.get(Operator.class, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void init() {
|
protected static void init() {
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
Operator.USER_SELF = s.get(Operator.class, -1);
|
Operator.USER_SELF = s.get(Operator.class, -1);
|
||||||
Operator.ADMIN = s.get(Operator.class, 0);
|
Operator.ADMIN = s.get(Operator.class, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.sql;
|
package love.sola.netsupport.sql;
|
||||||
|
|
||||||
import love.sola.netsupport.enums.Status;
|
import love.sola.netsupport.pojo.Operator;
|
||||||
import love.sola.netsupport.pojo.Ticket;
|
|
||||||
import love.sola.netsupport.pojo.User;
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.criterion.Order;
|
import org.hibernate.criterion.Order;
|
||||||
import org.hibernate.criterion.Projections;
|
import org.hibernate.criterion.Projections;
|
||||||
@@ -12,91 +27,115 @@ import org.hibernate.envers.query.AuditEntity;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import love.sola.netsupport.enums.Status;
|
||||||
|
import love.sola.netsupport.pojo.Ticket;
|
||||||
|
import love.sola.netsupport.pojo.User;
|
||||||
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/6.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class TableTicket extends SQLCore {
|
public class TableTicket extends SQLCore {
|
||||||
|
|
||||||
public static final String COLUMN_ID = "id";
|
public static final String COLUMN_ID = "id";
|
||||||
public static final String COLUMN_SID = "sid";
|
public static final String COLUMN_SID = "sid";
|
||||||
public static final String COLUMN_DESC = "description";
|
public static final String COLUMN_DESC = "description";
|
||||||
public static final String COLUMN_SUBMIT_TIME = "submittime";
|
public static final String COLUMN_SUBMIT_TIME = "submittime";
|
||||||
public static final String COLUMN_REMARK = "remark";
|
public static final String COLUMN_REMARK = "remark";
|
||||||
public static final String COLUMN_UPDATE_TIME = "updatetime";
|
public static final String COLUMN_UPDATE_TIME = "updatetime";
|
||||||
public static final String COLUMN_OPSID = "opsid";
|
public static final String COLUMN_OPSID = "opsid";
|
||||||
public static final String COLUMN_STATUS = "status";
|
public static final String COLUMN_STATUS = "status";
|
||||||
|
|
||||||
|
|
||||||
public static Ticket latestOpen(User u) {
|
public static Ticket latestOpen(User u) {
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
return (Ticket) s.createCriteria(Ticket.class)
|
return (Ticket) s.createCriteria(Ticket.class)
|
||||||
.addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME))
|
.addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME))
|
||||||
.add(Restrictions.eq(Ticket.PROPERTY_USER, u))
|
.add(Restrictions.eq(Ticket.PROPERTY_USER, u))
|
||||||
.add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
|
.add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
|
||||||
.setMaxResults(1)
|
.setMaxResults(1)
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Ticket latest(User u) {
|
public static Ticket latest(User u) {
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
return (Ticket) s.createCriteria(Ticket.class)
|
return (Ticket) s.createCriteria(Ticket.class)
|
||||||
.addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME))
|
.addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME))
|
||||||
.add(Restrictions.eq(Ticket.PROPERTY_USER, u))
|
.add(Restrictions.eq(Ticket.PROPERTY_USER, u))
|
||||||
.setMaxResults(1)
|
.setMaxResults(1)
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasOpen(User u) {
|
public static boolean hasOpen(User u) {
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
return (long) s.createCriteria(Ticket.class)
|
return (long) s.createCriteria(Ticket.class)
|
||||||
.add(Restrictions.eq(Ticket.PROPERTY_USER, u))
|
.add(Restrictions.eq(Ticket.PROPERTY_USER, u))
|
||||||
.add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
|
.add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
|
||||||
.setProjection(Projections.rowCount())
|
.setProjection(Projections.rowCount())
|
||||||
.uniqueResult() > 0;
|
.uniqueResult() > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static List<Ticket> unsolvedByBlock(int b) {
|
public static List<Ticket> unsolvedByBlock(int b) {
|
||||||
if (b == 0) return unsolved();
|
if (b == 0) return unsolved();
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
return s.createCriteria(Ticket.class)
|
return s.createCriteria(Ticket.class)
|
||||||
.addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME))
|
.addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME))
|
||||||
.add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
|
.add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
|
||||||
.createCriteria(Ticket.PROPERTY_USER)
|
.createCriteria(Ticket.PROPERTY_USER)
|
||||||
.add(Restrictions.between(User.PROPERTY_BLOCK, b * 10, (b + 1) * 10 - 1))
|
.add(Restrictions.between(User.PROPERTY_BLOCK, b * 10, (b + 1) * 10 - 1))
|
||||||
.list();
|
.list();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static List<Ticket> unsolved() {
|
public static List<Ticket> unsolved() {
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
return s.createCriteria(Ticket.class)
|
return s.createCriteria(Ticket.class)
|
||||||
.createAlias(Ticket.PROPERTY_USER, "u")
|
.createAlias(Ticket.PROPERTY_USER, "u")
|
||||||
.addOrder(Order.asc("u." + User.PROPERTY_BLOCK))
|
.addOrder(Order.asc("u." + User.PROPERTY_BLOCK))
|
||||||
.addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME))
|
.addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME))
|
||||||
.add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
|
.add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
|
||||||
.list();
|
.list();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static List<Object[]> track(int tid) {
|
public static List<Object[]> track(int tid) {
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
AuditReader reader = getAuditReader(s);
|
AuditReader reader = getAuditReader(s);
|
||||||
return reader.createQuery()
|
List<Object[]> resultList = reader.createQuery()
|
||||||
.forRevisionsOfEntity(Ticket.class, false, true)
|
.forRevisionsOfEntity(Ticket.class, false, true)
|
||||||
.addOrder(AuditEntity.revisionNumber().desc())
|
.addOrder(AuditEntity.revisionNumber().desc())
|
||||||
.add(AuditEntity.id().eq(tid))
|
.add(AuditEntity.id().eq(tid))
|
||||||
.getResultList()
|
.getResultList();
|
||||||
;
|
return initializeTickets(resultList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this is a hacky method to initialize all related entities of ticket
|
||||||
|
*/
|
||||||
|
public static List<Object[]> initializeTickets(List<Object[]> resultList) {
|
||||||
|
for (Object[] result : resultList) {
|
||||||
|
Ticket value = ((Ticket) result[0]);
|
||||||
|
HibernateProxy proxiedUser = (HibernateProxy) value.getUser();
|
||||||
|
if (proxiedUser != null) {
|
||||||
|
User unproxiedUser = ((User) proxiedUser.getHibernateLazyInitializer()
|
||||||
|
.getImplementation());
|
||||||
|
value.setUser(unproxiedUser);
|
||||||
|
}
|
||||||
|
HibernateProxy proxiedOperator = (HibernateProxy) value.getOperator();
|
||||||
|
if (proxiedOperator != null) {
|
||||||
|
Operator unproxiedOperator = ((Operator) proxiedOperator.getHibernateLazyInitializer()
|
||||||
|
.getImplementation());
|
||||||
|
value.setOperator(unproxiedOperator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,98 +1,114 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.sql;
|
package love.sola.netsupport.sql;
|
||||||
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
import love.sola.netsupport.config.Settings;
|
|
||||||
import love.sola.netsupport.pojo.User;
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import love.sola.netsupport.config.Settings;
|
||||||
|
import love.sola.netsupport.pojo.User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/11/10.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public class TableUser extends SQLCore {
|
public class TableUser extends SQLCore {
|
||||||
|
|
||||||
public static final String COLUMN_ID = "id";
|
public static final String COLUMN_ID = "id";
|
||||||
public static final String COLUMN_NAME = "name";
|
public static final String COLUMN_NAME = "name";
|
||||||
public static final String COLUMN_ISP = "isp";
|
public static final String COLUMN_ISP = "isp";
|
||||||
public static final String COLUMN_NET_ACCOUNT = "netaccount";
|
public static final String COLUMN_NET_ACCOUNT = "netaccount";
|
||||||
public static final String COLUMN_WECHAT = "wechat";
|
public static final String COLUMN_WECHAT = "wechat";
|
||||||
public static final String COLUMN_BLOCK = "block";
|
public static final String COLUMN_BLOCK = "block";
|
||||||
public static final String COLUMN_ROOM = "room";
|
public static final String COLUMN_ROOM = "room";
|
||||||
public static final String COLUMN_PHONE = "phone";
|
public static final String COLUMN_PHONE = "phone";
|
||||||
|
|
||||||
public static User getById(long id) {
|
public static User getById(long id) {
|
||||||
try (Session s = sf.openSession()) {
|
try (Session s = sf.openSession()) {
|
||||||
return s.get(User.class, id);
|
return s.get(User.class, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static User getByName(String name) {
|
public static User getByName(String name) {
|
||||||
try (Session s = sf.openSession()) {
|
try (Session s = sf.openSession()) {
|
||||||
return (User) s.createCriteria(User.class).add(Restrictions.eq(User.PROPERTY_NAME, name)).uniqueResult();
|
return (User) s.createCriteria(User.class).add(Restrictions.eq(User.PROPERTY_NAME, name)).uniqueResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static User getByWechat(String wechat) {
|
public static User getByWechat(String wechat) {
|
||||||
try {
|
try {
|
||||||
User u = cache.get(wechat);
|
User u = cache.get(wechat);
|
||||||
return u == NULL_USER ? null : u;
|
return u == NULL_USER ? null : u;
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int update(User user) {
|
public static int update(User user) {
|
||||||
try (Session s = sf.openSession()) {
|
try (Session s = sf.openSession()) {
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
s.update(user);
|
s.update(user);
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
cache.put(user.getWechatId(), user);
|
cache.put(user.getWechatId(), user);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void init() {
|
protected static void init() {
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
User.OFFICIAL_CHINA_UNICOM_XH = s.get(User.class, 100104L);
|
User.OFFICIAL_CHINA_UNICOM_XH = s.get(User.class, 100104L);
|
||||||
User.OFFICIAL_CHINA_MOBILE_XH = s.get(User.class, 100864L);
|
User.OFFICIAL_CHINA_MOBILE_XH = s.get(User.class, 100864L);
|
||||||
User.OFFICIAL_CHINA_MOBILE_FX = s.get(User.class, 100865L);
|
User.OFFICIAL_CHINA_MOBILE_FX = s.get(User.class, 100865L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static LoadingCache<String, User> cache = CacheBuilder.newBuilder()
|
private static LoadingCache<String, User> cache = CacheBuilder.newBuilder()
|
||||||
.concurrencyLevel(4)
|
.concurrencyLevel(4)
|
||||||
.maximumSize(4096)
|
.maximumSize(4096)
|
||||||
.expireAfterWrite(Settings.I.User_Wechat_Cache_Expire_Time, TimeUnit.SECONDS)
|
.expireAfterAccess(Settings.I.User_Wechat_Cache_Expire_Time, TimeUnit.SECONDS)
|
||||||
.build(new ValueLoader());
|
.build(new ValueLoader());
|
||||||
|
|
||||||
private static class ValueLoader extends CacheLoader<String, User> {
|
private static class ValueLoader extends CacheLoader<String, User> {
|
||||||
@Override
|
@Override
|
||||||
public User load(String key) throws Exception {
|
public User load(String key) throws Exception {
|
||||||
User u = TableUser.getByWechat0(key);
|
User u = TableUser.getByWechat0(key);
|
||||||
return u == null ? NULL_USER : u;
|
return u == null ? NULL_USER : u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final User NULL_USER = new User();
|
private static final User NULL_USER = new User();
|
||||||
|
|
||||||
public static void flushCache() {
|
public static void flushCache() {
|
||||||
cache.invalidateAll();
|
cache.invalidateAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static User getByWechat0(String wechat) {
|
private static User getByWechat0(String wechat) {
|
||||||
try (Session s = sf.openSession()) {
|
try (Session s = sf.openSession()) {
|
||||||
return (User) s.createCriteria(User.class).add(Restrictions.eq(User.PROPERTY_WECHAT, wechat)).uniqueResult();
|
return (User) s.createCriteria(User.class).add(Restrictions.eq(User.PROPERTY_WECHAT, wechat)).uniqueResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,95 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.util;
|
package love.sola.netsupport.util;
|
||||||
|
|
||||||
import love.sola.netsupport.enums.Attribute;
|
|
||||||
import love.sola.netsupport.enums.Block;
|
import love.sola.netsupport.enums.Block;
|
||||||
import love.sola.netsupport.enums.ISP;
|
import love.sola.netsupport.enums.ISP;
|
||||||
import love.sola.netsupport.wechat.Command;
|
|
||||||
import love.sola.netsupport.wechat.WechatSession;
|
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/12.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class Checker {
|
public class Checker {
|
||||||
|
|
||||||
public static final String STUDENT_ID_REGEX = "^(2010|2012|2013|2014|2015)[0-9]{9}$";
|
public static final String STUDENT_ID_REGEX = "^(2|1)[0-9]{9,12}$";
|
||||||
public static final String PHONE_NUMBER_REGEX = "^1[34578][0-9]{9}$";
|
public static final String PHONE_NUMBER_REGEX = "^1[3456789][0-9]{9}$";
|
||||||
|
|
||||||
public static boolean hasNull(Object... v) {
|
public static boolean hasNull(Object... v) {
|
||||||
for (Object o : v) if (o == null) return true;
|
for (Object o : v) if (o == null) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WxSession isAuthorized(HttpServletRequest r, Command c) {
|
public static long checkStudentId(String studentId) {
|
||||||
String t = r.getParameter("token");
|
if (studentId == null) return -1;
|
||||||
if (t == null || t.isEmpty()) return null;
|
if (studentId.matches(STUDENT_ID_REGEX)) {
|
||||||
WxSession s = WechatSession.get(t, false);
|
try {
|
||||||
return s == null ? null : s.getAttribute(Attribute.AUTHORIZED) == c ? s : null;
|
return Long.parseLong(studentId);
|
||||||
}
|
} catch (NumberFormatException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
public static long checkStudentId(String studentId) {
|
public static long checkPhoneNumber(String phone) {
|
||||||
if (studentId == null) return -1;
|
if (phone == null) return -1;
|
||||||
if (studentId.matches(STUDENT_ID_REGEX)) {
|
if (!phone.matches(PHONE_NUMBER_REGEX)) return -1;
|
||||||
try {
|
try {
|
||||||
return Long.parseLong(studentId);
|
return Long.parseLong(phone);
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
}
|
}
|
||||||
}
|
return -1;
|
||||||
return -1;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static long checkPhoneNumber(String phone) {
|
public static ISP checkISP(String isp) {
|
||||||
if (phone == null) return -1;
|
if (isp == null) return null;
|
||||||
if (!phone.matches(PHONE_NUMBER_REGEX)) return -1;
|
try {
|
||||||
try {
|
return ISP.fromId(Integer.parseInt(isp));
|
||||||
return Long.parseLong(phone);
|
} catch (NumberFormatException ignored) {
|
||||||
} catch (NumberFormatException ignored) { }
|
}
|
||||||
return -1;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ISP checkISP(String isp) {
|
public static String checkNetAccount(String account, ISP isp) {
|
||||||
if (isp == null) return null;
|
if (isp == null) return null;
|
||||||
try {
|
if (account == null) return null;
|
||||||
return ISP.fromId(Integer.parseInt(isp));
|
if (!account.matches(isp.accountRegex)) return null;
|
||||||
} catch (NumberFormatException ignored) { }
|
return account;
|
||||||
return null;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static String checkNetAccount(String account, ISP isp) {
|
public static int checkBlock(String block) {
|
||||||
if (isp == null) return null;
|
if (block == null) return -1;
|
||||||
if (account == null) return null;
|
try {
|
||||||
if (!account.matches(isp.accountRegex)) return null;
|
int b = Integer.parseInt(block);
|
||||||
return account;
|
if (Block.inverseMap.containsKey(b))
|
||||||
}
|
return b;
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
public static int checkBlock(String block) {
|
public static int checkRoom(String room, int block) {
|
||||||
if (block == null) return -1;
|
if (block == -1) return -1;
|
||||||
try {
|
if (room == null) return -1;
|
||||||
int b = Integer.parseInt(block);
|
try {
|
||||||
if (Block.inverseMap.containsKey(b))
|
Integer i = Integer.parseInt(room);
|
||||||
return b;
|
if (Block.checkRoom(block, i))
|
||||||
else
|
return i;
|
||||||
return -1;
|
else
|
||||||
} catch (NumberFormatException ignored) { }
|
return -1;
|
||||||
return -1;
|
} catch (NumberFormatException ignored) {
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
public static int checkRoom(String room, int block) {
|
}
|
||||||
if (block == -1) return -1;
|
|
||||||
if (room == null) return -1;
|
|
||||||
try {
|
|
||||||
Integer i = Integer.parseInt(room);
|
|
||||||
if (Block.checkRoom(block, i))
|
|
||||||
return i;
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
} catch (NumberFormatException ignored) { }
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.util;
|
package love.sola.netsupport.util;
|
||||||
|
|
||||||
import org.mindrot.jbcrypt.BCrypt;
|
import org.mindrot.jbcrypt.BCrypt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/6.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class Crypto {
|
public class Crypto {
|
||||||
|
|
||||||
public static String hash(String pw) {
|
public static String hash(String pw) {
|
||||||
return BCrypt.hashpw(pw, BCrypt.gensalt());
|
return BCrypt.hashpw(pw, BCrypt.gensalt());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean check(String plain, String hash) {
|
public static boolean check(String plain, String hash) {
|
||||||
return BCrypt.checkpw(plain, hash);
|
return BCrypt.checkpw(plain, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,40 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.util;
|
package love.sola.netsupport.util;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
import love.sola.netsupport.enums.Status;
|
import love.sola.netsupport.enums.Status;
|
||||||
import love.sola.netsupport.pojo.Ticket;
|
import love.sola.netsupport.pojo.Ticket;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
|
|
||||||
import static love.sola.netsupport.config.Lang.lang;
|
import static love.sola.netsupport.config.Lang.lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/11.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class ParseUtil {
|
public class ParseUtil {
|
||||||
|
|
||||||
public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm EEE");
|
public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm EEE");
|
||||||
|
|
||||||
public static String parseTicket(Ticket t) {
|
public static String parseTicket(Ticket t) {
|
||||||
StringBuilder sb = new StringBuilder()
|
StringBuilder sb = new StringBuilder()
|
||||||
.append(lang("Ticket_Info_Id")).append(t.getId()).append("\n")
|
.append(lang("Ticket_Info_Id")).append(t.getId()).append("\n")
|
||||||
.append(lang("Ticket_Info_Desc")).append(t.getDescription()).append("\n")
|
.append(lang("Ticket_Info_Desc")).append(t.getDescription()).append("\n")
|
||||||
.append(lang("Ticket_Info_Submit_Time")).append(dateFormat.format(t.getSubmitTime())).append("\n");
|
.append(lang("Ticket_Info_Submit_Time")).append(dateFormat.format(t.getSubmitTime())).append("\n");
|
||||||
if (t.getOperator() != null) sb.append(lang("Ticket_Info_Operator")).append(t.getOperator().getId()).append("\n");
|
if (t.getOperator() != null)
|
||||||
if (t.getRemark() != null) sb.append(lang("Ticket_Info_Remark")).append(t.getRemark()).append("\n");
|
sb.append(lang("Ticket_Info_Operator")).append(t.getOperator().getId()).append("\n");
|
||||||
if (t.getUpdateTime() != null) sb.append(lang("Ticket_Info_Update_Time")).append(dateFormat.format(t.getUpdateTime())).append("\n");
|
if (t.getRemark() != null)
|
||||||
sb.append(lang("Ticket_Info_Status")).append(Status.getLocalized(t.getStatus()));
|
sb.append(lang("Ticket_Info_Remark")).append(t.getRemark()).append("\n");
|
||||||
return sb.toString();
|
if (t.getUpdateTime() != null)
|
||||||
}
|
sb.append(lang("Ticket_Info_Update_Time")).append(dateFormat.format(t.getUpdateTime())).append("\n");
|
||||||
|
sb.append(lang("Ticket_Info_Status")).append(Status.getLocalized(t.getStatus()));
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public static String parseJsonP(HttpServletRequest request, String json) {
|
|
||||||
String jsonp = request.getParameter("jsonp");
|
|
||||||
if (jsonp == null || jsonp.isEmpty())
|
|
||||||
return json;
|
|
||||||
else
|
|
||||||
return jsonp.replace("{0}", json);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
package love.sola.netsupport.util;
|
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.Key;
|
|
||||||
import java.security.KeyPair;
|
|
||||||
import java.security.KeyPairGenerator;
|
|
||||||
|
|
||||||
public class RSAUtil {
|
|
||||||
|
|
||||||
|
|
||||||
public static Key publicKey;
|
|
||||||
public static Key privateKey;
|
|
||||||
public static String publicKey_s;
|
|
||||||
public static String privateKey_s;
|
|
||||||
|
|
||||||
static {
|
|
||||||
genKeyPair();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void genKeyPair() {
|
|
||||||
try {
|
|
||||||
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
|
|
||||||
kpg.initialize(1024);
|
|
||||||
KeyPair kp = kpg.genKeyPair();
|
|
||||||
publicKey = kp.getPublic();
|
|
||||||
privateKey = kp.getPrivate();
|
|
||||||
publicKey_s = Base64.encodeBase64String(publicKey.getEncoded());
|
|
||||||
privateKey_s = Base64.encodeBase64String(privateKey.getEncoded());
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String encrypt(String value) {
|
|
||||||
try {
|
|
||||||
Cipher cipher = Cipher.getInstance("RSA");
|
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
|
|
||||||
byte[] encrypted = cipher.doFinal(value.getBytes(StandardCharsets.UTF_8));
|
|
||||||
return Base64.encodeBase64String(encrypted);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String decrypt(String encrypted) {
|
|
||||||
try {
|
|
||||||
Cipher cipher = Cipher.getInstance("RSA");
|
|
||||||
cipher.init(Cipher.DECRYPT_MODE, privateKey);
|
|
||||||
byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted));
|
|
||||||
return new String(original, StandardCharsets.UTF_8);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,27 +1,135 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.util;
|
package love.sola.netsupport.util;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import com.google.common.net.UrlEscapers;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import static love.sola.netsupport.config.Lang.lang;
|
import static love.sola.netsupport.config.Lang.lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/6.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class Redirect {
|
public class Redirect {
|
||||||
|
|
||||||
public static final String REDIRECT_PAGE = lang("Result_Page");
|
private static final String REDIRECT_PAGE = lang("Result_Page");
|
||||||
|
|
||||||
public static void message(HttpServletResponse response, int type, String message) throws IOException {
|
private static final int SUCCESS = 1;
|
||||||
response.sendRedirect(
|
private static final int ERROR = 0;
|
||||||
response.encodeRedirectURL(REDIRECT_PAGE +
|
private static final int WARNING = -1;
|
||||||
"?msg=" + message +
|
private static final int NON_WECHAT = 88;
|
||||||
"&type=" + type
|
|
||||||
)
|
public static RedirectBuilder success() {
|
||||||
);
|
return new RedirectBuilder(SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RedirectBuilder error() {
|
||||||
|
return new RedirectBuilder(ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RedirectBuilder {
|
||||||
|
|
||||||
|
private StringBuilder sb;
|
||||||
|
|
||||||
|
RedirectBuilder(int type) {
|
||||||
|
sb = new StringBuilder(REDIRECT_PAGE).append("?");
|
||||||
|
type(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
private RedirectBuilder type(int type) {
|
||||||
|
sb.append("type=").append(type).append("&");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RedirectBuilder msg(String msg) {
|
||||||
|
sb.append("msg=").append(escape(msg)).append("&");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RedirectBuilder title(String title) {
|
||||||
|
sb.append("title=").append(escape(title)).append("&");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RedirectBuilder noButton() {
|
||||||
|
sb.append("btn=").append("hide").append("&");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RedirectBuilder button(String text) {
|
||||||
|
sb.append("btn=").append(escape(text)).append("&");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RedirectBuilder icon(WeUIIcon icon) {
|
||||||
|
sb.append("icon=").append(icon.toString()).append("&");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RedirectBuilder to(String url) {
|
||||||
|
sb.append("redirect=").append(escape(url)).append("&");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void go(HttpServletResponse resp) throws IOException {
|
||||||
|
resp.sendRedirect(sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String escape(String str) {
|
||||||
|
return UrlEscapers.urlFragmentEscaper().escape(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum WeUIIcon {
|
||||||
|
SUCCESS("weui_icon_success"),
|
||||||
|
SUCCESS_CIRCLE("weui_icon_success_circle"),
|
||||||
|
SUCCESS_NO_CIRCLE("weui_icon_success_no_circle"),
|
||||||
|
SUCCESS_SAFE("weui_icon_safe_success"),
|
||||||
|
INFO("weui_icon_info"),
|
||||||
|
INFO_CIRCLE("weui_icon_info_circle"),
|
||||||
|
WAITING("weui_icon_waiting"),
|
||||||
|
WAITING_CIRCLE("weui_icon_waiting_circle"),
|
||||||
|
CIRCLE("weui_icon_circle"),
|
||||||
|
WARN("weui_icon_warn"),
|
||||||
|
WARN_SAFE("weui_icon_safe_warn"),
|
||||||
|
DOWNLOAD("weui_icon_download"),
|
||||||
|
CANCEL("weui_icon_cancel"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
WeUIIcon(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,59 +1,79 @@
|
|||||||
package love.sola.netsupport.wechat;
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
import love.sola.netsupport.wechat.handler.*;
|
package love.sola.netsupport.wechat;
|
||||||
import love.sola.netsupport.wechat.handler.admin.LoginHandler;
|
|
||||||
import love.sola.netsupport.wechat.handler.admin.OperatorInfoHandler;
|
|
||||||
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import love.sola.netsupport.wechat.handler.CancelHandler;
|
||||||
|
import love.sola.netsupport.wechat.handler.ProfileHandler;
|
||||||
|
import love.sola.netsupport.wechat.handler.QueryHandler;
|
||||||
|
import love.sola.netsupport.wechat.handler.RegisterHandler;
|
||||||
|
import love.sola.netsupport.wechat.handler.SubmitHandler;
|
||||||
|
import love.sola.netsupport.wechat.handler.admin.LoginHandler;
|
||||||
|
import love.sola.netsupport.wechat.handler.admin.OperatorInfoHandler;
|
||||||
|
import love.sola.netsupport.wechat.handler.admin.SignHandler;
|
||||||
|
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
||||||
|
|
||||||
import static love.sola.netsupport.config.Lang.lang;
|
import static love.sola.netsupport.config.Lang.lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/11/26.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public enum Command {
|
public enum Command {
|
||||||
|
|
||||||
REGISTER(0, RegisterHandler.class),
|
REGISTER(0, RegisterHandler.class),
|
||||||
QUERY(1, QueryHandler.class),
|
QUERY(1, QueryHandler.class),
|
||||||
SUBMIT(2, SubmitHandler.class),
|
SUBMIT(2, SubmitHandler.class),
|
||||||
CANCEL(3, CancelHandler.class),
|
CANCEL(3, CancelHandler.class),
|
||||||
PROFILE(4, ProfileHandler.class),
|
PROFILE(4, ProfileHandler.class),
|
||||||
LOGIN(10, LoginHandler.class),
|
LOGIN(10, LoginHandler.class),
|
||||||
OPERATOR_INFO(11, OperatorInfoHandler.class),
|
OPERATOR_INFO(11, OperatorInfoHandler.class),
|
||||||
;
|
SIGN(12, SignHandler.class), //FIXME
|
||||||
|
;
|
||||||
|
|
||||||
private static final Map<Integer, Command> ID_MAP = new HashMap<>();
|
private static final Map<Integer, Command> ID_MAP = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for (Command type : values()) {
|
for (Command type : values()) {
|
||||||
if (type.id >= 0) {
|
if (type.id >= 0) {
|
||||||
ID_MAP.put(type.id, type);
|
ID_MAP.put(type.id, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String regex;
|
public final String regex;
|
||||||
public final Class<? extends WxMpMessageHandler> handler;
|
public final Class<? extends WxMpMessageHandler> handler;
|
||||||
public final int id;
|
public final int id;
|
||||||
|
|
||||||
Command(int id, Class<? extends WxMpMessageHandler> handler) {
|
Command(int id, Class<? extends WxMpMessageHandler> handler) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.regex = lang("REGEX_" + name());
|
this.regex = lang("REGEX_" + name());
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Command fromId(int id) {
|
public static Command fromId(int id) {
|
||||||
return ID_MAP.get(id);
|
return ID_MAP.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name();
|
return name();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
package love.sola.netsupport.wechat;
|
|
||||||
|
|
||||||
import love.sola.netsupport.config.Settings;
|
|
||||||
import me.chanjar.weixin.common.session.*;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ***********************************************
|
|
||||||
* Created by Sola on 2015/12/14.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
|
||||||
public class WechatSession {
|
|
||||||
|
|
||||||
private static StandardSessionManager manager;
|
|
||||||
|
|
||||||
static{
|
|
||||||
manager = new StandardSessionManager();
|
|
||||||
manager.setMaxInactiveInterval(Settings.I.User_Session_Max_Inactive);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static WxSession get(String id, boolean create) {
|
|
||||||
WxSession session = manager.getSession(id, create);
|
|
||||||
if (session != null) {
|
|
||||||
((StandardSessionFacade) session).getInternalSession().endAccess();
|
|
||||||
}
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static WxSession get(String id) {
|
|
||||||
return get(id, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String genId() {
|
|
||||||
return UUID.randomUUID().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static InternalSession[] list() {
|
|
||||||
return manager.findSessions();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,119 +1,144 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.wechat;
|
package love.sola.netsupport.wechat;
|
||||||
|
|
||||||
import love.sola.netsupport.config.Settings;
|
import java.io.IOException;
|
||||||
import love.sola.netsupport.wechat.handler.RegisterHandler;
|
|
||||||
import love.sola.netsupport.wechat.handler.SubscribeHandler;
|
|
||||||
import love.sola.netsupport.wechat.matcher.CheckSpamMatcher;
|
|
||||||
import love.sola.netsupport.wechat.matcher.RegisterMatcher;
|
|
||||||
import me.chanjar.weixin.common.api.WxConsts;
|
|
||||||
import me.chanjar.weixin.common.util.StringUtils;
|
|
||||||
import me.chanjar.weixin.mp.api.*;
|
|
||||||
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
|
||||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.annotation.WebServlet;
|
import javax.servlet.annotation.WebServlet;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
|
||||||
|
import love.sola.netsupport.auth.OAuth2;
|
||||||
|
import love.sola.netsupport.auth.OAuth2Handler;
|
||||||
|
import love.sola.netsupport.config.Settings;
|
||||||
|
import love.sola.netsupport.sql.SQLCore;
|
||||||
|
import love.sola.netsupport.wechat.handler.RegisterHandler;
|
||||||
|
import love.sola.netsupport.wechat.handler.SubscribeHandler;
|
||||||
|
import love.sola.netsupport.wechat.matcher.CheckSpamMatcher;
|
||||||
|
import love.sola.netsupport.wechat.matcher.RegisterMatcher;
|
||||||
|
import me.chanjar.weixin.common.api.WxConsts;
|
||||||
|
import me.chanjar.weixin.common.util.StringUtils;
|
||||||
|
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
|
||||||
|
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
||||||
|
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
|
||||||
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
|
import me.chanjar.weixin.mp.api.WxMpServiceImpl;
|
||||||
|
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
||||||
|
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
||||||
|
|
||||||
import static love.sola.netsupport.config.Lang.lang;
|
import static love.sola.netsupport.config.Lang.lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/11/2.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
@WebServlet(name = "WxMpServlet", urlPatterns = "/wechat", loadOnStartup = 99)
|
@WebServlet(name = "WxMpServlet", urlPatterns = "/wechat", loadOnStartup = 99)
|
||||||
public class WxMpServlet extends HttpServlet {
|
public class WxMpServlet extends HttpServlet {
|
||||||
|
|
||||||
public static WxMpServlet instance;
|
public static WxMpServlet instance;
|
||||||
protected WxMpInMemoryConfigStorage config;
|
protected WxMpInMemoryConfigStorage config;
|
||||||
public WxMpService wxMpService;
|
public WxMpService wxMpService;
|
||||||
protected WxMpMessageRouter wxMpMessageRouter;
|
protected WxMpMessageRouter wxMpMessageRouter;
|
||||||
protected CheckSpamMatcher checkSpamMatcher;
|
protected CheckSpamMatcher checkSpamMatcher;
|
||||||
|
|
||||||
public WxMpServlet() {
|
public WxMpServlet() {
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() throws ServletException {
|
public void init() throws ServletException {
|
||||||
super.init();
|
super.init();
|
||||||
|
|
||||||
config = new WxMpInMemoryConfigStorage();
|
config = new WxMpInMemoryConfigStorage();
|
||||||
config.setAppId(Settings.I.Wechat_AppId);
|
config.setAppId(Settings.I.Wechat_AppId);
|
||||||
config.setSecret(Settings.I.Wechat_Secret);
|
config.setSecret(Settings.I.Wechat_Secret);
|
||||||
config.setToken(Settings.I.Wechat_Token);
|
config.setToken(Settings.I.Wechat_Token);
|
||||||
config.setAesKey(Settings.I.Wechat_AesKey);
|
config.setAesKey(Settings.I.Wechat_AesKey);
|
||||||
|
|
||||||
wxMpService = new WxMpServiceImpl();
|
wxMpService = new WxMpServiceImpl();
|
||||||
wxMpService.setWxMpConfigStorage(config);
|
wxMpService.setWxMpConfigStorage(config);
|
||||||
|
|
||||||
checkSpamMatcher = new CheckSpamMatcher();
|
checkSpamMatcher = new CheckSpamMatcher();
|
||||||
wxMpMessageRouter = new WxMpMessageRouter(wxMpService);
|
wxMpMessageRouter = new WxMpMessageRouter(wxMpService);
|
||||||
wxMpMessageRouter.rule()
|
wxMpMessageRouter.rule()
|
||||||
.async(false)
|
.async(false)
|
||||||
.msgType(WxConsts.XML_MSG_EVENT)
|
.msgType(WxConsts.XML_MSG_EVENT)
|
||||||
.event(WxConsts.EVT_SUBSCRIBE)
|
.event(WxConsts.EVT_SUBSCRIBE)
|
||||||
.handler(new SubscribeHandler())
|
.handler(new SubscribeHandler())
|
||||||
.end();
|
.end();
|
||||||
wxMpMessageRouter.rule()
|
wxMpMessageRouter.rule()
|
||||||
.async(false)
|
.async(false)
|
||||||
.matcher(new CheckSpamMatcher())
|
.matcher(new CheckSpamMatcher())
|
||||||
.handler((wxMessage, context, wxMpService1, sessionManager)
|
.handler((wxMessage, context, wxMpService1, sessionManager)
|
||||||
-> WxMpXmlOutMessage.TEXT()
|
-> WxMpXmlOutMessage.TEXT()
|
||||||
.fromUser(wxMessage.getToUserName())
|
.fromUser(wxMessage.getToUserName())
|
||||||
.toUser(wxMessage.getFromUserName())
|
.toUser(wxMessage.getFromUserName())
|
||||||
.content(lang("Message_Spam")).build())
|
.content(lang("Message_Spam")).build())
|
||||||
.end();
|
.end();
|
||||||
wxMpMessageRouter.rule()
|
wxMpMessageRouter.rule()
|
||||||
.async(false)
|
.async(false)
|
||||||
.matcher(new RegisterMatcher())
|
.matcher(new RegisterMatcher())
|
||||||
.handler(new RegisterHandler())
|
.handler(new RegisterHandler())
|
||||||
.end();
|
.end();
|
||||||
try {
|
try {
|
||||||
registerCommands(wxMpMessageRouter);
|
registerCommands(wxMpMessageRouter);
|
||||||
} catch (IllegalAccessException | InstantiationException e) {
|
} catch (IllegalAccessException | InstantiationException e) {
|
||||||
throw new ServletException(e);
|
throw new ServletException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerCommands(WxMpMessageRouter router) throws IllegalAccessException, InstantiationException {
|
public static void registerCommands(WxMpMessageRouter router) throws IllegalAccessException, InstantiationException {
|
||||||
for (Command c : Command.values()) {
|
for (Command c : Command.values()) {
|
||||||
WxMpMessageHandler handler = c.handler.newInstance();
|
WxMpMessageHandler handler = c.handler.newInstance();
|
||||||
router.rule().async(false).msgType(WxConsts.XML_MSG_TEXT).rContent(c.regex).handler(handler).end();
|
router.rule().async(false).msgType(WxConsts.XML_MSG_TEXT).rContent(c.regex).handler(handler).end();
|
||||||
router.rule().async(false).msgType(WxConsts.XML_MSG_EVENT).event(WxConsts.EVT_CLICK).eventKey(c.name()).handler(handler).end();
|
router.rule().async(false).msgType(WxConsts.XML_MSG_EVENT).event(WxConsts.EVT_CLICK).eventKey(c.name()).handler(handler).end();
|
||||||
}
|
if (handler instanceof OAuth2Handler) {
|
||||||
}
|
OAuth2.registerOAuth2Handler(c.name(), (OAuth2Handler) handler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
|
|
||||||
response.setContentType("text/html;charset=utf-8");
|
response.setContentType("text/html;charset=utf-8");
|
||||||
response.setStatus(HttpServletResponse.SC_OK);
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
|
|
||||||
String signature = request.getParameter("signature");
|
String signature = request.getParameter("signature");
|
||||||
String nonce = request.getParameter("nonce");
|
String nonce = request.getParameter("nonce");
|
||||||
String timestamp = request.getParameter("timestamp");
|
String timestamp = request.getParameter("timestamp");
|
||||||
|
|
||||||
if (!wxMpService.checkSignature(timestamp, nonce, signature)) {
|
if (!wxMpService.checkSignature(timestamp, nonce, signature)) {
|
||||||
// Signature fail
|
// Signature fail
|
||||||
response.getWriter().println(lang("Access_Denied"));
|
response.getWriter().println(lang("Access_Denied"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String echostr = request.getParameter("echostr");
|
String echostr = request.getParameter("echostr");
|
||||||
if (StringUtils.isNotBlank(echostr)) {
|
if (StringUtils.isNotBlank(echostr)) {
|
||||||
// validate request
|
// validate request
|
||||||
response.getWriter().println(echostr);
|
response.getWriter().println(echostr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String encryptType = StringUtils.isBlank(request.getParameter("encrypt_type")) ? "raw" : request.getParameter("encrypt_type");
|
String encryptType = StringUtils.isBlank(request.getParameter("encrypt_type")) ? "raw" : request.getParameter("encrypt_type");
|
||||||
|
|
||||||
// if ("raw".equals(encryptType)) {
|
// if ("raw".equals(encryptType)) {
|
||||||
// WxMpXmlMessage inMessage = WxMpXmlMessage.fromXml(request.getInputStream());
|
// WxMpXmlMessage inMessage = WxMpXmlMessage.fromXml(request.getInputStream());
|
||||||
@@ -129,28 +154,32 @@ public class WxMpServlet extends HttpServlet {
|
|||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if ("aes".equals(encryptType)) {
|
if ("aes".equals(encryptType)) {
|
||||||
String msgSignature = request.getParameter("msg_signature");
|
String msgSignature = request.getParameter("msg_signature");
|
||||||
WxMpXmlMessage inMessage = WxMpXmlMessage.fromEncryptedXml(request.getInputStream(), config, timestamp, nonce, msgSignature);
|
WxMpXmlMessage inMessage = WxMpXmlMessage.fromEncryptedXml(request.getInputStream(), config, timestamp, nonce, msgSignature);
|
||||||
WxMpXmlOutMessage outMessage = wxMpMessageRouter.route(inMessage);
|
WxMpXmlOutMessage outMessage = wxMpMessageRouter.route(inMessage);
|
||||||
if (outMessage == null) {
|
if (outMessage == null) {
|
||||||
outMessage = WxMpXmlOutMessage.TEXT()
|
outMessage = WxMpXmlOutMessage.TEXT()
|
||||||
.fromUser(inMessage.getToUserName())
|
.fromUser(inMessage.getToUserName())
|
||||||
.toUser(inMessage.getFromUserName())
|
.toUser(inMessage.getFromUserName())
|
||||||
.content(lang("Invalid_Operation"))
|
.content(lang("Invalid_Operation"))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
response.getWriter().write(outMessage.toEncryptedXml(config));
|
response.getWriter().write(outMessage.toEncryptedXml(config));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
response.getWriter().println(lang("Unknown_Encrypt_Type"));
|
response.getWriter().println(lang("Unknown_Encrypt_Type"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
doPost(req, resp);
|
doPost(req, resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
SQLCore.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.wechat.handler;
|
package love.sola.netsupport.wechat.handler;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||||
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
||||||
@@ -7,20 +26,15 @@ import me.chanjar.weixin.mp.api.WxMpService;
|
|||||||
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
||||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/29.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class AutoReplyHandler implements WxMpMessageHandler {
|
public class AutoReplyHandler implements WxMpMessageHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
||||||
//TODO auto reply
|
//TODO auto reply
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.wechat.handler;
|
package love.sola.netsupport.wechat.handler;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import love.sola.netsupport.enums.Status;
|
import love.sola.netsupport.enums.Status;
|
||||||
import love.sola.netsupport.pojo.Operator;
|
import love.sola.netsupport.pojo.Operator;
|
||||||
import love.sola.netsupport.pojo.Ticket;
|
import love.sola.netsupport.pojo.Ticket;
|
||||||
@@ -16,48 +38,41 @@ import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
|||||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
||||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutNewsMessage;
|
import me.chanjar.weixin.mp.bean.WxMpXmlOutNewsMessage;
|
||||||
import me.chanjar.weixin.mp.bean.outxmlbuilder.NewsBuilder;
|
import me.chanjar.weixin.mp.bean.outxmlbuilder.NewsBuilder;
|
||||||
import org.hibernate.Session;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static love.sola.netsupport.config.Lang.lang;
|
import static love.sola.netsupport.config.Lang.lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/11.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class CancelHandler implements WxMpMessageHandler {
|
public class CancelHandler implements WxMpMessageHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
||||||
User u = TableUser.getByWechat(wxMessage.getFromUserName());
|
User u = TableUser.getByWechat(wxMessage.getFromUserName());
|
||||||
Ticket t = TableTicket.latestOpen(u);
|
Ticket t = TableTicket.latestOpen(u);
|
||||||
if (t == null) {
|
if (t == null) {
|
||||||
return WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
|
return WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
|
||||||
.content(lang("No_Open_Ticket_Available")).build();
|
.content(lang("No_Open_Ticket_Available")).build();
|
||||||
}
|
}
|
||||||
try (Session s = SQLCore.sf.openSession()) {
|
try (Session s = SQLCore.sf.openSession()) {
|
||||||
t.setOperator(Operator.USER_SELF);
|
t.setOperator(Operator.USER_SELF);
|
||||||
t.setUpdateTime(new Date());
|
t.setUpdateTime(new Date());
|
||||||
t.setRemark(lang("User_Cancel_Remark"));
|
t.setRemark(lang("User_Cancel_Remark"));
|
||||||
t.setStatus(Status.SOLVED);
|
t.setStatus(Status.SOLVED);
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
s.update(t);
|
s.update(t);
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
NewsBuilder out = WxMpXmlOutMessage.NEWS().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
NewsBuilder out = WxMpXmlOutMessage.NEWS().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
||||||
WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
|
WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
|
||||||
item.setTitle(lang("Cancel_Title"));
|
item.setTitle(lang("Cancel_Title"));
|
||||||
item.setDescription(ParseUtil.parseTicket(t));
|
item.setDescription(ParseUtil.parseTicket(t));
|
||||||
out.addArticle(item);
|
out.addArticle(item);
|
||||||
return out.build();
|
return out.build();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
|
return WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
|
||||||
.content(lang("Cancel_Failed")).build();
|
.content(lang("Cancel_Failed")).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.wechat.handler;
|
package love.sola.netsupport.wechat.handler;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.AsyncContext;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import love.sola.netsupport.auth.OAuth2Handler;
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.pojo.User;
|
import love.sola.netsupport.pojo.User;
|
||||||
|
import love.sola.netsupport.session.WechatSession;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
import love.sola.netsupport.sql.TableUser;
|
import love.sola.netsupport.sql.TableUser;
|
||||||
|
import love.sola.netsupport.util.Redirect;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import love.sola.netsupport.wechat.WechatSession;
|
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||||
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
||||||
import me.chanjar.weixin.mp.api.WxMpService;
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
@@ -14,29 +38,45 @@ import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
|||||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
||||||
import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder;
|
import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static love.sola.netsupport.config.Lang.format;
|
import static love.sola.netsupport.config.Lang.format;
|
||||||
|
import static love.sola.netsupport.config.Lang.lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/15.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class ProfileHandler implements WxMpMessageHandler {
|
public class ProfileHandler implements WxMpMessageHandler, OAuth2Handler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
||||||
User u = TableUser.getByWechat(wxMessage.getFromUserName());
|
User u = TableUser.getByWechat(wxMessage.getFromUserName());
|
||||||
String id = WechatSession.genId();
|
WxSession session = WechatSession.create();
|
||||||
WxSession session = WechatSession.get(id, true);
|
session.setAttribute(Attribute.AUTHORIZED, Command.PROFILE);
|
||||||
session.setAttribute(Attribute.AUTHORIZED, Command.PROFILE);
|
session.setAttribute(Attribute.WECHAT, wxMessage.getFromUserName());
|
||||||
session.setAttribute(Attribute.WECHAT, wxMessage.getFromUserName());
|
session.setAttribute(Attribute.USER, u);
|
||||||
session.setAttribute(Attribute.USER, u);
|
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
||||||
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
out.content(format("Profile_Modify", format("User_Profile_Link", session.getId(), u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone())));
|
||||||
out.content(format("Profile_Modify", format("User_Profile_Link", id, u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone())));
|
return out.build();
|
||||||
return out.build();
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public void onOAuth2(AsyncContext actx, HttpServletResponse resp, String user, WxSession session) {
|
||||||
|
try {
|
||||||
|
User u = TableUser.getByWechat(user);
|
||||||
|
if (u == null) {
|
||||||
|
session.setAttribute(Attribute.AUTHORIZED, Command.REGISTER);
|
||||||
|
session.setAttribute(Attribute.WECHAT, user);
|
||||||
|
Redirect.error().icon(Redirect.WeUIIcon.INFO).noButton()
|
||||||
|
.title(lang("Need_Register_Title")).msg(lang("Need_Register"))
|
||||||
|
.to(format("User_Register_Link", session.getId())).go(resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
session.setAttribute(Attribute.AUTHORIZED, Command.PROFILE);
|
||||||
|
session.setAttribute(Attribute.WECHAT, user);
|
||||||
|
session.setAttribute(Attribute.USER, u);
|
||||||
|
resp.sendRedirect(format("User_Profile_Link", session.getId(), u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.wechat.handler;
|
package love.sola.netsupport.wechat.handler;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.pojo.Ticket;
|
import love.sola.netsupport.pojo.Ticket;
|
||||||
import love.sola.netsupport.pojo.User;
|
import love.sola.netsupport.pojo.User;
|
||||||
|
import love.sola.netsupport.session.WechatSession;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
import love.sola.netsupport.sql.TableTicket;
|
import love.sola.netsupport.sql.TableTicket;
|
||||||
import love.sola.netsupport.sql.TableUser;
|
import love.sola.netsupport.sql.TableUser;
|
||||||
import love.sola.netsupport.util.ParseUtil;
|
import love.sola.netsupport.util.ParseUtil;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import love.sola.netsupport.wechat.WechatSession;
|
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||||
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
||||||
import me.chanjar.weixin.mp.api.WxMpService;
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
@@ -18,41 +37,35 @@ import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
|||||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutNewsMessage;
|
import me.chanjar.weixin.mp.bean.WxMpXmlOutNewsMessage;
|
||||||
import me.chanjar.weixin.mp.bean.outxmlbuilder.NewsBuilder;
|
import me.chanjar.weixin.mp.bean.outxmlbuilder.NewsBuilder;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static love.sola.netsupport.config.Lang.format;
|
import static love.sola.netsupport.config.Lang.format;
|
||||||
import static love.sola.netsupport.config.Lang.lang;
|
import static love.sola.netsupport.config.Lang.lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/8.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class QueryHandler implements WxMpMessageHandler {
|
public class QueryHandler implements WxMpMessageHandler {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
||||||
User u = TableUser.getByWechat(wxMessage.getFromUserName());
|
User u = TableUser.getByWechat(wxMessage.getFromUserName());
|
||||||
Ticket t = TableTicket.latest(u);
|
Ticket t = TableTicket.latest(u);
|
||||||
if (t == null) {
|
if (t == null) {
|
||||||
return WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
|
return WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
|
||||||
.content(lang("No_Ticket_Available")).build();
|
.content(lang("No_Ticket_Available")).build();
|
||||||
}
|
}
|
||||||
String id = WechatSession.genId();
|
WxSession session = WechatSession.create();
|
||||||
WxSession session = WechatSession.get(id, true);
|
session.setAttribute(Attribute.AUTHORIZED, Command.QUERY);
|
||||||
session.setAttribute(Attribute.AUTHORIZED, Command.QUERY);
|
session.setAttribute(Attribute.WECHAT, wxMessage.getFromUserName());
|
||||||
session.setAttribute(Attribute.WECHAT, wxMessage.getFromUserName());
|
session.setAttribute(Attribute.USER, u);
|
||||||
session.setAttribute(Attribute.USER, u);
|
|
||||||
|
|
||||||
NewsBuilder out = WxMpXmlOutMessage.NEWS().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
NewsBuilder out = WxMpXmlOutMessage.NEWS().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
||||||
WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
|
WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
|
||||||
item.setTitle(lang("Query_Title"));
|
item.setTitle(lang("Query_Title"));
|
||||||
item.setDescription(ParseUtil.parseTicket(t) + "\n" + lang("More_Details"));
|
item.setDescription(ParseUtil.parseTicket(t) + "\n" + lang("More_Details"));
|
||||||
item.setUrl(format("User_Query_Link", id));
|
item.setUrl(format("User_Query_Link", session.getId()));
|
||||||
out.addArticle(item);
|
out.addArticle(item);
|
||||||
return out.build();
|
return out.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.wechat.handler;
|
package love.sola.netsupport.wechat.handler;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.pojo.User;
|
import love.sola.netsupport.pojo.User;
|
||||||
|
import love.sola.netsupport.session.WechatSession;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
import love.sola.netsupport.sql.TableUser;
|
import love.sola.netsupport.sql.TableUser;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import love.sola.netsupport.wechat.WechatSession;
|
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||||
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
||||||
import me.chanjar.weixin.mp.api.WxMpService;
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
@@ -14,37 +33,31 @@ import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
|||||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
||||||
import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder;
|
import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static love.sola.netsupport.config.Lang.format;
|
import static love.sola.netsupport.config.Lang.format;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/11/4.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class RegisterHandler implements WxMpMessageHandler {
|
public class RegisterHandler implements WxMpMessageHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager)
|
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager)
|
||||||
throws WxErrorException {
|
throws WxErrorException {
|
||||||
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
||||||
String fromUser = wxMessage.getFromUserName();
|
String fromUser = wxMessage.getFromUserName();
|
||||||
User u = TableUser.getByWechat(fromUser);
|
User u = TableUser.getByWechat(fromUser);
|
||||||
String id = WechatSession.genId();
|
WxSession session = WechatSession.create();
|
||||||
WxSession session = WechatSession.get(id, true);
|
if (u != null) {
|
||||||
if (u != null) {
|
session.setAttribute(Attribute.AUTHORIZED, Command.PROFILE);
|
||||||
session.setAttribute(Attribute.AUTHORIZED, Command.PROFILE);
|
session.setAttribute(Attribute.WECHAT, fromUser);
|
||||||
session.setAttribute(Attribute.WECHAT, fromUser);
|
session.setAttribute(Attribute.USER, u);
|
||||||
session.setAttribute(Attribute.USER, u);
|
out.content(format("Already_Registered", format("User_Profile_Link", session.getId(), u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone())));
|
||||||
out.content(format("Already_Registered", format("User_Profile_Link", id, u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone())));
|
} else {
|
||||||
} else {
|
session.setAttribute(Attribute.AUTHORIZED, Command.REGISTER);
|
||||||
session.setAttribute(Attribute.AUTHORIZED, Command.REGISTER);
|
session.setAttribute(Attribute.WECHAT, fromUser);
|
||||||
session.setAttribute(Attribute.WECHAT, fromUser);
|
out.content(format("User_Register", format("User_Register_Link", session.getId())));
|
||||||
out.content(format("User_Register", format("User_Register_Link", id)));
|
}
|
||||||
}
|
return out.build();
|
||||||
return out.build();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.wechat.handler;
|
package love.sola.netsupport.wechat.handler;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.pojo.User;
|
import love.sola.netsupport.pojo.User;
|
||||||
|
import love.sola.netsupport.session.WechatSession;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
import love.sola.netsupport.sql.TableTicket;
|
import love.sola.netsupport.sql.TableTicket;
|
||||||
import love.sola.netsupport.sql.TableUser;
|
import love.sola.netsupport.sql.TableUser;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import love.sola.netsupport.wechat.WechatSession;
|
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||||
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
||||||
import me.chanjar.weixin.mp.api.WxMpService;
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
@@ -16,39 +35,33 @@ import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
|||||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutNewsMessage;
|
import me.chanjar.weixin.mp.bean.WxMpXmlOutNewsMessage;
|
||||||
import me.chanjar.weixin.mp.bean.outxmlbuilder.NewsBuilder;
|
import me.chanjar.weixin.mp.bean.outxmlbuilder.NewsBuilder;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static love.sola.netsupport.config.Lang.format;
|
import static love.sola.netsupport.config.Lang.format;
|
||||||
import static love.sola.netsupport.config.Lang.lang;
|
import static love.sola.netsupport.config.Lang.lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/9.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class SubmitHandler implements WxMpMessageHandler {
|
public class SubmitHandler implements WxMpMessageHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
||||||
User u = TableUser.getByWechat(wxMessage.getFromUserName());
|
User u = TableUser.getByWechat(wxMessage.getFromUserName());
|
||||||
if (TableTicket.hasOpen(u)) {
|
if (TableTicket.hasOpen(u)) {
|
||||||
return WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
|
return WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
|
||||||
.content(lang("Already_Opening_Ticket")).build();
|
.content(lang("Already_Opening_Ticket")).build();
|
||||||
}
|
}
|
||||||
String id = WechatSession.genId();
|
WxSession session = WechatSession.create();
|
||||||
WxSession session = WechatSession.get(id, true);
|
session.setAttribute(Attribute.AUTHORIZED, Command.SUBMIT);
|
||||||
session.setAttribute(Attribute.AUTHORIZED, Command.SUBMIT);
|
session.setAttribute(Attribute.WECHAT, wxMessage.getFromUserName());
|
||||||
session.setAttribute(Attribute.WECHAT, wxMessage.getFromUserName());
|
session.setAttribute(Attribute.USER, u);
|
||||||
session.setAttribute(Attribute.USER, u);
|
|
||||||
|
|
||||||
NewsBuilder out = WxMpXmlOutMessage.NEWS().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
NewsBuilder out = WxMpXmlOutMessage.NEWS().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
||||||
WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
|
WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
|
||||||
item.setTitle(lang("Submit_Title"));
|
item.setTitle(lang("Submit_Title"));
|
||||||
item.setDescription(lang("Submit_Desc"));
|
item.setDescription(lang("Submit_Desc"));
|
||||||
item.setUrl(format("User_Submit_Link", id, u.getName(), u.getIsp().id, u.getRoom(), u.getBlock(), u.getPhone()));
|
item.setUrl(format("User_Submit_Link", session.getId(), u.getName(), u.getIsp().id, u.getRoom(), u.getBlock(), u.getPhone()));
|
||||||
out.addArticle(item);
|
out.addArticle(item);
|
||||||
return out.build();
|
return out.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.wechat.handler;
|
package love.sola.netsupport.wechat.handler;
|
||||||
|
|
||||||
import love.sola.netsupport.api.user.Register;
|
import java.util.Map;
|
||||||
|
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.pojo.Operator;
|
import love.sola.netsupport.pojo.Operator;
|
||||||
import love.sola.netsupport.pojo.User;
|
import love.sola.netsupport.pojo.User;
|
||||||
|
import love.sola.netsupport.session.WechatSession;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
import love.sola.netsupport.sql.TableOperator;
|
import love.sola.netsupport.sql.TableOperator;
|
||||||
import love.sola.netsupport.sql.TableUser;
|
import love.sola.netsupport.sql.TableUser;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import love.sola.netsupport.wechat.WechatSession;
|
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||||
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
||||||
import me.chanjar.weixin.mp.api.WxMpService;
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
@@ -17,43 +35,35 @@ import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
|||||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
||||||
import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder;
|
import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static love.sola.netsupport.config.Lang.format;
|
import static love.sola.netsupport.config.Lang.format;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/25.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class SubscribeHandler implements WxMpMessageHandler {
|
public class SubscribeHandler implements WxMpMessageHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
||||||
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
||||||
String fromUser = wxMessage.getFromUserName();
|
String fromUser = wxMessage.getFromUserName();
|
||||||
User u = TableUser.getByWechat(fromUser);
|
User u = TableUser.getByWechat(fromUser);
|
||||||
String id = WechatSession.genId();
|
WxSession session = WechatSession.create();
|
||||||
WxSession session = WechatSession.get(id, true);
|
if (u != null) {
|
||||||
if (u != null) {
|
session.setAttribute(Attribute.AUTHORIZED, Command.PROFILE);
|
||||||
session.setAttribute(Attribute.AUTHORIZED, Command.PROFILE);
|
session.setAttribute(Attribute.WECHAT, fromUser);
|
||||||
session.setAttribute(Attribute.WECHAT, fromUser);
|
session.setAttribute(Attribute.USER, u);
|
||||||
session.setAttribute(Attribute.USER, u);
|
out.content(format("Event_Subscribe", format("Already_Registered", format("User_Profile_Link", session.getId(), u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone()))));
|
||||||
out.content(format("Event_Subscribe", format("Already_Registered", format("User_Profile_Link", id, u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone()))));
|
|
||||||
|
|
||||||
Operator op = TableOperator.get(fromUser);
|
Operator op = TableOperator.get(fromUser);
|
||||||
if (op != null) {
|
if (op != null) {
|
||||||
wxMpService.userUpdateGroup(fromUser, 100L);
|
wxMpService.userUpdateGroup(fromUser, 100L);
|
||||||
} else {
|
}
|
||||||
Register.converterWithRetry(u); //TODO remove me
|
} else {
|
||||||
}
|
session.setAttribute(Attribute.AUTHORIZED, Command.REGISTER);
|
||||||
} else {
|
session.setAttribute(Attribute.WECHAT, fromUser);
|
||||||
session.setAttribute(Attribute.AUTHORIZED, Command.REGISTER);
|
out.content(format("Event_Subscribe", format("User_Register", format("User_Register_Link", session.getId()))));
|
||||||
session.setAttribute(Attribute.WECHAT, fromUser);
|
}
|
||||||
out.content(format("Event_Subscribe", format("User_Register", format("User_Register_Link", id))));
|
return out.build();
|
||||||
}
|
}
|
||||||
return out.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.wechat.handler.admin;
|
package love.sola.netsupport.wechat.handler.admin;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.AsyncContext;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import love.sola.netsupport.auth.OAuth2Handler;
|
||||||
import love.sola.netsupport.enums.Access;
|
import love.sola.netsupport.enums.Access;
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.pojo.Operator;
|
import love.sola.netsupport.pojo.Operator;
|
||||||
|
import love.sola.netsupport.session.WechatSession;
|
||||||
|
import love.sola.netsupport.session.WxSession;
|
||||||
import love.sola.netsupport.sql.TableOperator;
|
import love.sola.netsupport.sql.TableOperator;
|
||||||
|
import love.sola.netsupport.util.Redirect;
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import love.sola.netsupport.wechat.WechatSession;
|
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
import me.chanjar.weixin.common.session.WxSession;
|
|
||||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||||
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
||||||
import me.chanjar.weixin.mp.api.WxMpService;
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
@@ -15,42 +39,59 @@ import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
|||||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
||||||
import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder;
|
import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static love.sola.netsupport.config.Lang.format;
|
import static love.sola.netsupport.config.Lang.format;
|
||||||
import static love.sola.netsupport.config.Lang.lang;
|
import static love.sola.netsupport.config.Lang.lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/12.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class LoginHandler implements WxMpMessageHandler {
|
public class LoginHandler implements WxMpMessageHandler, OAuth2Handler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
||||||
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
||||||
try {
|
try {
|
||||||
Operator operator = TableOperator.get(wxMessage.getFromUserName());
|
Operator operator = TableOperator.get(wxMessage.getFromUserName());
|
||||||
if (operator == null)
|
if (operator == null)
|
||||||
out.content(lang("Not_Operator"));
|
out.content(lang("Not_Operator"));
|
||||||
else if (operator.getAccess() >= Access.NO_LOGIN) {
|
else if (operator.getAccess() >= Access.NO_LOGIN) {
|
||||||
out.content(lang("No_Login"));
|
out.content(lang("No_Login"));
|
||||||
} else {
|
} else {
|
||||||
String id = WechatSession.genId();
|
WxSession session = WechatSession.create();
|
||||||
WxSession session = WechatSession.get(id, true);
|
session.setAttribute(Attribute.AUTHORIZED, Command.LOGIN);
|
||||||
session.setAttribute(Attribute.AUTHORIZED, Command.LOGIN);
|
session.setAttribute(Attribute.WECHAT, wxMessage.getFromUserName());
|
||||||
session.setAttribute(Attribute.WECHAT, wxMessage.getFromUserName());
|
session.setAttribute(Attribute.OPERATOR, operator);
|
||||||
session.setAttribute(Attribute.OPERATOR, operator);
|
out.content(format("Home_Page_Msg", format("Operator_Home_Page", session.getId())));
|
||||||
out.content(format("Operator_Home_Page", id));
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
out.content(lang("Login_Error"));
|
||||||
|
}
|
||||||
|
return out.build();
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
@Override
|
||||||
out.content(lang("Login_Error"));
|
public void onOAuth2(AsyncContext actx, HttpServletResponse resp, String user, WxSession session) {
|
||||||
}
|
try {
|
||||||
return out.build();
|
Operator operator = TableOperator.get(user);
|
||||||
}
|
if (operator == null) {
|
||||||
|
Redirect.error().icon(Redirect.WeUIIcon.WARN_SAFE).noButton()
|
||||||
|
.title(lang("Not_Operator")).msg(lang("Not_Operator_OAuth2")).go(resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (operator.getAccess() >= Access.NO_LOGIN) {
|
||||||
|
Redirect.error().icon(Redirect.WeUIIcon.WAITING).noButton()
|
||||||
|
.title(lang("Left_Operator_Title")).msg(lang("Left_Operator")).go(resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
session.setAttribute(Attribute.AUTHORIZED, Command.LOGIN);
|
||||||
|
session.setAttribute(Attribute.WECHAT, user);
|
||||||
|
session.setAttribute(Attribute.OPERATOR, operator);
|
||||||
|
resp.sendRedirect(format("Operator_Home_Page", session.getId()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.wechat.handler.admin;
|
package love.sola.netsupport.wechat.handler.admin;
|
||||||
|
|
||||||
import love.sola.netsupport.enums.Access;
|
import java.util.Map;
|
||||||
|
|
||||||
import love.sola.netsupport.pojo.Operator;
|
import love.sola.netsupport.pojo.Operator;
|
||||||
import love.sola.netsupport.sql.TableOperator;
|
import love.sola.netsupport.sql.TableOperator;
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
@@ -11,36 +29,31 @@ import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
|||||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
||||||
import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder;
|
import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static love.sola.netsupport.config.Lang.format;
|
import static love.sola.netsupport.config.Lang.format;
|
||||||
import static love.sola.netsupport.config.Lang.lang;
|
import static love.sola.netsupport.config.Lang.lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/28.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class OperatorInfoHandler implements WxMpMessageHandler {
|
public class OperatorInfoHandler implements WxMpMessageHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
||||||
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
||||||
try {
|
try {
|
||||||
Operator op = TableOperator.get(wxMessage.getFromUserName());
|
Operator op = TableOperator.get(wxMessage.getFromUserName());
|
||||||
if (op == null)
|
if (op == null) {
|
||||||
out.content(lang("Not_Operator"));
|
out.content(lang("Not_Operator"));
|
||||||
else if (op.getAccess() >= Access.NO_LOGIN) {
|
// } else if (op.getAccess() >= Access.NO_LOGIN) {
|
||||||
out.content(lang("No_Login"));
|
// out.content(lang("No_Login"));
|
||||||
} else {
|
} else {
|
||||||
out.content(format("Operator_Info", op.getId(), op.getName(), op.getAccess(), op.getBlock(), op.getWeek()));
|
out.content(format("Operator_Info", op.getId(), op.getName(), op.getAccess(), op.getBlock(), op.getWeek()));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
out.content(lang("Login_Error"));
|
out.content(lang("Login_Error"));
|
||||||
}
|
}
|
||||||
return out.build();
|
return out.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.wechat.handler.admin;
|
package love.sola.netsupport.wechat.handler.admin;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import love.sola.netsupport.sql.SQLCore;
|
import love.sola.netsupport.sql.SQLCore;
|
||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||||
@@ -9,80 +34,73 @@ import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
|||||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
||||||
import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder;
|
import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/12/26.
|
* @deprecated limited time only
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class SignHandler implements WxMpMessageHandler {
|
public class SignHandler implements WxMpMessageHandler {
|
||||||
|
|
||||||
public static Pattern pat = Pattern.compile("(?i)^Auth (\\d{4})");
|
public static Pattern pat = Pattern.compile("^(?i)Auth (\\d{4})");
|
||||||
|
public static final int INVALID_ID = -1;
|
||||||
|
public static final int SIGNED_ID = -2;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
||||||
String msg = wxMessage.getContent();
|
String msg = wxMessage.getContent();
|
||||||
TextBuilder out = WxMpXmlOutMessage.TEXT().toUser(wxMessage.getFromUserName()).fromUser(wxMessage.getToUserName());
|
TextBuilder out = WxMpXmlOutMessage.TEXT().toUser(wxMessage.getFromUserName()).fromUser(wxMessage.getToUserName());
|
||||||
Matcher mat = pat.matcher(msg);
|
Matcher mat = pat.matcher(msg);
|
||||||
|
|
||||||
root:
|
root:
|
||||||
if (mat.find()) {
|
if (mat.find()) {
|
||||||
int id = Integer.parseInt(mat.group(1));
|
int id = Integer.parseInt(mat.group(1));
|
||||||
try (Connection conn = SQLCore.ds.getConnection()) {
|
try (Connection conn = SQLCore.ds.getConnection()) {
|
||||||
switch (checkID(conn, id)) {
|
switch (checkID(conn, id)) {
|
||||||
case -1:
|
case INVALID_ID:
|
||||||
out.content("无效ID。");
|
out.content("无效ID。");
|
||||||
break root;
|
break root;
|
||||||
case -2:
|
case SIGNED_ID:
|
||||||
out.content("该ID已登记过。");
|
out.content("该ID已登记过。");
|
||||||
break root;
|
break root;
|
||||||
}
|
}
|
||||||
if (checkDuplicated(conn, wxMessage.getFromUserName())) {
|
if (checkDuplicated(conn, wxMessage.getFromUserName())) {
|
||||||
out.content("你的微信已经登记过。");
|
out.content("你的微信已经登记过。");
|
||||||
break root;
|
break root;
|
||||||
}
|
}
|
||||||
PreparedStatement ps = conn.prepareStatement("UPDATE auth SET wechat=? WHERE id=?");
|
PreparedStatement ps = conn.prepareStatement("UPDATE auth SET wechat=? WHERE id=?");
|
||||||
ps.setString(1, wxMessage.getFromUserName());
|
ps.setString(1, wxMessage.getFromUserName());
|
||||||
ps.setInt(2, id);
|
ps.setInt(2, id);
|
||||||
if (ps.executeUpdate() == 1) {
|
if (ps.executeUpdate() == 1) {
|
||||||
out.content("登记成功。");
|
out.content("登记成功。");
|
||||||
} else {
|
} else {
|
||||||
out.content("登记失败,请联系管理员。");
|
out.content("登记失败,请联系管理员。");
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
out.content("系统异常,请联系管理员。");
|
out.content("系统异常,请联系管理员。");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
out.content("无效ID。");
|
out.content("无效ID。");
|
||||||
}
|
}
|
||||||
return out.build();
|
return out.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int checkID(Connection conn, int id) throws SQLException {
|
private static int checkID(Connection conn, int id) throws SQLException {
|
||||||
PreparedStatement ps = conn.prepareStatement("SELECT wechat FROM auth WHERE id=?");
|
PreparedStatement ps = conn.prepareStatement("SELECT wechat FROM auth WHERE id=?");
|
||||||
ps.setInt(1, id);
|
ps.setInt(1, id);
|
||||||
ResultSet rs = ps.executeQuery();
|
ResultSet rs = ps.executeQuery();
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
return rs.getString("wechat") != null ? -2 : 0;
|
return rs.getString("wechat") != null ? SIGNED_ID : 0;
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return INVALID_ID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean checkDuplicated(Connection conn, String wechat) throws SQLException {
|
private static boolean checkDuplicated(Connection conn, String wechat) throws SQLException {
|
||||||
PreparedStatement ps = conn.prepareStatement("SELECT wechat FROM auth WHERE wechat=?");
|
PreparedStatement ps = conn.prepareStatement("SELECT wechat FROM auth WHERE wechat=?");
|
||||||
ps.setString(1, wechat);
|
ps.setString(1, wechat);
|
||||||
ResultSet rs = ps.executeQuery();
|
ResultSet rs = ps.executeQuery();
|
||||||
return rs.next();
|
return rs.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,43 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.wechat.matcher;
|
package love.sola.netsupport.wechat.matcher;
|
||||||
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import love.sola.netsupport.config.Settings;
|
import love.sola.netsupport.config.Settings;
|
||||||
import me.chanjar.weixin.mp.api.WxMpMessageMatcher;
|
import me.chanjar.weixin.mp.api.WxMpMessageMatcher;
|
||||||
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/11/4.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class CheckSpamMatcher implements WxMpMessageMatcher {
|
public class CheckSpamMatcher implements WxMpMessageMatcher {
|
||||||
|
|
||||||
private class ValueLoader extends CacheLoader<String, Long> {
|
private class ValueLoader extends CacheLoader<String, Long> {
|
||||||
@Override
|
@Override
|
||||||
public Long load(String key) throws Exception {
|
public Long load(String key) throws Exception {
|
||||||
return System.currentTimeMillis() + Settings.I.Check_Spam_Interval;
|
return System.currentTimeMillis() + Settings.I.Check_Spam_Interval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private LoadingCache<String, Long> cache = CacheBuilder.newBuilder()
|
private LoadingCache<String, Long> cache = CacheBuilder.newBuilder()
|
||||||
.concurrencyLevel(4)
|
.concurrencyLevel(4)
|
||||||
.maximumSize(4096)
|
.maximumSize(4096)
|
||||||
.expireAfterWrite(Settings.I.Check_Spam_Cache_Expire_Time, TimeUnit.SECONDS)
|
.expireAfterWrite(Settings.I.Check_Spam_Cache_Expire_Time, TimeUnit.SECONDS)
|
||||||
.build(new ValueLoader());
|
.build(new ValueLoader());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean match(WxMpXmlMessage wxMessage) {
|
public boolean match(WxMpXmlMessage wxMessage) {
|
||||||
Long l = cache.getIfPresent(wxMessage.getFromUserName());
|
Long l = cache.getIfPresent(wxMessage.getFromUserName());
|
||||||
if (l != null && l > System.currentTimeMillis()) {
|
if (l != null && l > System.currentTimeMillis()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
cache.refresh(wxMessage.getFromUserName());
|
cache.refresh(wxMessage.getFromUserName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.wechat.matcher;
|
package love.sola.netsupport.wechat.matcher;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import love.sola.netsupport.wechat.Command;
|
import love.sola.netsupport.wechat.Command;
|
||||||
import me.chanjar.weixin.mp.api.WxMpMessageMatcher;
|
import me.chanjar.weixin.mp.api.WxMpMessageMatcher;
|
||||||
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/11/26.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class CommandMatcher implements WxMpMessageMatcher {
|
public class CommandMatcher implements WxMpMessageMatcher {
|
||||||
|
|
||||||
public static Map<String, Command> inCmdUsers = new ConcurrentHashMap<>();
|
public static Map<String, Command> inCmdUsers = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
Command command;
|
Command command;
|
||||||
|
|
||||||
public CommandMatcher(Command command) {
|
public CommandMatcher(Command command) {
|
||||||
this.command = command;
|
this.command = command;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean match(WxMpXmlMessage message) {
|
public boolean match(WxMpXmlMessage message) {
|
||||||
String fromUser = message.getFromUserName();
|
String fromUser = message.getFromUserName();
|
||||||
if (inCmdUsers.containsKey(fromUser)) {
|
if (inCmdUsers.containsKey(fromUser)) {
|
||||||
return command == inCmdUsers.get(fromUser);
|
return command == inCmdUsers.get(fromUser);
|
||||||
} else {
|
} else {
|
||||||
return message.getContent().matches(command.regex);
|
return message.getContent().matches(command.regex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of WechatTicketSystem.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* WechatTicketSystem is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with WechatTicketSystem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package love.sola.netsupport.wechat.matcher;
|
package love.sola.netsupport.wechat.matcher;
|
||||||
|
|
||||||
import love.sola.netsupport.sql.TableUser;
|
import love.sola.netsupport.sql.TableUser;
|
||||||
@@ -5,16 +22,13 @@ import me.chanjar.weixin.mp.api.WxMpMessageMatcher;
|
|||||||
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2015/11/26.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class RegisterMatcher implements WxMpMessageMatcher {
|
public class RegisterMatcher implements WxMpMessageMatcher {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean match(WxMpXmlMessage message) {
|
public boolean match(WxMpXmlMessage message) {
|
||||||
return TableUser.getByWechat(message.getFromUserName()) == null;
|
return TableUser.getByWechat(message.getFromUserName()) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
<?xml version='1.0' encoding='utf-8'?>
|
<?xml version='1.0' encoding='utf-8'?><!--
|
||||||
<!--
|
|
||||||
~ Hibernate, Relational Persistence for Idiomatic Java
|
~ Hibernate, Relational Persistence for Idiomatic Java
|
||||||
~
|
~
|
||||||
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
-->
|
--><!DOCTYPE hibernate-configuration PUBLIC
|
||||||
<!DOCTYPE hibernate-configuration PUBLIC
|
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
|
||||||
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
|
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
|
||||||
|
|
||||||
<hibernate-configuration>
|
<hibernate-configuration>
|
||||||
|
|
||||||
@@ -28,7 +26,8 @@
|
|||||||
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
|
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
|
||||||
|
|
||||||
<!-- Disable the second-level cache -->
|
<!-- Disable the second-level cache -->
|
||||||
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
|
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider
|
||||||
|
</property>
|
||||||
|
|
||||||
<!-- Echo all executed SQL to stdout -->
|
<!-- Echo all executed SQL to stdout -->
|
||||||
<property name="show_sql">true</property>
|
<property name="show_sql">true</property>
|
||||||
@@ -37,10 +36,11 @@
|
|||||||
<property name="hbm2ddl.auto">validate</property>
|
<property name="hbm2ddl.auto">validate</property>
|
||||||
|
|
||||||
<!-- Names the annotated entity class -->
|
<!-- Names the annotated entity class -->
|
||||||
<mapping class="love.sola.netsupport.pojo.User"/>
|
<mapping class="love.sola.netsupport.pojo.User" />
|
||||||
<mapping class="love.sola.netsupport.pojo.Ticket"/>
|
<mapping class="love.sola.netsupport.pojo.Ticket" />
|
||||||
<mapping class="love.sola.netsupport.pojo.Operator"/>
|
<mapping class="love.sola.netsupport.pojo.Operator" />
|
||||||
|
<mapping class="love.sola.netsupport.pojo.ToolsCheck" />
|
||||||
|
|
||||||
</session-factory>
|
</session-factory>
|
||||||
|
|
||||||
</hibernate-configuration>
|
</hibernate-configuration>
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
#System Exception
|
#System Exception
|
||||||
Access_Denied: 'Access denied.'
|
Access_Denied: 'Access denied.'
|
||||||
Illegal_Request: "Access denied.\nYou are doing a illegal request, and our system has logged your behaviors.\nYou need to take this seriously, if you do this frequently, you may be banned from our system."
|
Illegal_Request: |
|
||||||
|
Access denied.
|
||||||
|
You are doing an illegal request, and our system has logged your behaviors.
|
||||||
|
You have to take this seriously, you may be banned from our system if you do this frequently.
|
||||||
Unknown_Encrypt_Type: 'Unknown encrypt-type.'
|
Unknown_Encrypt_Type: 'Unknown encrypt-type.'
|
||||||
|
|
||||||
#Command Regex
|
#Command Regex
|
||||||
@@ -11,9 +14,10 @@ REGEX_CANCEL: '^(?i)(Cancel)|(取消)|(撤销)|(qx)|(cx)$'
|
|||||||
REGEX_LOGIN: '^(?i)Authme$'
|
REGEX_LOGIN: '^(?i)Authme$'
|
||||||
REGEX_PROFILE: '^(?i)(EditProfile)|(修改资料)|(修改信息)|(xgzl)|(xgxx)$'
|
REGEX_PROFILE: '^(?i)(EditProfile)|(修改资料)|(修改信息)|(xgzl)|(xgxx)$'
|
||||||
REGEX_OPERATOR_INFO: '^(?i)(OpInfo)|(网维资料)|(wwzl)$'
|
REGEX_OPERATOR_INFO: '^(?i)(OpInfo)|(网维资料)|(wwzl)$'
|
||||||
|
REGEX_SIGN: '^(?i)Auth (\d{4})$'
|
||||||
|
|
||||||
#Misc
|
#Misc
|
||||||
Invalid_Operation: 'Whoops,报修姬找不到你想要的东西啦 (╯‵□′)╯︵┻━┻。'
|
Invalid_Operation: 'Whoops,本报修平台暂未开放聊天功能哦,请点击下方菜单选择你想进行的操作。'
|
||||||
Message_Spam: '你的打字速度太快了,喝一杯82年的Java压压惊吧。'
|
Message_Spam: '你的打字速度太快了,喝一杯82年的Java压压惊吧。'
|
||||||
#Subscribe
|
#Subscribe
|
||||||
Event_Subscribe: "欢迎使用电子科技大学中山学院网络维护科微信自助报修平台。\n\n{0}"
|
Event_Subscribe: "欢迎使用电子科技大学中山学院网络维护科微信自助报修平台。\n\n{0}"
|
||||||
@@ -28,13 +32,13 @@ No_Ticket_Available: '您尚未提交过任何报修。'
|
|||||||
Already_Opening_Ticket: "您上次提交的报修单仍在处理中. 若需要查询报修单状态,请发送 '查询' 。"
|
Already_Opening_Ticket: "您上次提交的报修单仍在处理中. 若需要查询报修单状态,请发送 '查询' 。"
|
||||||
Submit_Title: '在网维工作人员上门解决您的问题之前...'
|
Submit_Title: '在网维工作人员上门解决您的问题之前...'
|
||||||
Submit_Desc: |
|
Submit_Desc: |
|
||||||
在网维工作人员上门解决您的问题之前,您可以尝试以下方法来更有效地解决您的问题:
|
在网维工作人员上门解决您的问题之前,您可以尝试以下方法来更有效地解决您的问题:
|
||||||
- 重新插拔您电脑的网线以及墙上的端口。
|
- 重新插拔您电脑的网线以及墙上的端口。
|
||||||
- 尝试卸载掉您的wifi共享软件并重启电脑。
|
- 尝试卸载掉您的wifi共享软件并重启电脑。
|
||||||
- 请您检查一下您的账号是否余额充足。
|
- 请您检查一下您的账号是否余额充足。
|
||||||
- 若您的电脑出现明显异常,请尝试使用他人的电脑能否正常登录,网维的工作成员主要负责网络的维护工作,可能无法解决您的个人电脑问题。
|
- 若您的电脑出现明显异常,请尝试使用他人的电脑能否正常登录,网维的工作成员主要负责网络的维护工作,可能无法解决您的个人电脑问题。
|
||||||
|
|
||||||
若以上步骤对您没有帮助,请点此提交报修表单。
|
若以上步骤对您没有帮助,请点此提交报修表单。
|
||||||
#Cancel
|
#Cancel
|
||||||
No_Open_Ticket_Available: '您当前没有未解决的报修表单。'
|
No_Open_Ticket_Available: '您当前没有未解决的报修表单。'
|
||||||
Cancel_Title: '报修已取消:'
|
Cancel_Title: '报修已取消:'
|
||||||
@@ -42,28 +46,34 @@ User_Cancel_Remark: '用户手动取消报修。'
|
|||||||
Cancel_Failed: '取消失败。'
|
Cancel_Failed: '取消失败。'
|
||||||
#Modify
|
#Modify
|
||||||
Profile_Modify: '<a href="{0}">> 点此修改资料 <</a>'
|
Profile_Modify: '<a href="{0}">> 点此修改资料 <</a>'
|
||||||
|
Need_Register_Title: '尚未进行微信绑定'
|
||||||
|
Need_Register: '您尚未进行微信绑定,3秒后将自动跳转至微信绑定页面。'
|
||||||
#Login
|
#Login
|
||||||
|
Home_Page_Msg: '<a href="{0}">CLICK HERE</a>'
|
||||||
Not_Operator: '嘟嘟嘟……'
|
Not_Operator: '嘟嘟嘟……'
|
||||||
|
Not_Operator_OAuth2: '看起来你并不是我们网维大家族的一员,但我们随时都欢迎你的加入哦!'
|
||||||
No_Login: 'Permission Denied.'
|
No_Login: 'Permission Denied.'
|
||||||
|
Left_Operator_Title: '一路上有你'
|
||||||
|
Left_Operator: '网络维护科的茁壮成长离不开每一位成员的陪伴。一路上有你,感谢你对网络维护科的贡献!'
|
||||||
Internal_Error: '啊哦,登录失败了哦。'
|
Internal_Error: '啊哦,登录失败了哦。'
|
||||||
#Operator_Info
|
#Operator_Info
|
||||||
Operator_Info: |
|
Operator_Info: |
|
||||||
网维成员资料:
|
网维成员资料:
|
||||||
网维ID: {0,number,#}
|
网维ID: {0,number,#}
|
||||||
姓名: {1}
|
姓名: {1}
|
||||||
岗位: {2,choice,0#'Administrator >ω<'|3#值班组长|6#正式成员|7#实习成员|}
|
岗位: {2,choice,0#'Administrator >ω<'|3#值班组长|6#正式成员|7#实习成员|9#'曾经的一员(TдT)'}
|
||||||
值班片区: {3,choice,0#'全图 >ω<'|1#岐头片区|2#北门片区|3#东门片区|4#香灰片区|5#凤翔片区}
|
值班片区: {3,choice,0#'全图 >ω<'|1#岐头片区|2#北门片区|3#东门片区|4#香灰片区|5#凤翔片区|8#朝晖片区}
|
||||||
值班日: {4,choice,0#'2月30日 >ω<'|1#周一|2#周二|3#周三|4#周四|5#周五|6#周六|7#周日}
|
值班日: {4,choice,0#'2月30日 >ω<'|1#周一|2#周二|3#周三|4#周四|5#周五|6#周六|7#周日}
|
||||||
|
|
||||||
若以上信息有误,请及时联系@15-排污-沙子森。
|
若以上信息有误,请及时联系@15-沙子森。
|
||||||
#URL
|
#URL
|
||||||
User_Register_Link: 'http://topaz.sinaapp.com/nm/v2/user/reg.html?token={0}'
|
User_Register_Link: 'https://wwbx.zsxyww.htroy.com/nm/v2/user/reg.html?token={0}'
|
||||||
User_Query_Link: 'http://topaz.sinaapp.com/nm/v2/user/list.html?token={0}'
|
User_Query_Link: 'https://wwbx.zsxyww.htroy.com/nm/v2/user/list.html?token={0}'
|
||||||
User_Submit_Link: 'http://topaz.sinaapp.com/nm/v2/user/rrepair.html?token={0}&name={1}&isp={2}&room={3}&block={4}&phone={5,number,#}'
|
User_Submit_Link: 'https://wwbx.zsxyww.htroy.com/nm/v2/user/rrepair.html?token={0}&name={1}&isp={2}&room={3}&block={4}&phone={5,number,#}'
|
||||||
User_Profile_Link: 'http://topaz.sinaapp.com/nm/v2/user/modi.html?token={0}&name={1}&isp={2}&username={3}&block={4}&room={5}&phone={6,number,#}'
|
User_Profile_Link: 'https://wwbx.zsxyww.htroy.com/nm/v2/user/modi.html?token={0}&name={1}&isp={2}&username={3}&block={4}&room={5}&phone={6,number,#}'
|
||||||
Result_Page: 'http://topaz.sinaapp.com/nm/v2/result.html'
|
Result_Page: 'https://wwbx.zsxyww.htroy.com/nm/v2/result.html'
|
||||||
Operator_Home_Page: '<a href="http://topaz.sinaapp.com/nm/v2/man/home.html?token={0}">CLICK HERE</a>'
|
Operator_Home_Page: 'https://wwbx.zsxyww.htroy.com/nm/v2/man/home.html?token={0}'
|
||||||
Operator_Login_Page: 'http://topaz.sinaapp.com/nm/v2/man/login.html?pkey={0}'
|
Operator_Login_Page: 'https://wwbx.zsxyww.htroy.com/nm/v2/man/login.html?pkey={0}'
|
||||||
|
|
||||||
#Localized
|
#Localized
|
||||||
#Status
|
#Status
|
||||||
@@ -76,4 +86,4 @@ Ticket_Info_Submit_Time: '提交时间: '
|
|||||||
Ticket_Info_Operator: '操作员: '
|
Ticket_Info_Operator: '操作员: '
|
||||||
Ticket_Info_Remark: '维修描述: '
|
Ticket_Info_Remark: '维修描述: '
|
||||||
Ticket_Info_Update_Time: '更新时间: '
|
Ticket_Info_Update_Time: '更新时间: '
|
||||||
Ticket_Info_Status: '报修单状态: '
|
Ticket_Info_Status: '报修单状态: '
|
||||||
|
|||||||
@@ -24,6 +24,26 @@
|
|||||||
"key": "PROFILE"
|
"key": "PROFILE"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "关于网维",
|
||||||
|
"sub_button": [
|
||||||
|
{
|
||||||
|
"type": "view",
|
||||||
|
"name": "关于报修系统",
|
||||||
|
"url": "https://wwbx.zsxyww.htroy.com/nm/v2/"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "view",
|
||||||
|
"name": "联系我们",
|
||||||
|
"url": "https://wwbx.zsxyww.htroy.com/nm/v2/404.html"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "view",
|
||||||
|
"name": "关于网维",
|
||||||
|
"url": "https://wwbx.zsxyww.htroy.com/nm/v2/404.html"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
<wechat-config>
|
|
||||||
<appId>****</appId>
|
|
||||||
<secret>****</secret>
|
|
||||||
<token>****</token>
|
|
||||||
<aesKey>****</aesKey>
|
|
||||||
</wechat-config>
|
|
||||||
38
src/main/webapp/META-INF/context.xml
Normal file
38
src/main/webapp/META-INF/context.xml
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?xml version='1.0' encoding='utf-8'?><!--
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
--><!-- The contents of this file will be loaded for each web application --><!-- Don't swallowOutput for debugging, true for logging(production) -->
|
||||||
|
<Context antiResourceLocking="true">
|
||||||
|
|
||||||
|
<!-- Default set of monitored resources -->
|
||||||
|
<WatchedResource>WEB-INF/web.xml</WatchedResource>
|
||||||
|
|
||||||
|
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
|
||||||
|
<!--
|
||||||
|
<Manager pathname="" />
|
||||||
|
-->
|
||||||
|
<Resource auth="Container" description="C3P0 database connection pool"
|
||||||
|
driverClass="com.mysql.jdbc.Driver" maxPoolSize="10" minPoolSize="2" acquireIncrement="1"
|
||||||
|
maxIdleTime="3600" idleConnectionTestPeriod="1800" name="jdbc/netsupport" user="root"
|
||||||
|
password="" factory="org.apache.naming.factory.BeanFactory"
|
||||||
|
type="com.mchange.v2.c3p0.ComboPooledDataSource"
|
||||||
|
jdbcUrl="jdbc:mysql://localhost:3306/netsupport?autoReconnect=true&characterEncoding=utf8" />
|
||||||
|
<!-- Uncomment this to enable Comet connection tacking (provides events
|
||||||
|
on session expiration as well as webapp lifecycle) -->
|
||||||
|
<!--
|
||||||
|
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
|
||||||
|
-->
|
||||||
|
|
||||||
|
</Context>
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
||||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
|
||||||
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
|
||||||
version="3.1">
|
|
||||||
|
|
||||||
<!-- General description of your web application -->
|
<!-- General description of your web application -->
|
||||||
|
|
||||||
@@ -23,4 +21,4 @@
|
|||||||
<session-timeout>10</session-timeout> <!-- 30 minutes -->
|
<session-timeout>10</session-timeout> <!-- 30 minutes -->
|
||||||
</session-config>
|
</session-config>
|
||||||
|
|
||||||
</web-app>
|
</web-app>
|
||||||
|
|||||||
@@ -1,34 +1,20 @@
|
|||||||
package love.sola.netsupport.api;
|
package love.sola.netsupport.api;
|
||||||
|
|
||||||
import com.google.common.reflect.ClassPath;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.reflections.Reflections;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ***********************************************
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
* Created by Sola on 2014/8/20.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
*/
|
||||||
public class ReflectionTest {
|
public class ReflectionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws IOException, IllegalAccessException, InstantiationException {
|
public void test() {
|
||||||
int count = 0;
|
Reflections reflections = new Reflections(getClass().getPackage().getName());
|
||||||
ClassPath path = ClassPath.from(getClass().getClassLoader());
|
Set<Class<? extends API>> set = reflections.getSubTypesOf(API.class);
|
||||||
Set<ClassPath.ClassInfo> classes = path.getTopLevelClassesRecursive(getClass().getPackage().getName());
|
assert set.size() == 15;
|
||||||
for (ClassPath.ClassInfo info : classes) {
|
}
|
||||||
Class<?> clz = info.load();
|
|
||||||
if (!API.class.equals(clz) && API.class.isAssignableFrom(clz)) {
|
|
||||||
System.out.println("Loading API: " + clz.getName());
|
|
||||||
API obj = (API) clz.newInstance();
|
|
||||||
System.out.println("Registered API: " + obj);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println("Total " + count + " API(s) loaded.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package love.sola.netsupport.config;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
|
*/
|
||||||
|
public class ReflectionTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLang() {
|
||||||
|
assert Lang.messages != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
25
src/test/java/love/sola/netsupport/enums/ReflectionTest.java
Normal file
25
src/test/java/love/sola/netsupport/enums/ReflectionTest.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package love.sola.netsupport.enums;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
|
*/
|
||||||
|
public class ReflectionTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBlock() {
|
||||||
|
assert Block.inverseMap != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAccess() {
|
||||||
|
assert Access.inverseMap != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStatus() {
|
||||||
|
assert Status.inverseMap != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
34
src/test/java/love/sola/netsupport/util/GsonTest.java
Normal file
34
src/test/java/love/sola/netsupport/util/GsonTest.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package love.sola.netsupport.util;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.JsonDeserializer;
|
||||||
|
import com.google.gson.JsonPrimitive;
|
||||||
|
import com.google.gson.JsonSerializer;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import love.sola.netsupport.enums.ISP;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
|
*/
|
||||||
|
public class GsonTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJsonDate() {
|
||||||
|
Gson gson = new GsonBuilder()
|
||||||
|
.registerTypeAdapter(Date.class, (JsonDeserializer<Date>) (json, typeOfT, context) -> new Date(json.getAsJsonPrimitive().getAsLong()))
|
||||||
|
.registerTypeAdapter(Date.class, (JsonSerializer<Date>) (src, typeOfSrc, context) -> new JsonPrimitive(src.getTime()))
|
||||||
|
.registerTypeAdapter(ISP.class, (JsonDeserializer<ISP>) (json, typeOfT, context) -> ISP.fromId(json.getAsJsonPrimitive().getAsInt()))
|
||||||
|
.registerTypeAdapter(ISP.class, (JsonSerializer<ISP>) (src, typeOfSrc, context) -> new JsonPrimitive(src.id))
|
||||||
|
.create();
|
||||||
|
Date date = new Date();
|
||||||
|
assert gson.fromJson(gson.toJson(date), Date.class).compareTo(date) == 0;
|
||||||
|
assert gson.fromJson(gson.toJson(ISP.TELECOM), ISP.class) == ISP.TELECOM;
|
||||||
|
assert gson.toJson(ISP.TELECOM).equals("1");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
32
src/test/java/love/sola/netsupport/util/URLEncodeTest.java
Normal file
32
src/test/java/love/sola/netsupport/util/URLEncodeTest.java
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package love.sola.netsupport.util;
|
||||||
|
|
||||||
|
import com.google.common.net.UrlEscapers;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sola {@literal <dev@sola.love>}
|
||||||
|
*/
|
||||||
|
public class URLEncodeTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEncode() throws UnsupportedEncodingException {
|
||||||
|
assertThat(
|
||||||
|
UrlEscapers.urlFragmentEscaper().escape("Test Title"),
|
||||||
|
equalTo("Test%20Title")
|
||||||
|
);
|
||||||
|
assertThat(
|
||||||
|
Redirect.success()
|
||||||
|
.title("Test Title")
|
||||||
|
.msg("Test Message")
|
||||||
|
.toString(),
|
||||||
|
equalTo("http://wwbx.zsc.edu.cn/nm/v2/result.html?type=1&title=Test%20Title&msg=Test%20Message&")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package love.sola.netsupport.wechat;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ***********************************************
|
|
||||||
* Created by Sola on 2015/12/3.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
|
||||||
public class TestDate {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
System.out.println(new Date());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package love.sola.netsupport.wechat;
|
|
||||||
|
|
||||||
import love.sola.netsupport.util.RSAUtil;
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.mindrot.jbcrypt.BCrypt;
|
|
||||||
|
|
||||||
import java.security.KeyFactory;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.spec.InvalidKeySpecException;
|
|
||||||
import java.security.spec.X509EncodedKeySpec;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ***********************************************
|
|
||||||
* Created by Sola on 2015/12/6.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
|
||||||
public class TestEncrypt {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBCrypt() {
|
|
||||||
String hash = BCrypt.hashpw("mypasswordhere", BCrypt.gensalt());
|
|
||||||
assert BCrypt.checkpw("mypasswordhere", hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRSA() {
|
|
||||||
assert "Hello World".equals(RSAUtil.decrypt(RSAUtil.encrypt("Hello World")));
|
|
||||||
assert "Encrypt".equals(RSAUtil.decrypt(RSAUtil.encrypt("Encrypt")));
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
public void testRSASpecKey() throws NoSuchAlgorithmException, InvalidKeySpecException {
|
|
||||||
System.out.println("RSAUtil.privateKey_s = " + RSAUtil.privateKey_s);
|
|
||||||
System.out.println("RSAUtil.publicKey_s = " + RSAUtil.publicKey_s);
|
|
||||||
// String pkey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCA0qyARvHSCIUQ6YM6K+e/QgiZ+dc/MpVz5DIFwQab5iiifruQiaoA74ilHOOiq5i0ToR1VxNhCUZcAy2saHNifoYKTauMOUSV6IoP4X5jp691PlI9yxNx328mSlPNM9+7BgOzrUP1pR71d+T4LDn0o4J6Ad82vVIe7yWszzF4qQIDAQAB";
|
|
||||||
String pkey = RSAUtil.publicKey_s;
|
|
||||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
|
||||||
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(Base64.decodeBase64(pkey));
|
|
||||||
RSAUtil.publicKey = keyFactory.generatePublic(keySpec);
|
|
||||||
System.out.println("RSAUtil.encrypt(\"233\") = " + RSAUtil.encrypt("233"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package love.sola.netsupport.wechat;
|
|
||||||
|
|
||||||
import com.google.gson.*;
|
|
||||||
import love.sola.netsupport.config.Lang;
|
|
||||||
import love.sola.netsupport.enums.ISP;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ***********************************************
|
|
||||||
* Created by Sola on 2015/12/2.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
|
||||||
public class TestMessageFormat {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLang() {
|
|
||||||
assert Lang.messages != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testJsonDate() {
|
|
||||||
Gson gson = new GsonBuilder()
|
|
||||||
.registerTypeAdapter(Date.class, (JsonDeserializer<Date>) (json, typeOfT, context) -> new Date(json.getAsJsonPrimitive().getAsLong()))
|
|
||||||
.registerTypeAdapter(Date.class, (JsonSerializer<Date>) (src, typeOfSrc, context) -> new JsonPrimitive(src.getTime()))
|
|
||||||
.registerTypeAdapter(ISP.class, (JsonDeserializer<ISP>) (json, typeOfT, context) -> ISP.fromId(json.getAsJsonPrimitive().getAsInt()))
|
|
||||||
.registerTypeAdapter(ISP.class, (JsonSerializer<ISP>) (src, typeOfSrc, context) -> new JsonPrimitive(src.id))
|
|
||||||
.create();
|
|
||||||
Date date = new Date();
|
|
||||||
assert gson.fromJson(gson.toJson(date), Date.class).compareTo(date) == 0;
|
|
||||||
assert gson.fromJson(gson.toJson(ISP.TELECOM), ISP.class) == ISP.TELECOM;
|
|
||||||
assert gson.toJson(ISP.TELECOM).equals("1");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLong() {
|
|
||||||
assert "15838838438".equals(MessageFormat.format("{0,number,#}", 15838838438L));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOpInfo() {
|
|
||||||
assert !Lang.format("Operator_Info", 1541, "Sola", 0, 0, 4).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package love.sola.netsupport.wechat;
|
|
||||||
|
|
||||||
import love.sola.netsupport.enums.Block;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ***********************************************
|
|
||||||
* Created by Sola on 2015/12/6.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
|
||||||
public class TestReflection {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBlock() {
|
|
||||||
assert Block.inverseMap != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package love.sola.netsupport.wechat;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ***********************************************
|
|
||||||
* Created by Sola on 2015/11/26.
|
|
||||||
* Don't modify this source without my agreement
|
|
||||||
* ***********************************************
|
|
||||||
*/
|
|
||||||
public class TestRegex {
|
|
||||||
|
|
||||||
public static final String STUDENT_ID_REGEX = "^(2012|2013|2014|2015)[0-9]{9}";
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testStudentId() {
|
|
||||||
assert !"2011130201233".matches(STUDENT_ID_REGEX);
|
|
||||||
assert "2015130201233".matches(STUDENT_ID_REGEX);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user