Skip to content

Commit

Permalink
获取微信群二维码
Browse files Browse the repository at this point in the history
  • Loading branch information
tangllty committed Jan 10, 2024
1 parent 28541ff commit 8ac9667
Showing 1 changed file with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package com.tang.admin.controller;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.tang.commons.utils.AjaxResult;
import com.tang.system.service.log.SysLogLoginService;

import jakarta.servlet.http.HttpServletResponse;

/**
* 首页逻辑控制层
*
Expand All @@ -18,6 +27,8 @@ public class IndexController {

private final SysLogLoginService logLoginService;

private final HttpClient httpClient = HttpClient.newBuilder().build();

public IndexController(SysLogLoginService logLoginService) {
this.logLoginService = logLoginService;
}
Expand All @@ -33,4 +44,46 @@ public AjaxResult userVisit() {
return AjaxResult.success(userVisit);
}

/**
* 获取微信二维码(Gitee)
*
* @param response 响应
* @throws IOException IO异常
* @throws InterruptedException 中断异常
* @throws URISyntaxException URI异常
*/
@GetMapping("/get-wechat-gitee")
public void getWechatGitee(HttpServletResponse response) throws IOException, InterruptedException, URISyntaxException {
var url = "https://gitee.com/tangllty/tang-docs/raw/master/docs/public/wechat.png";
var requestResult = HttpRequest.newBuilder()
.uri(new URI(url))
.GET()
.build();

var responseResult = httpClient.send(requestResult, HttpResponse.BodyHandlers.ofByteArray());
response.setContentType("image/png");
response.getOutputStream().write(responseResult.body());
}

/**
* 获取微信二维码(Github)
*
* @param response 响应
* @throws IOException IO异常
* @throws InterruptedException 中断异常
* @throws URISyntaxException URI异常
*/
@GetMapping("/get-wechat-github")
public void getWechatGithub(HttpServletResponse response) throws IOException, InterruptedException, URISyntaxException {
var url = "https://raw.githubusercontent.com/tangllty/tang-docs/master/docs/public/wechat.png";
var requestResult = HttpRequest.newBuilder()
.uri(new URI(url))
.GET()
.build();

var responseResult = httpClient.send(requestResult, HttpResponse.BodyHandlers.ofByteArray());
response.setContentType("image/png");
response.getOutputStream().write(responseResult.body());
}

}

0 comments on commit 8ac9667

Please sign in to comment.