mod
This commit is contained in:
19
.classpath
19
.classpath
@@ -1,19 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="owner.project.facets" value="java"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
|
||||
<classpathentry kind="con" path="com.genuitec.runtime.library/com.genuitec.jstl_1.2.2">
|
||||
<attributes>
|
||||
<attribute name="org.eclipse.jst.component.dependency" value="WEB-INF/lib"/>
|
||||
<attribute name="owner.project.facets" value="jst.web.jstl"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v8.0"/>
|
||||
<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>
|
||||
</classpath>
|
||||
45
.gitignore
vendored
45
.gitignore
vendored
@@ -1,13 +1,38 @@
|
||||
*.class
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
/WebRoot/WEB-INF/classes
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
7
.idea/encodings.xml
generated
Normal file
7
.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
14
.idea/misc.xml
generated
Normal file
14
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
46
.project
46
.project
@@ -1,46 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>pay</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.genuitec.eclipse.ast.deploy.core.DeploymentBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="WebRoot"/>
|
||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
|
||||
<attributes>
|
||||
<attribute name="hide" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary/StandardBrowser/html5"/>
|
||||
<classpathentry kind="output" path=""/>
|
||||
</classpath>
|
||||
@@ -1,3 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
validator.Checked=WebRoot/js,WebRoot/index.html
|
||||
validator.Unchecked=
|
||||
@@ -1,2 +0,0 @@
|
||||
defaultTldInfo=f\=http\://java.sun.com/jsf/core;http\://java.sun.com/jsf/html\=h;http\://struts.apache.org/tags-bean\=bean;http\://java.sun.com/jsp/jstl/fmt\=fmt;bean\=http\://struts.apache.org/tags-bean;nested\=http\://struts.apache.org/tags-nested;http\://java.sun.com/jsp/jstl/sql\=sql;c\=http\://java.sun.com/jsp/jstl/core;fmt\=http\://java.sun.com/jsp/jstl/fmt;http\://struts.apache.org/tags-logic\=logic;http\://java.sun.com/jsp/jstl/xml\=x;http\://java.sun.com/jsp/jstl/core\=c;logic\=http\://struts.apache.org/tags-logic;h\=http\://java.sun.com/jsf/html;http\://struts.apache.org/tags-tiles\=tiles;http\://java.sun.com/jsp/jstl/functions\=fn;tiles\=http\://struts.apache.org/tags-tiles;sql\=http\://java.sun.com/jsp/jstl/sql;http\://struts.apache.org/tags-html\=html;html\=http\://struts.apache.org/tags-html;http\://struts.apache.org/tags-nested\=nested;http\://java.sun.com/jsf/core\=f;fn\=http\://java.sun.com/jsp/jstl/functions;x\=http\://java.sun.com/jsp/jstl/xml
|
||||
eclipse.preferences.version=1
|
||||
@@ -1,7 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
<wb-module deploy-name="tb">
|
||||
<wb-resource deploy-path="/" source-path="/WebRoot" tag="defaultRootSource"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
|
||||
<property name="java-output-path" value="/ROOT/WebRoot/WEB-INF/classes"/>
|
||||
<property name="context-root" value="/pay"/>
|
||||
</wb-module>
|
||||
</project-modules>
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<runtime name="Apache Tomcat v8.0"/>
|
||||
<fixed facet="jst.web"/>
|
||||
<fixed facet="wst.jsdt.web"/>
|
||||
<fixed facet="java"/>
|
||||
<installed facet="java" version="1.7"/>
|
||||
<installed facet="jst.web" version="3.1"/>
|
||||
<installed facet="jst.web.jstl" version="1.2.2"/>
|
||||
<installed facet="wst.jsdt.web" version="1.0"/>
|
||||
</faceted-project>
|
||||
@@ -1 +0,0 @@
|
||||
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
|
||||
@@ -1 +0,0 @@
|
||||
Window
|
||||
@@ -1,3 +0,0 @@
|
||||
Manifest-Version: 1.0
|
||||
Class-Path:
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||
version="2.5">
|
||||
<display-name>pay</display-name>
|
||||
<listener>
|
||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<context-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>classpath:applicationContext.xml</param-value>
|
||||
</context-param>
|
||||
<servlet>
|
||||
<servlet-name>springmvc</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>classpath:springmvc-servlet.xml</param-value>
|
||||
</init-param>
|
||||
</servlet>
|
||||
<welcome-file-list>
|
||||
<welcome-file>/index.html</welcome-file>
|
||||
<welcome-file>/index.jsp</welcome-file>
|
||||
</welcome-file-list>
|
||||
<servlet-mapping>
|
||||
<servlet-name>springmvc</servlet-name>
|
||||
<url-pattern>/</url-pattern>
|
||||
</servlet-mapping>
|
||||
<filter>
|
||||
<filter-name>encodingFilter</filter-name>
|
||||
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
|
||||
<init-param>
|
||||
<param-name>encoding</param-name>
|
||||
<param-value>UTF-8</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>forceEncoding</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
</filter>
|
||||
<filter-mapping>
|
||||
<filter-name>encodingFilter</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
</web-app>
|
||||
186
pom.xml
Normal file
186
pom.xml
Normal file
@@ -0,0 +1,186 @@
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.demo</groupId>
|
||||
<artifactId>alipayDemo</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<name>alipayDemo Maven Webapp</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>3.6.3</maven.compiler.source>
|
||||
<maven.compiler.target>3.6.3</maven.compiler.target>
|
||||
<spring.version>5.3.27</spring.version>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- spring start -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- spring end -->
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-configuration</groupId>
|
||||
<artifactId>commons-configuration</artifactId>
|
||||
<version>1.10</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.12.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.6</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jsoup</groupId>
|
||||
<artifactId>jsoup</artifactId>
|
||||
<version>1.15.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.10.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.15</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.14</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.coobird</groupId>
|
||||
<artifactId>thumbnailator</artifactId>
|
||||
<version>0.4.19</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.freewayso</groupId>
|
||||
<artifactId>image-combiner</artifactId>
|
||||
<version>2.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.zxing</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>3.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.dom4j</groupId>
|
||||
<artifactId>dom4j</artifactId>
|
||||
<version>2.1.4</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.xstream</groupId>
|
||||
<artifactId>xstream</artifactId>
|
||||
<version>1.4.20</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.11.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.38</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alipay.sdk</groupId>
|
||||
<artifactId>alipay-sdk-java</artifactId>
|
||||
<version>4.35.132.ALL</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--j2ee相关包 servlet、jsp、jstl -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>jsp-api</artifactId>
|
||||
<version>2.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>1.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>alipayDemo</finalName>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.3.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:task="http://www.springframework.org/schema/task" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://www.springframework.org/schema/task
|
||||
http://www.springframework.org/schema/task/spring-task-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
">
|
||||
|
||||
<!--
|
||||
<context:component-scan base-package="sc545.pay.*" />
|
||||
|
||||
<task:executor id="executor" pool-size="5" />
|
||||
<task:scheduler id="scheduler" pool-size="10" />
|
||||
<task:annotation-driven executor="executor" scheduler="scheduler" />
|
||||
-->
|
||||
</beans>
|
||||
@@ -1,2 +0,0 @@
|
||||
a=b
|
||||
c=d
|
||||
@@ -1,14 +1,10 @@
|
||||
package sc545.pay.main;
|
||||
package com.demo;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import sc545.pay.utils.DBUtil;
|
||||
import sc545.pay.utils.FileUtils;
|
||||
import sc545.pay.utils.ReadTxt;
|
||||
import sc545.pay.utils.Utils;
|
||||
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayClient;
|
||||
@@ -20,22 +16,37 @@ import com.alipay.api.request.AlipayTradeQueryRequest;
|
||||
import com.alipay.api.response.AlipayTradePrecreateResponse;
|
||||
import com.alipay.api.response.AlipayTradeQueryResponse;
|
||||
|
||||
public class core {
|
||||
import com.utils.DBUtil;
|
||||
import com.utils.Utils;
|
||||
|
||||
public class alipay_core {
|
||||
AlipayClient client = null;
|
||||
/**支付宝回调的接口地址*/
|
||||
private static String aliNotifyUrl = ReadTxt.getSetting(null, "setting.ini", "web", "localhost")+"/pay/alinotify";
|
||||
private static String aliNotifyUrl = "yourWebUrl/pay/alinotify";
|
||||
|
||||
|
||||
/**
|
||||
* 接口调用配置
|
||||
*/
|
||||
public void getConfig() {
|
||||
|
||||
String appid="一串数字ID";
|
||||
String private_key="私钥";
|
||||
String public_key="公钥";
|
||||
String sign_type="RSA2";
|
||||
|
||||
client =new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",appid,private_key,"json","utf-8",public_key,sign_type);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public core() {
|
||||
public alipay_core() {
|
||||
getConfig();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
//每天定时清空无订单和超时关闭的数据库数据
|
||||
core c=new core();
|
||||
c.queryOrder("1655263616880");
|
||||
c.updateOrder("1655272489467");
|
||||
|
||||
System.out.println(Utils.QrImgB64("aaa",200));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,7 +57,7 @@ public class core {
|
||||
HashMap<String, String> rs = new HashMap<>();
|
||||
AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();
|
||||
|
||||
String h=new Date().getTime()+Utils.randomNum(10, 99)+"";
|
||||
String h=new Date().getTime()+ Utils.randomNum(10, 99)+"";
|
||||
|
||||
AlipayTradePrecreateModel model = new AlipayTradePrecreateModel();
|
||||
model.setOutTradeNo(h);//订单号(保证不重复)
|
||||
@@ -69,7 +80,7 @@ public class core {
|
||||
if(i==1){
|
||||
rs.put("code", "1");
|
||||
rs.put("qrcode", response.getQrCode());
|
||||
rs.put("qrimg", FileUtils.QrImgB64(response.getQrCode(), 300));
|
||||
rs.put("qrimg", Utils.QrImgB64(response.getQrCode(), 300));
|
||||
rs.put("out_trade_no", response.getOutTradeNo());
|
||||
}else rs.put("errcode", "-1");
|
||||
} else {
|
||||
@@ -142,20 +153,5 @@ public class core {
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 接口调用配置
|
||||
*/
|
||||
public void getConfig() {
|
||||
|
||||
String appid="2021003131621776";
|
||||
String private_key="MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCZu1LRuq3Ka79zzv9OgAYNYFVEFetjSsrBJ/N34aBYY3BIOLe5dIt7EQNjx1QUNlSsWU7EwW3AFurXK6iWjXOZrJHZKcM9tzZfsuQeeufnpDtAU90zMSJcu17JfBsTXaXHUEBtQ0wjbuQJ+ihQMB5FtYBg3CuCxUtLqS2/g/n/qlW9ZKPTdnyBCro8pd8w1S5op591aiQGqIZ8ufW45ysCCfjZdOYkFmZMMM2Z5DQjtkQiXgX4aiN5VY5UhyEcGHd3kr9AaYPTC1hLZNUpZXsc2lgdOKQNrZ1FOmxJU4RpNJ9DxrbAgxUQIpvKj5/uOtBFaBmK/CYiVvjBRK5qilZFAgMBAAECggEBAIaNl1pr6wq9re9d4MXDdgilJVwXV1QrtTTEk+t8dsyGFFOSGPRgVmibpnzhjOy39Pp4nGHH7xhutpMn6kIDgoehrHIHhJRy1EuElvc6mdl8PEP8YyIYQjwp3ze4wTX9BElkK0+21GA7Aard4gT1aLmYt8mPSyIFLvcFFz6F8/1ZqKzOtv4jXigXjDzmu/cHks7jamHhknFOn3D7rzfUUViP+2J4HEiSaJXdmzU05aA5glJSLSw4366/GFHsy/Zh3d4FwcFuRu7L+X8gx5vlsPm6E9J7LAt0k+rL5XZVjdkR+Svzkou6EIX+vyZGgxPcUzsZj/V+jMumwALkqyyWP4ECgYEA5wbEJE+sx1NpzeF0/mrIDaB72mX51xpxX93zFCDLzGEY8HiJeR/+UodsNRtGn/W4kBXGSqh0nRnnASs12LGUO+uXcODS2AvSCcV2l5Uh3ecDFavTSeZfAX6yLlw6aecxvRbtDPugPhZ2+i1yc5elyGs5nTd8TjWrdEz0IrTx5eUCgYEAqlmRZpprAb4mSwAQ9+tr9ldvf5xezLzwYNmqRK221OpjFX9oi82MkZrnjcHuEIxpz8quc09A9C+IJ7a1RquWWL52wvjPk52Lbs/vKmGE1h7CF/5Dz4bTOCSF5Kp3SN3HjUI852InWX1pUw1WL5ufVK4mopGs1C3d8ifTSbW9qOECgYEAtO1inMFdIblcqiUAV+NOiwV9GZw1XtVRpu+OV9wbXxNH0cPEffylUwLFpo2W8N0iTo0O/xcQRJytggfSIsNnwMmPj5Iy7YnMU2S2rJ3ZqQwrKUSosz5cdzI+3vnRsXCjTl/vA/ToGNfFE8aV1JsV9XCr7Ukv65wyi2Fc7PViYFUCgYEAoXp+JjDCtsg1LGtHqntzv/RqMSFdi96eTnCGwsuYwIPeoQZBaCTU10FrtijbLryroNmUPKIoBFD6VAsSE4eb4UvK8E9DFb8F6WkaYaZHcWF+w5e3WAWKO3IDqhsdL+lrvC/J49xbSK1lJeFCjaaLho3++aP1nLxN47p0wy6QNoECgYBi5tW50hn9Kyx8WTgJZJgAPT4udLtrLhiLZsS2fucyvumUa5AWUvqF3jAn81ty4hsVXiY5/jiMplRDTCvOSkmmwD+55pSENuVXMDIJXyi9YCB5EJseSr5s5K3IziaVgYkIsiGBz3wVpordQAXID4gm53tWcuoZM7R9d7gwFkhnmQ==";
|
||||
String public_key="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsRU1//mlUZ9h0KP1P0ck/y5lPmDUkgNz9fXhZ9QRK2ZlrwnweYC6abOYauy5/Q2yQEjmWO41DfIUEJcejun2yq0hFJ8vz+BiKzEK7jkaHJfm1+MAQ06Y0QzCsPEgTpLiM/wXHvwezqVRjqvlkv6y9K4H0INyWcMi+1BpM0HWdyVeTDxYAG6grn9k6yLfPrqe0zZmVhRUxxQqkf/opZFjRDPQVpsqWU4kICh6/32J83SMPisvdJ7Ad5DJQnGNR/GCQ4tF2rAX/DEi3xuC6+JjIH+CbGYDQq+ovLNXNIS9se80kNRn0ge9guij91u9+JOF/sSMUrf66aUeMS41pZ3+8QIDAQAB";
|
||||
String sign_type="RSA2";
|
||||
|
||||
client =new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",appid,private_key,"json","utf-8",public_key,sign_type);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package sc545.pay.main;
|
||||
package com.demo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -6,6 +6,8 @@ import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.utils.DBUtil;
|
||||
import com.utils.Utils;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -13,21 +15,16 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
|
||||
import sc545.pay.utils.DBUtil;
|
||||
import sc545.pay.utils.GsonUtils;
|
||||
import sc545.pay.utils.Utils;
|
||||
|
||||
|
||||
|
||||
|
||||
@CrossOrigin(origins = "*", maxAge = 3600)
|
||||
@RequestMapping(value="/pay",produces="text/html;charset=UTF-8")
|
||||
@RestController
|
||||
public class MainController {
|
||||
public class payController {
|
||||
|
||||
|
||||
/**
|
||||
* 获取付款码
|
||||
* @param param
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
@@ -42,10 +39,10 @@ public class MainController {
|
||||
|
||||
double num = Utils.getNumDouble(n);
|
||||
if(num<0.01||num>2000) return "{\"errcode\":\"-1\",\"msg\":\"0<金额<2000\"}";
|
||||
core core=new core();
|
||||
HashMap<String, String> order = core.createOrder(num, t);
|
||||
alipay_core alipay_core =new alipay_core();
|
||||
HashMap<String, String> order = alipay_core.createOrder(num, t);
|
||||
|
||||
return GsonUtils.ObjectToJson(order);
|
||||
return Utils.ObjectToJson(order);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,10 +61,10 @@ public class MainController {
|
||||
) {
|
||||
|
||||
|
||||
core core=new core();
|
||||
Map<String, Object> order = core.queryOrder(id);
|
||||
alipay_core alipay_core =new alipay_core();
|
||||
Map<String, Object> order = alipay_core.queryOrder(id);
|
||||
|
||||
return GsonUtils.ObjectToJson(order);
|
||||
return Utils.ObjectToJson(order);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,8 +82,8 @@ public class MainController {
|
||||
) {
|
||||
|
||||
|
||||
core core=new core();
|
||||
Map<String, Object> order = core.queryOrder(id);
|
||||
alipay_core alipay_core =new alipay_core();
|
||||
Map<String, Object> order = alipay_core.queryOrder(id);
|
||||
|
||||
if(order!=null){
|
||||
if("3".equals(order.get("ostatus")+"")||"4".equals(order.get("ostatus")+"")) return "{\"msg\":\"已支付\"}";
|
||||
@@ -111,7 +108,7 @@ public class MainController {
|
||||
) {
|
||||
|
||||
DBUtil db = new DBUtil();
|
||||
core core=new core();
|
||||
alipay_core alipay_core =new alipay_core();
|
||||
|
||||
//只有支付成功后,支付宝才会回调应用接口,可直接获取支付宝响应的参数
|
||||
String order_id = param.get("out_trade_no");
|
||||
@@ -124,7 +121,7 @@ public class MainController {
|
||||
|
||||
//检查数据库是否有本数据,有就修改,没有新增
|
||||
int i = db.execSql("select * from _orders where out_trade_no = ?", new String[]{order_id});
|
||||
if(i>0) core.updateOrder(order_id);
|
||||
if(i>0) alipay_core.updateOrder(order_id);
|
||||
else{
|
||||
db.execUpdate("insert into _orders(out_trade_no,trade_no,otitle,onum,ostatus,zfbuser,paynum,getnum,zfbuserid,getbody) "
|
||||
+ "values("+order_id+",?,?,"+param.get("total_amount")+","+s+",?,"+param.get("buyer_pay_amount")+","+param.get("receipt_amount")+",?,?)", new String[]{param.get("trade_no"),param.get("subject"),param.get("buyer_logon_id"),param.get("buyer_id"),param.toString()});
|
||||
@@ -1,4 +1,4 @@
|
||||
package sc545.pay.utils;
|
||||
package com.utils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.Connection;
|
||||
@@ -16,11 +16,11 @@ import java.util.Map;
|
||||
public class DBUtil {
|
||||
|
||||
// 四大金刚
|
||||
String dname = ReadTxt.getSetting(null, "setting.ini", "MySqlName","test");
|
||||
String dname = "scbox";
|
||||
String driver = "com.mysql.jdbc.Driver";// 驱动名称
|
||||
String url = "jdbc:mysql://"+ReadTxt.getSetting(null, "setting.ini", "MySqlIP","127.0.0.1")+":"+ReadTxt.getSetting(null, "setting.ini", "MySqlPort","3306")+"/"+dname+"?useUnicode=false&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&autoReconnect=true&useSSL=false";// 连接
|
||||
String username = ReadTxt.getSetting(null, "setting.ini", "MySqlUserName","root");// 用户名
|
||||
String password = ReadTxt.getSetting(null, "setting.ini", "MySqlPassWord","cheng355217");// 密码
|
||||
String url = "jdbc:mysql://127.0.0.1:3306/"+dname+"?useUnicode=false&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&autoReconnect=true&useSSL=false";// 连接
|
||||
String username = "root";// 用户名
|
||||
String password = "root";// 密码
|
||||
|
||||
// 三剑客
|
||||
Connection con = null;// 连接对象
|
||||
@@ -223,20 +223,20 @@ public class DBUtil {
|
||||
name+="`"+fields[j].getName() + "`,";
|
||||
|
||||
// 字段值
|
||||
if (fields[j].getType().getName().equals(java.lang.String.class.getName())) {//String
|
||||
if (fields[j].getType().getName().equals(String.class.getName())) {//String
|
||||
|
||||
try {
|
||||
value[j]=(fields[j].get(obj));
|
||||
} catch (Exception e) {e.printStackTrace();
|
||||
}
|
||||
|
||||
} else if (fields[j].getType().getName().equals(java.lang.Long.class.getName()) || fields[j].getType().getName().equals("long")) {//int/long
|
||||
} else if (fields[j].getType().getName().equals(Long.class.getName()) || fields[j].getType().getName().equals("long")) {//int/long
|
||||
|
||||
try {
|
||||
value[j]=(fields[j].getLong(obj));
|
||||
} catch (Exception e) {e.printStackTrace();}
|
||||
|
||||
}else if (fields[j].getType().getName().equals(java.lang.Float.class.getName()) || fields[j].getType().getName().equals("float")) {//float/double
|
||||
}else if (fields[j].getType().getName().equals(Float.class.getName()) || fields[j].getType().getName().equals("float")) {//float/double
|
||||
|
||||
try {
|
||||
value[j]=(fields[j].getFloat(obj));
|
||||
142
src/main/java/com/utils/Utils.java
Normal file
142
src/main/java/com/utils/Utils.java
Normal file
@@ -0,0 +1,142 @@
|
||||
package com.utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.MultiFormatWriter;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class Utils {
|
||||
|
||||
//线程安全的
|
||||
private static final Gson GSON;
|
||||
private static final Gson GSON_NULL; // 不过滤空值
|
||||
static {
|
||||
GSON = new GsonBuilder().enableComplexMapKeySerialization() //当Map的key为复杂对象时,需要开启该方法
|
||||
// .serializeNulls() //当字段值为空或null时,依然对该字段进行转换
|
||||
// .excludeFieldsWithoutExposeAnnotation()//打开Export注解,但打开了这个注解,副作用,要转换和不转换都要加注解
|
||||
.setDateFormat("yyyy-MM-dd HH:mm:ss")//序列化日期格式 "yyyy-MM-dd"
|
||||
// .setPrettyPrinting() //自动格式化换行
|
||||
.disableHtmlEscaping() //防止特殊字符出现乱码
|
||||
.create();
|
||||
GSON_NULL = new GsonBuilder().enableComplexMapKeySerialization() //当Map的key为复杂对象时,需要开启该方法
|
||||
.serializeNulls() //当字段值为空或null时,依然对该字段进行转换
|
||||
// .excludeFieldsWithoutExposeAnnotation()//打开Export注解,但打开了这个注解,副作用,要转换和不转换都要加注解
|
||||
.setDateFormat("yyyy-MM-dd HH:mm:ss")//序列化日期格式 "yyyy-MM-dd"
|
||||
// .setPrettyPrinting() //自动格式化换行
|
||||
.disableHtmlEscaping() //防止特殊字符出现乱码
|
||||
.create();
|
||||
}
|
||||
|
||||
public static String ObjectToJson(Object object) {
|
||||
return GSON.toJson(object);
|
||||
}
|
||||
|
||||
public static double getNumDouble(String str) {
|
||||
|
||||
str = str.trim();
|
||||
String str2 = "";
|
||||
if (str != null && !"".equals(str)) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
if ((str.charAt(i) >= 48 && str.charAt(i) <= 57)
|
||||
|| str.charAt(i) == 43 || str.charAt(i) == 45
|
||||
|| str.charAt(i) == 46) {
|
||||
str2 += str.charAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean isok = true;
|
||||
for (int i = 1; i < str2.length(); i++) {
|
||||
if (str2.charAt(i) == 43 || str2.charAt(i) == 45) {
|
||||
isok = false;
|
||||
}
|
||||
}
|
||||
if (!isok)
|
||||
return Double.valueOf(getNum(str));
|
||||
if ("".equals(str2))
|
||||
str2 = "0";
|
||||
return Double.valueOf(str2);
|
||||
}
|
||||
|
||||
private static double getNum(String str) {
|
||||
str = str.trim();
|
||||
String str2 = "";
|
||||
if (str != null && !"".equals(str)) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
if (str.charAt(i) >= 48 && str.charAt(i) <= 57) {
|
||||
str2 += str.charAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ("".equals(str2))
|
||||
str2 = "-1";
|
||||
return Long.valueOf(str2);
|
||||
}
|
||||
|
||||
public static long randomNum(int min, int max) {
|
||||
int num = new Random().nextInt(max - min) + min;
|
||||
return num;
|
||||
}
|
||||
|
||||
public static String QrImgB64(String content,int widthHeight) {
|
||||
try {
|
||||
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
|
||||
Map<EncodeHintType, String> hints = new HashMap<EncodeHintType, String>();
|
||||
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
|
||||
BitMatrix bitMatrix= multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, widthHeight, widthHeight, hints);
|
||||
bitMatrix= deleteQRWhite(bitMatrix);
|
||||
BufferedImage imgbuf = toBufferedImage(bitMatrix);
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();//新建流。
|
||||
ImageIO.write(imgbuf, "jpg", os);//利用ImageIO类提供的write方法,将bi以png图片的数据模式写入流。
|
||||
byte b[] = os.toByteArray();//从流中获取数据数组。
|
||||
String str = Base64.encodeBase64String(b);
|
||||
return str;
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static final int BLACK = 0xFF000000;
|
||||
public static final int WHITE = 0xFFFFFFFF;
|
||||
public static BufferedImage toBufferedImage(BitMatrix matrix) {
|
||||
int width = matrix.getWidth();
|
||||
int height = matrix.getHeight();
|
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
image.setRGB(x, y, matrix.get(x, y) ? BLACK : WHITE);
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
public static BitMatrix deleteQRWhite(BitMatrix matrix) {
|
||||
int[] rec = matrix.getEnclosingRectangle();
|
||||
int resWidth = rec[2] + 1;
|
||||
int resHeight = rec[3] + 1;
|
||||
|
||||
BitMatrix resMatrix = new BitMatrix(resWidth, resHeight);
|
||||
resMatrix.clear();
|
||||
for (int i = 0; i < resWidth; i++) {
|
||||
for (int j = 0; j < resHeight; j++) {
|
||||
if (matrix.get(i + rec[0], j + rec[1]))
|
||||
resMatrix.set(i, j);
|
||||
}
|
||||
}
|
||||
return resMatrix;
|
||||
}
|
||||
|
||||
}
|
||||
12
src/main/resources/applicationContext.xml
Normal file
12
src/main/resources/applicationContext.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<context:component-scan base-package="com.*">
|
||||
<!--application父容器不扫描controller注解,这样两个配置文件各自各负责各自的-->
|
||||
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
|
||||
</context:component-scan>
|
||||
|
||||
</beans>
|
||||
34
src/main/resources/spring-mvc.xml
Normal file
34
src/main/resources/spring-mvc.xml
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<!--此文件负责整个mvc中的配置-->
|
||||
|
||||
<!-- 配置注解驱动 可以将request参数与绑定到controller参数上 -->
|
||||
<mvc:annotation-driven/>
|
||||
<!-- 将静态资源交于默认的servlet处理 -->
|
||||
|
||||
|
||||
<!--静态资源映射-->
|
||||
<!--本项目把静态资源放在了webapp的statics目录下,资源映射如下-->
|
||||
<!--<mvc:resources mapping="/css/**" location="/static/css/"/>-->
|
||||
<!--<mvc:resources mapping="/js/**" location="/static/js/"/>-->
|
||||
<!--<mvc:resources mapping="/image/**" location="/static/images/"/>-->
|
||||
<mvc:default-servlet-handler /> <!--这句要加上,要不然可能会访问不到静态资源,具体作用自行百度-->
|
||||
|
||||
<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀(如果最后一个还是表示文件夹,则最后的斜杠不要漏了) 使用JSP-->
|
||||
<!-- 默认的视图解析器 在上边的解析错误时使用 (默认使用html)- -->
|
||||
<bean id="defaultViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
<property name="prefix" value="/"/><!--设置JSP文件的目录位置-->
|
||||
<!--<property name="suffix" value=".jsp"/>-->
|
||||
</bean>
|
||||
|
||||
<bean id="multipartResolver" class="org.springframework.web.multipart.support.StandardServletMultipartResolver"/>
|
||||
|
||||
|
||||
<!-- 自动扫描装配,扫描controller包的注解,加入到容器中 -->
|
||||
<context:component-scan base-package="com.*"/>
|
||||
|
||||
</beans>
|
||||
35
src/main/webapp/WEB-INF/web.xml
Normal file
35
src/main/webapp/WEB-INF/web.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
|
||||
|
||||
<display-name>Archetype Created Web Application</display-name>
|
||||
<context-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>classpath:applicationContext.xml</param-value>
|
||||
</context-param>
|
||||
<listener>
|
||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
</listener>
|
||||
<servlet>
|
||||
<servlet-name>dispatcher</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!--springmvc的配置文件地址-->
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>classpath:spring-mvc.xml</param-value>
|
||||
</init-param><!--启动时间,跟服务器一起启动-->
|
||||
<load-on-startup>1</load-on-startup>
|
||||
|
||||
<multipart-config>
|
||||
<!-- 上传文件最大2M -->
|
||||
<max-file-size>100000000</max-file-size>
|
||||
<!-- 上传文件整个请求不超过4M -->
|
||||
<max-request-size>200000000</max-request-size>
|
||||
</multipart-config>
|
||||
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>dispatcher</servlet-name><!--拦截所有请求-->
|
||||
<url-pattern>/</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
|
||||
</web-app>
|
||||
@@ -5,7 +5,7 @@
|
||||
<meta charset='UTF-8'>
|
||||
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
|
||||
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||
<title>支付测试- 顺诚百宝箱</title>
|
||||
<title>支付测试</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 10px auto;
|
||||
@@ -21,7 +21,7 @@
|
||||
<div class="imgs"></div>
|
||||
|
||||
|
||||
<script src='/style/jq-weui/lib/jquery-2.1.4.js'></script>
|
||||
<script src='https://libs.baidu.com/jquery/2.0.0/jquery.min.js'></script>
|
||||
|
||||
<script>
|
||||
/**
|
||||
@@ -38,7 +38,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
let response = await fetch('/pay/createOrder?n=' + n + '&t=test');
|
||||
let response = await fetch('./pay/createOrder?n=' + n + '&t=test');
|
||||
let res = JSON.parse(await response.text());
|
||||
|
||||
if (res.code == 1) {
|
||||
@@ -64,7 +64,7 @@
|
||||
*轮询检查支付状态
|
||||
*/
|
||||
async function subscribe(id) {
|
||||
let response = await fetch("/pay/queryPay?id=" + id);
|
||||
let response = await fetch("./pay/queryPay?id=" + id);
|
||||
|
||||
if (response.status == 502) {
|
||||
// 连接超时,重新连接
|
||||
@@ -93,7 +93,7 @@
|
||||
* 手动查询支付状态
|
||||
*/
|
||||
async function selectPay(id) {
|
||||
let response = await fetch('/pay/queryPay?id=' + id);
|
||||
let response = await fetch('./pay/queryPay?id=' + id);
|
||||
let res = JSON.parse(await response.text());
|
||||
|
||||
if (response.status == 200 && res.msg == "已支付") {
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,138 +0,0 @@
|
||||
package sc545.pay.utils;
|
||||
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
public class GsonUtils{
|
||||
|
||||
//线程安全的
|
||||
private static final Gson GSON;
|
||||
private static final Gson GSON_NULL; // 不过滤空值
|
||||
static {
|
||||
GSON = new GsonBuilder().enableComplexMapKeySerialization() //当Map的key为复杂对象时,需要开启该方法
|
||||
// .serializeNulls() //当字段值为空或null时,依然对该字段进行转换
|
||||
// .excludeFieldsWithoutExposeAnnotation()//打开Export注解,但打开了这个注解,副作用,要转换和不转换都要加注解
|
||||
.setDateFormat("yyyy-MM-dd HH:mm:ss")//序列化日期格式 "yyyy-MM-dd"
|
||||
// .setPrettyPrinting() //自动格式化换行
|
||||
.disableHtmlEscaping() //防止特殊字符出现乱码
|
||||
.create();
|
||||
GSON_NULL = new GsonBuilder().enableComplexMapKeySerialization() //当Map的key为复杂对象时,需要开启该方法
|
||||
.serializeNulls() //当字段值为空或null时,依然对该字段进行转换
|
||||
// .excludeFieldsWithoutExposeAnnotation()//打开Export注解,但打开了这个注解,副作用,要转换和不转换都要加注解
|
||||
.setDateFormat("yyyy-MM-dd HH:mm:ss")//序列化日期格式 "yyyy-MM-dd"
|
||||
// .setPrettyPrinting() //自动格式化换行
|
||||
.disableHtmlEscaping() //防止特殊字符出现乱码
|
||||
.create();
|
||||
}
|
||||
|
||||
//获取gson解析器
|
||||
public static Gson getGson() {
|
||||
return GSON;
|
||||
}
|
||||
|
||||
//获取gson解析器 有空值 解析
|
||||
public static Gson getWriteNullGson() {
|
||||
return GSON_NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据对象返回json
|
||||
*/
|
||||
public static String ObjectToJson(Object object) {
|
||||
return GSON.toJson(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串转化对象
|
||||
*
|
||||
* @param json 源字符串
|
||||
* @param classOfT 目标对象类型
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> T JsonToObject(String json, Class<T> classOfT) {
|
||||
return GSON.fromJson(json, classOfT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串转化对象
|
||||
*
|
||||
* @param json 源字符串
|
||||
* @param t 目标对象类型
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> T JsonToObject(String json, Type t) {
|
||||
return GSON.fromJson(json, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将json转化为对应的实体对象
|
||||
* new TypeToken<List<T>>() {}.getType()
|
||||
* new TypeToken<Map<String, T>>() {}.getType()
|
||||
* new TypeToken<List<Map<String, T>>>() {}.getType()
|
||||
*/
|
||||
public static <T> T JsonToBean(String json, Type typeOfT) {
|
||||
return GSON.fromJson(json, typeOfT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转成list
|
||||
* @param gsonString
|
||||
* @param cls
|
||||
* @return
|
||||
*/
|
||||
public static <T> List<T> JsonToList(String gsonString, Class<T> cls) {
|
||||
return GSON.fromJson(gsonString, new TypeToken<List<T>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* 转成list中有map的
|
||||
* @param gsonString
|
||||
* @return
|
||||
*/
|
||||
public static <T> List<Map<String, T>> JsonToListMaps(String gsonString) {
|
||||
return GSON.fromJson(gsonString, new TypeToken<List<Map<String, String>>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* 转成map
|
||||
* @param gsonString
|
||||
* @return
|
||||
*/
|
||||
public static <T> Map<String, T> JsonToMaps(String gsonString) {
|
||||
return GSON.fromJson(gsonString, new TypeToken<Map<String, T>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取json字符串中的某个值
|
||||
* @param str json字符串
|
||||
* @param key 字段名
|
||||
* @param errorKey 若可能返回错误码且没有上述key这个字段,这里写错误码的字段名,否则填null
|
||||
* @return 若错误码,返回 "_errorKey_错误码字段值"
|
||||
*/
|
||||
public static String getJsonValue(String str,String key,String errorKey){
|
||||
if(str==null) return "";
|
||||
if(errorKey!=null&&str.indexOf(errorKey)>=0)
|
||||
return "_"+errorKey+"_"+new JsonParser().parse(str).getAsJsonObject().get(errorKey).getAsString();
|
||||
else
|
||||
return new JsonParser().parse(str).getAsJsonObject().get(key).getAsString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,657 +0,0 @@
|
||||
package sc545.pay.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.CookieStore;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.ssl.SSLContextBuilder;
|
||||
import org.apache.http.ssl.TrustStrategy;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 基于 httpclient 4.5版本的 http工具类
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class HttpUtils {
|
||||
|
||||
public static final String CHARSET = "UTF-8";
|
||||
|
||||
public static String doGet(String url, Map<String, String> params) {
|
||||
return doGet(url, params, CHARSET);
|
||||
}
|
||||
|
||||
public static String doGetSSL(String url, Map<String, String> params) {
|
||||
return doGetSSL(url, params, CHARSET);
|
||||
}
|
||||
|
||||
public static String doPost(String url, Map<String, String> params){
|
||||
return doPost(url, params, CHARSET);
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP Get 获取内容
|
||||
* @param url 请求的url地址 ?之前的地址
|
||||
* @param params 请求的参数
|
||||
* @param charset 编码格式
|
||||
* @return 页面内容
|
||||
*/
|
||||
public static String doGet(String url, Map<String, String> params, String charset) {
|
||||
if(charset==null||charset.trim().length()<1) charset="UTF-8";
|
||||
if (StringUtils.isBlank(url)) {
|
||||
return null;
|
||||
}
|
||||
CloseableHttpResponse response = null;
|
||||
HttpGet httpGet = null;
|
||||
RequestConfig config = RequestConfig.custom().setConnectTimeout(10000).setSocketTimeout(10000).setConnectionRequestTimeout(5000).build();
|
||||
CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
|
||||
try {
|
||||
if (params != null && !params.isEmpty()) {
|
||||
List<NameValuePair> pairs = new ArrayList<NameValuePair>(params.size());
|
||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||
String value = entry.getValue();
|
||||
if (value != null) {
|
||||
pairs.add(new BasicNameValuePair(entry.getKey(), value));
|
||||
}
|
||||
}
|
||||
// 将请求参数和url进行拼接
|
||||
url += "?" + EntityUtils.toString(new UrlEncodedFormEntity(pairs, charset));
|
||||
}
|
||||
httpGet = new HttpGet(url);
|
||||
response = httpClient.execute(httpGet);
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode != 200) {
|
||||
httpGet.abort();
|
||||
throw new RuntimeException("HttpClient,error status code :" + statusCode);
|
||||
}
|
||||
HttpEntity entity = response.getEntity();
|
||||
String result = null;
|
||||
if (entity != null) {
|
||||
result = EntityUtils.toString(entity, charset);
|
||||
}
|
||||
EntityUtils.consume(entity);
|
||||
response.close();
|
||||
if(!"UTF-8".equals(getEncoding(result))) result=GBKtoUTF8(result);
|
||||
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
System.out.println("url错误:::"+e.toString());
|
||||
try {
|
||||
response.close();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
try {
|
||||
response.close();
|
||||
httpClient.close();
|
||||
httpGet.reset();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* HTTP Post 获取内容
|
||||
* @param url 请求的url地址 ?之前的地址
|
||||
* @param params 请求的参数
|
||||
* @param charset 编码格式
|
||||
* @return 页面内容
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String doPost(String url, Map<String, String> params, String charset) {
|
||||
if(charset==null||charset.trim().length()<1) charset="UTF-8";
|
||||
if (StringUtils.isBlank(url)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<NameValuePair> pairs = null;
|
||||
if (params != null && !params.isEmpty()) {
|
||||
pairs = new ArrayList<NameValuePair>(params.size());
|
||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||
String value = entry.getValue();
|
||||
if (value != null) {
|
||||
pairs.add(new BasicNameValuePair(entry.getKey(), value));
|
||||
}
|
||||
}
|
||||
}
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
CloseableHttpResponse response = null;
|
||||
RequestConfig config = RequestConfig.custom().setConnectTimeout(10000).setSocketTimeout(10000).setConnectionRequestTimeout(5000).build();
|
||||
CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
|
||||
try {
|
||||
if (pairs != null && pairs.size() > 0) {
|
||||
httpPost.setEntity(new UrlEncodedFormEntity(pairs, CHARSET));
|
||||
}
|
||||
|
||||
response = httpClient.execute(httpPost);
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode != 200) {
|
||||
httpPost.abort();
|
||||
throw new RuntimeException("HttpClient,error status code :" + statusCode);
|
||||
}
|
||||
HttpEntity entity = response.getEntity();
|
||||
String result = null;
|
||||
if (entity != null) {
|
||||
result = EntityUtils.toString(entity, charset);
|
||||
}
|
||||
EntityUtils.consume(entity);
|
||||
if(!"UTF-8".equals(getEncoding(result))) result=GBKtoUTF8(result);
|
||||
return result;
|
||||
}catch (Exception e) {
|
||||
System.out.println("url错误:::"+e.toString());
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
try {
|
||||
response.close();
|
||||
httpClient.close();
|
||||
httpPost.reset();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTPS Get 获取内容
|
||||
* @param url 请求的url地址 ?之前的地址
|
||||
* @param params 请求的参数
|
||||
* @param charset 编码格式
|
||||
* @return 页面内容
|
||||
*/
|
||||
public static String doGetSSL(String url, Map<String, String> params, String charset) {
|
||||
if(charset==null||charset.trim().length()<1) charset="UTF-8";
|
||||
if (StringUtils.isBlank(url)) {
|
||||
return null;
|
||||
}
|
||||
CloseableHttpResponse response = null;
|
||||
HttpGet httpGet = null;
|
||||
CloseableHttpClient httpsClient = null;
|
||||
try {
|
||||
if (params != null && !params.isEmpty()) {
|
||||
List<NameValuePair> pairs = new ArrayList<NameValuePair>(params.size());
|
||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||
String value = entry.getValue();
|
||||
if (value != null) {
|
||||
pairs.add(new BasicNameValuePair(entry.getKey(), value));
|
||||
}
|
||||
}
|
||||
url += "?" + EntityUtils.toString(new UrlEncodedFormEntity(pairs, charset));
|
||||
}
|
||||
httpGet = new HttpGet(url);
|
||||
|
||||
// https 注意这里获取https内容,使用了忽略证书的方式,当然还有其他的方式来获取https内容
|
||||
httpsClient = HttpUtils.createSSLClientDefault();
|
||||
response = httpsClient.execute(httpGet);
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode != 200) {
|
||||
httpGet.abort();
|
||||
throw new RuntimeException("HttpClient,error status code :" + statusCode);
|
||||
}
|
||||
HttpEntity entity = response.getEntity();
|
||||
String result = null;
|
||||
if (entity != null) {
|
||||
result = EntityUtils.toString(entity, charset);
|
||||
}
|
||||
EntityUtils.consume(entity);
|
||||
response.close();
|
||||
if(!"UTF-8".equals(getEncoding(result))) result=GBKtoUTF8(result);
|
||||
return result;
|
||||
}catch (Exception e) {
|
||||
System.out.println("url错误:::"+e.toString());
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
try {
|
||||
response.close();
|
||||
httpsClient.close();
|
||||
httpGet.reset();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 这里创建了忽略整数验证的CloseableHttpClient对象
|
||||
* @return
|
||||
*/
|
||||
public static CloseableHttpClient createSSLClientDefault() {
|
||||
try {
|
||||
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
|
||||
// 信任所有
|
||||
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||
return true;
|
||||
}
|
||||
}).build();
|
||||
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext);
|
||||
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyStoreException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return HttpClients.createDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* 这里创建了忽略整数验证的CloseableHttpClient对象
|
||||
* @return
|
||||
*/
|
||||
public static CloseableHttpClient createSSLClientCookie(CookieStore cookie) {
|
||||
try {
|
||||
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
|
||||
// 信任所有
|
||||
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||
return true;
|
||||
}
|
||||
}).build();
|
||||
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext);
|
||||
return HttpClients.custom().setSSLSocketFactory(sslsf).setDefaultCookieStore(cookie).build();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyStoreException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return HttpClients.createDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送post请求
|
||||
* @param url 请求地址
|
||||
* @param json json格式字符串
|
||||
* @param contentType 这里用 "application/json"
|
||||
* @return
|
||||
*/
|
||||
public static String post(String url, String json, String contentType,String charset) {
|
||||
if(charset==null||charset.trim().length()<1) charset="UTF-8";
|
||||
if("json".equals(contentType)) contentType="application/json";
|
||||
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
|
||||
//HttpClient
|
||||
CloseableHttpClient client = httpClientBuilder.build();
|
||||
client = (CloseableHttpClient) wrapClient(client);
|
||||
HttpPost post = new HttpPost(url);
|
||||
CloseableHttpResponse res = null;
|
||||
try {
|
||||
StringEntity s = new StringEntity(json, "utf-8");
|
||||
if (StringUtils.isBlank(contentType)) {
|
||||
s.setContentType("application/json");
|
||||
}
|
||||
s.setContentType(contentType);
|
||||
post.setEntity(s);
|
||||
res = client.execute(post);
|
||||
HttpEntity entity = res.getEntity();
|
||||
String str = EntityUtils.toString(entity, charset);
|
||||
if(!"UTF-8".equals(getEncoding(str))) str=GBKtoUTF8(str);
|
||||
return str;
|
||||
}catch (Exception e) {
|
||||
System.out.println("url错误:::"+e.toString());
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
try {
|
||||
res.close();
|
||||
client.close();
|
||||
post.reset();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static org.apache.http.client.HttpClient wrapClient(HttpClient base) {
|
||||
try {
|
||||
SSLContext ctx = SSLContext.getInstance("TLSv1");
|
||||
X509TrustManager tm = new X509TrustManager() {
|
||||
public void checkClientTrusted(X509Certificate[] xcs,
|
||||
String string) throws CertificateException {
|
||||
}
|
||||
|
||||
public void checkServerTrusted(X509Certificate[] xcs,
|
||||
String string) throws CertificateException {
|
||||
}
|
||||
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
ctx.init(null, new TrustManager[]{tm}, null);
|
||||
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(ctx, new String[]{"TLSv1"}, null,
|
||||
SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
|
||||
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
|
||||
return httpclient;
|
||||
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//正则找出所有
|
||||
public static String getUrl(String s){
|
||||
String regex = "http[s]?:\\/\\/([\\w]+\\.)+[\\w]+([\\w./?%&=]*)?";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher m = pattern.matcher(s);
|
||||
String r="";
|
||||
while(m.find()){
|
||||
r+=m.group()+",";
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查url是否可访问
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static boolean ckUrl(String url) {
|
||||
|
||||
if (StringUtils.isBlank(url)) {
|
||||
return false;
|
||||
}
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
RequestConfig config = RequestConfig.custom().setConnectTimeout(10000).setSocketTimeout(10000).setConnectionRequestTimeout(5000).build();
|
||||
CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
|
||||
try {
|
||||
CloseableHttpResponse response = httpClient.execute(httpGet);
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode != 200) return false;
|
||||
} catch (Exception e) {
|
||||
String s = e.getMessage();
|
||||
if("Timeout waiting for connection from pool".equals(s)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**检查字符串编码格式*/
|
||||
public static String getEncoding(String str)
|
||||
{
|
||||
String encode;
|
||||
|
||||
encode = "UTF-16";
|
||||
try
|
||||
{
|
||||
if(str.equals(new String(str.getBytes(), encode)))
|
||||
{
|
||||
return encode;
|
||||
}
|
||||
}
|
||||
catch(Exception ex) {}
|
||||
|
||||
encode = "ASCII";
|
||||
try
|
||||
{
|
||||
if(str.equals(new String(str.getBytes(), encode)))
|
||||
{
|
||||
//字符串 str 中仅由数字和英文字母组成,无法识别其编码格式
|
||||
return "UTF-8";
|
||||
}
|
||||
}
|
||||
catch(Exception ex) {}
|
||||
|
||||
encode = "ISO-8859-1";
|
||||
try
|
||||
{
|
||||
if(str.equals(new String(str.getBytes(), encode)))
|
||||
{
|
||||
return encode;
|
||||
}
|
||||
}
|
||||
catch(Exception ex) {}
|
||||
|
||||
encode = "GB2312";
|
||||
try
|
||||
{
|
||||
if(str.equals(new String(str.getBytes(), encode)))
|
||||
{
|
||||
return encode;
|
||||
}
|
||||
}
|
||||
catch(Exception ex) {}
|
||||
|
||||
encode = "UTF-8";
|
||||
try
|
||||
{
|
||||
if(str.equals(new String(str.getBytes(), encode)))
|
||||
{
|
||||
return encode;
|
||||
}
|
||||
}
|
||||
catch(Exception ex) {}
|
||||
|
||||
/*
|
||||
*......待完善
|
||||
*/
|
||||
|
||||
return "UTF-8";
|
||||
}
|
||||
|
||||
/**将字符串转换字符编码*/
|
||||
public static String GBKtoUTF8(String str) {
|
||||
if("UTF-8".equals(getEncoding(str))) return str;
|
||||
|
||||
return getUTF8StringFromGBKString(str);
|
||||
|
||||
}
|
||||
|
||||
public static String getUTF8StringFromGBKString(String gbkStr) {
|
||||
try {
|
||||
return new String(getUTF8BytesFromGBKString(gbkStr), "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new InternalError();
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] getUTF8BytesFromGBKString(String gbkStr) {
|
||||
int n = gbkStr.length();
|
||||
byte[] utfBytes = new byte[3 * n];
|
||||
int k = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
int m = gbkStr.charAt(i);
|
||||
if (m < 128 && m >= 0) {
|
||||
utfBytes[k++] = (byte) m;
|
||||
continue;
|
||||
}
|
||||
utfBytes[k++] = (byte) (0xe0 | (m >> 12));
|
||||
utfBytes[k++] = (byte) (0x80 | ((m >> 6) & 0x3f));
|
||||
utfBytes[k++] = (byte) (0x80 | (m & 0x3f));
|
||||
}
|
||||
if (k < utfBytes.length) {
|
||||
byte[] tmp = new byte[k];
|
||||
System.arraycopy(utfBytes, 0, tmp, 0, k);
|
||||
return tmp;
|
||||
}
|
||||
return utfBytes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 带有cookie和header 的post请求
|
||||
* @param url
|
||||
* @param params
|
||||
* @param cookie
|
||||
* @param header
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static String doPost2(String url, Map<String, String> params, CookieStore cookie,Map<String, String> header,String charset) {
|
||||
if(charset==null||charset.trim().length()<1) charset="UTF-8";
|
||||
if (StringUtils.isBlank(url)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<NameValuePair> pairs = null;
|
||||
if (params != null && !params.isEmpty()) {
|
||||
pairs = new ArrayList<NameValuePair>(params.size());
|
||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||
String value = entry.getValue();
|
||||
if (value != null) {
|
||||
pairs.add(new BasicNameValuePair(entry.getKey(), value));
|
||||
}
|
||||
}
|
||||
}
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
|
||||
Set<Entry<String, String>> set = header.entrySet();
|
||||
Iterator<Entry<String, String>> s = set.iterator();
|
||||
while (s.hasNext()) {
|
||||
Map.Entry m = (Map.Entry) s.next();
|
||||
httpPost.addHeader(m.getKey().toString(),m.getValue().toString());
|
||||
}
|
||||
|
||||
CloseableHttpResponse response = null;
|
||||
CloseableHttpClient httpClientc = null;
|
||||
try {
|
||||
if (pairs != null && pairs.size() > 0) {
|
||||
httpPost.setEntity(new UrlEncodedFormEntity(pairs, CHARSET));
|
||||
}
|
||||
|
||||
httpClientc = HttpUtils.createSSLClientCookie(cookie);
|
||||
response = httpClientc.execute(httpPost);
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode != 200) {
|
||||
httpPost.abort();
|
||||
throw new RuntimeException("HttpClient,error status code :" + statusCode);
|
||||
}
|
||||
HttpEntity entity = response.getEntity();
|
||||
String result = null;
|
||||
if (entity != null) {
|
||||
result = EntityUtils.toString(entity, charset);
|
||||
}
|
||||
EntityUtils.consume(entity);
|
||||
if(!"UTF-8".equals(getEncoding(result))) result=GBKtoUTF8(result);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
System.out.println("url错误:::"+e.toString());
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
try {
|
||||
response.close();
|
||||
httpClientc.close();
|
||||
httpPost.reset();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 带有cookie和header 的get请求
|
||||
* @param url
|
||||
* @param params
|
||||
* @param cookie
|
||||
* @param header
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static String doGet2(String url, Map<String, String> params, CookieStore cookie,Map<String, String> header,String charset) {
|
||||
if(charset==null||charset.trim().length()<1) charset="UTF-8";
|
||||
if (StringUtils.isBlank(url)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
HttpGet httpGet = null;
|
||||
CloseableHttpClient httpsClient = null;
|
||||
CloseableHttpResponse response = null;
|
||||
try {
|
||||
if (params != null && !params.isEmpty()) {
|
||||
List<NameValuePair> pairs = new ArrayList<NameValuePair>(params.size());
|
||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||
String value = entry.getValue();
|
||||
if (value != null) {
|
||||
pairs.add(new BasicNameValuePair(entry.getKey(), value));
|
||||
}
|
||||
}
|
||||
url += "?" + EntityUtils.toString(new UrlEncodedFormEntity(pairs, charset));
|
||||
}
|
||||
httpGet = new HttpGet(url);
|
||||
|
||||
Set<Entry<String, String>> set = header.entrySet();
|
||||
Iterator<Entry<String, String>> s = set.iterator();
|
||||
while (s.hasNext()) {
|
||||
Map.Entry m = (Map.Entry) s.next();
|
||||
httpGet.addHeader(m.getKey().toString(),m.getValue().toString());
|
||||
}
|
||||
|
||||
// https 注意这里获取https内容,使用了忽略证书的方式,当然还有其他的方式来获取https内容
|
||||
httpsClient = HttpUtils.createSSLClientCookie(cookie);
|
||||
response = httpsClient.execute(httpGet);
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode != 200) {
|
||||
httpGet.abort();
|
||||
throw new RuntimeException("HttpClient,error status code :" + statusCode);
|
||||
}
|
||||
HttpEntity entity = response.getEntity();
|
||||
String result = null;
|
||||
if (entity != null) {
|
||||
result = EntityUtils.toString(entity, charset);
|
||||
}
|
||||
EntityUtils.consume(entity);
|
||||
response.close();
|
||||
if(!"UTF-8".equals(getEncoding(result))) result=GBKtoUTF8(result);
|
||||
return result;
|
||||
}catch (Exception e) {
|
||||
System.out.println("url错误:::"+e.toString());
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
try {
|
||||
response.close();
|
||||
httpsClient.close();
|
||||
httpGet.reset();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package sc545.pay.utils;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.Authenticator;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.PasswordAuthentication;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Transport;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
public class MailUtils {
|
||||
|
||||
private static final String USER = "scboxs@163.com"; // 发件人称号,同邮箱地址
|
||||
private static final String HOST = "smtp.163.com"; // SMTP服务器地址
|
||||
private static final String PASSWORD = "FUTSRKZXNDRSFXUW"; // 如果是qq邮箱可以使户端授权码,或者登录密码
|
||||
|
||||
public static void main(String[] args) {
|
||||
boolean t = sendMail("1782158860@qq.com", "这是一个测试邮件", "【顺诚百宝箱】测试邮件");
|
||||
System.out.println(t);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param to 收件人邮箱
|
||||
* @param text 邮件正文
|
||||
* @param title 标题
|
||||
*/
|
||||
/* 发送验证信息的邮件 */
|
||||
public static boolean sendMail(String to, String text, String title){
|
||||
try {
|
||||
final Properties props = new Properties();
|
||||
props.put("mail.smtp.auth", "true");
|
||||
props.put("mail.smtp.host", HOST);
|
||||
|
||||
// 发件人的账号
|
||||
props.put("mail.user", USER);
|
||||
//发件人的密码
|
||||
props.put("mail.password", PASSWORD);
|
||||
|
||||
// 构建授权信息,用于进行SMTP进行身份验证
|
||||
Authenticator authenticator = new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
// 用户名、密码
|
||||
String userName = props.getProperty("mail.user");
|
||||
String password = props.getProperty("mail.password");
|
||||
return new PasswordAuthentication(userName, password);
|
||||
}
|
||||
};
|
||||
// 使用环境属性和授权信息,创建邮件会话
|
||||
Session mailSession = Session.getInstance(props, authenticator);
|
||||
// 创建邮件消息
|
||||
MimeMessage message = new MimeMessage(mailSession);
|
||||
// 设置发件人
|
||||
String username = props.getProperty("mail.user");
|
||||
InternetAddress form = new InternetAddress(username);
|
||||
message.setFrom(form);
|
||||
message.setDescription("欢迎关注微信公众号【顺诚百宝箱】\n全网VIP视频、聚合全网小说,音乐等APP,破解软件游戏,大额优惠券福利,更多功能等你发现~");
|
||||
|
||||
// 设置收件人
|
||||
InternetAddress toAddress = new InternetAddress(to);
|
||||
message.setRecipient(Message.RecipientType.TO, toAddress);
|
||||
|
||||
// 设置邮件标题
|
||||
message.setSubject(title);
|
||||
|
||||
// 设置邮件的内容体
|
||||
message.setContent(text, "text/html;charset=UTF-8");
|
||||
// 发送邮件
|
||||
Transport transport = mailSession.getTransport("smtp");
|
||||
//设置授权码
|
||||
transport.connect(username,"授权码");
|
||||
transport.sendMessage(message,message.getAllRecipients());
|
||||
transport.close();
|
||||
return true;
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,710 +0,0 @@
|
||||
package sc545.pay.utils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
public class ReadTxt {
|
||||
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 按行读取txt文件
|
||||
*
|
||||
* @param path
|
||||
* 文件地址(默认D:\\scbox_settings开头)
|
||||
* @return ArrayList 返回每行数据为一个items的集合
|
||||
*/
|
||||
public static ArrayList<String> readFileLine(ServletContext servletContext, String path) {
|
||||
|
||||
if(path.indexOf("./")==0)
|
||||
path =path.substring(1, path.length());
|
||||
|
||||
if (servletContext == null) {
|
||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||
path = "D:\\scbox_settings\\" + path;
|
||||
} else {
|
||||
path = servletContext.getRealPath(path);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ArrayList<String> strarr = null;
|
||||
try {
|
||||
File file = new File(path);
|
||||
if (file.isFile() && file.exists()) { // 判断文件是否存在
|
||||
InputStreamReader read = new InputStreamReader(
|
||||
new FileInputStream(file), "UTF-8");
|
||||
BufferedReader bufferedReader = new BufferedReader(read);
|
||||
String lineTxt = null;
|
||||
strarr = new ArrayList<String>();
|
||||
while ((lineTxt = bufferedReader.readLine()) != null) {
|
||||
|
||||
strarr.add(lineTxt);
|
||||
}
|
||||
|
||||
read.close();
|
||||
} else {
|
||||
strarr = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return strarr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 写入txt文档,已存在就修改,否则写入末尾,自动加换行 (文件格式:key=value,换行分隔)
|
||||
*
|
||||
* @param path
|
||||
* 文件地址(默认D:\\scbox_settings开头)
|
||||
* @param keyname
|
||||
* 要修改的参数名
|
||||
* @param content
|
||||
* 要修改的参数值
|
||||
*/
|
||||
public static void writeSetting(ServletContext servletContext, String path, String keyname, String content) {
|
||||
|
||||
/**************/
|
||||
// 如果存在,则追加内容;如果文件不存在,则创建文件
|
||||
if(path.indexOf("./")==0)
|
||||
path =path.substring(1, path.length());
|
||||
|
||||
if (servletContext == null) {
|
||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||
path = "D:\\scbox_settings\\" + path;
|
||||
} else {
|
||||
path = servletContext.getRealPath(path);
|
||||
}
|
||||
|
||||
try {
|
||||
File file = new File(path);
|
||||
if (file.isFile() && file.exists()) { // 判断文件是否存在
|
||||
InputStreamReader read = new InputStreamReader(
|
||||
new FileInputStream(file), "UTF-8");
|
||||
BufferedReader bufferedReader = new BufferedReader(read);
|
||||
String lineTxt = null;
|
||||
boolean isread = false;// 是否读取到该行并修改
|
||||
// 将内容全部读出来,存为新的数据流
|
||||
// 读到要修改的行进行修改存入,否则原样读取存入
|
||||
StringBuffer buf = new StringBuffer();
|
||||
while ((lineTxt = bufferedReader.readLine()) != null) {
|
||||
if (lineTxt.startsWith(keyname + "=")) {
|
||||
buf.append(keyname + "=" + content + "\r\n");
|
||||
isread = true;
|
||||
} else {
|
||||
buf.append(lineTxt + "\r\n");
|
||||
}
|
||||
}
|
||||
read.close();
|
||||
if (!isread) {// 没有读取到,写入末尾
|
||||
buf.append(keyname + "=" + content + "\r\n");
|
||||
}
|
||||
|
||||
// 把新内容覆盖写入文件
|
||||
PrintWriter out = new PrintWriter(new BufferedWriter(
|
||||
new OutputStreamWriter(new FileOutputStream(path),
|
||||
"UTF-8")));
|
||||
out.write(buf.toString());
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
} else {// 不存在,创建写入
|
||||
String path2 = path.substring(0, path.replace("\\", "/").lastIndexOf("/"));
|
||||
File file1 = new File(path2);
|
||||
// 如果文件夹不存在则创建
|
||||
if (!file1.exists() && !file1.isDirectory()) {
|
||||
file1.mkdirs();
|
||||
}
|
||||
File file2 = new File(path);
|
||||
if (!file2.exists()) {
|
||||
file2.createNewFile();
|
||||
}
|
||||
|
||||
PrintWriter out = new PrintWriter(new BufferedWriter(
|
||||
new OutputStreamWriter(new FileOutputStream(path),
|
||||
"UTF-8")));
|
||||
out.write(keyname + "=" + content + "\r\n");
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
/**************/
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取txt配置,返回map集合(文件格式:key=value,换行分隔)
|
||||
*
|
||||
* @param path
|
||||
* 文件地址(默认D:\\scbox_settings开头)
|
||||
* @return hashmap
|
||||
*/
|
||||
public static HashMap<String, String> readSetting(ServletContext servletContext, String path) {
|
||||
if(path.indexOf("./")==0)
|
||||
path =path.substring(1, path.length());
|
||||
|
||||
if (servletContext == null) {
|
||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||
path = "D:\\scbox_settings\\" + path;
|
||||
} else {
|
||||
path = servletContext.getRealPath(path);
|
||||
}
|
||||
|
||||
HashMap<String, String> strarr = null;
|
||||
try {
|
||||
File file = new File(path);
|
||||
if (file.isFile() && file.exists()) { // 判断文件是否存在
|
||||
InputStreamReader read = new InputStreamReader(
|
||||
new FileInputStream(file), "UTF-8");
|
||||
BufferedReader bufferedReader = new BufferedReader(read);
|
||||
String lineTxt = null;
|
||||
strarr = new HashMap<String, String>();
|
||||
while ((lineTxt = bufferedReader.readLine()) != null) {
|
||||
if(lineTxt.indexOf("#")==0){
|
||||
continue;
|
||||
}
|
||||
String[] arr = new String[2];
|
||||
if (lineTxt.split("=").length >= 2) {
|
||||
arr[0] = lineTxt.split("=")[0];
|
||||
arr[1] = lineTxt.replace(arr[0]+"=", "");
|
||||
strarr.put(arr[0], arr[1]);
|
||||
}
|
||||
}
|
||||
|
||||
read.close();
|
||||
} else {
|
||||
strarr = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return strarr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取配置文件中所有设置属性(含注释)<br>
|
||||
* map.get("z") 取注释<br>
|
||||
* map.get("k") 取key<br>
|
||||
* map.get("v") 取value<br>
|
||||
*
|
||||
*
|
||||
* @param path
|
||||
* 文件地址(默认D:\\scbox_settings开头)
|
||||
*
|
||||
* @param t 只取以此字符开头的,不限制填null
|
||||
* @param st 从以此字符开头的行开始读取,不限制填null
|
||||
* @param et 读到以此字符开头的行结束,不限制填null
|
||||
* @return
|
||||
*/
|
||||
public static ArrayList<HashMap<String, String>> getSettingAll(ServletContext servletContext, String path,String t,String st,String et) {
|
||||
if(st==null||st.length()<1) st="";
|
||||
if(et==null||et.length()<1) et="";
|
||||
if(t==null||t.length()<1) t="";
|
||||
if(path.indexOf("./")==0)
|
||||
path =path.substring(1, path.length());
|
||||
|
||||
if (servletContext == null) {
|
||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||
path = "D:\\scbox_settings\\" + path;
|
||||
} else {
|
||||
path = servletContext.getRealPath(path);
|
||||
}
|
||||
|
||||
ArrayList<HashMap<String, String>> list=new ArrayList<>();
|
||||
try {
|
||||
File file = new File(path);
|
||||
if (file.isFile() && file.exists()) { // 判断文件是否存在
|
||||
InputStreamReader read = new InputStreamReader(
|
||||
new FileInputStream(file), "UTF-8");
|
||||
BufferedReader bufferedReader = new BufferedReader(read);
|
||||
String lineTxt = null;
|
||||
String zs="";//注释文本
|
||||
while ((lineTxt = bufferedReader.readLine()) != null) {
|
||||
if((!"".equals(st))||lineTxt.indexOf(st)!=0) continue;
|
||||
if((!"".equals(et))&&lineTxt.indexOf(et)==0) break;
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
if(lineTxt.indexOf("#")==0){
|
||||
zs=lineTxt;
|
||||
continue;
|
||||
}
|
||||
String[] arr = new String[2];
|
||||
if (lineTxt.split("=").length >= 2&&lineTxt.indexOf(t)==0) {
|
||||
arr[0] = lineTxt.split("=")[0];
|
||||
arr[1] = lineTxt.replace(arr[0]+"=", "");
|
||||
map.put("z", zs);
|
||||
map.put("k", arr[0]);
|
||||
map.put("v", arr[1]);
|
||||
list.add(map);
|
||||
//把注释也加进去
|
||||
zs="";
|
||||
}
|
||||
}
|
||||
|
||||
read.close();
|
||||
} else {
|
||||
list = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取txt配置文件的某一项设置值 (文件格式:key=value,换行分隔)
|
||||
*
|
||||
* @param path
|
||||
* 文件地址
|
||||
* @param settingName
|
||||
* 设置名
|
||||
* @param nullString
|
||||
* 设置值为空时默认返回的内容
|
||||
* @return string
|
||||
*/
|
||||
public static String getSetting(ServletContext servletContext, String path, String settingName,String nullString) {
|
||||
HashMap<String, String> setting = ReadTxt.readSetting(servletContext,path);
|
||||
String val = setting == null ? nullString : setting.get(settingName);
|
||||
val = val == null ? "" : val;
|
||||
return "".equals(val.trim()) ? nullString : val;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有设置名以[settingName]开头的数据
|
||||
* */
|
||||
public static ArrayList<String> getSettingW(ServletContext servletContext, String path, String settingName) {
|
||||
HashMap<String, String> setting = ReadTxt.readSetting(servletContext,path);
|
||||
if(setting==null||setting.size()<1) return null;
|
||||
Iterator<Entry<String, String>> it = setting.entrySet().iterator();
|
||||
ArrayList<String> rs=new ArrayList<>();
|
||||
while (it.hasNext()) {
|
||||
Entry<String, String> en=it.next();
|
||||
String k = en.getKey();
|
||||
String v = en.getValue();
|
||||
if(k.indexOf(settingName)==0){
|
||||
rs.add(k+"="+v);
|
||||
}
|
||||
}
|
||||
|
||||
return rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除某一项设置值 (文件格式:key=value,换行分隔)
|
||||
*
|
||||
* @param path
|
||||
* 文件地址
|
||||
* @param settingName
|
||||
* 设置名
|
||||
* @param nullString
|
||||
* 设置值为空时默认返回的内容
|
||||
* @return string
|
||||
*/
|
||||
public static void delSetting(ServletContext servletContext, String path, String settingName) {
|
||||
|
||||
|
||||
/**************/
|
||||
// 如果存在,则追加内容;如果文件不存在,则创建文件
|
||||
if(path.indexOf("./")==0)
|
||||
path =path.substring(1, path.length());
|
||||
|
||||
if (servletContext == null) {
|
||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||
path = "D:\\scbox_settings\\" + path;
|
||||
} else {
|
||||
path = servletContext.getRealPath(path);
|
||||
}
|
||||
|
||||
try {
|
||||
File file = new File(path);
|
||||
if (file.isFile() && file.exists()) { // 判断文件是否存在
|
||||
InputStreamReader read = new InputStreamReader(
|
||||
new FileInputStream(file), "UTF-8");
|
||||
BufferedReader bufferedReader = new BufferedReader(read);
|
||||
String lineTxt = null;
|
||||
// 将内容全部读出来,存为新的数据流
|
||||
// 读到要修改的行进行修改存入,否则原样读取存入
|
||||
StringBuffer buf = new StringBuffer();
|
||||
while ((lineTxt = bufferedReader.readLine()) != null) {
|
||||
if (lineTxt.startsWith(settingName + "=")) {
|
||||
} else {
|
||||
buf.append(lineTxt + "\r\n");
|
||||
}
|
||||
}
|
||||
read.close();
|
||||
|
||||
// 把新内容覆盖写入文件
|
||||
PrintWriter out = new PrintWriter(new BufferedWriter(
|
||||
new OutputStreamWriter(new FileOutputStream(path),
|
||||
"UTF-8")));
|
||||
out.write(buf.toString());
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
} else {// 不存在,创建
|
||||
String path2 = path.substring(0, path.replace("\\", "/").lastIndexOf("/"));
|
||||
File file1 = new File(path2);
|
||||
// 如果文件夹不存在则创建
|
||||
if (!file1.exists() && !file1.isDirectory()) {
|
||||
file1.mkdirs();
|
||||
}
|
||||
File file2 = new File(path);
|
||||
if (!file2.exists()) {
|
||||
file2.createNewFile();
|
||||
}
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
/**************/
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除设置名以[settingName]开头的数据
|
||||
* @param servletContext
|
||||
* @param path
|
||||
* @param settingName
|
||||
*/
|
||||
public static void delSettingW(ServletContext servletContext, String path, String settingName) {
|
||||
|
||||
|
||||
/**************/
|
||||
// 如果存在,则追加内容;如果文件不存在,则创建文件
|
||||
if(path.indexOf("./")==0)
|
||||
path =path.substring(1, path.length());
|
||||
|
||||
if (servletContext == null) {
|
||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||
path = "D:\\scbox_settings\\" + path;
|
||||
} else {
|
||||
path = servletContext.getRealPath(path);
|
||||
}
|
||||
|
||||
try {
|
||||
File file = new File(path);
|
||||
if (file.isFile() && file.exists()) { // 判断文件是否存在
|
||||
InputStreamReader read = new InputStreamReader(
|
||||
new FileInputStream(file), "UTF-8");
|
||||
BufferedReader bufferedReader = new BufferedReader(read);
|
||||
String lineTxt = null;
|
||||
// 将内容全部读出来,存为新的数据流
|
||||
// 读到要修改的行进行修改存入,否则原样读取存入
|
||||
StringBuffer buf = new StringBuffer();
|
||||
while ((lineTxt = bufferedReader.readLine()) != null) {
|
||||
if (lineTxt.split("=")[0].indexOf(settingName)==0) {
|
||||
} else {
|
||||
buf.append(lineTxt + "\r\n");
|
||||
}
|
||||
}
|
||||
read.close();
|
||||
|
||||
// 把新内容覆盖写入文件
|
||||
PrintWriter out = new PrintWriter(new BufferedWriter(
|
||||
new OutputStreamWriter(new FileOutputStream(path),
|
||||
"UTF-8")));
|
||||
out.write(buf.toString());
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
} else {// 不存在,创建
|
||||
String path2 = path.substring(0, path.replace("\\", "/").lastIndexOf("/"));
|
||||
File file1 = new File(path2);
|
||||
// 如果文件夹不存在则创建
|
||||
if (!file1.exists() && !file1.isDirectory()) {
|
||||
file1.mkdirs();
|
||||
}
|
||||
File file2 = new File(path);
|
||||
if (!file2.exists()) {
|
||||
file2.createNewFile();
|
||||
}
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
/**************/
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除过期的所有设置值 (文件格式:key=value,换行分隔)
|
||||
* <br>key为检测源
|
||||
* @param servletContext
|
||||
* @param path 路径
|
||||
* @param d 有效天数
|
||||
*/
|
||||
public static void delOutDateSetting(ServletContext servletContext, String path, int d) {
|
||||
|
||||
|
||||
/**************/
|
||||
// 如果存在,则追加内容;如果文件不存在,则创建文件
|
||||
if(path.indexOf("./")==0)
|
||||
path =path.substring(1, path.length());
|
||||
|
||||
if (servletContext == null) {
|
||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||
path = "D:\\scbox_settings\\" + path;
|
||||
} else {
|
||||
path = servletContext.getRealPath(path);
|
||||
}
|
||||
|
||||
try {
|
||||
File file = new File(path);
|
||||
if (file.isFile() && file.exists()) { // 判断文件是否存在
|
||||
InputStreamReader read = new InputStreamReader(
|
||||
new FileInputStream(file), "UTF-8");
|
||||
BufferedReader bufferedReader = new BufferedReader(read);
|
||||
String lineTxt = null;
|
||||
// 将内容全部读出来,存为新的数据流
|
||||
// 读到要修改的行进行修改存入,否则原样读取存入
|
||||
StringBuffer buf = new StringBuffer();
|
||||
boolean ts=false;
|
||||
while ((lineTxt = bufferedReader.readLine()) != null) {
|
||||
|
||||
if(lineTxt.indexOf("=")>0&&lineTxt.indexOf("#")<0){
|
||||
String[] ls = lineTxt.split("=");
|
||||
int has = ls[0].length()-ls[0].replaceAll("-", "").length();
|
||||
if(has>1){//日期时间
|
||||
if(Utils.dateout(ls[0], d)){
|
||||
buf.append(lineTxt + "\r\n");
|
||||
}else{
|
||||
ts=true;
|
||||
}//过期
|
||||
}else{//月份时间
|
||||
buf.append(lineTxt + "\r\n");
|
||||
}
|
||||
|
||||
}else{//注释或者不是setting
|
||||
buf.append(lineTxt + "\r\n");
|
||||
}
|
||||
|
||||
}
|
||||
read.close();
|
||||
if(ts){
|
||||
// 把新内容覆盖写入文件
|
||||
PrintWriter out = new PrintWriter(new BufferedWriter(
|
||||
new OutputStreamWriter(new FileOutputStream(path),
|
||||
"UTF-8")));
|
||||
out.write(buf.toString());
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
} else {// 不存在,创建
|
||||
String path2 = path.substring(0, path.replace("\\", "/").lastIndexOf("/"));
|
||||
File file1 = new File(path2);
|
||||
// 如果文件夹不存在则创建
|
||||
if (!file1.exists() && !file1.isDirectory()) {
|
||||
file1.mkdirs();
|
||||
}
|
||||
File file2 = new File(path);
|
||||
if (!file2.exists()) {
|
||||
file2.createNewFile();
|
||||
}
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
/**************/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 删除过期的所有设置值 (文件格式:key=value,换行分隔)
|
||||
* <br>value为检测源
|
||||
* @param servletContext
|
||||
* @param path 路径
|
||||
* @param d 有效天数
|
||||
*/
|
||||
public static void delOutDateSettingValue(ServletContext servletContext, String path, int d) {
|
||||
|
||||
|
||||
/**************/
|
||||
// 如果存在,则追加内容;如果文件不存在,则创建文件
|
||||
if(path.indexOf("./")==0)
|
||||
path =path.substring(1, path.length());
|
||||
|
||||
if (servletContext == null) {
|
||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||
path = "D:\\scbox_settings\\" + path;
|
||||
} else {
|
||||
path = servletContext.getRealPath(path);
|
||||
}
|
||||
|
||||
try {
|
||||
File file = new File(path);
|
||||
if (file.isFile() && file.exists()) { // 判断文件是否存在
|
||||
InputStreamReader read = new InputStreamReader(
|
||||
new FileInputStream(file), "UTF-8");
|
||||
BufferedReader bufferedReader = new BufferedReader(read);
|
||||
String lineTxt = null;
|
||||
// 将内容全部读出来,存为新的数据流
|
||||
// 读到要修改的行进行修改存入,否则原样读取存入
|
||||
StringBuffer buf = new StringBuffer();
|
||||
boolean ts=false;
|
||||
while ((lineTxt = bufferedReader.readLine()) != null) {
|
||||
|
||||
if(lineTxt.indexOf("=")>0&&lineTxt.indexOf("#")<0){
|
||||
String[] ls = lineTxt.split("=");
|
||||
int has = ls[1].length()-ls[1].replaceAll("-", "").length();
|
||||
if(has>1){//日期时间
|
||||
if(Utils.dateout(ls[1], d)){
|
||||
buf.append(lineTxt + "\r\n");
|
||||
}else{
|
||||
ts=true;
|
||||
}//过期
|
||||
}else{//月份时间
|
||||
buf.append(lineTxt + "\r\n");
|
||||
}
|
||||
|
||||
}else{//注释或者不是setting
|
||||
buf.append(lineTxt + "\r\n");
|
||||
}
|
||||
|
||||
}
|
||||
read.close();
|
||||
if(ts){
|
||||
// 把新内容覆盖写入文件
|
||||
PrintWriter out = new PrintWriter(new BufferedWriter(
|
||||
new OutputStreamWriter(new FileOutputStream(path),
|
||||
"UTF-8")));
|
||||
out.write(buf.toString());
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
} else {// 不存在,创建
|
||||
String path2 = path.substring(0, path.replace("\\", "/").lastIndexOf("/"));
|
||||
File file1 = new File(path2);
|
||||
// 如果文件夹不存在则创建
|
||||
if (!file1.exists() && !file1.isDirectory()) {
|
||||
file1.mkdirs();
|
||||
}
|
||||
File file2 = new File(path);
|
||||
if (!file2.exists()) {
|
||||
file2.createNewFile();
|
||||
}
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
/**************/
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除全部内容
|
||||
*
|
||||
* @param path
|
||||
* 文件地址
|
||||
* @param nullString
|
||||
* 设置值为空时默认返回的内容
|
||||
* @return string
|
||||
*/
|
||||
public static void delAll(ServletContext servletContext, String path) {
|
||||
|
||||
|
||||
/**************/
|
||||
// 如果存在,则追加内容;如果文件不存在,则创建文件
|
||||
if(path.indexOf("./")==0)
|
||||
path =path.substring(1, path.length());
|
||||
|
||||
if (servletContext == null) {
|
||||
if(path.indexOf(":") <= 0&&path.indexOf("/") <0)
|
||||
path = "D:\\scbox_settings\\" + path;
|
||||
} else {
|
||||
path = servletContext.getRealPath(path);
|
||||
}
|
||||
|
||||
try {
|
||||
File file = new File(path);
|
||||
if (file.isFile() && file.exists()) { // 判断文件是否存在
|
||||
|
||||
// 把新内容覆盖写入文件
|
||||
PrintWriter out = new PrintWriter(new BufferedWriter(
|
||||
new OutputStreamWriter(new FileOutputStream(path),
|
||||
"UTF-8")));
|
||||
out.write("".toString());
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
} else {// 不存在,创建
|
||||
String path2 = path.substring(0, path.replace("\\", "/").lastIndexOf("/"));
|
||||
File file1 = new File(path2);
|
||||
// 如果文件夹不存在则创建
|
||||
if (!file1.exists() && !file1.isDirectory()) {
|
||||
file1.mkdirs();
|
||||
}
|
||||
File file2 = new File(path);
|
||||
if (!file2.exists()) {
|
||||
file2.createNewFile();
|
||||
}
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
/**************/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 将InputStream装换成某种字符编码的String
|
||||
*
|
||||
* @param in
|
||||
* @param encoding
|
||||
* @return
|
||||
*/
|
||||
public static String InputStreamTOString(InputStream in, String encoding) {
|
||||
int BUFFER_SIZE = 4096;
|
||||
String res = null;
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
byte[] data = new byte[BUFFER_SIZE];
|
||||
int count = -1;
|
||||
try {
|
||||
while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) {
|
||||
outputStream.write(data, 0, count);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
res = new String(outputStream.toByteArray(), encoding);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,40 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/mvc
|
||||
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-4.0.xsd
|
||||
">
|
||||
<context:annotation-config />
|
||||
<!-- 扫描所有的 controller -->
|
||||
<context:component-scan base-package="sc545.pay" />
|
||||
|
||||
<!-- 将静态资源交于默认的servlet处理 -->
|
||||
<mvc:default-servlet-handler />
|
||||
|
||||
<!-- 启动注解驱动 SpringMVC 功能 -->
|
||||
<mvc:annotation-driven />
|
||||
|
||||
|
||||
<bean
|
||||
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
<property name="prefix" value="/" /> <!-- controller 返回的网页地址根目录 -->
|
||||
<!-- <property name="suffix" value=".jsp" /> -->
|
||||
|
||||
</bean>
|
||||
|
||||
<bean id="multipartResolver"
|
||||
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
|
||||
<property name="defaultEncoding" value="utf-8"></property>
|
||||
<property name="maxUploadSize" value="10485760000"></property>
|
||||
<property name="maxInMemorySize" value="40960"></property>
|
||||
</bean>
|
||||
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user