第一步:创建一个SpringBoot项目
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-thymeleafartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-testartifactId>
<scope>testscope>
dependency>
第二步:写一个controller测试接口能否调通
@Controller
public class VIPController {
@RequestMapping("/play")
public String play() {
return "play";
}
}
第三步:编写前端页面
DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<link th:href="@{/css/style.css}" rel="stylesheet" type="text/css">
<title>VIP视频title>
head>
<body>
<div id="app">
<form action="/doPlay" onsubmit="return urlCheck()">
<div>
<h2 style="margin:20px auto;text-align: center;color: white">本站点使用第三方提供的解析接口(仅用于学习和交流)h2>
div>
<div class="ibox">
<input class="input" name="url" type="search" placeholder="输入地址(腾讯视频/优酷/爱奇艺)视频地址">
<input id="ck" type="checkbox" name="isQR" value="true" onclick="changeText()"><label for="ck" style="color: white;padding: 10px">手机观看label>
<input id="btn" class="button" type="submit" value="在线播放">
div>
<div class="codes">
div>
form>
div>
<script>
function urlCheck() {
var value = document.querySelector(".input").value;
if (value == null || value == "") {
alert("请输入地址")
return false;
}
if (!value.startsWith("http")) {
alert("请输入正确的http/https链接")
return false;
}
return true
}
function changeText(){
var ck = document.querySelector("#ck").checked;
if(ck){
document.querySelector("#btn").value="生成二维码";
}else{
document.querySelector("#btn").value="在线播放";
}
}
script>
body>
html>
第四步:定义一个接口用来解析VIP网站
@RequestMapping("/doPlay")
public String doPlay(String url, boolean isQR, HttpServletResponse response) throws IOException {
if (isQR) {
String playUrl = "https://jx.bozrc.com:4433/player/?url=" + url;
BufferedImage image = QrCodeUtil.generate(playUrl, 400, 400);
// 把图片发送给浏览器
ImageIO.write(image,"png",response.getOutputStream());
} else {
return "redirect:https://jx.bozrc.com:4433/player/?url=" + url;
}
return null;
}