package token import ( "context" "fmt" "gitea.cdlsxd.cn/sdk/plugin/alipay" "gitea.cdlsxd.cn/sdk/plugin/alipay/utils" "github.com/carlmjohnson/requests" "time" ) type Token alipay.Client func (t *Token) Client(ctx context.Context, code string) (*AlipayTokenResponse, error) { cert, err := utils.GetCert(t.MchCertPath, t.RootCertPath, t.PukPath, t.AppId) if err != nil { return nil, err } param := &Param{ AlipayRootCertSn: cert.RootCertSN, AppCertSn: cert.MchCertSN, AppId: t.AppId, Method: "alipay.system.oauth.token", Format: alipay.Format, Charset: alipay.Charset, SignType: alipay.SignType, Timestamp: time.Now().Format(time.DateTime), Version: alipay.Version, Sign: "", GrantType: "authorization_code", Code: code, } uv, err := utils.UrlValues(t.Prk, param) if err != nil { return nil, err } var response AlipayTokenResponse err = requests.URL(alipay.BaseUri).Post().Params(uv).ToJSON(&response).Fetch(ctx) if err != nil { return nil, fmt.Errorf("请求异常,msg:" + err.Error()) } return &response, nil }