yshop1.7.2发布:新增小程序支付与登录,后台新增小程序跳转页面,升级swagger-bootstrap,swaager统一配置迁移到common(防止注解冲突)
This commit is contained in:
@ -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);
|
||||
|
||||
WxPayMpOrderResult wxAppPay(String orderId) throws WxPayException;
|
||||
|
||||
WxPayMpOrderResult wxPay(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 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);
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
Reference in New Issue
Block a user