yshop1.7.2发布:新增小程序支付与登录,后台新增小程序跳转页面,升级swagger-bootstrap,swaager统一配置迁移到common(防止注解冲突)

This commit is contained in:
hupeng
2020-01-09 16:09:50 +08:00
parent ebaee90bd9
commit 5c88f8281f
15 changed files with 224 additions and 118 deletions

View File

@ -129,7 +129,7 @@
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.3</version>
<version>1.9.6</version>
</dependency>
<!--Mysql依赖包-->

View File

@ -18,12 +18,6 @@
</properties>
<dependencies>
<dependency>
<groupId>co.yixiang</groupId>
<artifactId>yshop-common</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>co.yixiang</groupId>
<artifactId>yshop-tools</artifactId>

View File

@ -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();
}
}

View File

@ -77,6 +77,8 @@ public interface YxStoreOrderService extends BaseService<YxStoreOrder> {
void yuePay(String orderId,int uid);
WxPayMpOrderResult wxAppPay(String orderId) throws WxPayException;
WxPayMpOrderResult wxPay(String orderId) throws WxPayException;
WxPayMwebOrderResult wxH5Pay(String orderId) throws WxPayException;

View File

@ -1042,7 +1042,7 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
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("请配置微信支付");
throw new ErrorRequestException("请配置微信支付与公众号appId");
}
WxPayConfig wxPayConfig = new WxPayConfig();
wxPayConfig.setAppId(appId);
@ -1073,6 +1073,54 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
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
@ -1087,7 +1135,7 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
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("请配置微信支付");
throw new ErrorRequestException("请配置微信支付与公众号appId");
}
WxPayConfig wxPayConfig = new WxPayConfig();
wxPayConfig.setAppId(appId);

View File

@ -248,6 +248,19 @@ public class StoreOrderController extends BaseController {
map.put("result",orderDTO);
map.put("status","WECHAT_H5_PAY");
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{
map.put("status","WECHAT_PAY");
WxPayMpOrderResult wxPayMpOrderResult = storeOrderService

View File

@ -92,6 +92,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
).anonymous()
.antMatchers( HttpMethod.POST,"/"+loginPath).anonymous()
.antMatchers( HttpMethod.POST,"/wxapp/auth").anonymous()
//首页
.antMatchers("/index").anonymous()
.antMatchers("/article/**").anonymous()

View File

@ -108,9 +108,6 @@ public class WechatController extends BaseController {
@ApiOperation(value = "微信授权",notes = "微信授权")
public ApiResult<Object> 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);

View File

@ -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<Object> 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());

View File

@ -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:

View File

@ -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:

View 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;
}
}

View File

@ -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();
}
}

View File

@ -74,6 +74,9 @@ generator:
#是否开启 swagger-ui
swagger:
enabled: true
title: yshop商城管理后台API
serverUrl: http://localhost:8000
version: 1.7
# 文件存储路径
file:

View File

@ -78,7 +78,10 @@ generator:
#是否开启 swagger-ui
swagger:
enabled: false
enabled: true
title: yshop商城管理后台API
serverUrl: http://localhost:8000
version: 1.7
# 文件存储路径
file: