USVT-125 添加一个生成微信 QR 访问链接的 API

This commit is contained in:
YuCheng Hu 2022-12-04 09:00:14 -05:00
parent 80d3690ba7
commit 3fd361d0a4
1 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,67 @@
package com.northtecom.visatrack.api.controller.auth;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.northtecom.visatrack.api.service.impl.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*;
import java.util.UUID;
/**
* Created with IntelliJ IDEA.
*
* @Author: XieYang
* @Date: 2022/10/08/15:59
* @Description:
*/
@RestController
@Slf4j
@RequestMapping(WeChatController.BASE_URL)
@Tag(name = WeChatController.TAG_NAME, description = WeChatController.TAG_DESCRIPTION)
public class WeChatController {
protected static final String DATA_NAME = "授权";
protected static final String BASE_URL = "/auth/wechat";
protected static final String TAG_NAME = "Auth";
protected static final String TAG_DESCRIPTION = DATA_NAME + "管理API";
private final ObjectMapper objectMapper;
private final UserService userService;
private final AuthenticationManager authenticationManager;
@Autowired
public WeChatController(ObjectMapper objectMapper, UserService userService, AuthenticationManager authenticationManager, BCryptPasswordEncoder encoder) {
this.objectMapper = objectMapper;
this.userService = userService;
this.authenticationManager = authenticationManager;
}
@GetMapping("/qrconnect")
@ResponseBody
@Operation(summary = "用户注册接口", description = "用户注册接口,用户注册以后会给用户发送一封邮件,邮件中包含了激活链接,用户点击激活链接以后,用户的账号才会被激活")
public String getWeChatLoginQR() throws JsonProcessingException {
log.debug("Get WeChat Login QR link");
StringBuffer qrconnect = new StringBuffer();
qrconnect.append("https://open.weixin.qq.com/connect/qrconnect?");
qrconnect.append("appid=wx26e01c2be46730f3&");
qrconnect.append("redirect_uri=https%3A%2F%2Fwww.usvisatrack.com%2Fwechat%2Fcallback&");
qrconnect.append("response_type=code&");
qrconnect.append("scope=snsapi_login&");
qrconnect.append("state=" + UUID.randomUUID().toString() + "#wechat_redirect");
https:
//open.weixin.qq.com/connect/qrconnect?appid=wxbdc5610cc59c1631&redirect_uri=https%3A%2F%2Fpassport.yhd.com%2Fwechat%2Fcallback.do&response_type=code&scope=snsapi_login&state=3d6be0a4035d839573b04816624a415e#wechat_redirect
return qrconnect.toString();
}
}