Files
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

38 lines
1.3 KiB
Go

package activityclient
import (
"encoding/base64"
"encoding/json"
"fmt"
"91porn-server/common/crypt"
)
// SignPayload 签名载荷(与 activity-public-server 保持一致)
type SignPayload struct {
AppId string `json:"appId"` // 应用ID
UserId string `json:"userId"` // 用户ID
Nickname string `json:"nickname"` // 用户昵称
Avatar string `json:"avatar"` // 用户头像
Ts int64 `json:"ts"` // 时间戳(秒)
RegisteredAt int64 `json:"registeredAt"` // 用户注册时间(Unix秒)
RechargeAmount int `json:"rechargeAmount"` // 充值金额(分)
}
// EncryptSign AES-CBC 加密签名载荷,返回 Base64 URL Safe 编码
func EncryptSign(secretKeyBase64 string, payload *SignPayload) (string, error) {
secretKey, err := base64.StdEncoding.DecodeString(secretKeyBase64)
if err != nil {
return "", fmt.Errorf("decode secretKey failed: %w", err)
}
plaintext, err := json.Marshal(payload)
if err != nil {
return "", fmt.Errorf("marshal payload failed: %w", err)
}
ciphertext, err := crypt.AESCBCPck5Encrypt(plaintext, secretKey)
if err != nil {
return "", fmt.Errorf("encrypt failed: %w", err)
}
return base64.URLEncoding.EncodeToString(ciphertext), nil
}