实现面向个人客户的 7 个认证接口(A1-A7),覆盖资产验证、 微信公众号/小程序登录、手机号绑定/换绑、退出登录完整流程。 主要变更: - 新增 PersonalCustomerOpenID 模型,支持多 AppID 多 OpenID 管理 - 实现有状态 JWT(JWT + Redis 双重校验),支持服务端主动失效 - 扩展微信 SDK:小程序 Code2Session + 3 个 DB 动态工厂函数 - 实现 A1 资产验证 IP 限流(30/min)和 A4 三层验证码限流 - 新增 7 个错误码(1180-1186)和 6 个 Redis Key 函数 - 注册 /api/c/v1/auth/* 下 7 个端点并更新 OpenAPI 文档 - 数据库迁移 000083:新建 tb_personal_customer_openid 表
48 lines
1.6 KiB
Go
48 lines
1.6 KiB
Go
package wechat
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
)
|
|
|
|
// Service 微信服务接口(向后兼容)
|
|
type Service interface {
|
|
GetUserInfo(ctx context.Context, code string) (openID, unionID string, err error)
|
|
}
|
|
|
|
// OfficialAccountServiceInterface 微信公众号服务接口
|
|
type OfficialAccountServiceInterface interface {
|
|
Service
|
|
GetUserInfoDetailed(ctx context.Context, code string) (*UserInfo, error)
|
|
GetUserInfoByToken(ctx context.Context, accessToken, openID string) (*UserInfo, error)
|
|
}
|
|
|
|
// PaymentServiceInterface 微信支付服务接口
|
|
type PaymentServiceInterface interface {
|
|
CreateJSAPIOrder(ctx context.Context, orderNo, description, openID string, amount int) (*JSAPIPayResult, error)
|
|
CreateH5Order(ctx context.Context, orderNo, description string, amount int, sceneInfo *H5SceneInfo) (*H5PayResult, error)
|
|
QueryOrder(ctx context.Context, orderNo string) (*OrderInfo, error)
|
|
CloseOrder(ctx context.Context, orderNo string) error
|
|
HandlePaymentNotify(r *http.Request, callback PaymentNotifyCallback) (*http.Response, error)
|
|
}
|
|
|
|
// UserInfo 微信用户信息
|
|
type UserInfo struct {
|
|
OpenID string `json:"open_id"`
|
|
UnionID string `json:"union_id"`
|
|
Nickname string `json:"nickname"`
|
|
Avatar string `json:"avatar"`
|
|
Sex int `json:"sex"`
|
|
Province string `json:"province"`
|
|
City string `json:"city"`
|
|
Country string `json:"country"`
|
|
}
|
|
|
|
// 编译时类型检查
|
|
var (
|
|
_ Service = (*OfficialAccountService)(nil)
|
|
_ OfficialAccountServiceInterface = (*OfficialAccountService)(nil)
|
|
_ MiniAppServiceInterface = (*MiniAppService)(nil)
|
|
_ PaymentServiceInterface = (*PaymentService)(nil)
|
|
)
|