plugin/alipay/token/model.go

54 lines
1.7 KiB
Go
Raw Normal View History

2024-08-30 18:02:15 +08:00
package token
import (
"fmt"
2024-08-30 18:03:34 +08:00
"gitea.cdlsxd.cn/sdk/plugin/alipay"
2024-08-30 18:02:15 +08:00
"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 {
2024-10-23 15:39:51 +08:00
ErrorResponse *alipay.ErrorResponse `json:"error_response,omitempty"`
Response *AlipayTokenSuccessResponse `json:"alipay_system_oauth_token_response,omitempty"`
2024-08-30 18:02:15 +08:00
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
}