From 5c88f8281f2546e1807c5f958d99c4fddcd10c62 Mon Sep 17 00:00:00 2001 From: hupeng Date: Thu, 9 Jan 2020 16:09:50 +0800 Subject: [PATCH] =?UTF-8?q?yshop1.7.2=E5=8F=91=E5=B8=83:=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=94=AF=E4=BB=98=E4=B8=8E=E7=99=BB?= =?UTF-8?q?=E5=BD=95,=E5=90=8E=E5=8F=B0=E6=96=B0=E5=A2=9E=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E8=B7=B3=E8=BD=AC=E9=A1=B5=E9=9D=A2,?= =?UTF-8?q?=E5=8D=87=E7=BA=A7swagger-bootstrap,swaager=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=BF=81=E7=A7=BB=E5=88=B0common(=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E6=B3=A8=E8=A7=A3=E5=86=B2=E7=AA=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- yshop-api/pom.xml | 6 - .../yixiang/config/SwaggerConfiguration.java | 46 ------- .../order/service/YxStoreOrderService.java | 2 + .../service/impl/YxStoreOrderServiceImpl.java | 52 +++++++- .../web/controller/StoreOrderController.java | 13 ++ .../security/config/SecurityConfig.java | 1 + .../web/controller/WechatController.java | 3 - .../web/controller/WxMaUserController.java | 23 ++-- .../main/resources/config/application-dev.yml | 8 +- .../resources/config/application-prod.yml | 7 +- .../java/co/yixiang/config/SwaggerConfig.java | 126 ++++++++++++++++++ .../security/config/SwaggerConfiguration.java | 45 ------- .../main/resources/config/application-dev.yml | 3 + .../resources/config/application-prod.yml | 5 +- 15 files changed, 224 insertions(+), 118 deletions(-) delete mode 100644 yshop-api/src/main/java/co/yixiang/config/SwaggerConfiguration.java create mode 100644 yshop-common/src/main/java/co/yixiang/config/SwaggerConfig.java delete mode 100644 yshop-system/src/main/java/co/yixiang/modules/security/config/SwaggerConfiguration.java diff --git a/pom.xml b/pom.xml index ede5a350..ef6ba298 100644 --- a/pom.xml +++ b/pom.xml @@ -129,7 +129,7 @@ com.github.xiaoymin swagger-bootstrap-ui - 1.9.3 + 1.9.6 diff --git a/yshop-api/pom.xml b/yshop-api/pom.xml index 7876600e..ee0c6704 100644 --- a/yshop-api/pom.xml +++ b/yshop-api/pom.xml @@ -18,12 +18,6 @@ - - co.yixiang - yshop-common - 1.7 - - co.yixiang yshop-tools diff --git a/yshop-api/src/main/java/co/yixiang/config/SwaggerConfiguration.java b/yshop-api/src/main/java/co/yixiang/config/SwaggerConfiguration.java deleted file mode 100644 index 7f8034b9..00000000 --- a/yshop-api/src/main/java/co/yixiang/config/SwaggerConfiguration.java +++ /dev/null @@ -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(); - } -} diff --git a/yshop-api/src/main/java/co/yixiang/modules/order/service/YxStoreOrderService.java b/yshop-api/src/main/java/co/yixiang/modules/order/service/YxStoreOrderService.java index c40f0902..8a17cc7f 100644 --- a/yshop-api/src/main/java/co/yixiang/modules/order/service/YxStoreOrderService.java +++ b/yshop-api/src/main/java/co/yixiang/modules/order/service/YxStoreOrderService.java @@ -77,6 +77,8 @@ public interface YxStoreOrderService extends BaseService { void yuePay(String orderId,int uid); + WxPayMpOrderResult wxAppPay(String orderId) throws WxPayException; + WxPayMpOrderResult wxPay(String orderId) throws WxPayException; WxPayMwebOrderResult wxH5Pay(String orderId) throws WxPayException; diff --git a/yshop-api/src/main/java/co/yixiang/modules/order/service/impl/YxStoreOrderServiceImpl.java b/yshop-api/src/main/java/co/yixiang/modules/order/service/impl/YxStoreOrderServiceImpl.java index 02969720..4cb038a3 100644 --- a/yshop-api/src/main/java/co/yixiang/modules/order/service/impl/YxStoreOrderServiceImpl.java +++ b/yshop-api/src/main/java/co/yixiang/modules/order/service/impl/YxStoreOrderServiceImpl.java @@ -1042,7 +1042,7 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl authLogin(@RequestParam(value = "code") String code, @RequestParam(value = "spread") String spread) { - //todo 分销人 - //String url = "https://h5.dayouqiantu.cn/"; - //wxService.oauth2buildAuthorizationUrl(url, WxConsts.OAuth2Scope.SNSAPI_USERINFO, null); try { WxMpOAuth2AccessToken wxMpOAuth2AccessToken = wxService.oauth2getAccessToken(code); diff --git a/yshop-api/src/main/java/co/yixiang/modules/wechat/web/controller/WxMaUserController.java b/yshop-api/src/main/java/co/yixiang/modules/wechat/web/controller/WxMaUserController.java index dc857274..e04e66b3 100644 --- a/yshop-api/src/main/java/co/yixiang/modules/wechat/web/controller/WxMaUserController.java +++ b/yshop-api/src/main/java/co/yixiang/modules/wechat/web/controller/WxMaUserController.java @@ -20,6 +20,7 @@ import co.yixiang.modules.user.web.vo.YxUserQueryVo; import co.yixiang.utils.EncryptUtils; import co.yixiang.utils.OrderUtil; import co.yixiang.utils.RedisUtil; +import com.vdurmont.emoji.EmojiParser; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -62,14 +63,14 @@ public class WxMaUserController { /** * 小程序登陆接口 */ - @PostMapping("/wechat/mp_auth") + @PostMapping("/wxapp/auth") @ApiOperation(value = "小程序登陆",notes = "小程序登陆") public ApiResult login(@RequestParam(value = "code") String code, @RequestParam(value = "spread") String spread, @RequestParam(value = "encryptedData") String encryptedData, @RequestParam(value = "iv") String iv ) { if (StringUtils.isBlank(code)) { - return ApiResult.fail("empty jscode"); + return ApiResult.fail("请传code"); } try { //读取redis配置 @@ -78,12 +79,12 @@ public class WxMaUserController { if(StrUtil.isBlank(appId) || StrUtil.isBlank(secret)){ throw new ErrorRequestException("请先配置小程序"); } - WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl(); + WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl(); wxMaConfig.setAppid(appId); wxMaConfig.setSecret(secret); - wxMaService.setWxMaConfig(wxMaConfig); + wxMaService.setWxMaConfig(wxMaConfig); WxMaJscode2SessionResult session = wxMaService.getUserService().getSessionInfo(code); YxWechatUser wechatUser = wechatUserService.getUserInfo(session.getOpenid());; JwtUser jwtUser = null; @@ -104,17 +105,19 @@ public class WxMaUserController { }else{ WxMaUserInfo wxMpUser = wxMaService.getUserService() .getUserInfo(session.getSessionKey(), encryptedData, iv); + //过滤掉表情 + String nickname = EmojiParser.removeAllEmojis(wxMpUser.getNickName()); //用户保存 YxUser user = new YxUser(); - user.setAccount(wxMpUser.getNickName()); + user.setAccount(nickname); user.setUsername(wxMpUser.getOpenId()); user.setPassword(EncryptUtils.encryptPassword("123456")); user.setPwd(EncryptUtils.encryptPassword("123456")); user.setPhone(""); - user.setUserType("wechat"); + user.setUserType("routine"); user.setAddTime(OrderUtil.getSecondTimestampTwo()); user.setLastTime(OrderUtil.getSecondTimestampTwo()); - user.setNickname(wxMpUser.getNickName()); + user.setNickname(nickname); user.setAvatar(wxMpUser.getAvatarUrl()); user.setNowMoney(BigDecimal.ZERO); user.setBrokeragePrice(BigDecimal.ZERO); @@ -127,8 +130,8 @@ public class WxMaUserController { YxWechatUser yxWechatUser = new YxWechatUser(); // System.out.println("wxMpUser:"+wxMpUser); yxWechatUser.setAddTime(OrderUtil.getSecondTimestampTwo()); - yxWechatUser.setNickname(wxMpUser.getNickName()); - yxWechatUser.setOpenid(wxMpUser.getOpenId()); + yxWechatUser.setNickname(nickname); + yxWechatUser.setRoutineOpenid(wxMpUser.getOpenId()); int sub = 0; yxWechatUser.setSubscribe(sub); 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); userService.setSpread(Integer.valueOf(spread), jwtUser.getId().intValue()); diff --git a/yshop-api/src/main/resources/config/application-dev.yml b/yshop-api/src/main/resources/config/application-dev.yml index ea0764fb..d69f2523 100644 --- a/yshop-api/src/main/resources/config/application-dev.yml +++ b/yshop-api/src/main/resources/config/application-dev.yml @@ -55,6 +55,8 @@ spring: jwt: header: Authorization secret: JBqNQX7HD9xhwHP7 + # 令牌前缀 + token-start-with: Bearer # token 过期时间 6个小时 expiration: 210000000 # 在线用户key @@ -65,13 +67,13 @@ jwt: # 获取用户信息 account: /info -#是否允许生成代码,生产环境设置为false -generator: - enabled: true #是否开启 swagger-ui swagger: enabled: true + title: yshop商城移动端API + serverUrl: http://localhost:8009 + version: 1.7 # 文件存储路径 file: diff --git a/yshop-api/src/main/resources/config/application-prod.yml b/yshop-api/src/main/resources/config/application-prod.yml index d12e0dd5..c95d2235 100644 --- a/yshop-api/src/main/resources/config/application-prod.yml +++ b/yshop-api/src/main/resources/config/application-prod.yml @@ -56,6 +56,8 @@ spring: jwt: header: Authorization secret: JBqNQX7HD9xhwHP7YSHOP + # 令牌前缀 + token-start-with: Bearer # token 过期时间 2个小时 expiration: 7200000 # 在线用户key @@ -79,7 +81,10 @@ generator: #是否开启 swagger-ui swagger: - enabled: false + enabled: true + title: yshop商城移动端API + serverUrl: http://localhost:8009 + version: 1.7 # 文件存储路径 file: diff --git a/yshop-common/src/main/java/co/yixiang/config/SwaggerConfig.java b/yshop-common/src/main/java/co/yixiang/config/SwaggerConfig.java new file mode 100644 index 00000000..30f1a19d --- /dev/null +++ b/yshop-common/src/main/java/co/yixiang/config/SwaggerConfig.java @@ -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 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 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 sort; + } +} diff --git a/yshop-system/src/main/java/co/yixiang/modules/security/config/SwaggerConfiguration.java b/yshop-system/src/main/java/co/yixiang/modules/security/config/SwaggerConfiguration.java deleted file mode 100644 index 5153bde5..00000000 --- a/yshop-system/src/main/java/co/yixiang/modules/security/config/SwaggerConfiguration.java +++ /dev/null @@ -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(); - } -} diff --git a/yshop-system/src/main/resources/config/application-dev.yml b/yshop-system/src/main/resources/config/application-dev.yml index af30a6bc..af17854e 100644 --- a/yshop-system/src/main/resources/config/application-dev.yml +++ b/yshop-system/src/main/resources/config/application-dev.yml @@ -74,6 +74,9 @@ generator: #是否开启 swagger-ui swagger: enabled: true + title: yshop商城管理后台API + serverUrl: http://localhost:8000 + version: 1.7 # 文件存储路径 file: diff --git a/yshop-system/src/main/resources/config/application-prod.yml b/yshop-system/src/main/resources/config/application-prod.yml index 35e42d2b..6054d2e6 100644 --- a/yshop-system/src/main/resources/config/application-prod.yml +++ b/yshop-system/src/main/resources/config/application-prod.yml @@ -78,7 +78,10 @@ generator: #是否开启 swagger-ui swagger: - enabled: false + enabled: true + title: yshop商城管理后台API + serverUrl: http://localhost:8000 + version: 1.7 # 文件存储路径 file: