60 lines
2.1 KiB
Go
60 lines
2.1 KiB
Go
package wechat
|
||
|
||
import (
|
||
"context"
|
||
"net/http"
|
||
)
|
||
|
||
// Service 微信服务接口(向后兼容)
|
||
type Service interface {
|
||
GetUserInfo(ctx context.Context, code string) (openID, unionID string, err error)
|
||
}
|
||
|
||
// JSSDKConfig JSSDK 签名配置
|
||
// 用于前端调用 wx.config() 初始化微信 JS-SDK
|
||
type JSSDKConfig struct {
|
||
AppID string // 公众号 AppID
|
||
Timestamp int64 // 时间戳(秒)
|
||
NonceStr string // 随机字符串
|
||
Signature string // 签名(SHA1)
|
||
}
|
||
|
||
// OfficialAccountServiceInterface 微信公众号服务接口
|
||
type OfficialAccountServiceInterface interface {
|
||
Service
|
||
GetUserInfoDetailed(ctx context.Context, code string) (*UserInfo, error)
|
||
GetUserInfoByToken(ctx context.Context, accessToken, openID string) (*UserInfo, error)
|
||
// GetJSSDKConfig 获取 JSSDK 签名配置,用于前端调用 wx.config() 初始化
|
||
// url 为当前页面完整 URL(含协议和路径,不含 # 及其后内容)
|
||
GetJSSDKConfig(ctx context.Context, url string) (*JSSDKConfig, 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)
|
||
)
|