mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-08 21:47:17 +08:00
aes key api
This commit is contained in:
parent
068c2d4729
commit
aa3169f72c
22
internal/api/aesKey.go
Normal file
22
internal/api/aesKey.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
aesKey "github.com/OpenIMSDK/protocol/aeskey"
|
||||||
|
"github.com/OpenIMSDK/tools/a2r"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/rpcclient"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AesKeyApi rpcclient.AesKey
|
||||||
|
|
||||||
|
func NewAesKeyApi(client rpcclient.AesKey) AesKeyApi {
|
||||||
|
return AesKeyApi(client)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AesKeyApi) GetKey(c *gin.Context) {
|
||||||
|
a2r.Call(aesKey.AesKeyClient.AcquireAesKey, a.Client, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AesKeyApi) GetKeys(c *gin.Context) {
|
||||||
|
a2r.Call(aesKey.AesKeyClient.AcquireAesKeys, a.Client, c)
|
||||||
|
}
|
||||||
@ -59,9 +59,11 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
|
|||||||
conversationRpc := rpcclient.NewConversation(discov)
|
conversationRpc := rpcclient.NewConversation(discov)
|
||||||
authRpc := rpcclient.NewAuth(discov)
|
authRpc := rpcclient.NewAuth(discov)
|
||||||
thirdRpc := rpcclient.NewThird(discov)
|
thirdRpc := rpcclient.NewThird(discov)
|
||||||
|
aesKeyRpc := rpcclient.NewAesKey(discov)
|
||||||
|
|
||||||
u := NewUserApi(*userRpc)
|
u := NewUserApi(*userRpc)
|
||||||
m := NewMessageApi(messageRpc, userRpc)
|
m := NewMessageApi(messageRpc, userRpc)
|
||||||
|
k := NewAesKeyApi(*aesKeyRpc)
|
||||||
ParseToken := GinParseToken(rdb)
|
ParseToken := GinParseToken(rdb)
|
||||||
userRouterGroup := r.Group("/user")
|
userRouterGroup := r.Group("/user")
|
||||||
{
|
{
|
||||||
@ -205,6 +207,11 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
|
|||||||
statisticsGroup.POST("/group/create", g.GroupCreateCount)
|
statisticsGroup.POST("/group/create", g.GroupCreateCount)
|
||||||
statisticsGroup.POST("/group/active", m.GetActiveGroup)
|
statisticsGroup.POST("/group/active", m.GetActiveGroup)
|
||||||
}
|
}
|
||||||
|
aesKeyGroup := r.Group("/aes_key", ParseToken)
|
||||||
|
{
|
||||||
|
aesKeyGroup.POST("/get_key", k.GetKey)
|
||||||
|
aesKeyGroup.POST("/get_keys", k.GetKeys)
|
||||||
|
}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
38
pkg/rpcclient/aes_key.go
Normal file
38
pkg/rpcclient/aes_key.go
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package rpcclient
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
aesKey "github.com/OpenIMSDK/protocol/aeskey"
|
||||||
|
"github.com/OpenIMSDK/tools/discoveryregistry"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AesKey struct {
|
||||||
|
conn grpc.ClientConnInterface
|
||||||
|
Client aesKey.AesKeyClient
|
||||||
|
Discov discoveryregistry.SvcDiscoveryRegistry
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAesKey(discov discoveryregistry.SvcDiscoveryRegistry) *AesKey {
|
||||||
|
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImAesKeyName)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
client := aesKey.NewAesKeyClient(conn)
|
||||||
|
return &AesKey{Discov: discov, Client: client, conn: conn}
|
||||||
|
}
|
||||||
|
|
||||||
|
type AesKeyRpcClient AesKey
|
||||||
|
|
||||||
|
func NewAesKeyRpcClient(discov discoveryregistry.SvcDiscoveryRegistry) AesKeyRpcClient {
|
||||||
|
return AesKeyRpcClient(*NewAesKey(discov))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AesKeyRpcClient) AcquireAesKey(ctx context.Context, conversationType int32, userID, friendUserID, groupID string) (*aesKey.AcquireAesKeyResp, error) {
|
||||||
|
return a.Client.AcquireAesKey(ctx, &aesKey.AcquireAesKeyReq{ConversationType: conversationType, OwnerUserID: userID, FriendUserID: friendUserID, GroupID: groupID})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AesKeyRpcClient) AcquireAesKeys(ctx context.Context, userID string) (*aesKey.AcquireAesKeysResp, error) {
|
||||||
|
return a.Client.AcquireAesKeys(ctx, &aesKey.AcquireAesKeysReq{UserID: userID})
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user