微信支付
This commit is contained in:
25
internal/shared/payment/context.go
Normal file
25
internal/shared/payment/context.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package payment
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// GetUidFromCtx 从context中获取用户ID
|
||||
func GetUidFromCtx(ctx context.Context) (string, error) {
|
||||
userID := ctx.Value("user_id")
|
||||
if userID == nil {
|
||||
return "", fmt.Errorf("用户ID不存在于上下文中")
|
||||
}
|
||||
|
||||
id, ok := userID.(string)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("用户ID类型错误")
|
||||
}
|
||||
|
||||
if id == "" {
|
||||
return "", fmt.Errorf("用户ID为空")
|
||||
}
|
||||
|
||||
return id, nil
|
||||
}
|
||||
Reference in New Issue
Block a user