Skip to content

Commit

Permalink
新增签名接口
Browse files Browse the repository at this point in the history
  • Loading branch information
kebin6 committed Apr 23, 2024
1 parent d8c96c0 commit 0fea26b
Show file tree
Hide file tree
Showing 11 changed files with 1,350 additions and 494 deletions.
23 changes: 22 additions & 1 deletion desc/douyin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,27 @@ message SignatureReq {
string url = 1;
}


message SignatureResp {
string signature = 1;
string client_key = 2;
string nonce_str = 3;
int64 timestamp = 4;
}

message GetShareSchemaReq {
string state = 6;
string image_path = 7;
string image_list_path = 8;
string video_path = 9;
string hashtag_list = 10;
string micro_app_info = 11;
string share_to_publish = 12;
string title = 13;
string poi_id = 14;
}

message GetShareSchemaResp {
string schema = 1;
}

message AccessTokenReq {
Expand Down Expand Up @@ -49,6 +66,10 @@ service Douyin {
// 用于获取JSSDK调起半屏授权页方法需要的签名
rpc GetSignature(SignatureReq) returns (SignatureResp);

// group: dyApi
// 用于获取 分享Schema
rpc GetShareSchema(GetShareSchemaReq) returns (GetShareSchemaResp);

// group: dyApi
// 获取抖音AccessToken
rpc GetAccessToken(AccessTokenReq) returns (AccessTokenResp);
Expand Down
134 changes: 89 additions & 45 deletions douyin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,98 +3,136 @@ syntax = "proto3";
package douyin;
option go_package="./douyin";

message BaseIDUint32Resp {
uint32 id = 1;
string msg = 2;
message UUIDReq {
string id = 1;
}

message BaseUUIDResp {
string id = 1;
string msg = 2;
message PageInfoReq {
uint64 page = 1;
uint64 page_size = 2;
}

message SignatureResp {
string signature = 1;
string client_key = 2;
message IDsReq {
repeated uint64 ids = 1;
}

message IDReq {
uint64 id = 1;
message IDsInt32Req {
repeated int32 ids = 1;
}

message BaseIDInt64Resp {
int64 id = 1;
string msg = 2;
}

message BaseIDInt32Resp {
int32 id = 1;
string msg = 2;
}

message BaseIDInt64Resp {
int64 id = 1;
message UserInfoReq {
string openid = 1;
}

message IDUint32Req {
uint32 id = 1;
}

message BaseIDUint32Resp {
uint32 id = 1;
string msg = 2;
}

message UUIDReq {
string id = 1;
message BaseResp {
string msg = 1;
}

message IDsReq {
repeated uint64 ids = 1;
// base message
message Empty {}

message IDInt32Req {
int32 id = 1;
}

message IDsInt32Req {
repeated int32 ids = 1;
message BaseUUIDResp {
string id = 1;
string msg = 2;
}

message IDsInt64Req {
repeated int64 ids = 1;
message GetShareSchemaReq {
string state = 6;
string image_path = 7;
string image_list_path = 8;
string video_path = 9;
string hashtag_list = 10;
string micro_app_info = 11;
string share_to_publish = 12;
string title = 13;
string poi_id = 14;
}

message UUIDsReq {
repeated string ids = 1;
message AccessTokenReq {
string code = 1;
}

message PageInfoReq {
uint64 page = 1;
uint64 page_size = 2;
message UserInfo {
string avatar = 1;
string city = 2;
string country = 3;
string e_account_role = 4;
string gender = 5;
string nickname = 6;
string open_id = 7;
string province = 8;
string union_id = 9;
}

message SignatureReq {
string url = 1;
message UserInfoResp {
UserInfo user_info = 1;
}

message AccessTokenResp {
string access_token = 1;
message BaseIDResp {
uint64 id = 1;
string msg = 2;
}

message IDInt32Req {
int32 id = 1;
message IDsUint32Req {
repeated uint32 ids = 1;
}

message IDInt64Req {
int64 id = 1;
}

message IDUint32Req {
uint32 id = 1;
message IDsInt64Req {
repeated int64 ids = 1;
}

message IDsUint32Req {
repeated uint32 ids = 1;
message SignatureResp {
string signature = 1;
string client_key = 2;
string nonce_str = 3;
int64 timestamp = 4;
}

message BaseResp {
string msg = 1;
message IDReq {
uint64 id = 1;
}

message AccessTokenReq {
string code = 1;
message UUIDsReq {
repeated string ids = 1;
}

// base message
message Empty {}
message GetShareSchemaResp {
string schema = 1;
}

message BaseIDResp {
uint64 id = 1;
string msg = 2;
message SignatureReq {
string url = 1;
}

message AccessTokenResp {
string access_token = 1;
}

service Douyin {
Expand All @@ -104,7 +142,13 @@ service Douyin {
// 用于获取JSSDK调起半屏授权页方法需要的签名
rpc GetSignature(SignatureReq) returns (SignatureResp);
// group: dyApi
// 用于获取 分享Schema
rpc GetShareSchema(GetShareSchemaReq) returns (GetShareSchemaResp);
// group: dyApi
// 获取抖音AccessToken
rpc GetAccessToken(AccessTokenReq) returns (AccessTokenResp);
// group: dyApi
// 获取抖音用户信息
rpc GetUserInfo(UserInfoReq) returns (UserInfoResp);
}

61 changes: 39 additions & 22 deletions douyinclient/douyin.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions internal/logic/dyApi/get_share_schema_logic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package dyApi

import (
"context"
"fmt"
"github.com/kebin6/simple-douyin-rpc/open"
"github.com/kebin6/simple-douyin-rpc/open/share"

"github.com/kebin6/simple-douyin-rpc/internal/svc"
"github.com/kebin6/simple-douyin-rpc/types/douyin"

"github.com/zeromicro/go-zero/core/logx"
)

const (
schemaUrl = "snssdk1128://openplatform/share?share_type=%s&client_key=%s&nonce_str=%s&timestamp=%d&signature=%s&state=%s&image_path=%s&image_list_path=%s&video_path=%s&hashtag_list=%s&micro_app_info=%s&share_to_publish=%s&title=%s&poi_id=%s"
)

type GetShareSchemaLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}

func NewGetShareSchemaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetShareSchemaLogic {
return &GetShareSchemaLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}

func (l *GetShareSchemaLogic) GetShareSchema(in *douyin.GetShareSchemaReq) (*douyin.GetShareSchemaResp, error) {
dyCache := l.svcCtx.NewRedisCache(l.ctx, l.svcCtx.Redis)

dyConfig := l.svcCtx.Config.DouYinConf
dyConfig.Cache = dyCache
dyApi := open.NewOpenAPI(&dyConfig)
clientToken, err := dyApi.GetClientToken()
if err != nil {
return nil, err
}
// 获取 share_id,以便后续可以获取视频发布情况
shareId, err := share.NewDefaultShareId(clientToken, dyCache).GetShareId()
if err != nil {
return nil, err
}
// 获取签名
signatureLogic := NewGetSignatureLogic(l.ctx, l.svcCtx)
signatureResp, err := signatureLogic.GetSignature(&douyin.SignatureReq{})
if err != nil {
return nil, err
}

shareType := "h5"
clientKey := dyConfig.ClientKey
noceStr := signatureResp.NonceStr
timestamp := signatureResp.Timestamp
signature := signatureResp.Signature
state := shareId
imagePath := in.ImagePath
imageListPath := in.ImageListPath
videoPath := in.VideoPath
hashtagList := in.HashtagList
microAppInfo := in.MicroAppInfo
shareToPublish := in.ShareToPublish
title := in.Title
poiId := in.PoiId

schema := fmt.Sprintf(schemaUrl, shareType, clientKey, noceStr, timestamp, signature, state, imagePath, imageListPath, videoPath, hashtagList, microAppInfo, shareToPublish, title, poiId)
return &douyin.GetShareSchemaResp{
Schema: schema,
}, nil
}
Loading

0 comments on commit 0fea26b

Please sign in to comment.