Skip to content

Commit

Permalink
签名接口,url改成非必填
Browse files Browse the repository at this point in the history
  • Loading branch information
kebin6 committed Apr 23, 2024
1 parent 0fea26b commit f4af593
Show file tree
Hide file tree
Showing 4 changed files with 630 additions and 625 deletions.
2 changes: 1 addition & 1 deletion desc/douyin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ option go_package="./douyin";
message Empty {}

message SignatureReq {
string url = 1;
optional string url = 1;
}

message SignatureResp {
Expand Down
116 changes: 58 additions & 58 deletions douyin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,58 @@ syntax = "proto3";
package douyin;
option go_package="./douyin";

message UUIDReq {
string id = 1;
message IDReq {
uint64 id = 1;
}

message PageInfoReq {
uint64 page = 1;
uint64 page_size = 2;
message IDsInt32Req {
repeated int32 ids = 1;
}

message IDsReq {
repeated uint64 ids = 1;
message BaseResp {
string msg = 1;
}

message IDsInt32Req {
repeated int32 ids = 1;
message SignatureReq {
optional string url = 1;
}

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

message BaseIDInt32Resp {
int32 id = 1;
string msg = 2;
message IDsUint32Req {
repeated uint32 ids = 1;
}

message UserInfoReq {
string openid = 1;
}

message IDUint32Req {
uint32 id = 1;
message IDInt32Req {
int32 id = 1;
}

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

message BaseResp {
string msg = 1;
message IDUint32Req {
uint32 id = 1;
}

// base message
message Empty {}
message UUIDsReq {
repeated string ids = 1;
}

message IDInt32Req {
int32 id = 1;
message PageInfoReq {
uint64 page = 1;
uint64 page_size = 2;
}

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

Expand All @@ -75,37 +74,25 @@ message AccessTokenReq {
string code = 1;
}

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 UserInfoResp {
UserInfo user_info = 1;
message AccessTokenResp {
string access_token = 1;
}

message BaseIDResp {
uint64 id = 1;
string msg = 2;
message IDInt64Req {
int64 id = 1;
}

message IDsUint32Req {
repeated uint32 ids = 1;
message IDsInt64Req {
repeated int64 ids = 1;
}

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

message IDsInt64Req {
repeated int64 ids = 1;
message UUIDReq {
string id = 1;
}

message SignatureResp {
Expand All @@ -115,24 +102,37 @@ message SignatureResp {
int64 timestamp = 4;
}

message IDReq {
// base message
message Empty {}

message IDsReq {
repeated uint64 ids = 1;
}

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

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

message GetShareSchemaResp {
string schema = 1;
}

message SignatureReq {
string url = 1;
}

message AccessTokenResp {
string access_token = 1;
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;
}

service Douyin {
Expand Down
7 changes: 5 additions & 2 deletions internal/logic/dyApi/get_signature_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ func (l *GetSignatureLogic) GetSignature(in *douyin.SignatureReq) (*douyin.Signa
}, nil
}

func (l *GetSignatureLogic) Sign(jsapiTicket string, url string) (sign string, nonceStr string, timestamp int64) {
func (l *GetSignatureLogic) Sign(jsapiTicket string, url *string) (sign string, nonceStr string, timestamp int64) {
nonceStr = util.GenRandomString(16)
timestamp = time.Now().Unix()
// 对所有待签名参数按照字段名的 ASCII 码从小到大排序(字典序)后,使用 URL 键值对的格式(即 key1=value1&key2=value2…)拼接成字符串 string1
string1 := "jsapi_ticket=" + jsapiTicket + "&noncestr=" + nonceStr + "&timestamp=" + strconv.FormatInt(timestamp, 10) + "&url=" + url
string1 := "jsapi_ticket=" + jsapiTicket + "&noncestr=" + nonceStr + "&timestamp=" + strconv.FormatInt(timestamp, 10)
if url != nil {
string1 += "&url=" + *url
}
// 对 string1 进行 MD5 签名,得到 signature
hash := md5.Sum([]byte(string1))
return hex.EncodeToString(hash[:]), nonceStr, timestamp
Expand Down
Loading

0 comments on commit f4af593

Please sign in to comment.