yshop1.7.2发布:新增小程序支付与登录,后台新增小程序跳转页面,升级swagger-bootstrap,swaager统一配置迁移到common(防止注解冲突)
This commit is contained in:
2
pom.xml
2
pom.xml
@ -129,7 +129,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.xiaoymin</groupId>
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
<artifactId>swagger-bootstrap-ui</artifactId>
|
<artifactId>swagger-bootstrap-ui</artifactId>
|
||||||
<version>1.9.3</version>
|
<version>1.9.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--Mysql依赖包-->
|
<!--Mysql依赖包-->
|
||||||
|
@ -18,12 +18,6 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>co.yixiang</groupId>
|
|
||||||
<artifactId>yshop-common</artifactId>
|
|
||||||
<version>1.7</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>co.yixiang</groupId>
|
<groupId>co.yixiang</groupId>
|
||||||
<artifactId>yshop-tools</artifactId>
|
<artifactId>yshop-tools</artifactId>
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
package co.yixiang.config;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import springfox.documentation.builders.ApiInfoBuilder;
|
|
||||||
import springfox.documentation.builders.PathSelectors;
|
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
||||||
import springfox.documentation.service.ApiInfo;
|
|
||||||
import springfox.documentation.spi.DocumentationType;
|
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName SwaggerConfiguration
|
|
||||||
* @Author hupeng <610796224@qq.com>
|
|
||||||
* @Date 2019/6/28
|
|
||||||
**/
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableSwagger2
|
|
||||||
public class SwaggerConfiguration {
|
|
||||||
@Value("${swagger.enabled}")
|
|
||||||
private Boolean enabled;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Docket createRestApi() {
|
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
|
||||||
.enable(enabled)
|
|
||||||
.apiInfo(apiInfo())
|
|
||||||
.select()
|
|
||||||
.apis(RequestHandlerSelectors.basePackage("co.yixiang.modules"))
|
|
||||||
.paths(PathSelectors.any())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private ApiInfo apiInfo() {
|
|
||||||
return new ApiInfoBuilder()
|
|
||||||
.title("yshop商城移动端API")
|
|
||||||
.description("yshop商城移动端API")
|
|
||||||
.termsOfServiceUrl("http://localhost:8009/api")
|
|
||||||
.contact("610796224@qq.com")
|
|
||||||
.version("1.6")
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
@ -77,6 +77,8 @@ public interface YxStoreOrderService extends BaseService<YxStoreOrder> {
|
|||||||
|
|
||||||
void yuePay(String orderId,int uid);
|
void yuePay(String orderId,int uid);
|
||||||
|
|
||||||
|
WxPayMpOrderResult wxAppPay(String orderId) throws WxPayException;
|
||||||
|
|
||||||
WxPayMpOrderResult wxPay(String orderId) throws WxPayException;
|
WxPayMpOrderResult wxPay(String orderId) throws WxPayException;
|
||||||
|
|
||||||
WxPayMwebOrderResult wxH5Pay(String orderId) throws WxPayException;
|
WxPayMwebOrderResult wxH5Pay(String orderId) throws WxPayException;
|
||||||
|
@ -1042,7 +1042,7 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
|
|||||||
String mchId = RedisUtil.get("wxpay_mchId");
|
String mchId = RedisUtil.get("wxpay_mchId");
|
||||||
String mchKey = RedisUtil.get("wxpay_mchKey");
|
String mchKey = RedisUtil.get("wxpay_mchKey");
|
||||||
if(StrUtil.isBlank(appId) || StrUtil.isBlank(mchId) || StrUtil.isBlank(mchKey)){
|
if(StrUtil.isBlank(appId) || StrUtil.isBlank(mchId) || StrUtil.isBlank(mchKey)){
|
||||||
throw new ErrorRequestException("请配置微信支付");
|
throw new ErrorRequestException("请配置微信支付与公众号appId");
|
||||||
}
|
}
|
||||||
WxPayConfig wxPayConfig = new WxPayConfig();
|
WxPayConfig wxPayConfig = new WxPayConfig();
|
||||||
wxPayConfig.setAppId(appId);
|
wxPayConfig.setAppId(appId);
|
||||||
@ -1073,6 +1073,54 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
|
|||||||
return orderResult;
|
return orderResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小程序支付
|
||||||
|
* @param orderId
|
||||||
|
* @return
|
||||||
|
* @throws WxPayException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public WxPayMpOrderResult wxAppPay(String orderId) throws WxPayException {
|
||||||
|
String apiUrl = systemConfigService.getData("api_url");
|
||||||
|
if(StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址");
|
||||||
|
|
||||||
|
//读取redis配置
|
||||||
|
String appId = RedisUtil.get("wxapp_appId");
|
||||||
|
String mchId = RedisUtil.get("wxpay_mchId");
|
||||||
|
String mchKey = RedisUtil.get("wxpay_mchKey");
|
||||||
|
if(StrUtil.isBlank(appId) || StrUtil.isBlank(mchId) || StrUtil.isBlank(mchKey)){
|
||||||
|
throw new ErrorRequestException("请配置微信支付与小程序appId");
|
||||||
|
}
|
||||||
|
WxPayConfig wxPayConfig = new WxPayConfig();
|
||||||
|
wxPayConfig.setAppId(appId);
|
||||||
|
wxPayConfig.setMchId(mchId);
|
||||||
|
wxPayConfig.setMchKey(mchKey);
|
||||||
|
wxPayService.setConfig(wxPayConfig);
|
||||||
|
|
||||||
|
YxStoreOrderQueryVo orderInfo = getOrderInfo(orderId,0);
|
||||||
|
if(ObjectUtil.isNull(orderInfo)) throw new ErrorRequestException("订单不存在");
|
||||||
|
if(orderInfo.getPaid() == 1) throw new ErrorRequestException("该订单已支付");
|
||||||
|
|
||||||
|
if(orderInfo.getPayPrice().doubleValue() <= 0) throw new ErrorRequestException("该支付无需支付");
|
||||||
|
|
||||||
|
WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
||||||
|
YxWechatUser wechatUser = wechatUserService.getById(orderInfo.getUid());
|
||||||
|
if(ObjectUtil.isNull(wechatUser)) throw new ErrorRequestException("用户错误");
|
||||||
|
orderRequest.setTradeType("JSAPI");
|
||||||
|
orderRequest.setOpenid(wechatUser.getRoutineOpenid());
|
||||||
|
orderRequest.setBody("商品购买");
|
||||||
|
orderRequest.setOutTradeNo(orderId);
|
||||||
|
BigDecimal bigDecimal = new BigDecimal(100);
|
||||||
|
orderRequest.setTotalFee(bigDecimal.multiply(orderInfo.getPayPrice()).intValue());//元转成分
|
||||||
|
orderRequest.setSpbillCreateIp("127.0.0.1");
|
||||||
|
orderRequest.setNotifyUrl(apiUrl+"/api/wechat/notify");
|
||||||
|
|
||||||
|
|
||||||
|
WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest);
|
||||||
|
|
||||||
|
return orderResult;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信支付
|
* 微信支付
|
||||||
* @param orderId
|
* @param orderId
|
||||||
@ -1087,7 +1135,7 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
|
|||||||
String mchId = RedisUtil.get("wxpay_mchId");
|
String mchId = RedisUtil.get("wxpay_mchId");
|
||||||
String mchKey = RedisUtil.get("wxpay_mchKey");
|
String mchKey = RedisUtil.get("wxpay_mchKey");
|
||||||
if(StrUtil.isBlank(appId) || StrUtil.isBlank(mchId) || StrUtil.isBlank(mchKey)){
|
if(StrUtil.isBlank(appId) || StrUtil.isBlank(mchId) || StrUtil.isBlank(mchKey)){
|
||||||
throw new ErrorRequestException("请配置微信支付");
|
throw new ErrorRequestException("请配置微信支付与公众号appId");
|
||||||
}
|
}
|
||||||
WxPayConfig wxPayConfig = new WxPayConfig();
|
WxPayConfig wxPayConfig = new WxPayConfig();
|
||||||
wxPayConfig.setAppId(appId);
|
wxPayConfig.setAppId(appId);
|
||||||
|
@ -248,6 +248,19 @@ public class StoreOrderController extends BaseController {
|
|||||||
map.put("result",orderDTO);
|
map.put("result",orderDTO);
|
||||||
map.put("status","WECHAT_H5_PAY");
|
map.put("status","WECHAT_H5_PAY");
|
||||||
return ApiResult.ok(map);
|
return ApiResult.ok(map);
|
||||||
|
}else if(param.getFrom().equals("routine")){
|
||||||
|
map.put("status","WECHAT_PAY");
|
||||||
|
WxPayMpOrderResult wxPayMpOrderResult = storeOrderService
|
||||||
|
.wxAppPay(orderId);
|
||||||
|
jsConfig.put("appId",wxPayMpOrderResult.getAppId());
|
||||||
|
jsConfig.put("timeStamp",wxPayMpOrderResult.getTimeStamp());
|
||||||
|
jsConfig.put("nonceStr",wxPayMpOrderResult.getNonceStr());
|
||||||
|
jsConfig.put("package",wxPayMpOrderResult.getPackageValue());
|
||||||
|
jsConfig.put("signType",wxPayMpOrderResult.getSignType());
|
||||||
|
jsConfig.put("paySign",wxPayMpOrderResult.getPaySign());
|
||||||
|
orderDTO.setJsConfig(jsConfig);
|
||||||
|
map.put("result",orderDTO);
|
||||||
|
return ApiResult.ok(map,"订单创建成功");
|
||||||
}else{
|
}else{
|
||||||
map.put("status","WECHAT_PAY");
|
map.put("status","WECHAT_PAY");
|
||||||
WxPayMpOrderResult wxPayMpOrderResult = storeOrderService
|
WxPayMpOrderResult wxPayMpOrderResult = storeOrderService
|
||||||
|
@ -92,6 +92,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
).anonymous()
|
).anonymous()
|
||||||
|
|
||||||
.antMatchers( HttpMethod.POST,"/"+loginPath).anonymous()
|
.antMatchers( HttpMethod.POST,"/"+loginPath).anonymous()
|
||||||
|
.antMatchers( HttpMethod.POST,"/wxapp/auth").anonymous()
|
||||||
//首页
|
//首页
|
||||||
.antMatchers("/index").anonymous()
|
.antMatchers("/index").anonymous()
|
||||||
.antMatchers("/article/**").anonymous()
|
.antMatchers("/article/**").anonymous()
|
||||||
|
@ -108,9 +108,6 @@ public class WechatController extends BaseController {
|
|||||||
@ApiOperation(value = "微信授权",notes = "微信授权")
|
@ApiOperation(value = "微信授权",notes = "微信授权")
|
||||||
public ApiResult<Object> authLogin(@RequestParam(value = "code") String code,
|
public ApiResult<Object> authLogin(@RequestParam(value = "code") String code,
|
||||||
@RequestParam(value = "spread") String spread) {
|
@RequestParam(value = "spread") String spread) {
|
||||||
//todo 分销人
|
|
||||||
//String url = "https://h5.dayouqiantu.cn/";
|
|
||||||
//wxService.oauth2buildAuthorizationUrl(url, WxConsts.OAuth2Scope.SNSAPI_USERINFO, null);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = wxService.oauth2getAccessToken(code);
|
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = wxService.oauth2getAccessToken(code);
|
||||||
|
@ -20,6 +20,7 @@ import co.yixiang.modules.user.web.vo.YxUserQueryVo;
|
|||||||
import co.yixiang.utils.EncryptUtils;
|
import co.yixiang.utils.EncryptUtils;
|
||||||
import co.yixiang.utils.OrderUtil;
|
import co.yixiang.utils.OrderUtil;
|
||||||
import co.yixiang.utils.RedisUtil;
|
import co.yixiang.utils.RedisUtil;
|
||||||
|
import com.vdurmont.emoji.EmojiParser;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -62,14 +63,14 @@ public class WxMaUserController {
|
|||||||
/**
|
/**
|
||||||
* 小程序登陆接口
|
* 小程序登陆接口
|
||||||
*/
|
*/
|
||||||
@PostMapping("/wechat/mp_auth")
|
@PostMapping("/wxapp/auth")
|
||||||
@ApiOperation(value = "小程序登陆",notes = "小程序登陆")
|
@ApiOperation(value = "小程序登陆",notes = "小程序登陆")
|
||||||
public ApiResult<Object> login(@RequestParam(value = "code") String code,
|
public ApiResult<Object> login(@RequestParam(value = "code") String code,
|
||||||
@RequestParam(value = "spread") String spread,
|
@RequestParam(value = "spread") String spread,
|
||||||
@RequestParam(value = "encryptedData") String encryptedData,
|
@RequestParam(value = "encryptedData") String encryptedData,
|
||||||
@RequestParam(value = "iv") String iv ) {
|
@RequestParam(value = "iv") String iv ) {
|
||||||
if (StringUtils.isBlank(code)) {
|
if (StringUtils.isBlank(code)) {
|
||||||
return ApiResult.fail("empty jscode");
|
return ApiResult.fail("请传code");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
//读取redis配置
|
//读取redis配置
|
||||||
@ -78,12 +79,12 @@ public class WxMaUserController {
|
|||||||
if(StrUtil.isBlank(appId) || StrUtil.isBlank(secret)){
|
if(StrUtil.isBlank(appId) || StrUtil.isBlank(secret)){
|
||||||
throw new ErrorRequestException("请先配置小程序");
|
throw new ErrorRequestException("请先配置小程序");
|
||||||
}
|
}
|
||||||
WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
|
WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
|
||||||
wxMaConfig.setAppid(appId);
|
wxMaConfig.setAppid(appId);
|
||||||
wxMaConfig.setSecret(secret);
|
wxMaConfig.setSecret(secret);
|
||||||
|
|
||||||
|
|
||||||
wxMaService.setWxMaConfig(wxMaConfig);
|
wxMaService.setWxMaConfig(wxMaConfig);
|
||||||
WxMaJscode2SessionResult session = wxMaService.getUserService().getSessionInfo(code);
|
WxMaJscode2SessionResult session = wxMaService.getUserService().getSessionInfo(code);
|
||||||
YxWechatUser wechatUser = wechatUserService.getUserInfo(session.getOpenid());;
|
YxWechatUser wechatUser = wechatUserService.getUserInfo(session.getOpenid());;
|
||||||
JwtUser jwtUser = null;
|
JwtUser jwtUser = null;
|
||||||
@ -104,17 +105,19 @@ public class WxMaUserController {
|
|||||||
}else{
|
}else{
|
||||||
WxMaUserInfo wxMpUser = wxMaService.getUserService()
|
WxMaUserInfo wxMpUser = wxMaService.getUserService()
|
||||||
.getUserInfo(session.getSessionKey(), encryptedData, iv);
|
.getUserInfo(session.getSessionKey(), encryptedData, iv);
|
||||||
|
//过滤掉表情
|
||||||
|
String nickname = EmojiParser.removeAllEmojis(wxMpUser.getNickName());
|
||||||
//用户保存
|
//用户保存
|
||||||
YxUser user = new YxUser();
|
YxUser user = new YxUser();
|
||||||
user.setAccount(wxMpUser.getNickName());
|
user.setAccount(nickname);
|
||||||
user.setUsername(wxMpUser.getOpenId());
|
user.setUsername(wxMpUser.getOpenId());
|
||||||
user.setPassword(EncryptUtils.encryptPassword("123456"));
|
user.setPassword(EncryptUtils.encryptPassword("123456"));
|
||||||
user.setPwd(EncryptUtils.encryptPassword("123456"));
|
user.setPwd(EncryptUtils.encryptPassword("123456"));
|
||||||
user.setPhone("");
|
user.setPhone("");
|
||||||
user.setUserType("wechat");
|
user.setUserType("routine");
|
||||||
user.setAddTime(OrderUtil.getSecondTimestampTwo());
|
user.setAddTime(OrderUtil.getSecondTimestampTwo());
|
||||||
user.setLastTime(OrderUtil.getSecondTimestampTwo());
|
user.setLastTime(OrderUtil.getSecondTimestampTwo());
|
||||||
user.setNickname(wxMpUser.getNickName());
|
user.setNickname(nickname);
|
||||||
user.setAvatar(wxMpUser.getAvatarUrl());
|
user.setAvatar(wxMpUser.getAvatarUrl());
|
||||||
user.setNowMoney(BigDecimal.ZERO);
|
user.setNowMoney(BigDecimal.ZERO);
|
||||||
user.setBrokeragePrice(BigDecimal.ZERO);
|
user.setBrokeragePrice(BigDecimal.ZERO);
|
||||||
@ -127,8 +130,8 @@ public class WxMaUserController {
|
|||||||
YxWechatUser yxWechatUser = new YxWechatUser();
|
YxWechatUser yxWechatUser = new YxWechatUser();
|
||||||
// System.out.println("wxMpUser:"+wxMpUser);
|
// System.out.println("wxMpUser:"+wxMpUser);
|
||||||
yxWechatUser.setAddTime(OrderUtil.getSecondTimestampTwo());
|
yxWechatUser.setAddTime(OrderUtil.getSecondTimestampTwo());
|
||||||
yxWechatUser.setNickname(wxMpUser.getNickName());
|
yxWechatUser.setNickname(nickname);
|
||||||
yxWechatUser.setOpenid(wxMpUser.getOpenId());
|
yxWechatUser.setRoutineOpenid(wxMpUser.getOpenId());
|
||||||
int sub = 0;
|
int sub = 0;
|
||||||
yxWechatUser.setSubscribe(sub);
|
yxWechatUser.setSubscribe(sub);
|
||||||
yxWechatUser.setSex(Integer.valueOf(wxMpUser.getGender()));
|
yxWechatUser.setSex(Integer.valueOf(wxMpUser.getGender()));
|
||||||
@ -150,7 +153,7 @@ public class WxMaUserController {
|
|||||||
|
|
||||||
|
|
||||||
//设置推广关系
|
//设置推广关系
|
||||||
if(StrUtil.isNotEmpty(spread) && !spread.equals("NaN")){
|
if(StrUtil.isNotEmpty(spread)){
|
||||||
//System.out.println("spread:"+spread);
|
//System.out.println("spread:"+spread);
|
||||||
userService.setSpread(Integer.valueOf(spread),
|
userService.setSpread(Integer.valueOf(spread),
|
||||||
jwtUser.getId().intValue());
|
jwtUser.getId().intValue());
|
||||||
|
@ -55,6 +55,8 @@ spring:
|
|||||||
jwt:
|
jwt:
|
||||||
header: Authorization
|
header: Authorization
|
||||||
secret: JBqNQX7HD9xhwHP7
|
secret: JBqNQX7HD9xhwHP7
|
||||||
|
# 令牌前缀
|
||||||
|
token-start-with: Bearer
|
||||||
# token 过期时间 6个小时
|
# token 过期时间 6个小时
|
||||||
expiration: 210000000
|
expiration: 210000000
|
||||||
# 在线用户key
|
# 在线用户key
|
||||||
@ -65,13 +67,13 @@ jwt:
|
|||||||
# 获取用户信息
|
# 获取用户信息
|
||||||
account: /info
|
account: /info
|
||||||
|
|
||||||
#是否允许生成代码,生产环境设置为false
|
|
||||||
generator:
|
|
||||||
enabled: true
|
|
||||||
|
|
||||||
#是否开启 swagger-ui
|
#是否开启 swagger-ui
|
||||||
swagger:
|
swagger:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
title: yshop商城移动端API
|
||||||
|
serverUrl: http://localhost:8009
|
||||||
|
version: 1.7
|
||||||
|
|
||||||
# 文件存储路径
|
# 文件存储路径
|
||||||
file:
|
file:
|
||||||
|
@ -56,6 +56,8 @@ spring:
|
|||||||
jwt:
|
jwt:
|
||||||
header: Authorization
|
header: Authorization
|
||||||
secret: JBqNQX7HD9xhwHP7YSHOP
|
secret: JBqNQX7HD9xhwHP7YSHOP
|
||||||
|
# 令牌前缀
|
||||||
|
token-start-with: Bearer
|
||||||
# token 过期时间 2个小时
|
# token 过期时间 2个小时
|
||||||
expiration: 7200000
|
expiration: 7200000
|
||||||
# 在线用户key
|
# 在线用户key
|
||||||
@ -79,7 +81,10 @@ generator:
|
|||||||
|
|
||||||
#是否开启 swagger-ui
|
#是否开启 swagger-ui
|
||||||
swagger:
|
swagger:
|
||||||
enabled: false
|
enabled: true
|
||||||
|
title: yshop商城移动端API
|
||||||
|
serverUrl: http://localhost:8009
|
||||||
|
version: 1.7
|
||||||
|
|
||||||
# 文件存储路径
|
# 文件存储路径
|
||||||
file:
|
file:
|
||||||
|
126
yshop-common/src/main/java/co/yixiang/config/SwaggerConfig.java
Normal file
126
yshop-common/src/main/java/co/yixiang/config/SwaggerConfig.java
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
package co.yixiang.config;
|
||||||
|
|
||||||
|
import com.fasterxml.classmate.TypeResolver;
|
||||||
|
import com.google.common.base.Predicates;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.Ordered;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import springfox.documentation.builders.ApiInfoBuilder;
|
||||||
|
import springfox.documentation.builders.ParameterBuilder;
|
||||||
|
import springfox.documentation.builders.PathSelectors;
|
||||||
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||||
|
import springfox.documentation.schema.AlternateTypeRule;
|
||||||
|
import springfox.documentation.schema.AlternateTypeRuleConvention;
|
||||||
|
import springfox.documentation.schema.ModelRef;
|
||||||
|
import springfox.documentation.service.ApiInfo;
|
||||||
|
import springfox.documentation.service.Parameter;
|
||||||
|
import springfox.documentation.spi.DocumentationType;
|
||||||
|
import springfox.documentation.spring.web.plugins.Docket;
|
||||||
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import static com.google.common.collect.Lists.newArrayList;
|
||||||
|
import static springfox.documentation.schema.AlternateTypeRules.newRule;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* api页面 /doc.html
|
||||||
|
* @Author hupeng <610796224@qq.com>
|
||||||
|
* @Date 2019/1/9
|
||||||
|
**/
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableSwagger2
|
||||||
|
public class SwaggerConfig {
|
||||||
|
|
||||||
|
@Value("${jwt.header}")
|
||||||
|
private String tokenHeader;
|
||||||
|
|
||||||
|
@Value("${jwt.token-start-with}")
|
||||||
|
private String tokenStartWith;
|
||||||
|
|
||||||
|
@Value("${swagger.enabled}")
|
||||||
|
private Boolean enabled;
|
||||||
|
|
||||||
|
@Value("${swagger.title}")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Value("${swagger.version}")
|
||||||
|
private String version;
|
||||||
|
|
||||||
|
@Value("${swagger.serverUrl}")
|
||||||
|
private String serverUrl;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
public Docket createRestApi() {
|
||||||
|
ParameterBuilder ticketPar = new ParameterBuilder();
|
||||||
|
List<Parameter> pars = new ArrayList<>();
|
||||||
|
ticketPar.name(tokenHeader).description("token")
|
||||||
|
.modelRef(new ModelRef("string"))
|
||||||
|
.parameterType("header")
|
||||||
|
.defaultValue(tokenStartWith + " ")
|
||||||
|
.required(true)
|
||||||
|
.build();
|
||||||
|
pars.add(ticketPar.build());
|
||||||
|
return new Docket(DocumentationType.SWAGGER_2)
|
||||||
|
.enable(enabled)
|
||||||
|
.apiInfo(apiInfo())
|
||||||
|
.select()
|
||||||
|
.apis(RequestHandlerSelectors.basePackage("co.yixiang.modules"))
|
||||||
|
.paths(Predicates.not(PathSelectors.regex("/error.*")))
|
||||||
|
.build()
|
||||||
|
.globalOperationParameters(pars);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ApiInfo apiInfo() {
|
||||||
|
return new ApiInfoBuilder()
|
||||||
|
.title(title)
|
||||||
|
.termsOfServiceUrl(serverUrl)
|
||||||
|
.description(title)
|
||||||
|
.version(version)
|
||||||
|
.contact("610796224@qq.com")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将Pageable转换展示在swagger中
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
class SwaggerDataConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public AlternateTypeRuleConvention pageableConvention(final TypeResolver resolver) {
|
||||||
|
return new AlternateTypeRuleConvention() {
|
||||||
|
@Override
|
||||||
|
public int getOrder() {
|
||||||
|
return Ordered.HIGHEST_PRECEDENCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AlternateTypeRule> rules() {
|
||||||
|
return newArrayList(newRule(resolver.resolve(Pageable.class), resolver.resolve(Page.class)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiModel
|
||||||
|
@Data
|
||||||
|
private static class Page {
|
||||||
|
@ApiModelProperty("页码 (0..N)")
|
||||||
|
private Integer page;
|
||||||
|
|
||||||
|
@ApiModelProperty("每页显示的数目")
|
||||||
|
private Integer size;
|
||||||
|
|
||||||
|
@ApiModelProperty("以下列格式排序标准:property[,asc | desc]。 默认排序顺序为升序。 支持多种排序条件:如:id,asc")
|
||||||
|
private List<String> sort;
|
||||||
|
}
|
||||||
|
}
|
@ -1,45 +0,0 @@
|
|||||||
package co.yixiang.modules.security.config;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import springfox.documentation.builders.ApiInfoBuilder;
|
|
||||||
import springfox.documentation.builders.PathSelectors;
|
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
||||||
import springfox.documentation.service.ApiInfo;
|
|
||||||
import springfox.documentation.spi.DocumentationType;
|
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName SwaggerConfiguration
|
|
||||||
* @Author hupeng <610796224@qq.com>
|
|
||||||
* @Date 2019/6/28
|
|
||||||
**/
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableSwagger2
|
|
||||||
public class SwaggerConfiguration {
|
|
||||||
@Value("${swagger.enabled}")
|
|
||||||
private Boolean enabled;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Docket createRestApi() {
|
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
|
||||||
.apiInfo(apiInfo())
|
|
||||||
.select()
|
|
||||||
.apis(RequestHandlerSelectors.basePackage("co.yixiang.modules"))
|
|
||||||
.paths(PathSelectors.any())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private ApiInfo apiInfo() {
|
|
||||||
return new ApiInfoBuilder()
|
|
||||||
.title("yshop商城管理后台API")
|
|
||||||
.description("yshop商城管理后台API")
|
|
||||||
.termsOfServiceUrl("http://localhost:8000")
|
|
||||||
.contact("610796224@qq.com")
|
|
||||||
.version("1.6")
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
@ -74,6 +74,9 @@ generator:
|
|||||||
#是否开启 swagger-ui
|
#是否开启 swagger-ui
|
||||||
swagger:
|
swagger:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
title: yshop商城管理后台API
|
||||||
|
serverUrl: http://localhost:8000
|
||||||
|
version: 1.7
|
||||||
|
|
||||||
# 文件存储路径
|
# 文件存储路径
|
||||||
file:
|
file:
|
||||||
|
@ -78,7 +78,10 @@ generator:
|
|||||||
|
|
||||||
#是否开启 swagger-ui
|
#是否开启 swagger-ui
|
||||||
swagger:
|
swagger:
|
||||||
enabled: false
|
enabled: true
|
||||||
|
title: yshop商城管理后台API
|
||||||
|
serverUrl: http://localhost:8000
|
||||||
|
version: 1.7
|
||||||
|
|
||||||
# 文件存储路径
|
# 文件存储路径
|
||||||
file:
|
file:
|
||||||
|
Reference in New Issue
Block a user