plugin/alipay/token/model.go

54 lines
1.7 KiB
Go

package token
import (
"fmt"
"gitea.cdlsxd.cn/sdk/plugin/alipay"
"github.com/go-playground/validator/v10"
)
type Param struct {
AlipayRootCertSn string `json:"alipay_root_cert_sn"`
AppCertSn string `json:"app_cert_sn"`
AppId string `json:"app_id" validate:"required"`
Method string `json:"method" validate:"required"`
Format string `json:"format" validate:"required"`
Charset string `json:"charset" validate:"required"`
SignType string `json:"sign_type" validate:"required"`
Timestamp string `json:"timestamp" validate:"required"`
Version string `json:"version" validate:"required"`
BizContent string `json:"biz_content"`
Sign string `json:"sign"`
GrantType string `json:"grant_type"`
Code string `json:"code"`
}
type AlipayTokenSuccessResponse struct {
UserId string `json:"user_id"`
OpenId string `json:"open_id"`
AccessToken string `json:"access_token"`
ExpiresIn string `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
ReExpiresIn string `json:"re_expires_in"`
AuthStart string `json:"auth_start"`
}
type AlipayTokenResponse struct {
ErrorResponse *alipay.ErrorResponse `json:"error_response"`
Response *AlipayTokenSuccessResponse `json:"alipay_system_oauth_token_response"`
Sign string `json:"sign"`
}
func (req *Param) Validate() error {
err := validator.New().Struct(req)
if err != nil {
for _, err = range err.(validator.ValidationErrors) {
return fmt.Errorf("参数有误:" + err.Error())
}
}
return nil
}
func (r *AlipayTokenResponse) IsSuccess() bool {
return r.ErrorResponse == nil
}