schema commit

This commit is contained in:
danmo 2024-04-11 13:41:09 +08:00
parent f32a6fa8a3
commit ef38a2f990
13 changed files with 543 additions and 14 deletions

View File

@ -4,7 +4,7 @@ package com.dyj.common.domain;
* @author danmo
* @date 2024-04-09 11:30
**/
public class DySimpleResult {
public class DySimpleResult <T>{
private String err_msg;
@ -12,6 +12,8 @@ public class DySimpleResult {
private String log_id;
private T data;
public String getErr_msg() {
return err_msg;
}
@ -36,12 +38,21 @@ public class DySimpleResult {
this.log_id = log_id;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
@Override
public String toString() {
return "{" +
"err_msg='" + err_msg + '\'' +
", err_no=" + err_no +
", log_id='" + log_id + '\'' +
", data=" + data +
'}';
}
}

View File

@ -240,8 +240,32 @@ public enum DyConfigEnum {
*/
COMMENT_REPLY("commentReply","/item/comment/reply"),
/**
* H5分享跳转链接获取
*/
SCHEMA_GET_SHARE("schemaGetShare","/api/douyin/v1/schema/get_share"),
/**
* 个人页跳转链接获取
*/
SCHEMA_GET_USER_PROFILE("schemaGetUserProfile","/api/douyin/v1/schema/get_user_profile"),
/**
* 个人会话页跳转链接获取
*/
SCHEMA_GET_USER_CHAT("schemaGetUserChat","/api/douyin/v1/schema/get_chat"),
/**
* 视频详情页跳转链接获取
*/
SCHEMA_GET_ITEM_INFO("schemaGetItemInfo","/api/douyin/v1/schema/get_item_info"),
/**
* 直播间跳转链接获取
*/
SCHEMA_GET_LIVE("schemaGetLive","/api/douyin/v1/schema/get_live"),
;

View File

@ -11,7 +11,7 @@ public interface IAgentTokenService {
UserTokenInfo getTokenInfo(Integer tenantId, String clientKey, String openId) throws AuthTokenNotFoundException;
void setClientTokenInfo(Integer tenantId, String clientKey, String accessToken, Long expiresIn) throws AuthTokenNotFoundException;
ClientTokenInfo setClientTokenInfo(Integer tenantId, String clientKey, String accessToken, Long expiresIn);
ClientTokenInfo getClientTokenInfo(Integer tenantId, String clientKey) throws AuthTokenNotFoundException;

View File

@ -3,7 +3,6 @@ package com.dyj.common.service.impl;
import com.dyj.common.domain.ClientTokenInfo;
import com.dyj.common.domain.UserTokenInfo;
import com.dyj.common.exception.AuthTokenNotFoundException;
import com.dyj.common.exception.OpenIdIsNullException;
import com.dyj.common.service.IAgentTokenService;
import java.util.Map;
@ -32,7 +31,7 @@ public class CacheAgentTokenServiceImpl implements IAgentTokenService {
@Override
public UserTokenInfo getTokenInfo(Integer tenantId, String clientKey, String openId) throws AuthTokenNotFoundException {
UserTokenInfo userTokenInfo = userTokenMap.get(String.format("%s_%s_%s", tenantId, clientKey,openId));
UserTokenInfo userTokenInfo = userTokenMap.get(String.format("%s_%s_%s", tenantId, clientKey, openId));
if (Objects.isNull(userTokenInfo)) {
throw new AuthTokenNotFoundException("token not found");
}
@ -40,11 +39,12 @@ public class CacheAgentTokenServiceImpl implements IAgentTokenService {
}
@Override
public void setClientTokenInfo(Integer tenantId, String clientKey, String accessToken, Long expiresIn) throws AuthTokenNotFoundException {
public ClientTokenInfo setClientTokenInfo(Integer tenantId, String clientKey, String accessToken, Long expiresIn){
ClientTokenInfo clientTokenInfo = new ClientTokenInfo();
clientTokenInfo.setAccessToken(accessToken);
clientTokenInfo.setExpiresIn(expiresIn);
clientTokenMap.put(String.format("%s_%s", tenantId, clientKey), clientTokenInfo);
return clientTokenInfo;
}
@Override
@ -53,6 +53,4 @@ public class CacheAgentTokenServiceImpl implements IAgentTokenService {
}
}

View File

@ -551,4 +551,54 @@ public class DyWebClient {
return new CommentHandler(configuration().getAgentConfigService().loadAgentByTenantId(tenantId, clientKey)).commentReply(query);
}
/**
* H5分享跳转链接获取
* @param query 入参
* @return DySimpleResult<SchemaShareVo>
*/
public DySimpleResult<SchemaShareVo> getH5Share(GetH5ShareQuery query) {
return new SchemaHandler(configuration().getAgentConfigService().loadAgentByTenantId(tenantId, clientKey)).getH5Share(query);
}
/**
* 个人页跳转链接获取
* @param openId 用户ID
* @param account 抖音号
* @param expireAt 生成短链过期时间
* @return DySimpleResult<SchemaShareVo>
*/
public DySimpleResult<SchemaShareVo> getUserProfile(String openId, String account, Long expireAt) {
return new SchemaHandler(configuration().getAgentConfigService().loadAgentByTenantId(tenantId, clientKey)).getUserProfile(openId, account, expireAt);
}
/**
* 个人会话页跳转链接获取
* @param openId 用户ID
* @param account 抖音号
* @param expireAt 生成短链过期时间
* @return DySimpleResult<SchemaShareVo>
*/
DySimpleResult<SchemaShareVo> getUserChat(String openId,String account, Long expireAt){
return new SchemaHandler(configuration().getAgentConfigService().loadAgentByTenantId(tenantId, clientKey)).getUserChat(openId, account, expireAt);
}
/**
* 视频详情页跳转链接获取
* @param itemId 视频ID
* @param videoId 视频ID
* @param expireAt 生成短链过期时间
* @return DySimpleResult<SchemaShareVo>
*/
public DySimpleResult<SchemaShareVo> getItem(String itemId, String videoId, Long expireAt) {
return new SchemaHandler(configuration().getAgentConfigService().loadAgentByTenantId(tenantId, clientKey)).getItem(itemId, videoId, expireAt);
}
/**
* 直播间页跳转链接获取
* @param openId 用户ID
* @param account 抖音号
* @param expireAt 生成短链过期时间
* @return DySimpleResult<SchemaShareVo>
*/
public DySimpleResult<SchemaShareVo> getLive(String openId,String account, Long expireAt) {
return new SchemaHandler(configuration().getAgentConfigService().loadAgentByTenantId(tenantId, clientKey)).getLive(openId, account, expireAt);
}
}

View File

@ -0,0 +1,54 @@
package com.dyj.web.client;
import com.dtflys.forest.annotation.BaseRequest;
import com.dtflys.forest.annotation.JSONBody;
import com.dtflys.forest.annotation.Post;
import com.dtflys.forest.backend.ContentType;
import com.dyj.common.domain.DySimpleResult;
import com.dyj.web.domain.query.BaseQuery;
import com.dyj.web.domain.query.GetH5ShareQuery;
import com.dyj.web.domain.vo.SchemaShareVo;
import com.dyj.web.interceptor.ClientTokenInterceptor;
/**
* 场景跳转接口
*
* @author danmo
* @date 2024-04-11 11:17
**/
@BaseRequest(baseURL = "${domain}", contentType = ContentType.APPLICATION_JSON)
public interface SchemaClient {
/**
* H5分享跳转链接获取
*
* @param query 入参
*/
@Post(value = "${schemaGetShare}", interceptor = ClientTokenInterceptor.class)
DySimpleResult<SchemaShareVo> getH5Share(@JSONBody GetH5ShareQuery query);
/**
* 个人页跳转链接获取
*/
@Post(value = "${schemaGetUserProfile}", interceptor = ClientTokenInterceptor.class)
DySimpleResult<SchemaShareVo> getUserProfile(@JSONBody BaseQuery query, @JSONBody("open_id") String openId,@JSONBody("account") String account, @JSONBody("expire_at") Long expireAt);
/**
* 个人会话页跳转链接获取
*/
@Post(value = "${schemaGetUserChat}", interceptor = ClientTokenInterceptor.class)
DySimpleResult<SchemaShareVo> getUserChat(@JSONBody BaseQuery query, @JSONBody("open_id") String openId,@JSONBody("account") String account, @JSONBody("expire_at") Long expireAt);
/**
* 视频详情页跳转链接获取
*/
@Post(value = "${schemaGetItem}", interceptor = ClientTokenInterceptor.class)
DySimpleResult<SchemaShareVo> getItem(@JSONBody BaseQuery query, @JSONBody("item_id") String itemId, @JSONBody("video_id") String videoId, @JSONBody("expire_at") Long expireAt);
/**
* 直播间跳转链接获取
*/
@Post(value = "${schemaGetLive}", interceptor = ClientTokenInterceptor.class)
DySimpleResult<SchemaShareVo> getLive(@JSONBody BaseQuery query, @JSONBody("open_id") String openId, @JSONBody("account") String account, @JSONBody("expire_at") Long expireAt);
}

View File

@ -0,0 +1,24 @@
package com.dyj.web.domain;
/**
* @author danmo
* @date 2024-04-11 11:33
**/
public class MiroAppInfo {
/**
* 小程序appId
*/
private String appId;
/**
* 标题
*/
private String appTitle;
/**
* 小程序地址
*/
private String appUrl;
/**
* 小程序描述
*/
private String description;
}

View File

@ -0,0 +1,243 @@
package com.dyj.web.domain.query;
import com.dyj.web.domain.MiroAppInfo;
import java.util.List;
/**
* @author danmo
* @date 2024-04-11 11:28
**/
public class GetH5ShareQuery extends BaseQuery{
/**
* client_ticket
*/
private String client_ticket;
/**
* 过期时间
*/
private String expire_at;
/**
* 支持有第三方预设内容分享抖音时默认携带的话题
*/
private List<String> hashtag_list;
/**
* 图片文件路径(多个)图集模式分享
*/
private List<String> image_list_path;
/**
* 添加小程序视频成功发布视频后在视频左下角带有小程序入口
*/
private List<MiroAppInfo> micro_app_info;
/**
* 地理位置信息锚点id与小程序appId互斥优先展示小程序
*/
private String poi_id;
/**
* 为1时直接分享到抖音发布页仅视频
*/
private Integer share_to_publish;
/**
* 建议填写按照文档获取share_id可以获取视频发布情况
*/
private String state;
/**
* 视频标题
*/
private String title;
/**
* 视频文件路径单个不能超过128M)
*/
private String video_path;
public String getClient_ticket() {
return client_ticket;
}
public void setClient_ticket(String client_ticket) {
this.client_ticket = client_ticket;
}
public String getExpire_at() {
return expire_at;
}
public void setExpire_at(String expire_at) {
this.expire_at = expire_at;
}
public List<String> getHashtag_list() {
return hashtag_list;
}
public void setHashtag_list(List<String> hashtag_list) {
this.hashtag_list = hashtag_list;
}
public List<String> getImage_list_path() {
return image_list_path;
}
public void setImage_list_path(List<String> image_list_path) {
this.image_list_path = image_list_path;
}
public List<MiroAppInfo> getMicro_app_info() {
return micro_app_info;
}
public void setMicro_app_info(List<MiroAppInfo> micro_app_info) {
this.micro_app_info = micro_app_info;
}
public String getPoi_id() {
return poi_id;
}
public void setPoi_id(String poi_id) {
this.poi_id = poi_id;
}
public Integer getShare_to_publish() {
return share_to_publish;
}
public void setShare_to_publish(Integer share_to_publish) {
this.share_to_publish = share_to_publish;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getVideo_path() {
return video_path;
}
public void setVideo_path(String video_path) {
this.video_path = video_path;
}
public static GetH5ShareQueryBuilder builder() {
return new GetH5ShareQueryBuilder();
}
public static class GetH5ShareQueryBuilder {
private String clientTicket;
private String expireAt;
private List<String> hashtagList;
private List<String> imageListPath;
private List<MiroAppInfo> microAppInfo;
private String poiId;
private Integer shareToPublish;
private String state;
private String title;
private String videoPath;
public GetH5ShareQueryBuilder clientTicket(String clientTicket) {
this.clientTicket = clientTicket;
return this;
}
public GetH5ShareQueryBuilder expireAt(String expireAt) {
this.expireAt = expireAt;
return this;
}
public GetH5ShareQueryBuilder hashtagList(List<String> hashtagList) {
this.hashtagList = hashtagList;
return this;
}
public GetH5ShareQueryBuilder imageListPath(List<String> imageListPath) {
this.imageListPath = imageListPath;
return this;
}
public GetH5ShareQueryBuilder microAppInfo(List<MiroAppInfo> microAppInfo) {
this.microAppInfo = microAppInfo;
return this;
}
public GetH5ShareQueryBuilder poiId(String poiId) {
this.poiId = poiId;
return this;
}
public GetH5ShareQueryBuilder shareToPublish(Integer shareToPublish) {
this.shareToPublish = shareToPublish;
return this;
}
public GetH5ShareQueryBuilder state(String state) {
this.state = state;
return this;
}
public GetH5ShareQueryBuilder title(String title) {
this.title = title;
return this;
}
public GetH5ShareQueryBuilder videoPath(String videoPath) {
this.videoPath = videoPath;
return this;
}
public GetH5ShareQuery build() {
GetH5ShareQuery getH5ShareQuery = new GetH5ShareQuery();
getH5ShareQuery.setClient_ticket(clientTicket);
getH5ShareQuery.setExpire_at(expireAt);
getH5ShareQuery.setHashtag_list(hashtagList);
getH5ShareQuery.setImage_list_path(imageListPath);
getH5ShareQuery.setMicro_app_info(microAppInfo);
getH5ShareQuery.setPoi_id(poiId);
getH5ShareQuery.setShare_to_publish(shareToPublish);
getH5ShareQuery.setState(state);
getH5ShareQuery.setTitle(title);
getH5ShareQuery.setVideo_path(videoPath);
return getH5ShareQuery;
}
}
@Override
public String toString() {
return "GetH5ShareQuery{" +
"client_ticket='" + client_ticket + '\'' +
", expire_at='" + expire_at + '\'' +
", hashtag_list=" + hashtag_list +
", image_list_path=" + image_list_path +
", micro_app_info=" + micro_app_info +
", poi_id='" + poi_id + '\'' +
", share_to_publish=" + share_to_publish +
", state='" + state + '\'' +
", title='" + title + '\'' +
", video_path='" + video_path + '\'' +
", tenantId=" + tenantId +
", clientKey='" + clientKey + '\'' +
'}';
}
}

View File

@ -13,7 +13,7 @@ public class ClientTokenVo extends BaseVo{
/**
* access_token接口调用凭证超时时间单位)
*/
private Integer expires_in;
private Long expires_in;
public String getAccess_token() {
@ -24,11 +24,11 @@ public class ClientTokenVo extends BaseVo{
this.access_token = access_token;
}
public Integer getExpires_in() {
public Long getExpires_in() {
return expires_in;
}
public void setExpires_in(Integer expires_in) {
public void setExpires_in(Long expires_in) {
this.expires_in = expires_in;
}

View File

@ -0,0 +1,28 @@
package com.dyj.web.domain.vo;
/**
* @author danmo
* @date 2024-04-11 11:41
**/
public class SchemaShareVo {
/**
* Schema链接
*/
private String schema;
public String getSchema() {
return schema;
}
public void setSchema(String schema) {
this.schema = schema;
}
@Override
public String toString() {
return "SchemaShareVo{" +
"schema='" + schema + '\'' +
'}';
}
}

View File

@ -3,6 +3,7 @@ package com.dyj.web.handler;
import com.dyj.common.config.AgentConfiguration;
import com.dyj.spring.utils.SpringUtils;
import com.dyj.web.client.*;
import com.dyj.web.domain.query.BaseQuery;
/**
* @author danmo
@ -47,4 +48,12 @@ public abstract class AbstractWebHandler {
protected CommentClient getCommentClient() {
return SpringUtils.getBean(CommentClient.class);
}
protected SchemaClient getSchemaClient() {
return SpringUtils.getBean(SchemaClient.class);
}
void setBaseQuery(BaseQuery query){
query.setTenantId(agentConfiguration.getTenantId());
query.setClientKey(agentConfiguration.getClientKey());
}
}

View File

@ -0,0 +1,80 @@
package com.dyj.web.handler;
import com.dtflys.forest.annotation.JSONBody;
import com.dyj.common.config.AgentConfiguration;
import com.dyj.common.domain.DySimpleResult;
import com.dyj.web.domain.query.BaseQuery;
import com.dyj.web.domain.query.GetH5ShareQuery;
import com.dyj.web.domain.vo.SchemaShareVo;
/**
* @author danmo
* @date 2024-04-11 11:54
**/
public class SchemaHandler extends AbstractWebHandler {
public SchemaHandler(AgentConfiguration agentConfiguration) {
super(agentConfiguration);
}
/**
* H5分享跳转链接获取
* @param query
* @return
*/
public DySimpleResult<SchemaShareVo> getH5Share(GetH5ShareQuery query) {
setBaseQuery(query);
return getSchemaClient().getH5Share(query);
}
/**
* 个人页跳转链接获取
* @param openId 用户ID
* @param account 抖音号
* @param expireAt 生成短链过期时间
* @return DySimpleResult<SchemaShareVo>
*/
public DySimpleResult<SchemaShareVo> getUserProfile(String openId, String account, Long expireAt) {
BaseQuery query = new BaseQuery();
setBaseQuery(query);
return getSchemaClient().getUserProfile(query, openId, account, expireAt);
}
/**
* 个人会话页跳转链接获取
* @param openId 用户ID
* @param account 抖音号
* @param expireAt 生成短链过期时间
* @return DySimpleResult<SchemaShareVo>
*/
public DySimpleResult<SchemaShareVo> getUserChat(String openId, String account, Long expireAt){
BaseQuery query = new BaseQuery();
setBaseQuery(query);
return getSchemaClient().getUserChat(query, openId, account, expireAt);
}
/**
* 视频详情页跳转链接获取
* @param itemId 视频ID
* @param videoId 视频ID
* @param expireAt 生成短链过期时间
* @return DySimpleResult<SchemaShareVo>
*/
public DySimpleResult<SchemaShareVo> getItem(String itemId, String videoId, Long expireAt){
BaseQuery query = new BaseQuery();
setBaseQuery(query);
return getSchemaClient().getItem(query, itemId, videoId, expireAt);
}
/**
* 直播间页跳转链接获取
* @param openId 用户ID
* @param account 抖音号
* @param expireAt 生成短链过期时间
* @return DySimpleResult<SchemaShareVo>
*/
public DySimpleResult<SchemaShareVo> getLive(String openId,String account, Long expireAt){
BaseQuery query = new BaseQuery();
setBaseQuery(query);
return getSchemaClient().getLive(query, openId,account, expireAt);
}
}

View File

@ -10,8 +10,11 @@ import com.dyj.common.domain.DyResult;
import com.dyj.common.domain.UserTokenInfo;
import com.dyj.common.handler.RequestHandler;
import com.dyj.common.service.IAgentTokenService;
import com.dyj.common.utils.DyConfigUtils;
import com.dyj.web.DyWebClient;
import com.dyj.web.domain.query.BaseQuery;
import com.dyj.web.domain.query.UserInfoQuery;
import com.dyj.web.domain.vo.ClientTokenVo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -32,13 +35,18 @@ public class ClientTokenInterceptor implements Interceptor<DyResult> {
}
}
IAgentTokenService agentTokenService = RequestHandler.getInstance().getDyConfiguration().getAgentTokenService();
IAgentTokenService agentTokenService = DyConfigUtils.getAgentTokenService();
ClientTokenInfo clientTokenInfo = agentTokenService.getClientTokenInfo(tenantId, clientKey);
if (Objects.isNull(clientTokenInfo)) {
throw new RuntimeException("access_token is null");
ClientTokenVo clientToken = DyWebClient.getInstance().tenantId(tenantId).clientKey(clientKey).clientToken().getData();
if(Objects.nonNull(clientToken) && clientToken.getError_code() == 0){
clientTokenInfo = agentTokenService.setClientTokenInfo(tenantId, clientKey, clientToken.getAccess_token(), clientToken.getExpires_in());
}
}
request.addBody("access-token", clientTokenInfo.getAccessToken());
return Interceptor.super.beforeExecute(request);
if (Objects.nonNull(clientTokenInfo)) {
request.addBody("access-token", clientTokenInfo.getAccessToken());
}
return true;
}
@Override