feat:完善信息

This commit is contained in:
henry
2021-11-01 11:19:49 +08:00
parent 70ba3078b3
commit cf91d55ab2
34 changed files with 519 additions and 114 deletions

View File

@ -1,24 +1,23 @@
package platform
import "SciencesServer/utils"
import (
"SciencesServer/utils"
"errors"
)
type Wechat struct{}
type Wechat struct {
AppID, AppSecret string
}
type WechatScan struct{}
type WechatScanHandle func() *WechatScan
type WechatHandle func(appID, appSecret string) *Wechat
type (
WechatBasicRequest struct {
AppID, Secret string
}
WechatErrorResponse struct {
ErrCode int `json:"errcode"`
ErrMsg int `json:"errmsg"`
ErrCode int `json:"errcode"`
ErrMsg string `json:"errmsg"`
}
// WechatAccessTokenRequest 请求AccessToken参数
WechatAccessTokenRequest struct {
WechatBasicRequest
Code string
}
// WechatAccessTokenResponse 获取AccessToken响应参数
@ -29,7 +28,7 @@ type (
OpenID string `json:"openid"`
Scope string `json:"scope"`
UnionID string `json:"unionid"`
*WechatErrorResponse
WechatErrorResponse
}
)
@ -38,18 +37,18 @@ const (
WechatAccessTokenUrl string = "https://api.weixin.qq.com/sns/oauth2/access_token"
)
func (this *WechatScan) Login() {
func (this *Wechat) ScanLogin() {
}
func (this *WechatScan) Pay() {
func (this *Wechat) ScanPay() {
}
// 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",
"appid": this.AppID, "secret": this.AppSecret, "code": req.Code, "grant_type": "authorization_code",
}
resp, err := utils.NewClient(WechatAccessTokenUrl, utils.MethodForGet, params).Request(utils.RequestBodyFormatForXWWWFormUrlencoded)
@ -61,16 +60,14 @@ func (this *Wechat) AccessToken(req *WechatAccessTokenRequest) (*WechatAccessTok
if err = utils.FromJSONBytes(resp, out); err != nil {
return nil, err
}
if out.WechatErrorResponse.ErrCode != 0 {
return nil, errors.New(out.WechatErrorResponse.ErrMsg)
}
return out, nil
}
// Scan 扫码操作
func (this *Wechat) Scan() WechatScanHandle {
return func() *WechatScan {
return &WechatScan{}
func NewWechat() WechatHandle {
return func(appID, appSecret string) *Wechat {
return &Wechat{AppID: appID, AppSecret: appSecret}
}
}
func NewWechat() *Wechat {
return nil
}