调整 rsa 密钥解析函数
This commit is contained in:
@ -88,14 +88,15 @@ func (s *gamelifeClient) GetUserKeyIV(ctx context.Context, popenId string) (cach
|
||||
// base64编码
|
||||
base64Encode := encrypt.Base64Encode(key)
|
||||
// 向游戏人生发送请求
|
||||
result := struct {
|
||||
secret string `json:"secret"`
|
||||
key string `json:"key"` // 该用户的token,后续的账号绑定、登录态携带都需要此参数。
|
||||
}{}
|
||||
type httpResult struct {
|
||||
Secret string `json:"secret"`
|
||||
Key string `json:"key"` // 该用户的token,后续的账号绑定、登录态携带都需要此参数。
|
||||
}
|
||||
var result httpResult
|
||||
resp, err := resty.New().R().SetBody(map[string]string{
|
||||
"plat_id": s.PlatId,
|
||||
"key": base64Encode,
|
||||
}).SetResult(result).Post(s.keyivUrlMap[s.Mode])
|
||||
}).SetResult(&result).Post(s.keyivUrlMap[s.Mode])
|
||||
if err != nil {
|
||||
err = ecode.Fail.Sub("获取用户信息失败")
|
||||
return
|
||||
@ -107,7 +108,7 @@ func (s *gamelifeClient) GetUserKeyIV(ctx context.Context, popenId string) (cach
|
||||
|
||||
}
|
||||
|
||||
decode, err := encrypt.Base64Decode(result.secret)
|
||||
decode, err := encrypt.Base64Decode(result.Secret)
|
||||
if err != nil {
|
||||
err = ecode.Fail.Sub("解密用户信息失败")
|
||||
return
|
||||
@ -121,15 +122,15 @@ func (s *gamelifeClient) GetUserKeyIV(ctx context.Context, popenId string) (cach
|
||||
|
||||
}
|
||||
aesResult := struct {
|
||||
key string `json:"key"`
|
||||
iv string `json:"iv"`
|
||||
Key string `json:"key"`
|
||||
IV string `json:"iv"`
|
||||
}{}
|
||||
if err = json.Unmarshal(plain, &aesResult); err != nil {
|
||||
err = ecode.Fail.Sub("解密用户信息失败")
|
||||
return
|
||||
}
|
||||
|
||||
gamelifeCache := model.UserGamelifeCache{Aes: aesResult.key, IV: aesResult.iv, Token: result.key}
|
||||
gamelifeCache := model.UserGamelifeCache{Aes: aesResult.Key, IV: aesResult.IV, Token: result.Key}
|
||||
// 将用户的 aeskey 和 iv 存储到缓存当中,用于后续请求数据加密, 固定时间 2 小时同时不同用户加上一个随机时间
|
||||
if err = g.Redis().SetEX(ctx, fmt.Sprintf(consts.GameLifeUserKey, popenId), gamelifeCache, int64(consts.GameLifeUserExpire+grand.Intn(1000))); err != nil {
|
||||
err = ecode.Fail.Sub("设置用户信息失败")
|
||||
|
||||
Reference in New Issue
Block a user