|
@@ -1,5 +1,6 @@
|
|
package com.caimei.service.auth.impl;
|
|
package com.caimei.service.auth.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.caimei.components.RedisService;
|
|
import com.caimei.components.RedisService;
|
|
@@ -66,6 +67,8 @@ 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;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Description
|
|
* Description
|
|
@@ -956,7 +959,7 @@ public class AuthServiceImpl implements AuthService {
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public ResponseJson getclientToken(String title,String videoPath) throws IOException {
|
|
|
|
|
|
+ public ResponseJson getclientToken(String title,String videoPath,Integer authId) throws IOException {
|
|
//获取accessToken
|
|
//获取accessToken
|
|
String client_key = "awwwvh9tsnvo54w1";
|
|
String client_key = "awwwvh9tsnvo54w1";
|
|
String client_secret = "1dd7446d29e16738787447b771ced2df";
|
|
String client_secret = "1dd7446d29e16738787447b771ced2df";
|
|
@@ -985,7 +988,7 @@ public class AuthServiceImpl implements AuthService {
|
|
JSONObject params=JSONObject.parseObject(data);
|
|
JSONObject params=JSONObject.parseObject(data);
|
|
String accessToken=params.getString("access_token");
|
|
String accessToken=params.getString("access_token");
|
|
//根据accesstoken获取tiket
|
|
//根据accesstoken获取tiket
|
|
- schema = getDouYingTicket(accessToken, title,videoPath);
|
|
|
|
|
|
+ schema = getDouYingTicket(accessToken, title,videoPath,authId);
|
|
EntityUtils.consume(he);
|
|
EntityUtils.consume(he);
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -997,7 +1000,7 @@ public class AuthServiceImpl implements AuthService {
|
|
* 根据token获取ticket
|
|
* 根据token获取ticket
|
|
**/
|
|
**/
|
|
@RequestMapping("/getDouYingTicket")
|
|
@RequestMapping("/getDouYingTicket")
|
|
- public String getDouYingTicket(String clientToken,String title,String videoPath) throws IOException {
|
|
|
|
|
|
+ public String getDouYingTicket(String clientToken,String title,String videoPath,Integer authId) throws IOException {
|
|
//时间戳
|
|
//时间戳
|
|
long l = System.currentTimeMillis();
|
|
long l = System.currentTimeMillis();
|
|
String timestamp = String.valueOf(l);
|
|
String timestamp = String.valueOf(l);
|
|
@@ -1021,6 +1024,8 @@ public class AuthServiceImpl implements AuthService {
|
|
String ticket = params.getString("ticket");
|
|
String ticket = params.getString("ticket");
|
|
//getDouYingshareId
|
|
//getDouYingshareId
|
|
String shareId = getDouYingshareId(clientToken);
|
|
String shareId = getDouYingshareId(clientToken);
|
|
|
|
+ //保存shareId用于回调时存储item_id
|
|
|
|
+ authMapper.savaShareIdByAuthId(authId,shareId);
|
|
//获取签名 并且用md5加密
|
|
//获取签名 并且用md5加密
|
|
String signature = signatureAlgorithm(ticket, timestamp,noncestr);
|
|
String signature = signatureAlgorithm(ticket, timestamp,noncestr);
|
|
//获取schema(返回前端用于生成二维码发布视频)
|
|
//获取schema(返回前端用于生成二维码发布视频)
|
|
@@ -1113,13 +1118,14 @@ public class AuthServiceImpl implements AuthService {
|
|
* @param cursor 分页游标, 第一页请求cursor是0, response中会返回下一页请求用到的cursor, 同时response还会返回has_more来表明是否有更多的数据。
|
|
* @param cursor 分页游标, 第一页请求cursor是0, response中会返回下一页请求用到的cursor, 同时response还会返回has_more来表明是否有更多的数据。
|
|
* @param count 每页数量 10
|
|
* @param count 每页数量 10
|
|
*/
|
|
*/
|
|
- public void getVideoList(String openId,Integer cursor,Integer count,String accessToken){
|
|
|
|
|
|
+ public String getVideoList(String openId,Integer cursor,Integer count,String accessToken){
|
|
String requestUrl="https://open.douyin.com/video/list/?open_id="+openId+"&cursor="+cursor+"&count="+count;
|
|
String requestUrl="https://open.douyin.com/video/list/?open_id="+openId+"&cursor="+cursor+"&count="+count;
|
|
//创建httppost对象
|
|
//创建httppost对象
|
|
CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
|
|
CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
|
|
HttpGet hg = new HttpGet(requestUrl);
|
|
HttpGet hg = new HttpGet(requestUrl);
|
|
hg.setHeader("Content-Type","application/json");
|
|
hg.setHeader("Content-Type","application/json");
|
|
hg.addHeader("access-token",accessToken);
|
|
hg.addHeader("access-token",accessToken);
|
|
|
|
+ String resultList=null;
|
|
try {
|
|
try {
|
|
CloseableHttpResponse execute = closeableHttpClient.execute(hg);
|
|
CloseableHttpResponse execute = closeableHttpClient.execute(hg);
|
|
HttpEntity entity = execute.getEntity();
|
|
HttpEntity entity = execute.getEntity();
|
|
@@ -1127,15 +1133,15 @@ public class AuthServiceImpl implements AuthService {
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
String data = jsonObject.getString("data");
|
|
String data = jsonObject.getString("data");
|
|
JSONObject paramslist = JSONObject.parseObject(data);
|
|
JSONObject paramslist = JSONObject.parseObject(data);
|
|
- String itemIdlist = paramslist.getString("list");
|
|
|
|
- JSONArray params = JSONArray.parseArray(itemIdlist);
|
|
|
|
- String itemId = params.getJSONObject(0).get("item_id").toString();
|
|
|
|
|
|
+ resultList = paramslist.getString("list");
|
|
|
|
+// resultList = JSONArray.parseArray(itemIdlist);
|
|
|
|
+// String itemId = params.getJSONObject(0).get("item_id").toString();
|
|
//根据itemid获取视频的数据(点赞,播放,评论量)
|
|
//根据itemid获取视频的数据(点赞,播放,评论量)
|
|
EntityUtils.consume(entity);
|
|
EntityUtils.consume(entity);
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ return resultList;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1153,4 +1159,133 @@ public class AuthServiceImpl implements AuthService {
|
|
}
|
|
}
|
|
return sb.toString();
|
|
return sb.toString();
|
|
}
|
|
}
|
|
|
|
+ /**
|
|
|
|
+ * 保存视频信息
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson saveVideoInfo(ChallengeRoundVo cr){
|
|
|
|
+ Date date=new Date();
|
|
|
|
+ SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ String releaseTime = sf.format(date).replace("T", "");
|
|
|
|
+ authMapper.saveVideoInfo(cr.getUserName(),cr.getCover(),cr.getOssUrl(),cr.getOssName(),cr.getTitle(),releaseTime,cr.getAuthId(),cr.getAuthUserId());
|
|
|
|
+ return ResponseJson.success("保存成功",null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据authid获取authUserId
|
|
|
|
+ * @param authId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public boolean getauthUserId(Integer authId){
|
|
|
|
+ String authUserId= authMapper.getauthUserId(authId);
|
|
|
|
+ return StringUtils.isEmpty(authUserId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 判断是否存在userName
|
|
|
|
+ * @param userName
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public boolean getuserName(String userName){
|
|
|
|
+ String name= authMapper.getuserName(userName);
|
|
|
|
+ return StringUtils.isEmpty(name);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 验证是否在活动时间内
|
|
|
|
+ * @param releaseTime 发布时间
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public boolean checkActivityTime(String releaseTime){
|
|
|
|
+ Integer id= authMapper.checkActivityTime(releaseTime);
|
|
|
|
+ return id==null?true:false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取已发布视频列表
|
|
|
|
+ * @param clubUserName 手机号或者机构名
|
|
|
|
+ * @param status 用户发布状态
|
|
|
|
+ * @param cursor 页码
|
|
|
|
+ * @param count 条数
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<List<ChallengeRoundVo>> getPublishedVideoList(String clubUserName,Integer status,Integer cursor,Integer count,Integer authUserId){
|
|
|
|
+ List<ChallengeRoundVo> listChallengeRoundVo=authMapper.getPublishedVideoList(clubUserName,status,authUserId);
|
|
|
|
+ //调用抖音api获取视频数据
|
|
|
|
+ String dyopenId=redisService.get("DyopenId").toString();
|
|
|
|
+ String DYaccessToken=redisService.get("DYaccessToken").toString();
|
|
|
|
+ String paramsList = getVideoList(dyopenId, cursor, count, DYaccessToken);
|
|
|
|
+
|
|
|
|
+ List<DyVideoInfoVo> list= JSONArray.parseArray(paramsList, DyVideoInfoVo.class);
|
|
|
|
+ for (ChallengeRoundVo ChallengeRoundVo:listChallengeRoundVo) {
|
|
|
|
+ for (DyVideoInfoVo dyVideoInfoVo:list) {
|
|
|
|
+ if(dyVideoInfoVo.getItem_id().equals(ChallengeRoundVo.getItemId())){
|
|
|
|
+ StatisticsVo StatisticsVo= JSONObject.parseObject(dyVideoInfoVo.getStatistics(), StatisticsVo.class);
|
|
|
|
+ ChallengeRoundVo.setDigg_count(StatisticsVo.getDigg_count());
|
|
|
|
+ ChallengeRoundVo.setPlay_count(StatisticsVo.getPlay_count());
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //根据点赞量降序排序
|
|
|
|
+ List<ChallengeRoundVo> collect = listChallengeRoundVo.stream().sorted(Comparator.comparing(ChallengeRoundVo::getDigg_count).reversed().thenComparing(ChallengeRoundVo::getPlay_count, Comparator.reverseOrder())).collect(Collectors.toList());//先以属性一升序,升序结果进行属性一降序,再进行属性二降序
|
|
|
|
+ return ResponseJson.success(collect);
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 保存活动信息
|
|
|
|
+ * @param startTime
|
|
|
|
+ * @param endTime
|
|
|
|
+ * @param status
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson saveActivityTime(String startTime,String endTime,Integer status,Integer authUserId){
|
|
|
|
+ //如果数据库有值则修改,没值则新增
|
|
|
|
+ Integer aid = authMapper.checkActivityId();
|
|
|
|
+ if(aid==null){
|
|
|
|
+ authMapper.saveActivityInfo(startTime,endTime,status,authUserId);
|
|
|
|
+ }else {
|
|
|
|
+ authMapper.upActivityInfo(startTime,endTime,status,authUserId);
|
|
|
|
+ }
|
|
|
|
+ return ResponseJson.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取活动信息
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<ChallengeActivityVo> getActivityTime(Integer authUserId){
|
|
|
|
+ return ResponseJson.success(authMapper.getActivityTime(authUserId));
|
|
|
|
+ }
|
|
|
|
+ @Override
|
|
|
|
+ public boolean getShareId(String shareId){
|
|
|
|
+ return StringUtils.isNotEmpty(authMapper.getShareId(shareId));
|
|
|
|
+ }
|
|
|
|
+ @Override
|
|
|
|
+ public void savaItemIdByShareId(String shareId,String itemId){
|
|
|
|
+ authMapper.savaItemIdByShareId(shareId,itemId);
|
|
|
|
+ }
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<ChallengeActivityVo> getActivitty(Integer authUserId){
|
|
|
|
+ ChallengeActivityVo activityTime = authMapper.getActivityTime(authUserId);
|
|
|
|
+ Date date=new Date();
|
|
|
|
+ SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ String releaseTime = sf.format(date).replace("T", "");
|
|
|
|
+ if(activityTime!=null){
|
|
|
|
+ if(activityTime.getStartTime().compareTo(releaseTime)>0){
|
|
|
|
+ activityTime.setActivityState(0);
|
|
|
|
+ }else if(activityTime.getStartTime().compareTo(releaseTime)<0&&activityTime.getEndtime().compareTo(releaseTime)>0){
|
|
|
|
+ activityTime.setActivityState(1);
|
|
|
|
+ }else {
|
|
|
|
+ activityTime.setActivityState(2);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return ResponseJson.success(activityTime);
|
|
|
|
+ }
|
|
}
|
|
}
|