Commit 654c19e2 authored by liuyang's avatar liuyang

update

parent dc174da3
......@@ -232,11 +232,11 @@
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.github.binarywang</groupId>-->
<!-- <artifactId>weixin-java-mp</artifactId>-->
<!-- <version>${weixin-java.version}</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-mp</artifactId>
<version>${weixin-java.version}</version>
</dependency>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-miniapp</artifactId>
......
......@@ -22,7 +22,7 @@ public class PriceConfigController {
@ApiOperation("获取系统价格配置")
@GetMapping("/get")
@RequiresRoles(value = {BizConstants.ROLE_ADMIN,BizConstants.ROLE_OPERATOR},logical = Logical.OR)
@RequiresRoles(value = {BizConstants.ROLE_ADMIN,BizConstants.ROLE_OPERATOR,BizConstants.ROLE_USER,BizConstants.ROLE_ENTERPRISE_ADMIN},logical = Logical.OR)
public Result<PriceConfigModel> get() {
return Result.succeed(priceConfigService.findConfig());
}
......
......@@ -74,7 +74,7 @@ public class ProductOrderService extends ServiceImpl<ProductOrderMapper, Product
return dateStr + RandomUtil.randomNumbers(4);
}
private <T> T wxCreateOrder(ProductOrderPO order, PaySourceEnum source) throws WxPayException {
private <T> T wxCreateOrder(ProductOrderPO order, PaySourceEnum source,String openId) throws WxPayException {
WxPayUnifiedOrderRequest payRequest = new WxPayUnifiedOrderRequest();
if(wxService.getConfig().isUseSandboxEnv()){
String key = wxService.getSandboxSignKey();
......@@ -94,6 +94,9 @@ public class ProductOrderService extends ServiceImpl<ProductOrderMapper, Product
payRequest.setSpbillCreateIp(IPUtils.getIpAddr(HttpContextUtils.getHttpServletRequest()));
payRequest.setNotifyUrl(StrUtil.format("{}{}",frontendDomain,"/online-edu-backend/wx/pay/notify/order"));
payRequest.setTradeType(source.name());
if (source == PaySourceEnum.JSAPI){
payRequest.setOpenid(openId);
}
return wxService.createOrder(payRequest);
}
......@@ -103,14 +106,14 @@ public class ProductOrderService extends ServiceImpl<ProductOrderMapper, Product
ProductOrderPO orderPO = createPO(model);
save(orderPO);
result.setOrderNo(orderPO.getOrderNo());
Object rtObj = prePay(orderPO,model.getSource());
Object rtObj = prePay(orderPO,model.getSource(),model.getOpenId());
result.setResult(rtObj);
return result;
}
private Object prePay(ProductOrderPO orderPO,PaySourceEnum source){
private Object prePay(ProductOrderPO orderPO,PaySourceEnum source,String openId){
if (orderPO.getPayMethod() == PayMethodEnum.WeiXin){
try {
Object rtObj = wxCreateOrder(orderPO,source);
Object rtObj = wxCreateOrder(orderPO,source,openId);
return rtObj;
} catch (WxPayException e) {
log.error(e.getMessage(),e);
......@@ -258,8 +261,8 @@ public class ProductOrderService extends ServiceImpl<ProductOrderMapper, Product
}
public CreateOrderResult payAgain(String orderNo,PaySourceEnum source) {
ProductOrderPO orderPO = getByOrderNo(orderNo);
public CreateOrderResult payAgain(CreateOrderModel model) {
ProductOrderPO orderPO = getByOrderNo(model.getOrderNo());
if (orderPO == null){
throw new BusinessException("请求错误,订单不存在");
}
......@@ -267,8 +270,8 @@ public class ProductOrderService extends ServiceImpl<ProductOrderMapper, Product
throw new BusinessException("订单已完成,请不要重覆支付");
}
CreateOrderResult result = new CreateOrderResult();
result.setOrderNo(orderNo);
Object rtObj = prePay(orderPO,source);
result.setOrderNo(model.getOrderNo());
Object rtObj = prePay(orderPO,model.getSource(),model.getOpenId());
result.setResult(rtObj);
return result;
}
......
package com.qkdata.biz.web.controller;
import cn.hutool.core.util.StrUtil;
import com.qkdata.biz.common.BizConstants;
import com.qkdata.biz.enums.PaySourceEnum;
import com.qkdata.biz.enums.ProductOrderStatusEnum;
......@@ -12,8 +13,12 @@ import com.qkdata.biz.web.vo.CreateOrderResult;
import com.qkdata.common.base.exception.BusinessException;
import com.qkdata.common.base.model.Result;
import com.qkdata.common.util.UserContext;
import com.qkdata.wx.mp.config.WxMpProperties;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -27,6 +32,10 @@ public class FrontendProductOrderController {
private ProductOrderService orderService;
@Autowired
private CourseService courseService;
@Autowired
private WxMpService wxMpService;
@Autowired
private WxMpProperties wxMpProperties;
@ApiOperation("购买时新建订单")
@PostMapping("/createOrder")
......@@ -46,6 +55,14 @@ public class FrontendProductOrderController {
if (model.getCount() <= 0){
throw new BusinessException("请求错误,购买数量不能为0");
}
if (model.getSource() == null){
throw new BusinessException("请求错误,source不能为空");
}
if (model.getSource() == PaySourceEnum.JSAPI){
if (StrUtil.isBlank(model.getOpenId())){
throw new BusinessException("请求错误,openId不能为空");
}
}
CreateOrderResult result = orderService.createOrder(model);
return Result.succeed(result);
}
......@@ -59,8 +76,30 @@ public class FrontendProductOrderController {
@ApiOperation("重新支付")
@PostMapping("/payAgain")
@RequiresRoles(value = {BizConstants.ROLE_USER,BizConstants.ROLE_ENTERPRISE_ADMIN},logical = Logical.OR)
public Result<CreateOrderResult> payAgain(@RequestParam String orderNo, @RequestParam PaySourceEnum source){
CreateOrderResult result = orderService.payAgain(orderNo,source);
public Result<CreateOrderResult> payAgain(@RequestBody CreateOrderModel model){
if (StrUtil.isBlank(model.getOrderNo())){
throw new BusinessException("请求错误,订单号不能为空");
}
if (StrUtil.isBlank(model.getOpenId())){
throw new BusinessException("请求错误,openId不能为空");
}
if (model.getSource() == null){
throw new BusinessException("请求错误,source不能为空");
}
CreateOrderResult result = orderService.payAgain(model);
return Result.succeed(result);
}
@ApiOperation("获取openId")
@GetMapping("/openIdByCode")
@RequiresRoles(value = {BizConstants.ROLE_USER,BizConstants.ROLE_ENTERPRISE_ADMIN},logical = Logical.OR)
public Result<String> getOpenIdByCode(@RequestParam String code) throws WxErrorException {
WxOAuth2AccessToken accessToken = wxMpService.getOAuth2Service().getAccessToken(code);
return Result.succeed(accessToken.getOpenId());
}
@ApiOperation("获取appId")
@GetMapping("/appId")
@RequiresRoles(value = {BizConstants.ROLE_USER,BizConstants.ROLE_ENTERPRISE_ADMIN},logical = Logical.OR)
public Result<String> getAppId(){
return Result.succeed(wxMpProperties.getAppId());
}
}
......@@ -17,4 +17,6 @@ public class CreateOrderModel {
private Long courseId;
private PayMethodEnum payMethod;
private PaySourceEnum source;
private String openId;
private String orderNo;
}
/*
package com.qkdata.wx.miniapp.config;
import cn.binarywang.wx.miniapp.api.WxMaService;
......@@ -22,9 +23,11 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
*/
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
*//*
@Configuration
@EnableConfigurationProperties(WxMaProperties.class)
public class WxMaConfiguration {
......@@ -145,3 +148,4 @@ public class WxMaConfiguration {
};
}
*/
/*
package com.qkdata.wx.miniapp.config;
import java.util.List;
......@@ -6,9 +7,11 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import lombok.Data;
*/
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
*//*
@Data
@ConfigurationProperties(prefix = "wx.miniapp")
public class WxMaProperties {
......@@ -17,30 +20,41 @@ public class WxMaProperties {
@Data
public static class Config {
/**
*/
/**
* 设置微信小程序的appid
*/
*//*
private String appid;
/**
*/
/**
* 设置微信小程序的Secret
*/
*//*
private String secret;
/**
*/
/**
* 设置微信小程序消息服务器配置的token
*/
*//*
private String token;
/**
*/
/**
* 设置微信小程序消息服务器配置的EncodingAESKey
*/
*//*
private String aesKey;
/**
*/
/**
* 消息格式,XML或者JSON
*/
*//*
private String msgDataFormat;
}
}
*/
/*
package com.qkdata.wx.miniapp.controller;
import cn.binarywang.wx.miniapp.api.WxMaService;
......@@ -11,9 +12,11 @@ import org.springframework.web.bind.annotation.*;
import java.util.Objects;
*/
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
*//*
@RestController
@RequestMapping("/wx/portal/{appid}")
public class WxPortalController {
......@@ -96,3 +99,4 @@ public class WxPortalController {
}
}
*/
package com.qkdata.wx.mp.config;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* wechat mp configuration
*
* @author Binary Wang(https://github.com/binarywang)
*/
@AllArgsConstructor
@Configuration
@EnableConfigurationProperties(WxMpProperties.class)
public class WxMpConfiguration {
private final WxMpProperties properties;
@Bean
public WxMpService wxMpService() {
// 代码里 getConfigs()处报错的同学,请注意仔细阅读项目说明,你的IDE需要引入lombok插件!!!!
WxMpService service = new WxMpServiceImpl();
WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl();
configStorage.setAppId(properties.getAppId());
configStorage.setSecret(properties.getSecret());
configStorage.setAesKey(properties.getAesKey());
configStorage.setToken(properties.getToken());
service.setWxMpConfigStorage(configStorage);
return service;
}
}
package com.qkdata.wx.mp.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
@Data
@ConfigurationProperties(prefix = "wx.mp")
public class WxMpProperties {
/**
* 设置微信公众号的appid
*/
private String appId;
/**
* 设置微信公众号的app secret
*/
private String secret;
/**
* 设置微信公众号的token
*/
private String token;
/**
* 设置微信公众号的EncodingAESKey
*/
private String aesKey;
}
......@@ -97,13 +97,18 @@ jwt:
exp: 720 #24*30 30天
wx:
miniapp:
configs:
- appid: wx4a74df8356c465a5 #微信小程序的appid
secret: 415f8d52311eeb0e5eef32a5e41758ae #微信小程序的Secret
token: #微信小程序消息服务器配置的token
aesKey: #微信小程序消息服务器配置的EncodingAESKey
msgDataFormat: JSON
mp:
appid: wx9b423ad87c070728
secret: 7e701dac9a770e452ecfac5d04f101cc
token: qkdata # 接口配置里的Token值
aesKey: jqeWoe5oziHcvrSaI2Q7YE7RNReWv7eoM7YtMiJtiqf # 接口配置里的EncodingAESKey值
# miniapp:
# configs:
# - appid: wx4a74df8356c465a5 #微信小程序的appid
# secret: 415f8d52311eeb0e5eef32a5e41758ae #微信小程序的Secret
# token: #微信小程序消息服务器配置的token
# aesKey: #微信小程序消息服务器配置的EncodingAESKey
# msgDataFormat: JSON
pay:
appId: wx9b423ad87c070728
mchId: 1610013675
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment