蛋蛋星球-制度模式
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 rivejä
3.0 KiB

  1. package alipay
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "github.com/go-pay/gopay"
  8. )
  9. // alipay.open.auth.token.app(换取应用授权令牌)
  10. // 文档地址:https://opendocs.alipay.com/isv/04h3uf
  11. func (a *Client) OpenAuthTokenApp(ctx context.Context, bm gopay.BodyMap) (aliRsp *OpenAuthTokenAppResponse, err error) {
  12. if bm.GetString("code") == gopay.NULL && bm.GetString("refresh_token") == gopay.NULL {
  13. return nil, errors.New("code and refresh_token are not allowed to be null at the same time")
  14. }
  15. err = bm.CheckEmptyError("grant_type")
  16. if err != nil {
  17. return nil, err
  18. }
  19. var bs []byte
  20. if bs, err = a.doAliPay(ctx, bm, "alipay.open.auth.token.app"); err != nil {
  21. return nil, err
  22. }
  23. aliRsp = new(OpenAuthTokenAppResponse)
  24. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  25. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  26. }
  27. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  28. return aliRsp, err
  29. }
  30. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  31. aliRsp.SignData = signData
  32. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  33. }
  34. // alipay.open.auth.token.app.query(查询某个应用授权AppAuthToken的授权信息)
  35. // 文档地址:https://opendocs.alipay.com/isv/04hgcp
  36. func (a *Client) OpenAuthTokenAppQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *OpenAuthTokenAppQueryResponse, err error) {
  37. err = bm.CheckEmptyError("app_auth_token")
  38. if err != nil {
  39. return nil, err
  40. }
  41. var bs []byte
  42. if bs, err = a.doAliPay(ctx, bm, "alipay.open.auth.token.app.query"); err != nil {
  43. return nil, err
  44. }
  45. aliRsp = new(OpenAuthTokenAppQueryResponse)
  46. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  47. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  48. }
  49. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  50. return aliRsp, err
  51. }
  52. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  53. aliRsp.SignData = signData
  54. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  55. }
  56. // alipay.open.auth.appauth.invite.create(ISV向商户发起应用授权邀约)
  57. // 文档地址:https://opendocs.alipay.com/isv/06evao
  58. func (a *Client) OpenAuthTokenAppInviteCreate(ctx context.Context, bm gopay.BodyMap) (aliRsp *OpenAuthTokenAppInviteCreateResponse, err error) {
  59. if err = bm.CheckEmptyError("auth_app_id"); err != nil {
  60. return nil, err
  61. }
  62. var bs []byte
  63. if bs, err = a.doAliPay(ctx, bm, "alipay.open.auth.appauth.invite.create"); err != nil {
  64. return nil, err
  65. }
  66. aliRsp = new(OpenAuthTokenAppInviteCreateResponse)
  67. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  68. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  69. }
  70. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  71. return aliRsp, err
  72. }
  73. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  74. aliRsp.SignData = signData
  75. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  76. }