|
@@ -1,5 +1,8 @@
|
|
package com.caimei.service.auth.impl;
|
|
package com.caimei.service.auth.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.caimei.components.RedisService;
|
|
import com.caimei.config.FastDfsClient;
|
|
import com.caimei.config.FastDfsClient;
|
|
import com.caimei.mapper.cmMapper.AuthMapper;
|
|
import com.caimei.mapper.cmMapper.AuthMapper;
|
|
import com.caimei.mapper.cmMapper.AuthProductMapper;
|
|
import com.caimei.mapper.cmMapper.AuthProductMapper;
|
|
@@ -13,10 +16,27 @@ import com.caimei.service.auth.ShopService;
|
|
import com.caimei.service.auth.UploadService;
|
|
import com.caimei.service.auth.UploadService;
|
|
import com.caimei.utils.Base64Util;
|
|
import com.caimei.utils.Base64Util;
|
|
import com.caimei.utils.ImageUtils;
|
|
import com.caimei.utils.ImageUtils;
|
|
|
|
+import com.caimei.utils.Md5Util;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import lombok.val;
|
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.apache.http.Consts;
|
|
|
|
+import org.apache.http.HttpEntity;
|
|
|
|
+import org.apache.http.NameValuePair;
|
|
|
|
+import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
|
+import org.apache.http.client.methods.HttpGet;
|
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
|
+import org.apache.http.client.utils.URIBuilder;
|
|
|
|
+import org.apache.http.entity.ContentType;
|
|
|
|
+import org.apache.http.entity.mime.MultipartEntityBuilder;
|
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
|
+import org.apache.http.message.BasicNameValuePair;
|
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.apache.poi.xssf.usermodel.*;
|
|
import org.apache.poi.xssf.usermodel.*;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -25,16 +45,24 @@ import org.springframework.core.io.ClassPathResource;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.imageio.ImageIO;
|
|
import javax.imageio.ImageIO;
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
import javax.swing.*;
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.awt.*;
|
|
import java.awt.Font;
|
|
import java.awt.Font;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
+import java.net.URISyntaxException;
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -88,6 +116,9 @@ public class AuthServiceImpl implements AuthService {
|
|
@Value("${caimei.imageDomain}")
|
|
@Value("${caimei.imageDomain}")
|
|
private String imageDomain;
|
|
private String imageDomain;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private RedisService redisService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public ResponseJson<PageInfo<AuthVo>> getAuthList(Integer listType, Integer authUserId, String authParty,
|
|
public ResponseJson<PageInfo<AuthVo>> getAuthList(Integer listType, Integer authUserId, String authParty,
|
|
String mobile, Integer status, Integer starFlag, Integer auditStatus,
|
|
String mobile, Integer status, Integer starFlag, Integer auditStatus,
|
|
@@ -741,4 +772,392 @@ public class AuthServiceImpl implements AuthService {
|
|
List<AuthFormVo> clubBindAuth = authMapper.getClubBindAuth(authUserId);
|
|
List<AuthFormVo> clubBindAuth = authMapper.getClubBindAuth(authUserId);
|
|
return ResponseJson.success(clubBindAuth);
|
|
return ResponseJson.success(clubBindAuth);
|
|
}
|
|
}
|
|
|
|
+//------------------------------------------v1.7.5上传视频至抖音---------------------------------------------------------------------------------------
|
|
|
|
+///用户授权(用于获取数据)
|
|
|
|
+ /**
|
|
|
|
+ * 用户扫码授权,获取code值
|
|
|
|
+ * @param response
|
|
|
|
+ * @return true :token没过期 false:token过期需重新授权
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson getDouYingCode(HttpServletResponse response) throws IOException {
|
|
|
|
+ //验证是否是第一次登录(根据redis缓存中的token验证)
|
|
|
|
+ long dYaccessTok = redisService.getExpireTime("DYaccessToken");
|
|
|
|
+ boolean s=redisService.exists("DYaccessToken");
|
|
|
|
+ String s1= redisService.get("DyopenId").toString();
|
|
|
|
+// if(!redisService.exists("DYaccessToken")){
|
|
|
|
+ //验证token是否过期
|
|
|
|
+ long dYaccessToken = redisService.getExpireTime("DYaccessToken");
|
|
|
|
+ if(dYaccessToken<=0){ //tonken过期
|
|
|
|
+ //判断refreshToken是否过期
|
|
|
|
+ long DyrefreshToken = redisService.getExpireTime("DyrefreshToken");
|
|
|
|
+ if(DyrefreshToken>=0){ //refreshToken
|
|
|
|
+ //根据refreshToken刷新token,重新缓存token
|
|
|
|
+ String refreshToken=redisService.get("DyrefreshToken").toString();
|
|
|
|
+ String accessToken = refreshAccessToken(refreshToken);
|
|
|
|
+ redisService.set("DYaccessToken",accessToken , 60L * 60 * 24 * 15);
|
|
|
|
+ boolean flag= redisService.exists("DYaccessToken");
|
|
|
|
+ return ResponseJson.success(true);
|
|
|
|
+ }else{ //根据refreshToken刷新refreshToken(总共可以刷新3次,次数完后需重新扫码授权)
|
|
|
|
+ String refreshToken=redisService.get("DyrefreshToken").toString();
|
|
|
|
+ String newRefreshToken = resetRefreshAccessToken(refreshToken);
|
|
|
|
+ if(StringUtils.isNotEmpty(newRefreshToken)){
|
|
|
|
+ String accessToken = refreshAccessToken(newRefreshToken);
|
|
|
|
+ redisService.set("DYaccessToken",accessToken,60L * 60 * 24 * 15);
|
|
|
|
+ return ResponseJson.success(true);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ return ResponseJson.success(true);
|
|
|
|
+ }
|
|
|
|
+// }
|
|
|
|
+// String clintKey = "awwwvh9tsnvo54w1";//应用唯一标识
|
|
|
|
+// String responestype = "code";//写死为'code'即可
|
|
|
|
+// String scope = "video.data,video.list,trial.whitelist,data.external.item";//应用授权作用域,多个授权作用域以英文逗号(,)分隔
|
|
|
|
+// String redirectUrl = "https://www.caimei365.com";//回调地址,应用中配置
|
|
|
|
+// String state = "false";//用于保持请求和回调的状态
|
|
|
|
+// String code = "https://open.douyin.com/platform/oauth/connect/?client_key=" + clintKey
|
|
|
|
+// + "&response_type=" + responestype + "&scope=" + scope + "&redirect_uri=" + redirectUrl + "&state=" + state;
|
|
|
|
+// response.sendRedirect(code);
|
|
|
|
+ return ResponseJson.success(false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据用户的code值获取AcessToken
|
|
|
|
+ * ccode 用户授权登录code
|
|
|
|
+ **/
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson getDouYingAcessToken(String code) throws IOException {
|
|
|
|
+ String clintKey = "awwwvh9tsnvo54w1";//应用唯一标识
|
|
|
|
+ String clintSecret = "1dd7446d29e16738787447b771ced2df";//应用唯一标识对应的密钥
|
|
|
|
+ String grantType = "authorization_code";//固定值
|
|
|
|
+ String requestUrl = "https://open.douyin.com/oauth/access_token/";//请求地址
|
|
|
|
+ CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
|
|
|
|
+ //创建httppost对象
|
|
|
|
+ HttpPost hp = new HttpPost(requestUrl);
|
|
|
|
+ hp.addHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
|
|
|
|
+// hp.setHeader("Content-Type","application/x-www-form-urlencoded");
|
|
|
|
+ //拼接请求参数
|
|
|
|
+ List<NameValuePair> list = new ArrayList();
|
|
|
|
+ list.add(new BasicNameValuePair("client_key", clintKey));
|
|
|
|
+ list.add(new BasicNameValuePair("client_secret", clintSecret));
|
|
|
|
+ list.add(new BasicNameValuePair("code", code));
|
|
|
|
+ list.add(new BasicNameValuePair("grant_type", grantType));
|
|
|
|
+ UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, StandardCharsets.UTF_8);
|
|
|
|
+ hp.setEntity(entity);
|
|
|
|
+ //发送请求
|
|
|
|
+ CloseableHttpResponse execute = closeableHttpClient.execute(hp);
|
|
|
|
+ HttpEntity he = execute.getEntity();
|
|
|
|
+ String result = EntityUtils.toString(he, StandardCharsets.UTF_8);
|
|
|
|
+ //获取access_token,open_id(用于获取视频数据),refresh_token(刷新token)
|
|
|
|
+ JSONObject jsonObject =JSONObject.parseObject(result);
|
|
|
|
+ String data = jsonObject.getString("data");
|
|
|
|
+ JSONObject params =JSONObject.parseObject(data);
|
|
|
|
+ String accessToken = params.getString("access_token");
|
|
|
|
+ String openId = params.getString("open_id");
|
|
|
|
+ String refreshToken = params.getString("refresh_token");
|
|
|
|
+ //用redis缓存access_token,refresh_token
|
|
|
|
+ redisService.set("DYaccessToken",accessToken , 60L);// * 60 * 24 * 15
|
|
|
|
+ redisService.set("DyrefreshToken",refreshToken,60l*2);
|
|
|
|
+ redisService.set("DyopenId",openId,60L * 60 * 24 * 30);
|
|
|
|
+ EntityUtils.consume(he);
|
|
|
|
+ String DYaccessToken=redisService.get("DYaccessToken").toString();
|
|
|
|
+ String DyrefreshToken=redisService.get("DyrefreshToken").toString();
|
|
|
|
+ String DyopenId=redisService.get("DyopenId").toString();
|
|
|
|
+ if (StringUtils.isNotEmpty(DYaccessToken)&&StringUtils.isNotEmpty(DyrefreshToken)&&StringUtils.isNotEmpty(DyopenId)){
|
|
|
|
+ return ResponseJson.success();
|
|
|
|
+ }else {
|
|
|
|
+ return ResponseJson.success("tonken缓存失败",null);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 刷新tonken
|
|
|
|
+ * @param refreshToken
|
|
|
|
+ */
|
|
|
|
+ public String refreshAccessToken(String refreshToken){
|
|
|
|
+ String requestUrl="https://open.douyin.com/oauth/refresh_token/";
|
|
|
|
+ String clintKey = "awwwvh9tsnvo54w1";//应用唯一标识
|
|
|
|
+ String grantType = "refresh_token";//固定值
|
|
|
|
+ String accessToken=null;
|
|
|
|
+ //创建httppost对象
|
|
|
|
+ CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
|
|
|
|
+ HttpPost hp = new HttpPost(requestUrl);
|
|
|
|
+ hp.addHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
|
|
|
|
+// hp.setHeader("Content-Type","application/x-www-form-urlencoded");
|
|
|
|
+ //拼接请求参数
|
|
|
|
+ List<NameValuePair> list = new ArrayList();
|
|
|
|
+ list.add(new BasicNameValuePair("client_key", clintKey));
|
|
|
|
+ list.add(new BasicNameValuePair("grant_type", grantType));
|
|
|
|
+ list.add(new BasicNameValuePair("refresh_token", refreshToken));
|
|
|
|
+ UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, StandardCharsets.UTF_8);
|
|
|
|
+ hp.setEntity(entity);
|
|
|
|
+ try {
|
|
|
|
+ CloseableHttpResponse execute = closeableHttpClient.execute(hp);
|
|
|
|
+ HttpEntity he = execute.getEntity();
|
|
|
|
+ String result = EntityUtils.toString(he, StandardCharsets.UTF_8);
|
|
|
|
+ JSONObject params=JSONObject.parseObject(result);
|
|
|
|
+ String data=params.getString("data");
|
|
|
|
+ JSONObject datalist=JSONObject.parseObject(data);
|
|
|
|
+ accessToken=datalist.getString("access_token");
|
|
|
|
+ EntityUtils.consume(he);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ hp.setEntity(entity);
|
|
|
|
+ return accessToken;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 刷新refreshAccessToken
|
|
|
|
+ * @param refreshToken
|
|
|
|
+ */
|
|
|
|
+ public String resetRefreshAccessToken(String refreshToken){
|
|
|
|
+ String requestUrl="https://open.douyin.com/oauth/renew_refresh_token/";
|
|
|
|
+ String clintKey = "awwwvh9tsnvo54w1";//应用唯一标识
|
|
|
|
+ String renewRefreshAccessToken=null;
|
|
|
|
+ //创建httppost对象
|
|
|
|
+ CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
|
|
|
|
+ HttpPost hp = new HttpPost(requestUrl);
|
|
|
|
+ List<NameValuePair> list = new ArrayList();
|
|
|
|
+ list.add(new BasicNameValuePair("client_key", clintKey));
|
|
|
|
+ list.add(new BasicNameValuePair("refresh_token", refreshToken));
|
|
|
|
+ list.add(new BasicNameValuePair("Content-Type", "multipart/form-data"));
|
|
|
|
+ UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, StandardCharsets.UTF_8);
|
|
|
|
+ hp.setEntity(entity);
|
|
|
|
+ try {
|
|
|
|
+ CloseableHttpResponse execute = closeableHttpClient.execute(hp);
|
|
|
|
+ HttpEntity he = execute.getEntity();
|
|
|
|
+ String result = EntityUtils.toString(he, StandardCharsets.UTF_8);
|
|
|
|
+ JSONObject jsonObject=JSONObject.parseObject(result);
|
|
|
|
+ String data = jsonObject.getString("data");
|
|
|
|
+ JSONObject params=JSONObject.parseObject(data);
|
|
|
|
+ renewRefreshAccessToken = params.getString("refresh_token");
|
|
|
|
+ EntityUtils.consume(he);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ hp.setEntity(entity);
|
|
|
|
+ return renewRefreshAccessToken;
|
|
|
|
+ }
|
|
|
|
+ //----------------------------------------------------h5的方式上传视频------------------------------------------------
|
|
|
|
+ /**
|
|
|
|
+ * h5的方式上传视频
|
|
|
|
+ * @return
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson getclientToken(String title,String videoPath) throws IOException {
|
|
|
|
+ //获取accessToken
|
|
|
|
+ String client_key = "awwwvh9tsnvo54w1";
|
|
|
|
+ String client_secret = "1dd7446d29e16738787447b771ced2df";
|
|
|
|
+ String grant_type = "client_credential";
|
|
|
|
+ String url = "https://open.douyin.com/oauth/client_token/?client_key=" + client_key
|
|
|
|
+ + "&client_secret=" + client_secret
|
|
|
|
+ + "&grant_type=" + grant_type;
|
|
|
|
+ CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
|
|
|
|
+ //创建httppost对象
|
|
|
|
+ HttpPost hp = new HttpPost(url);
|
|
|
|
+ MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
|
|
|
+ builder.setCharset(Consts.UTF_8);
|
|
|
|
+ builder.setContentType(ContentType.MULTIPART_FORM_DATA);
|
|
|
|
+ //构建参数
|
|
|
|
+ HttpEntity entity = builder.build();
|
|
|
|
+ hp.setEntity(entity);
|
|
|
|
+ CloseableHttpResponse response = null;
|
|
|
|
+ String schema=null;
|
|
|
|
+ try {
|
|
|
|
+ response = closeableHttpClient.execute(hp);
|
|
|
|
+ HttpEntity he = response.getEntity();
|
|
|
|
+ String result = EntityUtils.toString(he, StandardCharsets.UTF_8);
|
|
|
|
+ //把返回结果转json获取access_token
|
|
|
|
+ JSONObject jsonObject=JSONObject.parseObject(result);
|
|
|
|
+ String data=jsonObject.getString("data");
|
|
|
|
+ JSONObject params=JSONObject.parseObject(data);
|
|
|
|
+ String accessToken=params.getString("access_token");
|
|
|
|
+ System.out.println(result);
|
|
|
|
+ System.out.println(accessToken);
|
|
|
|
+// String accessToken = result.substring(result.indexOf("access_token") + "access_token".length() + 3, result.indexOf(",") - 1);
|
|
|
|
+// System.out.println("access_token----"+accessToken);
|
|
|
|
+ //根据accesstoken获取tiket
|
|
|
|
+ schema = getDouYingTicket(accessToken, title,videoPath);
|
|
|
|
+ EntityUtils.consume(he);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return ResponseJson.success(schema);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据token获取ticket
|
|
|
|
+ **/
|
|
|
|
+ @RequestMapping("/getDouYingTicket")
|
|
|
|
+ public String getDouYingTicket(String clientToken,String title,String videoPath) throws IOException {
|
|
|
|
+ //时间戳
|
|
|
|
+ long l = System.currentTimeMillis();
|
|
|
|
+ String timestamp = String.valueOf(l);
|
|
|
|
+ //随机数
|
|
|
|
+ String noncestr = randomGen(16);
|
|
|
|
+ String uri = "https://open.douyin.com/open/getticket/";
|
|
|
|
+ CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
|
|
|
|
+ HttpGet httpGet = new HttpGet(uri);
|
|
|
|
+ httpGet.setHeader("access-token", clientToken);
|
|
|
|
+ httpGet.setHeader("Content-Type","application/json");
|
|
|
|
+ CloseableHttpResponse response = null;
|
|
|
|
+ String schema=null;
|
|
|
|
+ try {
|
|
|
|
+ response = closeableHttpClient.execute(httpGet);
|
|
|
|
+ HttpEntity he = response.getEntity();
|
|
|
|
+ String result = EntityUtils.toString(he, StandardCharsets.UTF_8);
|
|
|
|
+ System.out.println(result);
|
|
|
|
+ //获取ticket
|
|
|
|
+ JSONObject jsonObject=JSONObject.parseObject(result);
|
|
|
|
+ String data = jsonObject.getString("data");
|
|
|
|
+ JSONObject params=JSONObject.parseObject(data);
|
|
|
|
+ String ticket = params.getString("ticket");
|
|
|
|
+ System.out.println("ticket--"+ticket);
|
|
|
|
+ //getDouYingshareId
|
|
|
|
+ String shareId = getDouYingshareId(clientToken);
|
|
|
|
+ //获取签名 并且用md5加密
|
|
|
|
+ String signature = signatureAlgorithm(ticket, timestamp,noncestr);
|
|
|
|
+ //获取schema(返回前端用于生成二维码发布视频)
|
|
|
|
+ schema = appendSchema(signature, shareId, timestamp,noncestr, title, videoPath);
|
|
|
|
+ System.out.println("schema--:"+schema);
|
|
|
|
+ EntityUtils.consume(he);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return schema;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取签名 并且用md5加密
|
|
|
|
+ * ticket
|
|
|
|
+ **/
|
|
|
|
+ @RequestMapping("/signatureAlgorithm")
|
|
|
|
+ public String signatureAlgorithm(String ticket, String timestamp,String noncestr) {
|
|
|
|
+ TreeMap<String, String> treeMap = new TreeMap<>();
|
|
|
|
+ treeMap.put("nonce_str", noncestr);
|
|
|
|
+ treeMap.put("ticket", ticket);
|
|
|
|
+ treeMap.put("timestamp", timestamp);
|
|
|
|
+
|
|
|
|
+ StringBuffer stringBuffer = new StringBuffer();
|
|
|
|
+ Iterator<Map.Entry<String, String>> it = treeMap.entrySet().iterator();
|
|
|
|
+ while (it.hasNext()) {
|
|
|
|
+ Map.Entry<String, String> entry = it.next();
|
|
|
|
+ stringBuffer.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
|
|
|
|
+ }
|
|
|
|
+ String result = stringBuffer.substring(0, stringBuffer.length() - 1);
|
|
|
|
+ System.out.println(result);
|
|
|
|
+ //进行md5签名
|
|
|
|
+ String signature = Md5Util.md5(result).toLowerCase();
|
|
|
|
+ System.out.println(signature);
|
|
|
|
+ return signature;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Schema 生成
|
|
|
|
+ **/
|
|
|
|
+ public String appendSchema(String signature, String shareId, String timestamp,String noncestr,String title,String videoPath) {
|
|
|
|
+ URIBuilder uri = null;
|
|
|
|
+ String schema = null;
|
|
|
|
+ try {
|
|
|
|
+ uri = new URIBuilder("snssdk1128://openplatform/share");
|
|
|
|
+ uri.addParameter("share_type", "h5");//固定h5
|
|
|
|
+ uri.addParameter("client_key", "awwwvh9tsnvo54w1");//应用唯一标识
|
|
|
|
+ uri.addParameter("nonce_str", noncestr);//随机数(必须和签名时的nonce_str一致)
|
|
|
|
+ uri.addParameter("timestamp", timestamp);//时间戳(必须和签名时的timestamp一致)
|
|
|
|
+ uri.addParameter("signature", signature);//签名
|
|
|
|
+ uri.addParameter("state", shareId);//通过方法获取(基于webhook,获取视频发布回调信息,不传则收不到回调信息)
|
|
|
|
+//https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4
|
|
|
|
+ //视频地址(必须为网络地址,本地地址无法发布)单视频上传
|
|
|
|
+ uri.addParameter("video_path",videoPath);//"https://caimei-oss.oss-cn-shenzhen.aliyuncs.com/beta/authFile/5c7bfb6e-9919-48b1-a905-88a888f22a11.mp4");//https://caimei-oss.oss-cn-shenzhen.aliyuncs.com/beta/authFile/5c7bfb6e-9919-48b1-a905-88a888f22a11.mp4
|
|
|
|
+ uri.addParameter("share_to_publish", "1");//为1则直接发布视频至抖音
|
|
|
|
+ uri.addParameter("title",title);//"给大佐都整emo了");//视频标题
|
|
|
|
+ schema = uri.toString();
|
|
|
|
+ } catch (URISyntaxException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return schema;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取shareId 用于生成schema
|
|
|
|
+ **/
|
|
|
|
+ @RequestMapping("/getDouYingshareId")
|
|
|
|
+ public String getDouYingshareId(String clientToken) throws IOException {
|
|
|
|
+ String uri = "https://open.douyin.com/share-id/?need_callback=true&default_hashtag=hashtag";
|
|
|
|
+ CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
|
|
|
|
+ HttpGet httpGet = new HttpGet(uri);
|
|
|
|
+ httpGet.setHeader("access-token", clientToken);
|
|
|
|
+ CloseableHttpResponse response = null;
|
|
|
|
+ String shareId = "";
|
|
|
|
+ try {
|
|
|
|
+ response = closeableHttpClient.execute(httpGet);
|
|
|
|
+ HttpEntity he = response.getEntity();
|
|
|
|
+ String result = EntityUtils.toString(he, StandardCharsets.UTF_8);
|
|
|
|
+ JSONObject jsonObject=JSONObject.parseObject(result);
|
|
|
|
+ String data = jsonObject.getString("data");
|
|
|
|
+ JSONObject params=JSONObject.parseObject(data);
|
|
|
|
+ shareId = params.getString("share_id");
|
|
|
|
+ System.out.println(result);
|
|
|
|
+ System.out.println(shareId);
|
|
|
|
+ EntityUtils.consume(he);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return shareId;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取已发布视频列表
|
|
|
|
+ * @param openId 用户唯一标志
|
|
|
|
+ * @param cursor 分页游标, 第一页请求cursor是0, response中会返回下一页请求用到的cursor, 同时response还会返回has_more来表明是否有更多的数据。
|
|
|
|
+ * @param count 每页数量 10
|
|
|
|
+ */
|
|
|
|
+ public void getVideoList(String openId,Integer cursor,Integer count,String accessToken){
|
|
|
|
+ String requestUrl="https://open.douyin.com/video/list/?open_id="+openId+"&cursor="+cursor+"&count="+count;
|
|
|
|
+ //创建httppost对象
|
|
|
|
+ CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
|
|
|
|
+ HttpGet hg = new HttpGet(requestUrl);
|
|
|
|
+ hg.setHeader("Content-Type","application/json");
|
|
|
|
+ hg.addHeader("access-token",accessToken);
|
|
|
|
+ try {
|
|
|
|
+ CloseableHttpResponse execute = closeableHttpClient.execute(hg);
|
|
|
|
+ HttpEntity entity = execute.getEntity();
|
|
|
|
+ String result=EntityUtils.toString(entity,StandardCharsets.UTF_8);
|
|
|
|
+ System.out.println(result);
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
|
+ String data = jsonObject.getString("data");
|
|
|
|
+ JSONObject paramslist = JSONObject.parseObject(data);
|
|
|
|
+ String itemIdlist = paramslist.getString("list");
|
|
|
|
+ System.out.println("list----"+itemIdlist);
|
|
|
|
+ JSONArray params = JSONArray.parseArray(itemIdlist);
|
|
|
|
+ String itemId = params.getJSONObject(0).get("item_id").toString();
|
|
|
|
+ System.out.println("item_id-----"+itemId);
|
|
|
|
+ //根据itemid获取视频的数据(点赞,播放,评论量)
|
|
|
|
+ EntityUtils.consume(entity);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 生成随机数
|
|
|
|
+ *
|
|
|
|
+ * @param place
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public String randomGen(int place) {
|
|
|
|
+ String base = "wqetryuioplkjhgfdsazxcvbmnABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
|
+ Random rd = new Random();
|
|
|
|
+ for (int i = 0; i < place; i++) {
|
|
|
|
+ sb.append(base.charAt(rd.nextInt(base.length())));
|
|
|
|
+ }
|
|
|
|
+ return sb.toString();
|
|
|
|
+ }
|
|
}
|
|
}
|