微信相关能力

This commit is contained in:
2026-01-30 17:25:30 +08:00
parent 4856a88d41
commit bf591095a2
43 changed files with 4297 additions and 391 deletions

View File

@@ -1,21 +1,46 @@
package wechat
import "context"
import (
"context"
"net/http"
)
// Service 微信服务接口
// Service 微信服务接口(向后兼容)
type Service interface {
// GetUserInfo 通过授权码获取用户信息
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"` // 微信 OpenID
UnionID string `json:"union_id"` // 微信 UnionID开放平台统一ID
Nickname string `json:"nickname"` // 昵称
Avatar string `json:"avatar"` // 头像URL
Sex int `json:"sex"` // 性别 0-未知 1-男 2-女
Province string `json:"province"` // 省份
City string `json:"city"` // 城市
Country string `json:"country"` // 国家
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)
_ PaymentServiceInterface = (*PaymentService)(nil)
)