release-抖音分享

release-2024-04-25
wangqing 4 weeks ago
parent 6bebe1bf08
commit 962e33b730

@ -123,7 +123,7 @@
<artifactId>docker-maven-plugin</artifactId> <artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version> <version>0.4.13</version>
<configuration> <configuration>
<imageName>116.62.145.60:5000/${project.artifactId}:${project.version}</imageName> <imageName>116.62.145.60:5000/${project.artifactId}:1.0dev</imageName>
<baseImage>jdk1.8</baseImage> <baseImage>jdk1.8</baseImage>
<entryPoint>["java", "-jar","/${project.build.finalName}.jar"]</entryPoint> <entryPoint>["java", "-jar","/${project.build.finalName}.jar"]</entryPoint>
<resources> <resources>

@ -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<Map> 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);
}
}

@ -8,7 +8,23 @@
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>luoo_user</artifactId> <artifactId>luoo_user</artifactId>
<repositories>
<repository>
<id>douyin-openapi-repo</id>
<url>https://artifacts-cn-beijing.volces.com/repository/douyin-openapi/</url>
</repository>
</repositories>
<dependencies> <dependencies>
<dependency>
<groupId>com.douyin.openapi</groupId>
<artifactId>sdk</artifactId>
<version>1.0.0</version>
</dependency>
<dependency> <dependency>
<groupId>com.github.wechatpay-apiv3</groupId> <groupId>com.github.wechatpay-apiv3</groupId>
<artifactId>wechatpay-java</artifactId> <artifactId>wechatpay-java</artifactId>

@ -9,6 +9,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; 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.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -25,7 +27,7 @@ import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
@EnableMongoPlus @EnableMongoPlus
@SpringBootApplication @SpringBootApplication(exclude = { GsonAutoConfiguration.class })
@EnableEurekaClient @EnableEurekaClient
@EnableJpaAuditing @EnableJpaAuditing
@EnableAsync @EnableAsync

@ -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<Map> 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.SDKtokenpathOpenAPI SDK token
使token
header:
sdkcontent-typecontent-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<String, String> 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+"&timestamp="+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();
}
}

@ -30,6 +30,7 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version> <version>2.0.1.RELEASE</version>
<!-- <version>2.0.1.RELEASE</version>-->
<relativePath /> <relativePath />
</parent> </parent>
@ -73,6 +74,7 @@
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
@ -113,6 +115,7 @@
<repositories> <repositories>
<repository> <repository>
<id>spring-snapshots</id> <id>spring-snapshots</id>
<name>Spring Snapshots</name> <name>Spring Snapshots</name>

Loading…
Cancel
Save