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
Eladmin
Commits
1ec10e3d
Commit
1ec10e3d
authored
Dec 31, 2018
by
郑杰
Browse files
v1.3 版本发布,详细信息查看发行版说明
parent
d329b0c8
Changes
48
Hide whitespace changes
Inline
Side-by-side
src/main/java/me/zhengjie/system/rest/VerificationCodeController.java
View file @
1ec10e3d
package
me.zhengjie.system.rest
;
import
me.zhengjie.common.utils.ElAdminConstant
;
import
me.zhengjie.common.utils.RequestHolder
;
import
me.zhengjie.core.security.JwtUser
;
import
me.zhengjie.core.utils.JwtTokenUtil
;
import
me.zhengjie.system.domain.VerificationCode
;
import
me.zhengjie.system.service.VerificationCodeService
;
import
me.zhengjie.tools.domain.vo.EmailVo
;
import
me.zhengjie.tools.service.EmailService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.web.bind.annotation.*
;
/**
...
...
@@ -18,10 +26,33 @@ public class VerificationCodeController {
@Autowired
private
VerificationCodeService
verificationCodeService
;
@PostMapping
(
value
=
"/code/sendEmail"
)
public
ResponseEntity
sendEmail
(
@RequestBody
VerificationCode
code
){
@Autowired
private
JwtTokenUtil
jwtTokenUtil
;
@Autowired
@Qualifier
(
"jwtUserDetailsService"
)
private
UserDetailsService
userDetailsService
;
@Autowired
private
EmailService
emailService
;
@PostMapping
(
value
=
"/code/resetEmail"
)
public
ResponseEntity
resetEmail
(
@RequestBody
VerificationCode
code
)
throws
Exception
{
code
.
setScenes
(
ElAdminConstant
.
RESET_MAIL
);
EmailVo
emailVo
=
verificationCodeService
.
sendEmail
(
code
);
emailService
.
send
(
emailVo
,
emailService
.
find
());
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
@PostMapping
(
value
=
"/code/email/resetPass"
)
public
ResponseEntity
resetPass
()
throws
Exception
{
JwtUser
jwtUser
=
(
JwtUser
)
userDetailsService
.
loadUserByUsername
(
jwtTokenUtil
.
getUserName
(
RequestHolder
.
getHttpServletRequest
()));
VerificationCode
code
=
new
VerificationCode
();
code
.
setType
(
"email"
);
verificationCodeService
.
sendEmail
(
code
);
code
.
setValue
(
jwtUser
.
getEmail
());
code
.
setScenes
(
ElAdminConstant
.
RESET_MAIL
);
EmailVo
emailVo
=
verificationCodeService
.
sendEmail
(
code
);
emailService
.
send
(
emailVo
,
emailService
.
find
());
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
...
...
src/main/java/me/zhengjie/system/service/UserService.java
View file @
1ec10e3d
package
me.zhengjie.system.service
;
import
me.zhengjie.core.security.JwtUser
;
import
me.zhengjie.system.domain.User
;
import
me.zhengjie.system.service.dto.UserDTO
;
import
org.springframework.cache.annotation.CacheConfig
;
...
...
@@ -50,4 +51,25 @@ public interface UserService {
*/
@Cacheable
(
key
=
"'findByName'+#p0"
)
User
findByName
(
String
userName
);
/**
* 修改密码
* @param jwtUser
* @param encryptPassword
*/
void
updatePass
(
JwtUser
jwtUser
,
String
encryptPassword
);
/**
* 修改头像
* @param jwtUser
* @param url
*/
void
updateAvatar
(
JwtUser
jwtUser
,
String
url
);
/**
* 修改邮箱
* @param jwtUser
* @param email
*/
void
updateEmail
(
JwtUser
jwtUser
,
String
email
);
}
src/main/java/me/zhengjie/system/service/VerificationCodeService.java
View file @
1ec10e3d
package
me.zhengjie.system.service
;
import
me.zhengjie.system.domain.VerificationCode
;
import
me.zhengjie.tools.domain.vo.EmailVo
;
/**
* @author jie
...
...
@@ -12,7 +13,7 @@ public interface VerificationCodeService {
* 发送邮件验证码
* @param code
*/
void
sendEmail
(
VerificationCode
code
);
EmailVo
sendEmail
(
VerificationCode
code
);
/**
* 验证
...
...
src/main/java/me/zhengjie/system/service/impl/MenuServiceImpl.java
View file @
1ec10e3d
package
me.zhengjie.system.service.impl
;
import
cn.hutool.core.util.StrUtil
;
import
me.zhengjie.common.exception.BadRequestException
;
import
me.zhengjie.common.exception.EntityExistException
;
import
me.zhengjie.common.utils.ValidationUtil
;
import
me.zhengjie.system.domain.Menu
;
...
...
@@ -51,6 +52,11 @@ public class MenuServiceImpl implements MenuService {
if
(
menuRepository
.
findByName
(
resources
.
getName
())
!=
null
){
throw
new
EntityExistException
(
Menu
.
class
,
"name"
,
resources
.
getName
());
}
if
(
resources
.
getIFrame
()){
if
(!(
resources
.
getPath
().
toLowerCase
().
startsWith
(
"http://"
)||
resources
.
getPath
().
toLowerCase
().
startsWith
(
"https://"
)))
{
throw
new
BadRequestException
(
"外链必须以http://或者https://开头"
);
}
}
return
menuMapper
.
toDto
(
menuRepository
.
save
(
resources
));
}
...
...
@@ -59,13 +65,17 @@ public class MenuServiceImpl implements MenuService {
Optional
<
Menu
>
optionalPermission
=
menuRepository
.
findById
(
resources
.
getId
());
ValidationUtil
.
isNull
(
optionalPermission
,
"Permission"
,
"id"
,
resources
.
getId
());
if
(
resources
.
getIFrame
()){
if
(!(
resources
.
getPath
().
toLowerCase
().
startsWith
(
"http://"
)||
resources
.
getPath
().
toLowerCase
().
startsWith
(
"https://"
)))
{
throw
new
BadRequestException
(
"外链必须以http://或者https://开头"
);
}
}
Menu
menu
=
optionalPermission
.
get
();
Menu
menu1
=
menuRepository
.
findByName
(
resources
.
getName
());
if
(
menu1
!=
null
&&
!
menu1
.
getId
().
equals
(
menu
.
getId
())){
throw
new
EntityExistException
(
Menu
.
class
,
"name"
,
resources
.
getName
());
}
menu
.
setName
(
resources
.
getName
());
menu
.
setComponent
(
resources
.
getComponent
());
menu
.
setPath
(
resources
.
getPath
());
...
...
src/main/java/me/zhengjie/system/service/impl/UserServiceImpl.java
View file @
1ec10e3d
...
...
@@ -4,6 +4,7 @@ import me.zhengjie.common.exception.BadRequestException;
import
me.zhengjie.common.exception.EntityExistException
;
import
me.zhengjie.common.exception.EntityNotFoundException
;
import
me.zhengjie.common.utils.ValidationUtil
;
import
me.zhengjie.core.security.JwtUser
;
import
me.zhengjie.core.utils.EncryptUtils
;
import
me.zhengjie.core.utils.JwtTokenUtil
;
import
me.zhengjie.system.domain.User
;
...
...
@@ -130,4 +131,22 @@ public class UserServiceImpl implements UserService {
return
user
;
}
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updatePass
(
JwtUser
jwtUser
,
String
pass
)
{
userRepository
.
updatePass
(
jwtUser
.
getId
(),
pass
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updateAvatar
(
JwtUser
jwtUser
,
String
url
)
{
userRepository
.
updateAvatar
(
jwtUser
.
getId
(),
url
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updateEmail
(
JwtUser
jwtUser
,
String
email
)
{
userRepository
.
updateEmail
(
jwtUser
.
getId
(),
email
);
}
}
src/main/java/me/zhengjie/system/service/impl/VerificationCodeServiceImpl.java
View file @
1ec10e3d
package
me.zhengjie.system.service.impl
;
import
cn.hutool.core.util.RandomUtil
;
import
me.zhengjie.common.exception.BadRequestException
;
import
me.zhengjie.common.utils.ElAdminConstant
;
import
me.zhengjie.system.domain.VerificationCode
;
import
me.zhengjie.system.repository.VerificationCodeRepository
;
import
me.zhengjie.system.service.VerificationCodeService
;
import
me.zhengjie.tools.domain.vo.EmailVo
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Arrays
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
/**
* @author jie
* @date 2018-12-26
*/
@Service
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
VerificationCodeServiceImpl
implements
VerificationCodeService
{
@Override
public
void
sendEmail
(
VerificationCode
code
)
{
@Autowired
private
VerificationCodeRepository
verificationCodeRepository
;
@Value
(
"${code.expiration}"
)
private
Integer
expiration
;
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
EmailVo
sendEmail
(
VerificationCode
code
)
{
EmailVo
emailVo
=
null
;
String
content
=
""
;
VerificationCode
verificationCode
=
verificationCodeRepository
.
findByScenesAndTypeAndValueAndStatusIsTrue
(
code
.
getScenes
(),
code
.
getType
(),
code
.
getValue
());
// 如果不存在有效的验证码,就创建一个新的
if
(
verificationCode
==
null
){
code
.
setCode
(
RandomUtil
.
randomNumbers
(
6
));
content
=
ElAdminConstant
.
EMAIL_CODE
+
code
.
getCode
()
+
"</p>"
;
emailVo
=
new
EmailVo
(
Arrays
.
asList
(
code
.
getValue
()),
"eladmin后台管理系统"
,
content
);
timedDestruction
(
verificationCodeRepository
.
save
(
code
));
// 存在就再次发送原来的验证码
}
else
{
content
=
ElAdminConstant
.
EMAIL_CODE
+
verificationCode
.
getCode
()
+
"</p>"
;
emailVo
=
new
EmailVo
(
Arrays
.
asList
(
verificationCode
.
getValue
()),
"eladmin后台管理系统"
,
content
);
}
return
emailVo
;
}
@Override
public
void
validated
(
VerificationCode
code
)
{
VerificationCode
verificationCode
=
verificationCodeRepository
.
findByScenesAndTypeAndValueAndStatusIsTrue
(
code
.
getScenes
(),
code
.
getType
(),
code
.
getValue
());
if
(
verificationCode
==
null
||
!
verificationCode
.
getCode
().
equals
(
code
.
getCode
())){
throw
new
BadRequestException
(
"无效验证码"
);
}
else
{
verificationCode
.
setStatus
(
false
);
verificationCodeRepository
.
save
(
verificationCode
);
}
}
/**
* 定时任务,指定分钟后改变验证码状态
* @param verifyCode
*/
private
void
timedDestruction
(
VerificationCode
verifyCode
)
{
//以下示例为程序调用结束继续运行
ScheduledExecutorService
executorService
=
Executors
.
newSingleThreadScheduledExecutor
();
try
{
executorService
.
schedule
(()
->
{
verifyCode
.
setStatus
(
false
);
verificationCodeRepository
.
save
(
verifyCode
);
},
expiration
*
60
*
1000L
,
TimeUnit
.
MILLISECONDS
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
}
}
src/main/java/me/zhengjie/tools/domain/AlipayConfig.java
0 → 100644
View file @
1ec10e3d
package
me.zhengjie.tools.domain
;
import
lombok.Data
;
import
javax.persistence.*
;
import
javax.validation.constraints.NotBlank
;
import
java.io.Serializable
;
/**
* 支付宝配置类
* @author jie
* @date 2018-12-31
*/
@Data
@Entity
@Table
(
name
=
"alipay_config"
)
public
class
AlipayConfig
implements
Serializable
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Long
id
;
/**
* 应用ID,APPID,收款账号既是APPID对应支付宝账号
*/
@NotBlank
private
String
appID
;
/**
* 商户私钥,您的PKCS8格式RSA2私钥
*/
@NotBlank
@Column
(
length
=
2000
)
private
String
privateKey
;
/**
* 支付宝公钥
*/
@NotBlank
@Column
(
length
=
2000
)
private
String
publicKey
;
/**
* 签名方式,固定格式
*/
private
String
signType
=
"RSA2"
;
/**
* 支付宝开放安全地址,一般不会变
*/
private
String
gatewayUrl
=
"https://openapi.alipaydev.com/gateway.do"
;
/**
* 编码,固定格式
*/
private
String
charset
=
"utf-8"
;
/**
* 异步通知地址
*/
@NotBlank
private
String
notifyUrl
;
/**
* 订单完成后返回的页面
*/
@NotBlank
private
String
returnUrl
;
/**
* 类型,固定格式
*/
private
String
format
=
"JSON"
;
/**
* 商户号
*/
@NotBlank
private
String
sysServiceProviderId
;
}
src/main/java/me/zhengjie/tools/domain/QiniuConfig.java
0 → 100644
View file @
1ec10e3d
package
me.zhengjie.tools.domain
;
import
lombok.Data
;
import
javax.persistence.*
;
import
javax.validation.constraints.NotBlank
;
import
java.io.Serializable
;
/**
* 七牛云对象存储配置类
* @author jie
* @date 2018-12-31
*/
@Data
@Entity
@Table
(
name
=
"qiniu_config"
)
public
class
QiniuConfig
implements
Serializable
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Long
id
;
/**
* 一个账号最多拥有两对密钥(Access/Secret Key)
*/
@NotBlank
private
String
accessKey
;
/**
* 一个账号最多拥有两对密钥(Access/Secret Key)
*/
@NotBlank
private
String
secretKey
;
/**
* 存储空间名称作为唯一的 Bucket 识别符
*/
@NotBlank
private
String
bucket
;
/**
* Zone表示与机房的对应关系
* 华东 Zone.zone0()
* 华北 Zone.zone1()
* 华南 Zone.zone2()
* 北美 Zone.zoneNa0()
* 东南亚 Zone.zoneAs0()
*/
@NotBlank
private
String
zone
;
/**
* 外链域名,可自定义,需在七牛云绑定
*/
@NotBlank
private
String
host
;
/**
* 空间类型:公开/私有
*/
private
String
type
=
"公开"
;
}
src/main/java/me/zhengjie/tools/domain/QiniuContent.java
0 → 100644
View file @
1ec10e3d
package
me.zhengjie.tools.domain
;
import
lombok.Data
;
import
org.hibernate.annotations.UpdateTimestamp
;
import
javax.persistence.*
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
/**
* 上传成功后,存储结果
* @author jie
* @date 2018-12-31
*/
@Data
@Entity
@Table
(
name
=
"qiniu_content"
)
public
class
QiniuContent
implements
Serializable
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Long
id
;
/**
* 文件名,如qiniu.jpg
*/
@Column
(
name
=
"name"
,
unique
=
false
)
private
String
key
;
/**
* 空间名
*/
private
String
bucket
;
/**
* 大小
*/
private
String
size
;
/**
* 文件地址
*/
private
String
url
;
/**
* 空间类型:公开/私有
*/
private
String
type
=
"公开"
;
/**
* 更新时间
*/
@UpdateTimestamp
private
Timestamp
updateTime
;
}
src/main/java/me/zhengjie/tools/domain/vo/EmailVo.java
View file @
1ec10e3d
package
me.zhengjie.tools.domain.vo
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotEmpty
;
...
...
@@ -13,6 +15,8 @@ import java.util.List;
* @date 2018/09/28 12:02:14
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
EmailVo
{
/**
...
...
src/main/java/me/zhengjie/tools/domain/vo/TradeVo.java
0 → 100644
View file @
1ec10e3d
package
me.zhengjie.tools.domain.vo
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
javax.validation.constraints.NotBlank
;
import
java.sql.Date
;
import
java.sql.Timestamp
;
/**
* 交易详情,按需应该存入数据库,这里存入数据库,仅供临时测试
* @author jie
* @date 2018-12-31
*/
@Data
public
class
TradeVo
{
/**
* (必填)商品描述
*/
@NotBlank
private
String
body
;
/**
* (必填)商品名称
*/
@NotBlank
private
String
subject
;
/**
* (必填)商户订单号,应该由后台生成
*/
@ApiModelProperty
(
hidden
=
true
)
private
String
outTradeNo
;
/**
* (必填)第三方订单号
*/
@ApiModelProperty
(
hidden
=
true
)
private
String
tradeNo
;
/**
* (必填)价格
*/
@NotBlank
private
String
totalAmount
;
/**
* 订单状态,已支付,未支付,作废
*/
@ApiModelProperty
(
hidden
=
true
)
private
String
state
;
/**
* 创建时间,存入数据库时需要
*/
@ApiModelProperty
(
hidden
=
true
)
private
Timestamp
createTime
;
/**
* 作废时间,存入数据库时需要
*/
@ApiModelProperty
(
hidden
=
true
)
private
Date
cancelTime
;
}
src/main/java/me/zhengjie/tools/repository/AlipayRepository.java
0 → 100644
View file @
1ec10e3d
package
me.zhengjie.tools.repository
;
import
me.zhengjie.tools.domain.AlipayConfig
;
import
org.springframework.data.jpa.repository.JpaRepository
;
/**
* @author jie
* @date 2018-12-31
*/
public
interface
AlipayRepository
extends
JpaRepository
<
AlipayConfig
,
Long
>
{
}
src/main/java/me/zhengjie/tools/repository/QiNiuConfigRepository.java
0 → 100644
View file @
1ec10e3d
package
me.zhengjie.tools.repository
;
import
me.zhengjie.tools.domain.QiniuConfig
;
import
org.springframework.data.jpa.repository.JpaRepository
;
/**
* @author jie
* @date 2018-12-31
*/
public
interface
QiNiuConfigRepository
extends
JpaRepository
<
QiniuConfig
,
Long
>
{
}
src/main/java/me/zhengjie/tools/repository/QiniuContentRepository.java
0 → 100644
View file @
1ec10e3d
package
me.zhengjie.tools.repository
;
import
me.zhengjie.tools.domain.QiniuContent
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
/**
* @author jie
* @date 2018-12-31
*/
public
interface
QiniuContentRepository
extends
JpaRepository
<
QiniuContent
,
Long
>,
JpaSpecificationExecutor
{
/**
* 根据key查询
* @param key
* @return
*/
QiniuContent
findByKey
(
String
key
);
}
src/main/java/me/zhengjie/tools/rest/AliPayController.java
0 → 100644
View file @
1ec10e3d
package
me.zhengjie.tools.rest
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
me.zhengjie.common.aop.log.Log
;
import
me.zhengjie.tools.domain.AlipayConfig
;
import
me.zhengjie.tools.domain.vo.TradeVo
;
import
me.zhengjie.tools.service.AlipayService
;
import
me.zhengjie.tools.util.AliPayStatusEnum
;
import
me.zhengjie.tools.util.AlipayUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
springfox.documentation.annotations.ApiIgnore
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.Map
;
/**
* @author jie
* @date 2018-12-31
*/
@Slf4j
@RestController
@RequestMapping
(
"/api"
)
public
class
AliPayController
{
@Autowired
AlipayUtils
alipayUtils
;
@Autowired
private
AlipayService
alipayService
;
@GetMapping
(
value
=
"/aliPay"
)
public
ResponseEntity
get
(){
return
new
ResponseEntity
(
alipayService
.
find
(),
HttpStatus
.
OK
);
}
@Log
(
description
=
"配置支付宝"
)
@PutMapping
(
value
=
"/aliPay"
)
public
ResponseEntity
payConfig
(
@Validated
@RequestBody
AlipayConfig
alipayConfig
){
alipayConfig
.
setId
(
1L
);
alipayService
.
update
(
alipayConfig
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
@Log
(
description
=
"支付宝PC网页支付"
)
@ApiOperation
(
value
=
"PC网页支付"
)
@PostMapping
(
value
=
"/aliPay/toPayAsPC"
)
public
ResponseEntity
toPayAsPC
(
@Validated@RequestBody
TradeVo
trade
)
throws
Exception
{
log
.
warn
(
"REST request to toPayAsPC Trade : {}"
+
trade
);
AlipayConfig
alipay
=
alipayService
.
find
();
trade
.
setOutTradeNo
(
alipayUtils
.
getOrderCode
());
String
payUrl
=
alipayService
.
toPayAsPC
(
alipay
,
trade
);
return
ResponseEntity
.
ok
(
payUrl
);
}
@Log
(
description
=
"支付宝手机网页支付"
)
@ApiOperation
(
value
=
"手机网页支付"
)
@PostMapping
(
value
=
"/aliPay/toPayAsWeb"
)
public
ResponseEntity
toPayAsWeb
(
@Validated
@RequestBody
TradeVo
trade
)
throws
Exception
{
log
.
warn
(
"REST request to toPayAsWeb Trade : {}"
+
trade
);
AlipayConfig
alipay
=
alipayService
.
find
();
trade
.
setOutTradeNo
(
alipayUtils
.
getOrderCode
());
String
payUrl
=
alipayService
.
toPayAsWeb
(
alipay
,
trade
);
return
ResponseEntity
.
ok
(
payUrl
);
}
@ApiIgnore
@GetMapping
(
"/aliPay/return"
)
@ApiOperation
(
value
=
"支付之后跳转的链接"
)
public
ResponseEntity
returnPage
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
AlipayConfig
alipay
=
alipayService
.
find
();
response
.
setContentType
(
"text/html;charset="
+
alipay
.
getCharset
());
//内容验签,防止黑客篡改参数
if
(
alipayUtils
.
rsaCheck
(
request
,
alipay
)){
//商户订单号
String
outTradeNo
=
new
String
(
request
.
getParameter
(
"out_trade_no"
).
getBytes
(
"ISO-8859-1"
),
"UTF-8"
);
//支付宝交易号
String
tradeNo
=
new
String
(
request
.
getParameter
(
"trade_no"
).
getBytes
(
"ISO-8859-1"
),
"UTF-8"
);
System
.
out
.
println
(
"商户订单号"
+
outTradeNo
+
" "
+
"第三方交易号"
+
tradeNo
);
/**
* 根据业务需要返回数据,这里统一返回OK
*/
return
new
ResponseEntity
(
"payment successful"
,
HttpStatus
.
OK
);
}
else
{
/**
* 根据业务需要返回数据
*/
return
new
ResponseEntity
(
HttpStatus
.
BAD_REQUEST
);
}
}
@ApiIgnore
@RequestMapping
(
"/aliPay/notify"
)
@ApiOperation
(
value
=
"支付异步通知(要公网访问),接收异步通知,检查通知内容app_id、out_trade_no、total_amount是否与请求中的一致,根据trade_status进行后续业务处理"
)
public
ResponseEntity
notify
(
HttpServletRequest
request
)
throws
Exception
{
AlipayConfig
alipay
=
alipayService
.
find
();
Map
<
String
,
String
[]>
parameterMap
=
request
.
getParameterMap
();
StringBuilder
notifyBuild
=
new
StringBuilder
(
"/****************************** pay notify ******************************/\n"
);
parameterMap
.
forEach
((
key
,
value
)
->
notifyBuild
.
append
(
key
+
"="
+
value
[
0
]
+
"\n"
)
);
//内容验签,防止黑客篡改参数
if
(
alipayUtils
.
rsaCheck
(
request
,
alipay
))
{
//交易状态
String
tradeStatus
=
new
String
(
request
.
getParameter
(
"trade_status"
).
getBytes
(
"ISO-8859-1"
),
"UTF-8"
);
// 商户订单号
String
outTradeNo
=
new
String
(
request
.
getParameter
(
"out_trade_no"
).
getBytes
(
"ISO-8859-1"
),
"UTF-8"
);
//支付宝交易号
String
tradeNo
=
new
String
(
request
.
getParameter
(
"trade_no"
).
getBytes
(
"ISO-8859-1"
),
"UTF-8"
);
//付款金额
String
totalAmount
=
new
String
(
request
.
getParameter
(
"total_amount"
).
getBytes
(
"ISO-8859-1"
),
"UTF-8"
);
//验证
if
(
tradeStatus
.
equals
(
AliPayStatusEnum
.
SUCCESS
.
getValue
())||
tradeStatus
.
equals
(
AliPayStatusEnum
.
FINISHED
.
getValue
())){
/**
* 验证通过后应该根据业务需要处理订单
*/
}
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
return
new
ResponseEntity
(
HttpStatus
.
BAD_REQUEST
);
}
}
src/main/java/me/zhengjie/tools/rest/EmailController.java
View file @
1ec10e3d
...
...
@@ -25,13 +25,11 @@ public class EmailController {
@Autowired
private
EmailService
emailService
;
@PreAuthorize
(
"hasAnyRole('ADMIN')"
)
@GetMapping
(
value
=
"/email"
)
public
ResponseEntity
get
(){
return
new
ResponseEntity
(
emailService
.
find
(),
HttpStatus
.
OK
);
}
@PreAuthorize
(
"hasAnyRole('ADMIN')"
)
@Log
(
description
=
"配置邮件"
)
@PutMapping
(
value
=
"/email"
)
public
ResponseEntity
emailConfig
(
@Validated
@RequestBody
EmailConfig
emailConfig
){
...
...
@@ -39,7 +37,6 @@ public class EmailController {
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
@PreAuthorize
(
"hasAnyRole('ADMIN')"
)
@Log
(
description
=
"发送邮件"
)
@PostMapping
(
value
=
"/email"
)
public
ResponseEntity
send
(
@Validated
@RequestBody
EmailVo
emailVo
)
throws
Exception
{
...
...
src/main/java/me/zhengjie/tools/rest/QiniuController.java
0 → 100644
View file @
1ec10e3d
package
me.zhengjie.tools.rest
;
import
lombok.extern.slf4j.Slf4j
;
import
me.zhengjie.common.aop.log.Log
;
import
me.zhengjie.tools.domain.QiniuConfig
;
import
me.zhengjie.tools.domain.QiniuContent
;
import
me.zhengjie.tools.service.QiNiuService
;
import
me.zhengjie.tools.service.query.QiNiuQueryService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.UnsupportedEncodingException
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 发送邮件
* @author 郑杰
* @date 2018/09/28 6:55:53
*/
@Slf4j
@RestController
@RequestMapping
(
"api"
)
public
class
QiniuController
{
@Autowired
private
QiNiuService
qiNiuService
;
@Autowired
private
QiNiuQueryService
qiNiuQueryService
;
@GetMapping
(
value
=
"/qiNiuConfig"
)
public
ResponseEntity
get
(){
return
new
ResponseEntity
(
qiNiuService
.
find
(),
HttpStatus
.
OK
);
}
@Log
(
description
=
"配置七牛云存储"
)
@PutMapping
(
value
=
"/qiNiuConfig"
)
public
ResponseEntity
emailConfig
(
@Validated
@RequestBody
QiniuConfig
qiniuConfig
){
qiNiuService
.
update
(
qiniuConfig
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
@Log
(
description
=
"查询文件"
)
@GetMapping
(
value
=
"/qiNiuContent"
)
public
ResponseEntity
getRoles
(
QiniuContent
resources
,
Pageable
pageable
){
return
new
ResponseEntity
(
qiNiuQueryService
.
queryAll
(
resources
,
pageable
),
HttpStatus
.
OK
);
}
/**
* 上传文件到七牛云
* @param file
* @return
*/
@Log
(
description
=
"上传文件"
)
@PostMapping
(
value
=
"/qiNiuContent"
)
public
ResponseEntity
upload
(
@RequestParam
MultipartFile
file
){
QiniuContent
qiniuContent
=
qiNiuService
.
upload
(
file
,
qiNiuService
.
find
());
Map
map
=
new
HashMap
();
map
.
put
(
"errno"
,
0
);
map
.
put
(
"id"
,
qiniuContent
.
getId
());
map
.
put
(
"data"
,
new
String
[]{
qiniuContent
.
getUrl
()});
return
new
ResponseEntity
(
map
,
HttpStatus
.
OK
);
}
/**
* 同步七牛云数据到数据库
* @return
*/
@Log
(
description
=
"同步七牛云数据"
)
@PostMapping
(
value
=
"/qiNiuContent/synchronize"
)
public
ResponseEntity
synchronize
(){
log
.
warn
(
"REST request to synchronize qiNiu : {}"
);
qiNiuService
.
synchronize
(
qiNiuService
.
find
());
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
/**
* 下载七牛云文件
* @param id
* @return
* @throws Exception
*/
@Log
(
description
=
"下载文件"
)
@GetMapping
(
value
=
"/qiNiuContent/download/{id}"
)
public
ResponseEntity
download
(
@PathVariable
Long
id
){
return
new
ResponseEntity
(
qiNiuService
.
download
(
qiNiuService
.
findByContentId
(
id
),
qiNiuService
.
find
()),
HttpStatus
.
OK
);
}
/**
* 删除七牛云文件
* @param id
* @return
* @throws Exception
*/
@Log
(
description
=
"删除文件"
)
@DeleteMapping
(
value
=
"/qiNiuContent/{id}"
)
public
ResponseEntity
delete
(
@PathVariable
Long
id
){
qiNiuService
.
delete
(
qiNiuService
.
findByContentId
(
id
),
qiNiuService
.
find
());
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
}
src/main/java/me/zhengjie/tools/service/AlipayService.java
0 → 100644
View file @
1ec10e3d
package
me.zhengjie.tools.service
;
import
me.zhengjie.tools.domain.AlipayConfig
;
import
me.zhengjie.tools.domain.vo.TradeVo
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CachePut
;
import
org.springframework.cache.annotation.Cacheable
;
/**
* @author jie
* @date 2018-12-31
*/
@CacheConfig
(
cacheNames
=
"alipay"
)
public
interface
AlipayService
{
/**
* 处理来自PC的交易请求
* @param alipay
* @param trade
* @return
* @throws Exception
*/
String
toPayAsPC
(
AlipayConfig
alipay
,
TradeVo
trade
)
throws
Exception
;
/**
* 处理来自手机网页的交易请求
* @param alipay
* @param trade
* @return
* @throws Exception
*/
String
toPayAsWeb
(
AlipayConfig
alipay
,
TradeVo
trade
)
throws
Exception
;
/**
* 查询配置
* @return
*/
@Cacheable
(
key
=
"'1'"
)
AlipayConfig
find
();
/**
* 更新配置
* @param alipayConfig
* @return
*/
@CachePut
(
key
=
"'1'"
)
AlipayConfig
update
(
AlipayConfig
alipayConfig
);
}
src/main/java/me/zhengjie/tools/service/QiNiuService.java
0 → 100644
View file @
1ec10e3d
package
me.zhengjie.tools.service
;
import
me.zhengjie.tools.domain.QiniuConfig
;
import
me.zhengjie.tools.domain.QiniuContent
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.CachePut
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.UnsupportedEncodingException
;
/**
* @author jie
* @date 2018-12-31
*/
@CacheConfig
(
cacheNames
=
"qiNiu"
)
public
interface
QiNiuService
{
/**
* 查配置
* @return
*/
@Cacheable
(
key
=
"'1'"
)
QiniuConfig
find
();
/**
* 修改配置
* @param qiniuConfig
* @return
*/
@CachePut
(
key
=
"'1'"
)
QiniuConfig
update
(
QiniuConfig
qiniuConfig
);
/**
* 上传文件
* @param file
* @param qiniuConfig
*/
@CacheEvict
(
allEntries
=
true
)
QiniuContent
upload
(
MultipartFile
file
,
QiniuConfig
qiniuConfig
);
/**
* 查询文件
* @param id
* @return
*/
@Cacheable
(
key
=
"'content:'+#p0"
)
QiniuContent
findByContentId
(
Long
id
);
/**
* 下载文件
* @param content
* @param config
* @return
*/
String
download
(
QiniuContent
content
,
QiniuConfig
config
);
/**
* 删除文件
* @param content
* @param config
* @return
*/
@CacheEvict
(
allEntries
=
true
)
void
delete
(
QiniuContent
content
,
QiniuConfig
config
);
/**
* 同步数据
* @param config
*/
@CacheEvict
(
allEntries
=
true
)
void
synchronize
(
QiniuConfig
config
);
}
src/main/java/me/zhengjie/tools/service/impl/AlipayServiceImpl.java
0 → 100644
View file @
1ec10e3d
package
me.zhengjie.tools.service.impl
;
import
com.alipay.api.AlipayClient
;
import
com.alipay.api.DefaultAlipayClient
;
import
com.alipay.api.request.AlipayTradePagePayRequest
;
import
com.alipay.api.request.AlipayTradeWapPayRequest
;
import
me.zhengjie.common.exception.BadRequestException
;
import
me.zhengjie.tools.domain.AlipayConfig
;
import
me.zhengjie.tools.domain.vo.TradeVo
;
import
me.zhengjie.tools.repository.AlipayRepository
;
import
me.zhengjie.tools.service.AlipayService
;
import
me.zhengjie.tools.util.AlipayUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Optional
;
/**
* @author jie
* @date 2018-12-31
*/
@Service
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
AlipayServiceImpl
implements
AlipayService
{
@Autowired
AlipayUtils
alipayUtils
;
@Autowired
private
AlipayRepository
alipayRepository
;
@Override
public
String
toPayAsPC
(
AlipayConfig
alipay
,
TradeVo
trade
)
throws
Exception
{
if
(
alipay
.
getId
()
==
null
){
throw
new
BadRequestException
(
"请先添加相应配置,再操作"
);
}
AlipayClient
alipayClient
=
new
DefaultAlipayClient
(
alipay
.
getGatewayUrl
(),
alipay
.
getAppID
(),
alipay
.
getPrivateKey
(),
alipay
.
getFormat
(),
alipay
.
getCharset
(),
alipay
.
getPublicKey
(),
alipay
.
getSignType
());
double
money
=
Double
.
parseDouble
(
trade
.
getTotalAmount
());
if
(
money
<=
0
||
money
>=
5000
){
throw
new
BadRequestException
(
"测试金额过大"
);
}
/**
* 创建API对应的request(电脑网页版)
*/
AlipayTradePagePayRequest
request
=
new
AlipayTradePagePayRequest
();
/**
* 订单完成后返回的页面和异步通知地址
*/
request
.
setReturnUrl
(
alipay
.
getReturnUrl
());
request
.
setNotifyUrl
(
alipay
.
getNotifyUrl
());
/**
* 填充订单参数
*/
request
.
setBizContent
(
"{"
+
" \"out_trade_no\":\""
+
trade
.
getOutTradeNo
()+
"\","
+
" \"product_code\":\"FAST_INSTANT_TRADE_PAY\","
+
" \"total_amount\":"
+
trade
.
getTotalAmount
()+
","
+
" \"subject\":\""
+
trade
.
getSubject
()+
"\","
+
" \"body\":\""
+
trade
.
getBody
()+
"\","
+
" \"extend_params\":{"
+
" \"sys_service_provider_id\":\""
+
alipay
.
getSysServiceProviderId
()+
"\""
+
" }"
+
" }"
);
//填充业务参数
/**
* 调用SDK生成表单
* 通过GET方式,口可以获取url
*/
return
alipayClient
.
pageExecute
(
request
,
"GET"
).
getBody
();
}
@Override
public
String
toPayAsWeb
(
AlipayConfig
alipay
,
TradeVo
trade
)
throws
Exception
{
if
(
alipay
.
getId
()
==
null
){
throw
new
BadRequestException
(
"请先添加相应配置,再操作"
);
}
AlipayClient
alipayClient
=
new
DefaultAlipayClient
(
alipay
.
getGatewayUrl
(),
alipay
.
getAppID
(),
alipay
.
getPrivateKey
(),
alipay
.
getFormat
(),
alipay
.
getCharset
(),
alipay
.
getPublicKey
(),
alipay
.
getSignType
());
double
money
=
Double
.
parseDouble
(
trade
.
getTotalAmount
());
if
(
money
<=
0
||
money
>=
5000
){
throw
new
BadRequestException
(
"测试金额过大"
);
}
/**
* 创建API对应的request(手机网页版)
*/
AlipayTradeWapPayRequest
request
=
new
AlipayTradeWapPayRequest
();
/**
* 订单完成后返回的页面和异步通知地址
*/
request
.
setReturnUrl
(
alipay
.
getReturnUrl
());
request
.
setNotifyUrl
(
alipay
.
getNotifyUrl
());
/**
* 填充订单参数
*/
request
.
setBizContent
(
"{"
+
" \"out_trade_no\":\""
+
trade
.
getOutTradeNo
()+
"\","
+
" \"product_code\":\"FAST_INSTANT_TRADE_PAY\","
+
" \"total_amount\":"
+
trade
.
getTotalAmount
()+
","
+
" \"subject\":\""
+
trade
.
getSubject
()+
"\","
+
" \"body\":\""
+
trade
.
getBody
()+
"\","
+
" \"extend_params\":{"
+
" \"sys_service_provider_id\":\""
+
alipay
.
getSysServiceProviderId
()+
"\""
+
" }"
+
" }"
);
//填充业务参数
/**
* 调用SDK生成表单
* 通过GET方式,口可以获取url
*/
return
alipayClient
.
pageExecute
(
request
,
"GET"
).
getBody
();
}
@Override
public
AlipayConfig
find
()
{
Optional
<
AlipayConfig
>
alipayConfig
=
alipayRepository
.
findById
(
1L
);
if
(
alipayConfig
.
isPresent
()){
return
alipayConfig
.
get
();
}
else
{
return
new
AlipayConfig
();
}
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
AlipayConfig
update
(
AlipayConfig
alipayConfig
)
{
return
alipayRepository
.
saveAndFlush
(
alipayConfig
);
}
}
Prev
1
2
3
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