Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Jeepay
Commits
d53783a9
Commit
d53783a9
authored
Aug 12, 2017
by
jmdhappy
Browse files
初始化提交
parent
324ccaaf
Changes
465
Show whitespace changes
Inline
Side-by-side
xxpay4spring-cloud/xxpay-config/src/main/resources/shared/xxpay-service-test.properties
0 → 100644
View file @
d53783a9
# \u652F\u4ED8\u5B9D\u56DE\u8C03\u5730\u5740
ali.notify_url
=
http://api.xxpay.org/notify/aliPayNotifyRes.htm
# \u5FAE\u4FE1\u652F\u4ED8\u56DE\u8C03\u5730\u5740
wx.notify_url
=
http://api.xxpay.org/notify/wxPayNotifyRes.htm
xxpay4spring-cloud/xxpay-config/src/main/resources/shared/xxpay-service.yml
0 → 100755
View file @
d53783a9
server
:
port
:
3000
spring
:
datasource
:
type
:
com.alibaba.druid.pool.DruidDataSource
driver-class-name
:
com.mysql.jdbc.Driver
url
:
jdbc:mysql://139.129.231.219:3306/xxpaydb?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=true
username
:
xxpay
password
:
xxpay3qw13uM
initialSize
:
5
# 初始化大小
minIdle
:
5
# 最小
maxActive
:
20
# 最大
maxWait
:
60000
# 获取连接等待超时的时间
timeBetweenEvictionRunsMillis
:
60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
minEvictableIdleTimeMillis
:
300000
# 配置一个连接在池中最小生存的时间,单位是毫秒
validationQuery
:
SELECT 1 FROM DUAL
testWhileIdle
:
true
testOnBorrow
:
false
testOnReturn
:
false
poolPreparedStatements
:
true
# 打开PSCache
maxPoolPreparedStatementPerConnectionSize
:
20
# 指定每个连接上PSCache的大小
filters
:
stat,wall,log4j
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
connectionProperties
:
druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
activemq
:
broker-url
:
failover:(tcp://101.200.130.72:61616?wireFormat.maxInactivityDuration=0)
in-memory
:
true
pool
:
enabled
:
true
logging
:
file
:
./log/xxpay-service.log
ali
:
notify_url
:
http://xxpay.ngrok.cc/notify/pay/aliPayNotifyRes.htm
xxpay4spring-cloud/xxpay-config/src/main/resources/shared/xxpay-web.yml
0 → 100755
View file @
d53783a9
server
:
port
:
3010
hystrix
:
command
:
default
:
execution
:
isolation
:
thread
:
timeoutInMilliseconds
:
60000
logging
:
file
:
./log/xxpay-web.log
xxpay4spring-cloud/xxpay-gateway/pom.xml
0 → 100644
View file @
d53783a9
<?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"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
org.xxpay
</groupId>
<artifactId>
xxpay-gateway
</artifactId>
<version>
1.0.0
</version>
<packaging>
jar
</packaging>
<name>
xxpay-gateway
</name>
<description>
xxpay4spring-cloud
</description>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
1.3.5.RELEASE
</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>
org.xxpay
</groupId>
<artifactId>
xxpay-common
</artifactId>
<version>
1.0.0
</version>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-zuul
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-config
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-eureka-server
</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-dependencies
</artifactId>
<version>
Brixton.RELEASE
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
<!--<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/package.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>-->
</plugins>
</build>
</project>
\ No newline at end of file
xxpay4spring-cloud/xxpay-gateway/src/main/java/org/xxpay/XxPayGatewayApplication.java
0 → 100644
View file @
d53783a9
package
org.xxpay
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.cloud.client.SpringCloudApplication
;
import
org.springframework.cloud.netflix.zuul.EnableZuulProxy
;
import
org.springframework.context.annotation.Bean
;
import
org.xxpay.gateway.filter.AccessFilter
;
/**
* @Description: xxpay网关服务
* @author dingzhiwei jmdhappy@126.com
* @date 2017-07-05
* @version V1.0
* @Copyright: www.xxpay.org
*/
@EnableZuulProxy
@SpringCloudApplication
public
class
XxPayGatewayApplication
{
public
static
void
main
(
String
[]
args
)
{
new
SpringApplicationBuilder
(
XxPayGatewayApplication
.
class
).
web
(
true
).
run
(
args
);
}
@Bean
public
AccessFilter
accessFilter
()
{
return
new
AccessFilter
();
}
}
xxpay4spring-cloud/xxpay-gateway/src/main/java/org/xxpay/gateway/filter/AccessFilter.java
0 → 100644
View file @
d53783a9
package
org.xxpay.gateway.filter
;
import
com.netflix.zuul.ZuulFilter
;
import
com.netflix.zuul.context.RequestContext
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.xxpay.common.util.MyLog
;
import
javax.servlet.http.HttpServletRequest
;
/**
* @Description: Zuul过滤器
* @author dingzhiwei jmdhappy@126.com
* @date 2017-07-05
* @version V1.0
* @Copyright: www.xxpay.org
*/
public
class
AccessFilter
extends
ZuulFilter
{
private
static
final
MyLog
_log
=
MyLog
.
getLog
(
ZuulFilter
.
class
);
@Override
public
String
filterType
()
{
return
"pre"
;
}
@Override
public
int
filterOrder
()
{
return
0
;
}
@Override
public
boolean
shouldFilter
()
{
return
true
;
}
@Override
public
Object
run
()
{
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
HttpServletRequest
request
=
ctx
.
getRequest
();
_log
.
info
(
String
.
format
(
"%s request to %s"
,
request
.
getMethod
(),
request
.
getRequestURL
().
toString
()));
Object
accessToken
=
request
.
getParameter
(
"accessToken"
);
/*if(accessToken == null) {
log.warn("access token is empty");
ctx.setSendZuulResponse(false);
ctx.setResponseStatusCode(401);
return null;
}*/
return
null
;
}
}
xxpay4spring-cloud/xxpay-gateway/src/main/resources/bootstrap.yml
0 → 100755
View file @
d53783a9
spring
:
application
:
name
:
xxpay-gateway
cloud
:
config
:
discovery
:
enabled
:
true
# 默认false,设为true表示使用注册中心中的configserver配置而不自己配置configserver的uri
serviceId
:
xxpay-config
# 指定config server在服务发现中的serviceId,默认为:configserver
fail-fast
:
true
password
:
xxpay
username
:
user
eureka
:
client
:
serviceUrl
:
defaultZone
:
http://localhost:2000/eureka/
\ No newline at end of file
xxpay4spring-cloud/xxpay-server/pom.xml
0 → 100644
View file @
d53783a9
<?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"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
org.xxpay
</groupId>
<artifactId>
xxpay-server
</artifactId>
<version>
1.0.0
</version>
<packaging>
jar
</packaging>
<name>
xxpay-server
</name>
<description>
xxpay4spring-cloud
</description>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
1.3.5.RELEASE
</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<java.version>
1.8
</java.version>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-eureka-server
</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-dependencies
</artifactId>
<version>
Brixton.RELEASE
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
<!--<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/package.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>-->
</plugins>
</build>
</project>
\ No newline at end of file
xxpay4spring-cloud/xxpay-server/src/main/assembly/package.xml
0 → 100644
View file @
d53783a9
<assembly>
<id>
bin
</id>
<!-- 最终打包成一个用于发布的zip文件 -->
<formats>
<format>
tar.gz
</format>
</formats>
<!-- Adds dependencies to zip package under lib directory -->
<dependencySets>
<dependencySet>
<!-- 不使用项目的artifact,第三方jar不要解压,打包进zip文件的lib目录 -->
<useProjectArtifact>
false
</useProjectArtifact>
<outputDirectory>
lib
</outputDirectory>
<unpack>
false
</unpack>
</dependencySet>
</dependencySets>
<fileSets>
<!-- 把项目相关的说明文件,打包进zip文件的根目录 -->
<fileSet>
<directory>
${project.basedir}
</directory>
<outputDirectory>
/
</outputDirectory>
<includes>
<include>
README*
</include>
<include>
LICENSE*
</include>
<include>
NOTICE*
</include>
</includes>
</fileSet>
<!-- 把项目的配置文件,打包进zip文件的config目录 -->
<!--<fileSet>
<directory>${project.basedir}/src/main/resources</directory>
<outputDirectory>classes</outputDirectory>
<includes>
<include>*.xml</include>
<include>*.properties</include>
</includes>
</fileSet>-->
<!-- 把项目的脚本文件目录( src/main/scripts )中的启动脚本文件,打包进zip文件的跟目录 -->
<fileSet>
<directory>
${project.build.scriptSourceDirectory}
</directory>
<outputDirectory>
bin
</outputDirectory>
<includes>
<include>
*.*
</include>
</includes>
</fileSet>
<!-- 把项目的脚本文件(除了启动脚本文件),打包进zip文件的script目录 -->
<fileSet>
<directory>
${project.build.scriptSourceDirectory}
</directory>
<outputDirectory></outputDirectory>
<includes>
<include>
startup.*
</include>
</includes>
</fileSet>
<!-- 把项目自己编译出来的jar文件,打包进zip文件的根目录 -->
<!--<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>-->
<fileSet>
<directory>
${project.build.outputDirectory}
</directory>
<outputDirectory>
classes
</outputDirectory>
<includes>
<include>
**/*.class
</include>
<include>
**/*.xml
</include>
<include>
**/*.properties
</include>
</includes>
</fileSet>
</fileSets>
</assembly>
\ No newline at end of file
xxpay4spring-cloud/xxpay-server/src/main/java/org/xxpay/server/XxPayServerApplication.java
0 → 100644
View file @
d53783a9
package
org.xxpay.server
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.cloud.netflix.eureka.server.EnableEurekaServer
;
/**
* @Description: xxpay服务注册中心
* @author dingzhiwei jmdhappy@126.com
* @date 2017-07-05
* @version V1.0
* @Copyright: www.xxpay.org
*/
@EnableEurekaServer
@SpringBootApplication
public
class
XxPayServerApplication
{
public
static
void
main
(
String
[]
args
)
{
new
SpringApplicationBuilder
(
XxPayServerApplication
.
class
).
web
(
true
).
run
(
args
);
}
}
xxpay4spring-cloud/xxpay-server/src/main/resources/application.properties
0 → 100644
View file @
d53783a9
server.port
=
2000
eureka.client.register-with-eureka
=
false
eureka.client.fetch-registry
=
false
#\u7981\u7528\u81EA\u6211\u4FDD\u62A4\u6A21\u5F0F
eureka.server.enable-self-preservation
=
false
eureka.client.serviceUrl.defaultZone
=
http://localhost:${server.port}/eureka/
### \u65E5\u5FD7
logging.file
=
./log/xxpay-server.log
\ No newline at end of file
xxpay4spring-cloud/xxpay-server/src/main/scripts/server.sh
0 → 100755
View file @
d53783a9
#!/bin/sh
#
#该脚本为Linux下启动java程序的通用脚本。即可以作为开机自启动service脚本被调用,
#也可以作为启动java程序的独立脚本来使用。
#
#JDK所在路径
JAVA_HOME
=
"/usr/local/jdk/jdk1.8.0_121"
#Java程序所在的目录(classes的上一级目录)
APP_HOME
=
/home/xxpay/service/xxpay-service
#需要启动的Java主程序(main方法类)
APP_MAINCLASS
=
org.xxpay.XxpayServiceApplication
#拼凑完整的classpath参数,包括指定lib目录下所有的jar
CLASSPATH
=
$APP_HOME
/classes
for
i
in
"
$APP_HOME
"
/lib/
*
.jar
;
do
CLASSPATH
=
"
$CLASSPATH
"
:
"
$i
"
done
#java虚拟机启动参数
JAVA_OPTS
=
"-ms1024m -mx1024m -Xmn256m -Djava.awt.headless=true -XX:MaxPermSize=128m"
###################################
#(函数)判断程序是否已启动
#
#说明:
#使用JDK自带的JPS命令及grep命令组合,准确查找pid
#jps 加 l 参数,表示显示java的完整包路径
#使用awk,分割出pid ($1部分),及Java程序名称($2部分)
#当jps命令不可用时,使用: ps -ef | grep $APP_MAINCLASS | grep -v "grep" | awk '{print $2}' 代替
###################################
#初始化psid变量(全局)
psid
=
0
checkpid
()
{
javaps
=
`
$JAVA_HOME
/bin/jps
-l
|
grep
$APP_MAINCLASS
`
#javaps=`ps -ef | grep $APP_MAINCLASS | grep -v "grep" | awk '{print $2}'`
if
[
-n
"
$javaps
"
]
;
then
psid
=
`
echo
$javaps
|
awk
'{print $1}'
`
else
psid
=
0
fi
}
###################################
#(函数)启动程序
#
#说明:
#1. 首先调用checkpid函数,刷新$psid全局变量
#2. 如果程序已经启动($psid不等于0),则提示程序已启动
#3. 如果程序没有被启动,则执行启动命令行
#4. 启动命令执行后,再次调用checkpid函数
#5. 如果步骤4的结果能够确认程序的pid,则打印[OK],否则打印[Failed]
#注意:echo -n 表示打印字符后,不换行
#注意: "nohup 某命令 >/dev/null 2>&1 &" 的用法
###################################
start
()
{
checkpid
if
[
$psid
-ne
0
]
;
then
echo
"================================"
echo
"warn:
$APP_MAINCLASS
already started! (pid=
$psid
)"
echo
"================================"
else
echo
-n
"Starting
$APP_MAINCLASS
..."
# -DlogFn=active 指的是生产日志文件名为active
nohup
$JAVA_HOME
/bin/java
$JAVA_OPTS
-DlogFn
=
level
-classpath
$CLASSPATH
$APP_MAINCLASS
>
/dev/null 2>&1 &
checkpid
if
[
$psid
-ne
0
]
;
then
echo
"(pid=
$psid
) [OK]"
else
echo
"[Failed]"
fi
fi
}
###################################
#(函数)停止程序
#
#说明:
#1. 首先调用checkpid函数,刷新$psid全局变量
#2. 如果程序已经启动($psid不等于0),则开始执行停止,否则,提示程序未运行
#3. 使用kill -9 pid命令进行强制杀死进程
#4. 执行kill命令行紧接其后,马上查看上一句命令的返回值: $?
#5. 如果步骤4的结果$?等于0,则打印[OK],否则打印[Failed]
#6. 为了防止java程序被启动多次,这里增加反复检查进程,反复杀死的处理(递归调用stop)。
#注意:echo -n 表示打印字符后,不换行
#注意: 在shell编程中,"$?" 表示上一句命令或者一个函数的返回值
###################################
stop
()
{
checkpid
if
[
$psid
-ne
0
]
;
then
echo
-n
"Stopping
$APP_MAINCLASS
...(pid=
$psid
) "
kill
-9
$psid
if
[
$?
-eq
0
]
;
then
echo
"[OK]"
else
echo
"[Failed]"
fi
checkpid
if
[
$psid
-ne
0
]
;
then
stop
fi
else
echo
"================================"
echo
"warn:
$APP_MAINCLASS
is not running"
echo
"================================"
fi
}
###################################
#(函数)检查程序运行状态
#
#说明:
#1. 首先调用checkpid函数,刷新$psid全局变量
#2. 如果程序已经启动($psid不等于0),则提示正在运行并表示出pid
#3. 否则,提示程序未运行
###################################
status
()
{
checkpid
if
[
$psid
-ne
0
]
;
then
echo
"
$APP_MAINCLASS
is running! (pid=
$psid
)"
else
echo
"
$APP_MAINCLASS
is not running"
fi
}
###################################
#(函数)打印系统环境参数
###################################
info
()
{
echo
"System Information:"
echo
"****************************"
echo
`
head
-n
1 /etc/issue
`
echo
`
uname
-a
`
echo
echo
"JAVA_HOME=
$JAVA_HOME
"
echo
`
$JAVA_HOME
/bin/java
-version
`
echo
echo
"APP_HOME=
$APP_HOME
"
echo
"APP_MAINCLASS=
$APP_MAINCLASS
"
echo
"****************************"
}
###################################
#读取脚本的第一个参数($1),进行判断
#参数取值范围:{start|stop|restart|status|info}
#如参数不在指定范围之内,则打印帮助信息
###################################
case
"
$1
"
in
'start'
)
start
;;
'stop'
)
stop
;;
'restart'
)
stop
start
;;
'status'
)
status
;;
'info'
)
info
;;
*
)
echo
"Usage:
$0
{start|stop|restart|status|info}"
exit
1
esac
exit
0
\ No newline at end of file
xxpay4spring-cloud/xxpay-service/pom.xml
0 → 100644
View file @
d53783a9
<?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"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
org.xxpay
</groupId>
<artifactId>
xxpay-service
</artifactId>
<version>
1.0.0
</version>
<packaging>
jar
</packaging>
<name>
xxpay-service
</name>
<description>
xxpay4spring-cloud
</description>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
1.3.5.RELEASE
</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<java.version>
1.8
</java.version>
</properties>
<dependencies>
<dependency>
<groupId>
org.xxpay
</groupId>
<artifactId>
xxpay-dal
</artifactId>
<version>
1.0.0
</version>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-eureka
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-config
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.mybatis.spring.boot
</groupId>
<artifactId>
mybatis-spring-boot-starter
</artifactId>
<version>
1.1.1
</version>
</dependency>
<!--微信支付依赖-->
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpcore
</artifactId>
<version>
4.3.2
</version>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<version>
4.3.5
</version>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient-cache
</artifactId>
<version>
4.3.5
</version>
</dependency>
<dependency>
<groupId>
com.thoughtworks.xstream
</groupId>
<artifactId>
xstream
</artifactId>
<version>
1.4.7
</version>
</dependency>
<!--alipay依赖-->
<dependency>
<groupId>
commons-httpclient
</groupId>
<artifactId>
commons-httpclient
</artifactId>
<version>
3.0.1
</version>
</dependency>
<dependency>
<groupId>
jaxen
</groupId>
<artifactId>
jaxen
</artifactId>
<version>
1.1.6
</version>
</dependency>
<!--activeMq-->
<!--<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
<version>5.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
<version>5.7.0</version>
</dependency>-->
<!-- SpringBoot ActiveMQ依赖 -->
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-jms
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.activemq
</groupId>
<artifactId>
activemq-client
</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-dependencies
</artifactId>
<version>
Brixton.RELEASE
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<finalName>
xxpay-service
</finalName>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
<!--<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/package.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>-->
</plugins>
</build>
</project>
\ No newline at end of file
xxpay4spring-cloud/xxpay-service/src/main/assembly/package.xml
0 → 100644
View file @
d53783a9
<assembly>
<id>
bin
</id>
<!-- 最终打包成一个用于发布的zip文件 -->
<formats>
<format>
tar.gz
</format>
</formats>
<!-- Adds dependencies to zip package under lib directory -->
<dependencySets>
<dependencySet>
<!-- 不使用项目的artifact,第三方jar不要解压,打包进zip文件的lib目录 -->
<useProjectArtifact>
false
</useProjectArtifact>
<outputDirectory>
lib
</outputDirectory>
<unpack>
false
</unpack>
</dependencySet>
</dependencySets>
<fileSets>
<!-- 把项目相关的说明文件,打包进zip文件的根目录 -->
<fileSet>
<directory>
${project.basedir}
</directory>
<outputDirectory>
/
</outputDirectory>
<includes>
<include>
README*
</include>
<include>
LICENSE*
</include>
<include>
NOTICE*
</include>
</includes>
</fileSet>
<!-- 把项目的配置文件,打包进zip文件的config目录 -->
<!--<fileSet>
<directory>${project.basedir}/src/main/resources</directory>
<outputDirectory>classes</outputDirectory>
<includes>
<include>*.xml</include>
<include>*.properties</include>
</includes>
</fileSet>-->
<!-- 把项目的脚本文件目录( src/main/scripts )中的启动脚本文件,打包进zip文件的跟目录 -->
<fileSet>
<directory>
${project.build.scriptSourceDirectory}
</directory>
<outputDirectory>
bin
</outputDirectory>
<includes>
<include>
*.*
</include>
</includes>
</fileSet>
<!-- 把项目的脚本文件(除了启动脚本文件),打包进zip文件的script目录 -->
<fileSet>
<directory>
${project.build.scriptSourceDirectory}
</directory>
<outputDirectory></outputDirectory>
<includes>
<include>
startup.*
</include>
</includes>
</fileSet>
<!-- 把项目自己编译出来的jar文件,打包进zip文件的根目录 -->
<!--<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>-->
<fileSet>
<directory>
${project.build.outputDirectory}
</directory>
<outputDirectory>
classes
</outputDirectory>
<includes>
<include>
**/*.class
</include>
<include>
**/*.xml
</include>
<include>
**/*.properties
</include>
</includes>
</fileSet>
</fileSets>
</assembly>
\ No newline at end of file
xxpay4spring-cloud/xxpay-service/src/main/java/org/xxpay/XxPayServiceApplication.java
0 → 100644
View file @
d53783a9
package
org.xxpay
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.context.annotation.Configuration
;
/**
* @Description: xxpay支付核心服务,包括:各支付渠道接口,通知处理
* @author dingzhiwei jmdhappy@126.com
* @date 2017-07-05
* @version V1.0
* @Copyright: www.xxpay.org
*/
@EnableDiscoveryClient
@SpringBootApplication
public
class
XxPayServiceApplication
{
public
static
void
main
(
String
[]
args
)
{
new
SpringApplicationBuilder
(
XxPayServiceApplication
.
class
).
web
(
true
).
run
(
args
);
}
}
xxpay4spring-cloud/xxpay-service/src/main/java/org/xxpay/service/channel/alipay/config/AlipayConfig.java
0 → 100644
View file @
d53783a9
package
org.xxpay.service.channel.alipay.config
;
/* *
*类名:AlipayConfig
*功能:基础配置类
*详细:设置帐户有关信息及返回路径
*版本:3.3
*日期:2012-08-10
*说明:
*以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
*该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
*提示:如何获取安全校验码和合作身份者ID
*1.用您的签约支付宝账号登录支付宝网站(www.alipay.com)
*2.点击“商家服务”(https://b.alipay.com/order/myOrder.htm)
*3.点击“查询合作者身份(PID)”、“查询安全校验码(Key)”
*安全校验码查看时,输入支付密码后,页面呈灰色的现象,怎么办?
*解决方法:
*1、检查浏览器配置,不让浏览器做弹框屏蔽设置
*2、更换浏览器或电脑,重新登录查询。
*/
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.Assert
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.xxpay.common.constant.PayConstant
;
import
org.xxpay.common.util.MyLog
;
import
org.xxpay.common.util.PropertiesFileUtil
;
import
java.util.Date
;
import
java.util.Map
;
@RefreshScope
@Service
public
class
AlipayConfig
{
private
static
final
MyLog
_log
=
MyLog
.
getLog
(
AlipayConfig
.
class
);
public
AlipayConfig
init
(
String
configParam
)
{
Assert
.
notNull
(
configParam
,
"init alipay config error"
);
JSONObject
paramObj
=
JSON
.
parseObject
(
configParam
);
this
.
setAppId
(
paramObj
.
getString
(
"appid"
));
this
.
setPartner
(
paramObj
.
getString
(
"partner"
));
this
.
setAli_account
(
paramObj
.
getString
(
"ali_account"
));
this
.
setPrivate_key
(
paramObj
.
getString
(
"private_key"
));
return
this
;
}
//↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
// 合作身份者ID,以2088开头由16位纯数字组成的字符串
public
String
partner
=
""
;
// 商户的私钥
public
String
private_key
=
""
;
// 支付宝的公钥,无需修改该值
public
static
String
ali_public_key
=
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRAFljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQEB/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5KsiNG9zpgmLCUYuLkxpLQIDAQAB"
;
//↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
// 支付宝账号
public
String
ali_account
=
""
;
// 字符编码格式 目前支持 gbk 或 utf-8
public
static
String
input_charset
=
"utf-8"
;
// 签名方式 不需修改
public
static
String
sign_type
=
"RSA"
;
// 提供给支付宝的通知地址
@Value
(
"${ali.notify_url}"
)
private
String
notify_url
;
// 是否验证支付宝的通知地址
private
boolean
is_verify_notify_url
=
true
;
// 支付宝即时到帐网关
private
String
gateway
=
"https://mapi.alipay.com/gateway.do"
;
// 支付宝新网关(查询等)
private
String
openapiGateway
=
"https://openapi.alipay.com/gateway.do"
;
// appid
public
String
appId
=
""
;
// 配置加载时间
private
Long
loadTime
=
new
Date
().
getTime
();
public
String
getAppId
()
{
return
appId
;
}
public
void
setAppId
(
String
appId
)
{
this
.
appId
=
appId
;
}
public
String
getPartner
()
{
return
partner
;
}
public
void
setPartner
(
String
partner
)
{
this
.
partner
=
partner
;
}
public
String
getPrivate_key
()
{
return
private_key
;
}
public
void
setPrivate_key
(
String
private_key
)
{
this
.
private_key
=
private_key
;
}
public
String
getAli_account
()
{
return
ali_account
;
}
public
void
setAli_account
(
String
ali_account
)
{
this
.
ali_account
=
ali_account
;
}
public
String
getNotify_url
()
{
return
notify_url
;
}
public
void
setNotify_url
(
String
notify_url
)
{
this
.
notify_url
=
notify_url
;
}
public
boolean
is_verify_notify_url
()
{
return
is_verify_notify_url
;
}
public
void
setIs_verify_notify_url
(
boolean
is_verify_notify_url
)
{
this
.
is_verify_notify_url
=
is_verify_notify_url
;
}
public
String
getGateway
()
{
return
gateway
;
}
public
void
setGateway
(
String
gateway
)
{
this
.
gateway
=
gateway
;
}
public
String
getOpenapiGateway
()
{
return
openapiGateway
;
}
public
void
setOpenapiGateway
(
String
openapiGateway
)
{
this
.
openapiGateway
=
openapiGateway
;
}
public
Long
getLoadTime
()
{
return
loadTime
;
}
public
void
setLoadTime
(
Long
loadTime
)
{
this
.
loadTime
=
loadTime
;
}
@Override
public
String
toString
()
{
return
"AlipayConfig{"
+
"partner='"
+
partner
+
'\''
+
", private_key='"
+
private_key
+
'\''
+
", ali_account='"
+
ali_account
+
'\''
+
", notify_url='"
+
notify_url
+
'\''
+
", is_verify_notify_url='"
+
is_verify_notify_url
+
'\''
+
", gateway='"
+
gateway
+
'\''
+
", openapiGateway='"
+
openapiGateway
+
'\''
+
", appId='"
+
appId
+
'\''
+
", loadTime="
+
loadTime
+
'}'
;
}
}
\ No newline at end of file
xxpay4spring-cloud/xxpay-service/src/main/java/org/xxpay/service/channel/alipay/sign/Base64.java
0 → 100755
View file @
d53783a9
/*
* Copyright (C) 2010 The MobileSecurePay Project
* All right reserved.
* author: shiqun.shi@alipay.com
*/
package
org.xxpay.service.channel.alipay.sign
;
public
final
class
Base64
{
static
private
final
int
BASELENGTH
=
128
;
static
private
final
int
LOOKUPLENGTH
=
64
;
static
private
final
int
TWENTYFOURBITGROUP
=
24
;
static
private
final
int
EIGHTBIT
=
8
;
static
private
final
int
SIXTEENBIT
=
16
;
static
private
final
int
FOURBYTE
=
4
;
static
private
final
int
SIGN
=
-
128
;
static
private
final
char
PAD
=
'='
;
static
private
final
boolean
fDebug
=
false
;
static
final
private
byte
[]
base64Alphabet
=
new
byte
[
BASELENGTH
];
static
final
private
char
[]
lookUpBase64Alphabet
=
new
char
[
LOOKUPLENGTH
];
static
{
for
(
int
i
=
0
;
i
<
BASELENGTH
;
++
i
)
{
base64Alphabet
[
i
]
=
-
1
;
}
for
(
int
i
=
'Z'
;
i
>=
'A'
;
i
--)
{
base64Alphabet
[
i
]
=
(
byte
)
(
i
-
'A'
);
}
for
(
int
i
=
'z'
;
i
>=
'a'
;
i
--)
{
base64Alphabet
[
i
]
=
(
byte
)
(
i
-
'a'
+
26
);
}
for
(
int
i
=
'9'
;
i
>=
'0'
;
i
--)
{
base64Alphabet
[
i
]
=
(
byte
)
(
i
-
'0'
+
52
);
}
base64Alphabet
[
'+'
]
=
62
;
base64Alphabet
[
'/'
]
=
63
;
for
(
int
i
=
0
;
i
<=
25
;
i
++)
{
lookUpBase64Alphabet
[
i
]
=
(
char
)
(
'A'
+
i
);
}
for
(
int
i
=
26
,
j
=
0
;
i
<=
51
;
i
++,
j
++)
{
lookUpBase64Alphabet
[
i
]
=
(
char
)
(
'a'
+
j
);
}
for
(
int
i
=
52
,
j
=
0
;
i
<=
61
;
i
++,
j
++)
{
lookUpBase64Alphabet
[
i
]
=
(
char
)
(
'0'
+
j
);
}
lookUpBase64Alphabet
[
62
]
=
(
char
)
'+'
;
lookUpBase64Alphabet
[
63
]
=
(
char
)
'/'
;
}
private
static
boolean
isWhiteSpace
(
char
octect
)
{
return
(
octect
==
0x20
||
octect
==
0xd
||
octect
==
0xa
||
octect
==
0x9
);
}
private
static
boolean
isPad
(
char
octect
)
{
return
(
octect
==
PAD
);
}
private
static
boolean
isData
(
char
octect
)
{
return
(
octect
<
BASELENGTH
&&
base64Alphabet
[
octect
]
!=
-
1
);
}
/**
* Encodes hex octects into Base64
*
* @param binaryData Array containing binaryData
* @return Encoded Base64 array
*/
public
static
String
encode
(
byte
[]
binaryData
)
{
if
(
binaryData
==
null
)
{
return
null
;
}
int
lengthDataBits
=
binaryData
.
length
*
EIGHTBIT
;
if
(
lengthDataBits
==
0
)
{
return
""
;
}
int
fewerThan24bits
=
lengthDataBits
%
TWENTYFOURBITGROUP
;
int
numberTriplets
=
lengthDataBits
/
TWENTYFOURBITGROUP
;
int
numberQuartet
=
fewerThan24bits
!=
0
?
numberTriplets
+
1
:
numberTriplets
;
char
encodedData
[]
=
null
;
encodedData
=
new
char
[
numberQuartet
*
4
];
byte
k
=
0
,
l
=
0
,
b1
=
0
,
b2
=
0
,
b3
=
0
;
int
encodedIndex
=
0
;
int
dataIndex
=
0
;
if
(
fDebug
)
{
System
.
out
.
println
(
"number of triplets = "
+
numberTriplets
);
}
for
(
int
i
=
0
;
i
<
numberTriplets
;
i
++)
{
b1
=
binaryData
[
dataIndex
++];
b2
=
binaryData
[
dataIndex
++];
b3
=
binaryData
[
dataIndex
++];
if
(
fDebug
)
{
System
.
out
.
println
(
"b1= "
+
b1
+
", b2= "
+
b2
+
", b3= "
+
b3
);
}
l
=
(
byte
)
(
b2
&
0x0f
);
k
=
(
byte
)
(
b1
&
0x03
);
byte
val1
=
((
b1
&
SIGN
)
==
0
)
?
(
byte
)
(
b1
>>
2
)
:
(
byte
)
((
b1
)
>>
2
^
0xc0
);
byte
val2
=
((
b2
&
SIGN
)
==
0
)
?
(
byte
)
(
b2
>>
4
)
:
(
byte
)
((
b2
)
>>
4
^
0xf0
);
byte
val3
=
((
b3
&
SIGN
)
==
0
)
?
(
byte
)
(
b3
>>
6
)
:
(
byte
)
((
b3
)
>>
6
^
0xfc
);
if
(
fDebug
)
{
System
.
out
.
println
(
"val2 = "
+
val2
);
System
.
out
.
println
(
"k4 = "
+
(
k
<<
4
));
System
.
out
.
println
(
"vak = "
+
(
val2
|
(
k
<<
4
)));
}
encodedData
[
encodedIndex
++]
=
lookUpBase64Alphabet
[
val1
];
encodedData
[
encodedIndex
++]
=
lookUpBase64Alphabet
[
val2
|
(
k
<<
4
)];
encodedData
[
encodedIndex
++]
=
lookUpBase64Alphabet
[(
l
<<
2
)
|
val3
];
encodedData
[
encodedIndex
++]
=
lookUpBase64Alphabet
[
b3
&
0x3f
];
}
// form integral number of 6-bit groups
if
(
fewerThan24bits
==
EIGHTBIT
)
{
b1
=
binaryData
[
dataIndex
];
k
=
(
byte
)
(
b1
&
0x03
);
if
(
fDebug
)
{
System
.
out
.
println
(
"b1="
+
b1
);
System
.
out
.
println
(
"b1<<2 = "
+
(
b1
>>
2
));
}
byte
val1
=
((
b1
&
SIGN
)
==
0
)
?
(
byte
)
(
b1
>>
2
)
:
(
byte
)
((
b1
)
>>
2
^
0xc0
);
encodedData
[
encodedIndex
++]
=
lookUpBase64Alphabet
[
val1
];
encodedData
[
encodedIndex
++]
=
lookUpBase64Alphabet
[
k
<<
4
];
encodedData
[
encodedIndex
++]
=
PAD
;
encodedData
[
encodedIndex
++]
=
PAD
;
}
else
if
(
fewerThan24bits
==
SIXTEENBIT
)
{
b1
=
binaryData
[
dataIndex
];
b2
=
binaryData
[
dataIndex
+
1
];
l
=
(
byte
)
(
b2
&
0x0f
);
k
=
(
byte
)
(
b1
&
0x03
);
byte
val1
=
((
b1
&
SIGN
)
==
0
)
?
(
byte
)
(
b1
>>
2
)
:
(
byte
)
((
b1
)
>>
2
^
0xc0
);
byte
val2
=
((
b2
&
SIGN
)
==
0
)
?
(
byte
)
(
b2
>>
4
)
:
(
byte
)
((
b2
)
>>
4
^
0xf0
);
encodedData
[
encodedIndex
++]
=
lookUpBase64Alphabet
[
val1
];
encodedData
[
encodedIndex
++]
=
lookUpBase64Alphabet
[
val2
|
(
k
<<
4
)];
encodedData
[
encodedIndex
++]
=
lookUpBase64Alphabet
[
l
<<
2
];
encodedData
[
encodedIndex
++]
=
PAD
;
}
return
new
String
(
encodedData
);
}
/**
* Decodes Base64 data into octects
*
* @param encoded string containing Base64 data
* @return Array containind decoded data.
*/
public
static
byte
[]
decode
(
String
encoded
)
{
if
(
encoded
==
null
)
{
return
null
;
}
char
[]
base64Data
=
encoded
.
toCharArray
();
// remove white spaces
int
len
=
removeWhiteSpace
(
base64Data
);
if
(
len
%
FOURBYTE
!=
0
)
{
return
null
;
//should be divisible by four
}
int
numberQuadruple
=
(
len
/
FOURBYTE
);
if
(
numberQuadruple
==
0
)
{
return
new
byte
[
0
];
}
byte
decodedData
[]
=
null
;
byte
b1
=
0
,
b2
=
0
,
b3
=
0
,
b4
=
0
;
char
d1
=
0
,
d2
=
0
,
d3
=
0
,
d4
=
0
;
int
i
=
0
;
int
encodedIndex
=
0
;
int
dataIndex
=
0
;
decodedData
=
new
byte
[(
numberQuadruple
)
*
3
];
for
(;
i
<
numberQuadruple
-
1
;
i
++)
{
if
(!
isData
((
d1
=
base64Data
[
dataIndex
++]))
||
!
isData
((
d2
=
base64Data
[
dataIndex
++]))
||
!
isData
((
d3
=
base64Data
[
dataIndex
++]))
||
!
isData
((
d4
=
base64Data
[
dataIndex
++])))
{
return
null
;
}
//if found "no data" just return null
b1
=
base64Alphabet
[
d1
];
b2
=
base64Alphabet
[
d2
];
b3
=
base64Alphabet
[
d3
];
b4
=
base64Alphabet
[
d4
];
decodedData
[
encodedIndex
++]
=
(
byte
)
(
b1
<<
2
|
b2
>>
4
);
decodedData
[
encodedIndex
++]
=
(
byte
)
(((
b2
&
0xf
)
<<
4
)
|
((
b3
>>
2
)
&
0xf
));
decodedData
[
encodedIndex
++]
=
(
byte
)
(
b3
<<
6
|
b4
);
}
if
(!
isData
((
d1
=
base64Data
[
dataIndex
++]))
||
!
isData
((
d2
=
base64Data
[
dataIndex
++])))
{
return
null
;
//if found "no data" just return null
}
b1
=
base64Alphabet
[
d1
];
b2
=
base64Alphabet
[
d2
];
d3
=
base64Data
[
dataIndex
++];
d4
=
base64Data
[
dataIndex
++];
if
(!
isData
((
d3
))
||
!
isData
((
d4
)))
{
//Check if they are PAD characters
if
(
isPad
(
d3
)
&&
isPad
(
d4
))
{
if
((
b2
&
0xf
)
!=
0
)
//last 4 bits should be zero
{
return
null
;
}
byte
[]
tmp
=
new
byte
[
i
*
3
+
1
];
System
.
arraycopy
(
decodedData
,
0
,
tmp
,
0
,
i
*
3
);
tmp
[
encodedIndex
]
=
(
byte
)
(
b1
<<
2
|
b2
>>
4
);
return
tmp
;
}
else
if
(!
isPad
(
d3
)
&&
isPad
(
d4
))
{
b3
=
base64Alphabet
[
d3
];
if
((
b3
&
0x3
)
!=
0
)
//last 2 bits should be zero
{
return
null
;
}
byte
[]
tmp
=
new
byte
[
i
*
3
+
2
];
System
.
arraycopy
(
decodedData
,
0
,
tmp
,
0
,
i
*
3
);
tmp
[
encodedIndex
++]
=
(
byte
)
(
b1
<<
2
|
b2
>>
4
);
tmp
[
encodedIndex
]
=
(
byte
)
(((
b2
&
0xf
)
<<
4
)
|
((
b3
>>
2
)
&
0xf
));
return
tmp
;
}
else
{
return
null
;
}
}
else
{
//No PAD e.g 3cQl
b3
=
base64Alphabet
[
d3
];
b4
=
base64Alphabet
[
d4
];
decodedData
[
encodedIndex
++]
=
(
byte
)
(
b1
<<
2
|
b2
>>
4
);
decodedData
[
encodedIndex
++]
=
(
byte
)
(((
b2
&
0xf
)
<<
4
)
|
((
b3
>>
2
)
&
0xf
));
decodedData
[
encodedIndex
++]
=
(
byte
)
(
b3
<<
6
|
b4
);
}
return
decodedData
;
}
/**
* remove WhiteSpace from MIME containing encoded Base64 data.
*
* @param data the byte array of base64 data (with WS)
* @return the new length
*/
private
static
int
removeWhiteSpace
(
char
[]
data
)
{
if
(
data
==
null
)
{
return
0
;
}
// count characters that's not whitespace
int
newSize
=
0
;
int
len
=
data
.
length
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
if
(!
isWhiteSpace
(
data
[
i
]))
{
data
[
newSize
++]
=
data
[
i
];
}
}
return
newSize
;
}
}
xxpay4spring-cloud/xxpay-service/src/main/java/org/xxpay/service/channel/alipay/sign/RSA.java
0 → 100755
View file @
d53783a9
package
org.xxpay.service.channel.alipay.sign
;
import
javax.crypto.Cipher
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.InputStream
;
import
java.security.KeyFactory
;
import
java.security.PrivateKey
;
import
java.security.PublicKey
;
import
java.security.spec.PKCS8EncodedKeySpec
;
import
java.security.spec.X509EncodedKeySpec
;
public
class
RSA
{
public
static
final
String
SIGN_ALGORITHMS
=
"SHA1WithRSA"
;
/**
* RSA签名
* @param content 待签名数据
* @param privateKey 商户私钥
* @param input_charset 编码格式
* @return 签名值
*/
public
static
String
sign
(
String
content
,
String
privateKey
,
String
input_charset
)
{
try
{
PKCS8EncodedKeySpec
priPKCS8
=
new
PKCS8EncodedKeySpec
(
Base64
.
decode
(
privateKey
)
);
KeyFactory
keyf
=
KeyFactory
.
getInstance
(
"RSA"
);
PrivateKey
priKey
=
keyf
.
generatePrivate
(
priPKCS8
);
java
.
security
.
Signature
signature
=
java
.
security
.
Signature
.
getInstance
(
SIGN_ALGORITHMS
);
signature
.
initSign
(
priKey
);
signature
.
update
(
content
.
getBytes
(
input_charset
)
);
byte
[]
signed
=
signature
.
sign
();
return
Base64
.
encode
(
signed
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
/**
* RSA验签名检查
* @param content 待签名数据
* @param sign 签名值
* @param ali_public_key 支付宝公钥
* @param input_charset 编码格式
* @return 布尔值
*/
public
static
boolean
verify
(
String
content
,
String
sign
,
String
ali_public_key
,
String
input_charset
)
{
try
{
KeyFactory
keyFactory
=
KeyFactory
.
getInstance
(
"RSA"
);
byte
[]
encodedKey
=
Base64
.
decode
(
ali_public_key
);
PublicKey
pubKey
=
keyFactory
.
generatePublic
(
new
X509EncodedKeySpec
(
encodedKey
));
java
.
security
.
Signature
signature
=
java
.
security
.
Signature
.
getInstance
(
SIGN_ALGORITHMS
);
signature
.
initVerify
(
pubKey
);
signature
.
update
(
content
.
getBytes
(
input_charset
)
);
boolean
bverify
=
signature
.
verify
(
Base64
.
decode
(
sign
)
);
return
bverify
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
false
;
}
/**
* 解密
* @param content 密文
* @param private_key 商户私钥
* @param input_charset 编码格式
* @return 解密后的字符串
*/
public
static
String
decrypt
(
String
content
,
String
private_key
,
String
input_charset
)
throws
Exception
{
PrivateKey
prikey
=
getPrivateKey
(
private_key
);
Cipher
cipher
=
Cipher
.
getInstance
(
"RSA"
);
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
prikey
);
InputStream
ins
=
new
ByteArrayInputStream
(
Base64
.
decode
(
content
));
ByteArrayOutputStream
writer
=
new
ByteArrayOutputStream
();
//rsa解密的字节大小最多是128,将需要解密的内容,按128位拆开解密
byte
[]
buf
=
new
byte
[
128
];
int
bufl
;
while
((
bufl
=
ins
.
read
(
buf
))
!=
-
1
)
{
byte
[]
block
=
null
;
if
(
buf
.
length
==
bufl
)
{
block
=
buf
;
}
else
{
block
=
new
byte
[
bufl
];
for
(
int
i
=
0
;
i
<
bufl
;
i
++)
{
block
[
i
]
=
buf
[
i
];
}
}
writer
.
write
(
cipher
.
doFinal
(
block
));
}
return
new
String
(
writer
.
toByteArray
(),
input_charset
);
}
/**
* 得到私钥
* @param key 密钥字符串(经过base64编码)
* @throws Exception
*/
public
static
PrivateKey
getPrivateKey
(
String
key
)
throws
Exception
{
byte
[]
keyBytes
;
keyBytes
=
Base64
.
decode
(
key
);
PKCS8EncodedKeySpec
keySpec
=
new
PKCS8EncodedKeySpec
(
keyBytes
);
KeyFactory
keyFactory
=
KeyFactory
.
getInstance
(
"RSA"
);
PrivateKey
privateKey
=
keyFactory
.
generatePrivate
(
keySpec
);
return
privateKey
;
}
/*public static void main(String[] args) {
System.out.println(RSA.sign(
"_input_charset=utf-8&app_pay=Y&body=VV直播下单测试&it_b_pay=60m¬ify_url=${pay.url}/notify/aliPayNotifyRes.htm&out_trade_no=1494684553763&partner=2088521108562983&payment_type=1&seller_id=2088521108562983&service=alipay.wap.create.direct.pay.by.user&show_url=http://www.xxpay.org&subject=null&total_fee=0.01",
"MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAKOuhY6LYZBMiRrvRw2s71CjPW7OPCvapjZdJJNPt5x471E3kDCb9A7kQTyqFIIVcUNKDlKRNztKBhhlxAiI7d95UkN5pAMK+XUItjyA9nj9cqK/ajHjwC4AlIRUZhlsPvj6lt1Oj1Kf1sNDJMM/NZL9IR8EXr7HlIsCjJNVHFPvAgMBAAECgYBY1S7G3f5lQiRm6dW2JlT7fpyotmURp+jtOD/Rc0JDOZ8ohO9McldSfa6qLeRTdS+zRU3goc9H7jTAqPprZ2UxNTUwJ4uMh+2bCtXkvUPwoWF4fb095xGtEUdbKMFkv+yKpCQASrjDhqzVq5xD/uc796wd7HOHwr8xPNOrKKSGAQJBANfgcaiIyFeo8KK4vIUWtqSiqLgG6gp7ABx2WpMWX3wsjbiCBQGVbJbnFcCkB+bofCuKYj7BGLjEEqc3c6y+Ph8CQQDCGprovroKw09dOzqFFPpkMrZvkOpO2e+RhDhhLYq2e5lRLVePtB/ZX2iy2yKQEp/7VWbNFzobqYR6KPXEH5AxAkBx3oD1XhkXLBSqMHm4Ve/HTcljMLp5BsJbQQ6rsUxyimnC3kpXuILL4l61+4/ze8Qrj1YdNeudYkdYjsZkYwEPAkBoWedIEylvmdqz86CdZU7LyVu9FPpyk8WwxJWO4O3+9unQ84BseFjbAukFprupGuo5M4uF3OPXdUYMarLd0l4xAkAMjec0KXp15a93I5y/vfIEAMQ+CQj/LwOxyAM6tTSPVGJHu70pXFQVWtwY+ycMuzbxTdSLuQYxITstHnV3mu76", "utf-8"));
}*/
}
xxpay4spring-cloud/xxpay-service/src/main/java/org/xxpay/service/channel/alipay/util/AlipayCore.java
0 → 100755
View file @
d53783a9
package
org.xxpay.service.channel.alipay.util
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.apache.commons.httpclient.methods.multipart.FilePartSource
;
import
org.apache.commons.httpclient.methods.multipart.PartSource
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.*
;
/* *
*类名:AlipayFunction
*功能:支付宝接口公用函数类
*详细:该类是请求、通知返回两个文件所调用的公用函数核心处理文件,不需要修改
*版本:3.3
*日期:2012-08-14
*说明:
*以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
*该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
*/
public
class
AlipayCore
{
/**
* 除去数组中的空值和签名参数
* @param sArray 签名参数组
* @return 去掉空值与签名参数后的新签名参数组
*/
public
static
Map
<
String
,
String
>
paraFilter
(
Map
<
String
,
String
>
sArray
)
{
Map
<
String
,
String
>
result
=
new
HashMap
<
String
,
String
>();
if
(
sArray
==
null
||
sArray
.
size
()
<=
0
)
{
return
result
;
}
for
(
String
key
:
sArray
.
keySet
())
{
String
value
=
sArray
.
get
(
key
);
if
(
value
==
null
||
value
.
equals
(
""
)
||
key
.
equalsIgnoreCase
(
"sign"
)
||
key
.
equalsIgnoreCase
(
"sign_type"
))
{
continue
;
}
result
.
put
(
key
,
value
);
}
return
result
;
}
/**
* 把数组所有元素排序,并按照“参数=参数值”的模式用“&”字符拼接成字符串
* @param params 需要排序并参与字符拼接的参数组
* @return 拼接后字符串
*/
public
static
String
createLinkString
(
Map
<
String
,
String
>
params
)
{
List
<
String
>
keys
=
new
ArrayList
<
String
>(
params
.
keySet
());
Collections
.
sort
(
keys
);
String
prestr
=
""
;
for
(
int
i
=
0
;
i
<
keys
.
size
();
i
++)
{
String
key
=
keys
.
get
(
i
);
String
value
=
params
.
get
(
key
);
if
(
i
==
keys
.
size
()
-
1
)
{
//拼接时,不包括最后一个&字符
prestr
=
prestr
+
key
+
"="
+
value
;
}
else
{
prestr
=
prestr
+
key
+
"="
+
value
+
"&"
;
}
}
return
prestr
;
}
/**
* 生成文件摘要
* @param strFilePath 文件路径
* @param file_digest_type 摘要算法
* @return 文件摘要结果
*/
public
static
String
getAbstract
(
String
strFilePath
,
String
file_digest_type
)
throws
IOException
{
PartSource
file
=
new
FilePartSource
(
new
File
(
strFilePath
));
if
(
file_digest_type
.
equals
(
"MD5"
)){
return
DigestUtils
.
md5Hex
(
file
.
createInputStream
());
}
else
if
(
file_digest_type
.
equals
(
"SHA"
))
{
return
DigestUtils
.
sha256Hex
(
file
.
createInputStream
());
}
else
{
return
""
;
}
}
}
xxpay4spring-cloud/xxpay-service/src/main/java/org/xxpay/service/channel/alipay/util/AlipayNotify.java
0 → 100644
View file @
d53783a9
package
org.xxpay.service.channel.alipay.util
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Service
;
import
org.xxpay.service.channel.alipay.config.AlipayConfig
;
import
org.xxpay.service.channel.alipay.sign.RSA
;
import
org.xxpay.common.util.MyLog
;
import
java.io.BufferedReader
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.Map
;
/* *
*类名:AlipayNotify
*功能:支付宝通知处理类
*详细:处理支付宝各接口通知返回
*版本:3.3
*日期:2012-08-17
*说明:
*以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
*该代码仅供学习和研究支付宝接口使用,只是提供一个参考
*************************注意*************************
*调试通知返回时,可查看或改写log日志的写入TXT里的数据,来检查通知返回是否正常
*/
@Component
public
class
AlipayNotify
{
private
static
final
MyLog
_log
=
MyLog
.
getLog
(
AlipayNotify
.
class
);
/**
* 支付宝消息验证地址
*/
private
static
final
String
HTTPS_VERIFY_URL
=
"https://mapi.alipay.com/gateway.do?service=notify_verify&"
;
/**
* 验证消息是否是支付宝发出的合法消息
* @param params 通知返回来的参数数组
* @return 验证结果
*/
public
static
boolean
verify
(
AlipayConfig
alipayConfig
,
Map
<
String
,
String
>
params
)
{
//判断responsetTxt是否为true,isSign是否为true
//responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
//isSign不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
String
responseTxt
=
"true"
;
if
(
alipayConfig
.
is_verify_notify_url
())
{
responseTxt
=
"false"
;
if
(
params
.
get
(
"notify_id"
)
!=
null
)
{
String
notify_id
=
params
.
get
(
"notify_id"
);
responseTxt
=
verifyResponse
(
alipayConfig
,
notify_id
);
}
_log
.
info
(
"验证支付宝请求地址,结果responseTxt={}"
,
responseTxt
);
}
String
sign
=
""
;
if
(
params
.
get
(
"sign"
)
!=
null
)
{
sign
=
params
.
get
(
"sign"
);}
boolean
isSign
=
getSignVeryfy
(
params
,
sign
);
_log
.
info
(
"验证支付宝通知签名,isSign={}"
,
isSign
);
//写日志记录(若要调试,请取消下面两行注释)
//String sWord = "responseTxt=" + responseTxt + "\n isSign=" + isSign + "\n 返回回来的参数:" + AlipayCore.createLinkString(params);
//AlipayCore.logResult(sWord);
if
(
isSign
&&
responseTxt
.
equals
(
"true"
))
{
return
true
;
}
else
{
return
false
;
}
}
/**
* 根据反馈回来的信息,生成签名结果
* @param Params 通知返回来的参数数组
* @param sign 比对的签名结果
* @return 生成的签名结果
*/
private
static
boolean
getSignVeryfy
(
Map
<
String
,
String
>
Params
,
String
sign
)
{
//过滤空值、sign与sign_type参数
Map
<
String
,
String
>
sParaNew
=
AlipayCore
.
paraFilter
(
Params
);
//获取待签名字符串
String
preSignStr
=
AlipayCore
.
createLinkString
(
sParaNew
);
//获得签名验证结果
boolean
isSign
=
false
;
if
(
AlipayConfig
.
sign_type
.
equals
(
"RSA"
)){
isSign
=
RSA
.
verify
(
preSignStr
,
sign
,
AlipayConfig
.
ali_public_key
,
AlipayConfig
.
input_charset
);
}
return
isSign
;
}
/**
* 获取远程服务器ATN结果,验证返回URL
* @param notify_id 通知校验ID
* @return 服务器ATN结果
* 验证结果集:
* invalid命令参数不对 出现这个错误,请检测返回处理中partner和key是否为空
* true 返回正确信息
* false 请检查防火墙或者是服务器阻止端口问题以及验证时间是否超过一分钟
*/
private
static
String
verifyResponse
(
AlipayConfig
alipayConfig
,
String
notify_id
)
{
//获取远程服务器ATN结果,验证是否是支付宝服务器发来的请求
String
partner
=
alipayConfig
.
getPartner
();
String
veryfy_url
=
HTTPS_VERIFY_URL
+
"partner="
+
partner
+
"¬ify_id="
+
notify_id
;
_log
.
info
(
"请求支付宝URL={}"
,
veryfy_url
);
return
checkUrl
(
veryfy_url
);
}
/**
* 获取远程服务器ATN结果
* @param urlvalue 指定URL路径地址
* @return 服务器ATN结果
* 验证结果集:
* invalid命令参数不对 出现这个错误,请检测返回处理中partner和key是否为空
* true 返回正确信息
* false 请检查防火墙或者是服务器阻止端口问题以及验证时间是否超过一分钟
*/
private
static
String
checkUrl
(
String
urlvalue
)
{
String
inputLine
=
""
;
try
{
URL
url
=
new
URL
(
urlvalue
);
HttpURLConnection
urlConnection
=
(
HttpURLConnection
)
url
.
openConnection
();
BufferedReader
in
=
new
BufferedReader
(
new
InputStreamReader
(
urlConnection
.
getInputStream
()));
inputLine
=
in
.
readLine
().
toString
();
}
catch
(
Exception
e
)
{
_log
.
error
(
e
,
"验证支付宝通知请求地址异常.URL=%s"
,
urlvalue
);
inputLine
=
""
;
}
return
inputLine
;
}
}
Prev
1
…
15
16
17
18
19
20
21
22
23
24
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment