feat:完善信息
This commit is contained in:
76
app/common/platform/wechat.go
Normal file
76
app/common/platform/wechat.go
Normal file
@ -0,0 +1,76 @@
|
||||
package platform
|
||||
|
||||
import "SciencesServer/utils"
|
||||
|
||||
type Wechat struct{}
|
||||
|
||||
type WechatScan struct{}
|
||||
|
||||
type WechatScanHandle func() *WechatScan
|
||||
|
||||
type (
|
||||
WechatBasicRequest struct {
|
||||
AppID, Secret string
|
||||
}
|
||||
WechatErrorResponse struct {
|
||||
ErrCode int `json:"errcode"`
|
||||
ErrMsg int `json:"errmsg"`
|
||||
}
|
||||
// WechatAccessTokenRequest 请求AccessToken参数
|
||||
WechatAccessTokenRequest struct {
|
||||
WechatBasicRequest
|
||||
Code string
|
||||
}
|
||||
// WechatAccessTokenResponse 获取AccessToken响应参数
|
||||
WechatAccessTokenResponse struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
ExpiresIn int `json:"expires_in"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
OpenID string `json:"openid"`
|
||||
Scope string `json:"scope"`
|
||||
UnionID string `json:"unionid"`
|
||||
*WechatErrorResponse
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
// WechatAccessTokenUrl AccessToken访问地址
|
||||
WechatAccessTokenUrl string = "https://api.weixin.qq.com/sns/oauth2/access_token"
|
||||
)
|
||||
|
||||
func (this *WechatScan) Login() {
|
||||
|
||||
}
|
||||
|
||||
func (this *WechatScan) Pay() {
|
||||
|
||||
}
|
||||
|
||||
// AccessToken AccessToken操作
|
||||
func (this *Wechat) AccessToken(req *WechatAccessTokenRequest) (*WechatAccessTokenResponse, error) {
|
||||
params := map[string]interface{}{
|
||||
"appid": req.AppID, "secret": req.Secret, "code": req.Code, "grant_type": "authorization_code",
|
||||
}
|
||||
resp, err := utils.NewClient(WechatAccessTokenUrl, utils.MethodForGet, params).Request(utils.RequestBodyFormatForXWWWFormUrlencoded)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := new(WechatAccessTokenResponse)
|
||||
|
||||
if err = utils.FromJSONBytes(resp, out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Scan 扫码操作
|
||||
func (this *Wechat) Scan() WechatScanHandle {
|
||||
return func() *WechatScan {
|
||||
return &WechatScan{}
|
||||
}
|
||||
}
|
||||
|
||||
func NewWechat() *Wechat {
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user