From 962e33b73007aef7072f645adcb10c03e3c00b32 Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Wed, 25 Dec 2024 18:27:03 +0800 Subject: [PATCH] =?UTF-8?q?release-=E6=8A=96=E9=9F=B3=E5=88=86=E4=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- luoo_music/pom.xml | 2 +- .../music/controller/SliceController.java | 38 +++++ luoo_user/pom.xml | 16 +++ .../java/com/luoo/user/UserApplication.java | 4 +- .../user/controller/DouyinController.java | 136 ++++++++++++++++++ pom.xml | 3 + 6 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 luoo_music/src/main/java/com/luoo/music/controller/SliceController.java create mode 100644 luoo_user/src/main/java/com/luoo/user/controller/DouyinController.java diff --git a/luoo_music/pom.xml b/luoo_music/pom.xml index edfd431..f91471a 100644 --- a/luoo_music/pom.xml +++ b/luoo_music/pom.xml @@ -123,7 +123,7 @@ docker-maven-plugin 0.4.13 - 116.62.145.60:5000/${project.artifactId}:${project.version} + 116.62.145.60:5000/${project.artifactId}:1.0dev jdk1.8 ["java", "-jar","/${project.build.finalName}.jar"] diff --git a/luoo_music/src/main/java/com/luoo/music/controller/SliceController.java b/luoo_music/src/main/java/com/luoo/music/controller/SliceController.java new file mode 100644 index 0000000..616674e --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/controller/SliceController.java @@ -0,0 +1,38 @@ +package com.luoo.music.controller; + +import api.Result; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +/** + * @program: luoo_parent + * @description: 拿到视频地址 + * @author: wangqing + * @create: 2024-08-08 08:38 + **/ +@RestController +@CrossOrigin +@Slf4j +@RequestMapping("/slice") +@Api(tags = "分享视频素材") +public class SliceController { + + @GetMapping("/getSliceUrl/{objectId}/{type}") + @ApiOperation(value = "获取视频素材", notes = "获取视频素材,type 1为期刊,2为歌曲") + public Result getSlice(@PathVariable String objectId, @PathVariable int type) { + Random random = new Random(); + int i3 = random.nextInt(3) +1; + int i9 = random.nextInt(9) +1; + + String url = "https://cdn2.indie.cn/indie/slice/" + i3 + "/" + i9 +".mp4"; + Map map = new HashMap(); + map.put("url",url); + return Result.success(map); + } +} \ No newline at end of file diff --git a/luoo_user/pom.xml b/luoo_user/pom.xml index 650f815..907eaad 100644 --- a/luoo_user/pom.xml +++ b/luoo_user/pom.xml @@ -8,7 +8,23 @@ 1.0-SNAPSHOT luoo_user + + + + douyin-openapi-repo + https://artifacts-cn-beijing.volces.com/repository/douyin-openapi/ + + + + + com.douyin.openapi + sdk + 1.0.0 + + + + com.github.wechatpay-apiv3 wechatpay-java diff --git a/luoo_user/src/main/java/com/luoo/user/UserApplication.java b/luoo_user/src/main/java/com/luoo/user/UserApplication.java index 6c3cb35..266bc29 100644 --- a/luoo_user/src/main/java/com/luoo/user/UserApplication.java +++ b/luoo_user/src/main/java/com/luoo/user/UserApplication.java @@ -9,6 +9,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; @@ -25,7 +27,7 @@ import java.net.InetAddress; import java.net.UnknownHostException; @EnableMongoPlus -@SpringBootApplication +@SpringBootApplication(exclude = { GsonAutoConfiguration.class }) @EnableEurekaClient @EnableJpaAuditing @EnableAsync diff --git a/luoo_user/src/main/java/com/luoo/user/controller/DouyinController.java b/luoo_user/src/main/java/com/luoo/user/controller/DouyinController.java new file mode 100644 index 0000000..d5d5f28 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/controller/DouyinController.java @@ -0,0 +1,136 @@ +package com.luoo.user.controller; + + +import api.Result; + + +import com.aliyun.tea.TeaException; +import com.douyin.openapi.client.Client; +import com.douyin.openapi.client.models.JsGetticketRequest; +import com.douyin.openapi.client.models.JsGetticketResponse; +import com.douyin.openapi.client.models.OauthClientTokenRequest; +import com.douyin.openapi.client.models.OauthClientTokenResponse; +import com.douyin.openapi.credential.models.Config; +import com.github.houbb.heaven.util.lang.StringUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.RestTemplate; +import util.IdWorker; + +import java.nio.charset.StandardCharsets; +import java.security.*; + +import java.util.*; +import java.util.concurrent.TimeUnit; + + +@RestController +@CrossOrigin +@RequestMapping ("/douyin") +@Api(tags = "抖音签名") +public class DouyinController { + + @Autowired + private IdWorker idWorker; + + @Autowired + private StringRedisTemplate redisTemplate; + + @GetMapping ("/getSignature") + @ApiOperation(value = "获取抖音签名", notes = "获取抖音签名") + public Result getDouyinSignature() { + + String ticket = (String) redisTemplate.opsForValue().get("douyinTicket"); + + if(StringUtil.isBlank(ticket)) { + // 获取client_token + try { + Config config = new Config().setClientKey("aw05in5o84wsu9bn").setClientSecret("135659dbc7a68c809bd0e1e7b04e461b"); // 改成自己的app_id跟secret + Client client = new Client(config); + /* 构建请求参数,该代码示例中只给出部分参数,请用户根据需要自行构建参数值 + token: + 1.若用户自行维护token,将用户维护的token赋值给该参数即可 + 2.SDK包中有获取token的函数,请根据接口path在《OpenAPI SDK 总览》文档中查找获取token函数的名字 + 在使用过程中,请注意token互刷问题 + header: + sdk中默认填充content-type请求头,若不需要填充除content-type之外的请求头,删除该参数即可 + */ + OauthClientTokenRequest sdkRequest = new OauthClientTokenRequest(); + sdkRequest.setClientKey("aw05in5o84wsu9bn"); + sdkRequest.setClientSecret("135659dbc7a68c809bd0e1e7b04e461b"); + sdkRequest.setGrantType("client_credential"); +// Map requestHeader = new HashMap(); +// requestHeader.put("content-type", "application/json"); +// sdkRequest.setHeader(requestHeader); + OauthClientTokenResponse sdkResponse = client.OauthClientToken(sdkRequest); + System.out.println(sdkResponse.toString()); + JsGetticketRequest jsGetticketRequest = new JsGetticketRequest(); + jsGetticketRequest.setAccessToken(sdkResponse.getData().accessToken); + JsGetticketResponse jsGetticketResponse = client.JsGetticket(jsGetticketRequest); + System.out.println(jsGetticketResponse.toString()); + redisTemplate.opsForValue().set("douyinTicket", jsGetticketResponse.data.ticket,7200, TimeUnit.SECONDS); + } catch (TeaException e) { + System.out.println(e.getMessage()); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + + } + + + // 获取ticket + +// RestTemplate restTemplate = new RestTemplate(); +// String url = "https://open.douyin.com/open/getticket/"; +// restTemplate.get + + + String nonce_str = idWorker.nextId() + ""; + String timestamp = System.currentTimeMillis()+""; + Map map = new HashMap<>(); + map.put("nonce_str", nonce_str); + map.put("ticket", ticket); + map.put("timestamp", timestamp); + + String preSignStr = "nonce_str="+idWorker.nextId()+"&ticket="+ticket+"×tamp="+System.currentTimeMillis(); + String sign =md5FromStr(preSignStr); + Map responseMap = new HashMap(); + responseMap.put("share_type", "h5"); + responseMap.put("client_key", "aw05in5o84wsu9bn"); + responseMap.put("nonce_str", nonce_str); + responseMap.put("timestamp", timestamp); + responseMap.put("signature", sign); + + return Result.success(responseMap); + } + + + + + private static String md5FromStr(String inStr) { + MessageDigest md5; + try { + md5 = MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + return ""; + } + + byte[] byteArray = inStr.getBytes(StandardCharsets.UTF_8); + byte[] md5Bytes = md5.digest(byteArray); + StringBuilder hexValue = new StringBuilder(); + for (byte md5Byte : md5Bytes) { + int val = ((int) md5Byte) & 0xff; + if (val < 16) { + hexValue.append("0"); + } + hexValue.append(Integer.toHexString(val)); + } + return hexValue.toString(); + } +} diff --git a/pom.xml b/pom.xml index 5c95920..a27e151 100644 --- a/pom.xml +++ b/pom.xml @@ -30,6 +30,7 @@ org.springframework.boot spring-boot-starter-parent 2.0.1.RELEASE + @@ -73,6 +74,7 @@ pom import + @@ -113,6 +115,7 @@ + spring-snapshots Spring Snapshots