|
@@ -6,12 +6,16 @@ import cn.hutool.extra.qrcode.QrConfig;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.ylx.common.annotation.Log;
|
|
|
+import com.ylx.common.config.RuoYiConfig;
|
|
|
import com.ylx.common.constant.Constants;
|
|
|
import com.ylx.common.core.controller.BaseController;
|
|
|
+import com.ylx.common.core.domain.AjaxResult;
|
|
|
import com.ylx.common.core.domain.R;
|
|
|
import com.ylx.common.core.domain.model.WxLoginUser;
|
|
|
import com.ylx.common.enums.BusinessType;
|
|
|
import com.ylx.common.utils.MessageUtils;
|
|
|
+import com.ylx.common.utils.file.FileUploadUtils;
|
|
|
+import com.ylx.framework.config.ServerConfig;
|
|
|
import com.ylx.framework.manager.AsyncManager;
|
|
|
import com.ylx.framework.manager.factory.AsyncFactory;
|
|
|
import com.ylx.framework.web.service.WxTokenService;
|
|
@@ -19,6 +23,8 @@ import com.ylx.massage.domain.CouponReceive;
|
|
|
import com.ylx.massage.domain.TWxUser;
|
|
|
import com.ylx.massage.service.CouponReceiveService;
|
|
|
import com.ylx.massage.service.TWxUserService;
|
|
|
+import com.ylx.massage.service.TbFileService;
|
|
|
+import com.ylx.massage.utils.DateTimeUtils;
|
|
|
import com.ylx.massage.utils.WeChatUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -27,9 +33,11 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.File;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -53,7 +61,7 @@ public class WeChatController extends BaseController {
|
|
|
/**
|
|
|
* 二维码保存路径
|
|
|
*/
|
|
|
- private final static String IMG_PATH = "D:\\Users\\code.png";
|
|
|
+ private String IMG_PATH = "D:\\Users\\";
|
|
|
|
|
|
// private final WeChatUserService weChatUserService;
|
|
|
|
|
@@ -75,6 +83,9 @@ public class WeChatController extends BaseController {
|
|
|
@Resource
|
|
|
private WxTokenService wxTokenService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TbFileService tbFileService;
|
|
|
+
|
|
|
/**
|
|
|
* 微信Token验证
|
|
|
*
|
|
@@ -197,7 +208,6 @@ public class WeChatController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 刷新token,微信提供的token是有限时间的,但是对于财务报销系统仅需授权一次的情况下一般不需要进行更新
|
|
|
*
|
|
@@ -208,7 +218,7 @@ public class WeChatController extends BaseController {
|
|
|
|
|
|
WxLoginUser wxLoginUser = this.getWxLoginUser();
|
|
|
TWxUser user = wxUserService.getByOpenId(wxLoginUser.getCOpenid());
|
|
|
- if (user == null){
|
|
|
+ if (user == null) {
|
|
|
throw new RuntimeException("用户不存在");
|
|
|
}
|
|
|
// 发送get请求获取 RefreshToken
|
|
@@ -221,13 +231,30 @@ public class WeChatController extends BaseController {
|
|
|
wxUserService.updateById(user);
|
|
|
return accessToken;
|
|
|
}
|
|
|
+
|
|
|
@ApiOperation("获取公众号二维码")
|
|
|
@RequestMapping(value = "getwxQrCode", method = RequestMethod.GET)
|
|
|
public String getWxQrCodeUtil(@RequestParam String openId) {
|
|
|
|
|
|
- String token = this.refreshToken();
|
|
|
+ String token = weChatUtil.getToken();
|
|
|
Map<?, ?> url = weChatUtil.getUrl(token, openId);
|
|
|
return url.toString();
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation("获取公众号网页二维码")
|
|
|
+ @GetMapping("/getweQrCode")
|
|
|
+ public AjaxResult weiXinLogin1(String openId) {
|
|
|
+ QrConfig config = new QrConfig(300, 300);
|
|
|
+ // 设置边距,即二维码和背景之间的边距
|
|
|
+ config.setMargin(1);
|
|
|
+ // 生成二维码到文件,也可以到流
|
|
|
+ String code = "https://www.baidu.com?openId="+openId;
|
|
|
+ log.info("code:{}", code);
|
|
|
+ String str = IMG_PATH;
|
|
|
+ File generate = QrCodeUtil.generate(code, config, FileUtil.file(RuoYiConfig.getUploadPath() + "/code.png"));
|
|
|
+
|
|
|
+ MultipartFile multipartFile = FileUploadUtils.getMultipartFile(generate);
|
|
|
+ return tbFileService.uploadFile(multipartFile);
|
|
|
+ }
|
|
|
}
|