删除不要的模块

This commit is contained in:
2022-09-22 15:51:05 +08:00
parent 2f149911ba
commit 8e8730d0bf
84 changed files with 126 additions and 6575 deletions

View File

@@ -1,76 +0,0 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nl.domain;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* 支付宝配置类
* @author Zheng Jie
* @date 2018-12-31
*/
@Data
@Entity
@Table(name = "tool_alipay_config")
public class AlipayConfig implements Serializable {
@Id
@Column(name = "config_id")
@ApiModelProperty(value = "ID", hidden = true)
private Long id;
@NotBlank
@ApiModelProperty(value = "应用ID")
private String appId;
@NotBlank
@ApiModelProperty(value = "商户私钥")
private String privateKey;
@NotBlank
@ApiModelProperty(value = "支付宝公钥")
private String publicKey;
@ApiModelProperty(value = "签名方式")
private String signType="RSA2";
@Column(name = "gateway_url")
@ApiModelProperty(value = "支付宝开放安全地址", hidden = true)
private String gatewayUrl = "https://openapi.alipaydev.com/gateway.do";
@ApiModelProperty(value = "编码", hidden = true)
private String charset= "utf-8";
@NotBlank
@ApiModelProperty(value = "异步通知地址")
private String notifyUrl;
@NotBlank
@ApiModelProperty(value = "订单完成后返回的页面")
private String returnUrl;
@ApiModelProperty(value = "类型")
private String format="JSON";
@NotBlank
@ApiModelProperty(value = "商户号")
private String sysServiceProviderId;
}

View File

@@ -1,58 +0,0 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nl.domain;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* 邮件配置类,数据存覆盖式存入数据存
* @author Zheng Jie
* @date 2018-12-26
*/
@Entity
@Data
@Table(name = "tool_email_config")
public class EmailConfig implements Serializable {
@Id
@Column(name = "config_id")
@ApiModelProperty(value = "ID", hidden = true)
private Long id;
@NotBlank
@ApiModelProperty(value = "邮件服务器SMTP地址")
private String host;
@NotBlank
@ApiModelProperty(value = "邮件服务器 SMTP 端口")
private String port;
@NotBlank
@ApiModelProperty(value = "发件者用户名")
private String user;
@NotBlank
@ApiModelProperty(value = "密码")
private String pass;
@NotBlank
@ApiModelProperty(value = "收件人")
private String fromUser;
}

View File

@@ -1,44 +0,0 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nl.domain.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.util.List;
/**
* 发送邮件时,接收参数的类
* @author 郑杰
* @date 2018/09/28 12:02:14
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class EmailVo {
/** 收件人,支持多个收件人 */
@NotEmpty
private List<String> tos;
@NotBlank
private String subject;
@NotBlank
private String content;
}

View File

@@ -1,26 +0,0 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nl.repository;
import org.nl.domain.AlipayConfig;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* @author Zheng Jie
* @date 2018-12-31
*/
public interface AliPayRepository extends JpaRepository<AlipayConfig,Long> {
}

View File

@@ -1,26 +0,0 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nl.repository;
import org.nl.domain.EmailConfig;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* @author Zheng Jie
* @date 2018-12-26
*/
public interface EmailRepository extends JpaRepository<EmailConfig,Long> {
}

View File

@@ -1,135 +0,0 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nl.rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.annotation.AnonymousAccess;
import org.nl.annotation.Log;
import org.nl.annotation.rest.AnonymousGetMapping;
import org.nl.domain.vo.TradeVo;
import org.nl.domain.AlipayConfig;
import org.nl.utils.AliPayStatusEnum;
import org.nl.utils.AlipayUtils;
import org.nl.service.AliPayService;
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.nio.charset.StandardCharsets;
import java.util.Map;
/**
* @author Zheng Jie
* @date 2018-12-31
*/
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/aliPay")
@Api(tags = "工具:支付宝管理")
public class AliPayController {
private final AlipayUtils alipayUtils;
private final AliPayService alipayService;
@GetMapping
public ResponseEntity<AlipayConfig> queryConfig() {
return new ResponseEntity<>(alipayService.find(), HttpStatus.OK);
}
@Log("配置支付宝")
@ApiOperation("配置支付宝")
@PutMapping
public ResponseEntity<Object> updateConfig(@Validated @RequestBody AlipayConfig alipayConfig) {
alipayService.config(alipayConfig);
return new ResponseEntity<>(HttpStatus.OK);
}
@Log("支付宝PC网页支付")
@ApiOperation("PC网页支付")
@PostMapping(value = "/toPayAsPC")
public ResponseEntity<String> toPayAsPc(@Validated @RequestBody TradeVo trade) throws Exception {
AlipayConfig aliPay = alipayService.find();
trade.setOutTradeNo(alipayUtils.getOrderCode());
String payUrl = alipayService.toPayAsPc(aliPay, trade);
return ResponseEntity.ok(payUrl);
}
@Log("支付宝手机网页支付")
@ApiOperation("手机网页支付")
@PostMapping(value = "/toPayAsWeb")
public ResponseEntity<String> toPayAsWeb(@Validated @RequestBody TradeVo trade) throws Exception {
AlipayConfig alipay = alipayService.find();
trade.setOutTradeNo(alipayUtils.getOrderCode());
String payUrl = alipayService.toPayAsWeb(alipay, trade);
return ResponseEntity.ok(payUrl);
}
@ApiIgnore
@AnonymousGetMapping("/return")
@ApiOperation("支付之后跳转的链接")
public ResponseEntity<String> returnPage(HttpServletRequest request, HttpServletResponse response) {
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(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
//支付宝交易号
String tradeNo = new String(request.getParameter("trade_no").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
System.out.println("商户订单号" + outTradeNo + " " + "第三方交易号" + tradeNo);
// 根据业务需要返回数据这里统一返回OK
return new ResponseEntity<>("payment successful", HttpStatus.OK);
} else {
// 根据业务需要返回数据
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}
@ApiIgnore
@RequestMapping("/notify")
@AnonymousAccess
@ApiOperation("支付异步通知(要公网访问)接收异步通知检查通知内容app_id、out_trade_no、total_amount是否与请求中的一致根据trade_status进行后续业务处理")
public ResponseEntity<Object> notify(HttpServletRequest request) {
AlipayConfig alipay = alipayService.find();
Map<String, String[]> parameterMap = request.getParameterMap();
//内容验签,防止黑客篡改参数
if (alipayUtils.rsaCheck(request, alipay)) {
//交易状态
String tradeStatus = new String(request.getParameter("trade_status").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
// 商户订单号
String outTradeNo = new String(request.getParameter("out_trade_no").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
//支付宝交易号
String tradeNo = new String(request.getParameter("trade_no").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
//付款金额
String totalAmount = new String(request.getParameter("total_amount").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
//验证
if (tradeStatus.equals(AliPayStatusEnum.SUCCESS.getValue()) || tradeStatus.equals(AliPayStatusEnum.FINISHED.getValue())) {
// 验证通过后应该根据业务需要处理订单
}
return new ResponseEntity<>(HttpStatus.OK);
}
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}

View File

@@ -1,63 +0,0 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nl.rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.nl.annotation.Log;
import org.nl.domain.vo.EmailVo;
import org.nl.domain.EmailConfig;
import org.nl.service.EmailService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 发送邮件
* @author 郑杰
* @date 2018/09/28 6:55:53
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("api/email")
@Api(tags = "工具:邮件管理")
public class EmailController {
private final EmailService emailService;
@GetMapping
public ResponseEntity<Object> queryConfig(){
return new ResponseEntity<>(emailService.find(),HttpStatus.OK);
}
@Log("配置邮件")
@PutMapping
@ApiOperation("配置邮件")
public ResponseEntity<Object> updateConfig(@Validated @RequestBody EmailConfig emailConfig) throws Exception {
emailService.config(emailConfig,emailService.find());
return new ResponseEntity<>(HttpStatus.OK);
}
@Log("发送邮件")
@PostMapping
@ApiOperation("发送邮件")
public ResponseEntity<Object> sendEmail(@Validated @RequestBody EmailVo emailVo){
emailService.send(emailVo,emailService.find());
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@@ -1,57 +0,0 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nl.service;
import org.nl.domain.vo.TradeVo;
import org.nl.domain.AlipayConfig;
/**
* @author Zheng Jie
* @date 2018-12-31
*/
public interface AliPayService {
/**
* 查询配置
* @return AlipayConfig
*/
AlipayConfig find();
/**
* 更新配置
* @param alipayConfig 支付宝配置
* @return AlipayConfig
*/
AlipayConfig config(AlipayConfig alipayConfig);
/**
* 处理来自PC的交易请求
* @param alipay 支付宝配置
* @param trade 交易详情
* @return String
* @throws Exception 异常
*/
String toPayAsPc(AlipayConfig alipay, TradeVo trade) throws Exception;
/**
* 处理来自手机网页的交易请求
* @param alipay 支付宝配置
* @param trade 交易详情
* @return String
* @throws Exception 异常
*/
String toPayAsWeb(AlipayConfig alipay, TradeVo trade) throws Exception;
}

View File

@@ -1,49 +0,0 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nl.service;
import org.nl.domain.vo.EmailVo;
import org.nl.domain.EmailConfig;
/**
* @author Zheng Jie
* @date 2018-12-26
*/
public interface EmailService {
/**
* 更新邮件配置
* @param emailConfig 邮箱配置
* @param old /
* @return /
* @throws Exception /
*/
EmailConfig config(EmailConfig emailConfig, EmailConfig old) throws Exception;
/**
* 查询配置
* @return EmailConfig 邮件配置
*/
EmailConfig find();
/**
* 发送邮件
* @param emailVo 邮件发送的内容
* @param emailConfig 邮件配置
* @throws Exception /
*/
void send(EmailVo emailVo, EmailConfig emailConfig);
}

View File

@@ -1,119 +0,0 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nl.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 lombok.RequiredArgsConstructor;
import org.nl.domain.vo.TradeVo;
import org.nl.domain.AlipayConfig;
import org.nl.exception.BadRequestException;
import org.nl.repository.AliPayRepository;
import org.nl.service.AliPayService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Optional;
/**
* @author Zheng Jie
* @date 2018-12-31
*/
@Service
@RequiredArgsConstructor
@CacheConfig(cacheNames = "aliPay")
public class AliPayServiceImpl implements AliPayService {
private final AliPayRepository alipayRepository;
@Override
@Cacheable(key = "'config'")
public AlipayConfig find() {
Optional<AlipayConfig> alipayConfig = alipayRepository.findById(1L);
return alipayConfig.orElseGet(AlipayConfig::new);
}
@Override
@CachePut(key = "'config'")
@Transactional(rollbackFor = Exception.class)
public AlipayConfig config(AlipayConfig alipayConfig) {
alipayConfig.setId(1L);
return alipayRepository.save(alipayConfig);
}
@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());
// 创建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());
double maxMoney = 5000;
if(money <= 0 || money >= maxMoney){
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()+"\"" +
" }"+
" }");
return alipayClient.pageExecute(request, "GET").getBody();
}
}

View File

@@ -1,105 +0,0 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nl.service.impl;
import cn.hutool.extra.mail.Mail;
import cn.hutool.extra.mail.MailAccount;
import lombok.RequiredArgsConstructor;
import org.nl.domain.EmailConfig;
import org.nl.domain.vo.EmailVo;
import org.nl.exception.BadRequestException;
import org.nl.repository.EmailRepository;
import org.nl.service.EmailService;
import org.nl.utils.EncryptUtils;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Optional;
/**
* @author Zheng Jie
* @date 2018-12-26
*/
@Service
@RequiredArgsConstructor
@CacheConfig(cacheNames = "email")
public class EmailServiceImpl implements EmailService {
private final EmailRepository emailRepository;
@Override
@CachePut(key = "'config'")
@Transactional(rollbackFor = Exception.class)
public EmailConfig config(EmailConfig emailConfig, EmailConfig old) throws Exception {
emailConfig.setId(1L);
if(!emailConfig.getPass().equals(old.getPass())){
// 对称加密
emailConfig.setPass(EncryptUtils.desEncrypt(emailConfig.getPass()));
}
return emailRepository.save(emailConfig);
}
@Override
@Cacheable(key = "'config'")
public EmailConfig find() {
Optional<EmailConfig> emailConfig = emailRepository.findById(1L);
return emailConfig.orElseGet(EmailConfig::new);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void send(EmailVo emailVo, EmailConfig emailConfig){
if(emailConfig.getId() == null){
throw new BadRequestException("请先配置,再操作");
}
// 封装
MailAccount account = new MailAccount();
// 设置用户
String user = emailConfig.getFromUser().split("@")[0];
account.setUser(user);
account.setHost(emailConfig.getHost());
account.setPort(Integer.parseInt(emailConfig.getPort()));
account.setAuth(true);
try {
// 对称解密
account.setPass(EncryptUtils.desDecrypt(emailConfig.getPass()));
} catch (Exception e) {
throw new BadRequestException(e.getMessage());
}
account.setFrom(emailConfig.getUser()+"<"+emailConfig.getFromUser()+">");
// ssl方式发送
account.setSslEnable(true);
// 使用STARTTLS安全连接
account.setStarttlsEnable(true);
String content = emailVo.getContent();
// 发送
try {
int size = emailVo.getTos().size();
Mail.create(account)
.setTos(emailVo.getTos().toArray(new String[size]))
.setTitle(emailVo.getSubject())
.setContent(content)
.setHtml(true)
//关闭session
.setUseGlobalSession(false)
.send();
}catch (Exception e){
throw new BadRequestException(e.getMessage());
}
}
}

View File

@@ -1,46 +0,0 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nl.utils;
/**
* 支付状态
* @author zhengjie
* @date 2018/08/01 16:45:43
*/
public enum AliPayStatusEnum {
/** 交易成功 */
FINISHED("TRADE_FINISHED"),
/** 支付成功 */
SUCCESS("TRADE_SUCCESS"),
/** 交易创建 */
BUYER_PAY("WAIT_BUYER_PAY"),
/** 交易关闭 */
CLOSED("TRADE_CLOSED");
private final String value;
AliPayStatusEnum(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}

View File

@@ -1,85 +0,0 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nl.utils;
import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;
import org.nl.domain.AlipayConfig;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* 支付宝工具类
* @author zhengjie
* @date 2018/09/30 14:04:35
*/
@Component
public class AlipayUtils {
/**
* 生成订单号
* @return String
*/
public String getOrderCode() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
int a = (int)(Math.random() * 9000.0D) + 1000;
System.out.println(a);
Date date = new Date();
String str = sdf.format(date);
String[] split = str.split("-");
String s = split[0] + split[1] + split[2];
String[] split1 = s.split(" ");
String s1 = split1[0] + split1[1];
String[] split2 = s1.split(":");
return split2[0] + split2[1] + split2[2] + a;
}
/**
* 校验签名
* @param request HttpServletRequest
* @param alipay 阿里云配置
* @return boolean
*/
public boolean rsaCheck(HttpServletRequest request, AlipayConfig alipay){
// 获取支付宝POST过来反馈信息
Map<String,String> params = new HashMap<>(1);
Map<String, String[]> requestParams = request.getParameterMap();
for (Object o : requestParams.keySet()) {
String name = (String) o;
String[] values = requestParams.get(name);
String valueStr = "";
for (int i = 0; i < values.length; i++) {
valueStr = (i == values.length - 1) ? valueStr + values[i]
: valueStr + values[i] + ",";
}
params.put(name, valueStr);
}
try {
return AlipaySignature.rsaCheckV1(params,
alipay.getPublicKey(),
alipay.getCharset(),
alipay.getSignType());
} catch (AlipayApiException e) {
return false;
}
}
}