Browse Source

fix:save 7

jimmyyem 5 months ago
parent
commit
9f66ace527

+ 27 - 4
hook/aliyun/client.go → hook/aliyun/avatar.go

@@ -34,10 +34,10 @@ func CreateClient(accessKeyId, accessKeySecret string) (_result *avatar20220130.
 
 // StartInstance 启动数字人 userId=1234 bizId=xxoo
 func StartInstance(userId, bizId string) (*avatar20220130.StartInstanceResponseBodyData, error) {
-	accessKeyId := "LTAI5tET2mMQVTcMDftuM8Cp"
-	accessKeySecret := "AmGsD8VzwEuj8njZpUCUYnK7uUBTJa"
-	tenantId := int64(1317798064750399)
-	appId := "3dj6714h14"
+	accessKeyId := GetAccessKeyId()
+	accessKeySecret := GetAccessKeySecret()
+	tenantId := GetTenantId()
+	appId := GetAppId()
 
 	client, _err := CreateClient(accessKeyId, accessKeySecret)
 	if _err != nil {
@@ -118,10 +118,33 @@ func _main(args []*string) (_err error) {
 	return _err
 }
 
+// GetBizID 业务请求id,最大支持 64 位字符
+// (注意 可以使用该字段做业务启动数字人的幂等,服务端确保同一个 bizId 多次调用只会开启一路实例)
+// 鉴于以上原因这里确保每个用户只启动一个实例
 func GetBizID(userId uint64) string {
 	return jwt.HashidsEncode(int(userId))
 }
 
+// GetAccessKeyId 获取AccessKeyId
+func GetAccessKeyId() string {
+	return "LTAI5tET2mMQVTcMDftuM8Cp"
+}
+
+// GetAccessKeySecret 获取AccessKeySecret
+func GetAccessKeySecret() string {
+	return "AmGsD8VzwEuj8njZpUCUYnK7uUBTJa"
+}
+
+// GetAppId 获取AppId
+func GetAppId() string {
+	return "3dj6714h14"
+}
+
+// GetTenantId 租户ID
+func GetTenantId() int64 {
+	return int64(27174)
+}
+
 //func main() {
 //	err := _main(tea.StringSlice(os.Args[1:]))
 //	if err != nil {

+ 1 - 1
internal/logic/User/do_api_user_login_logic.go

@@ -62,7 +62,7 @@ func (l *DoApiUserLoginLogic) DoApiUserLogin(req *types.UserLoginReq) (*types.Us
 		return nil, errorx.NewApiInternalError("wechat login error")
 	}
 
-	if resp.ErrCode != 0 {
+	if resp != nil && resp.ErrCode != 0 {
 		return nil, errorx.NewApiInternalError(resp.ErrMSG)
 	}
 

+ 2 - 0
internal/logic/avatar/get_api_avatar_config_logic.go

@@ -3,6 +3,7 @@ package avatar
 import (
 	"context"
 	"encoding/json"
+	"fmt"
 	avatar20220130 "github.com/alibabacloud-go/avatar-20220130/v2/client"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"github.com/zeromicro/go-zero/core/errorx"
@@ -52,6 +53,7 @@ func (l *GetApiAvatarConfigLogic) GetApiAvatarConfig(req *types.AvatarConfigReq)
 	if jsonData.AiType == 1 { //TODO 阿里云数字人
 		userIdStr := strconv.Itoa(int(userId))
 		aiData, err = aliyun.StartInstance(userIdStr, aliyun.GetBizID(userId))
+		fmt.Printf("aliData=%v error=%v \n", aiData, err)
 		if err != nil {
 			return nil, errorx.NewInternalError(err.Error())
 		}

+ 16 - 4
internal/utils/jwt/hashids.go

@@ -2,15 +2,27 @@ package jwt
 
 import "github.com/speps/go-hashids/v2"
 
+var salt = "fastgpthashids"
+
 func HashidsEncode(num int) string {
 	hd := hashids.NewData()
-	hd.Salt = "fastgpthashids"
+	hd.Salt = salt
 	hd.MinLength = 20
 	h, _ := hashids.NewWithData(hd)
 	e, _ := h.Encode([]int{num})
 
 	return e
-	//fmt.Println(e)
-	//d, _ := h.DecodeWithError(e)
-	//fmt.Println(d)
+}
+
+func HashidsDecode(hashidstr string) int {
+	hd := hashids.NewData()
+	hd.Salt = salt
+	hd.MinLength = 20
+	h, _ := hashids.NewWithData(hd)
+	numbs, err := h.DecodeWithError(hashidstr)
+	if err != nil {
+		return -1
+	}
+
+	return numbs[0]
 }