蛋蛋星球-制度模式
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.

218 lines
8.8 KiB

  1. package alipay
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/go-pay/gopay"
  7. )
  8. // alipay.marketing.card.template.create(会员卡模板创建)
  9. // 文档地址:https://opendocs.alipay.com/open/b2854ad3_alipay.marketing.card.template.create
  10. func (a *Client) MarketingCardTemplateCreate(ctx context.Context, bm gopay.BodyMap) (aliRsp *MarketingCardTemplateCreateRsp, err error) {
  11. err = bm.CheckEmptyError("request_id", "template_style_info")
  12. if err != nil {
  13. return nil, err
  14. }
  15. var bs []byte
  16. if bs, err = a.doAliPay(ctx, bm, "alipay.marketing.card.template.create"); err != nil {
  17. return nil, err
  18. }
  19. aliRsp = new(MarketingCardTemplateCreateRsp)
  20. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  21. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  22. }
  23. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  24. return aliRsp, err
  25. }
  26. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  27. aliRsp.SignData = signData
  28. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  29. }
  30. // alipay.marketing.card.template.modify(会员卡模板修改)
  31. // 文档地址:https://opendocs.alipay.com/open/e3227c82_alipay.marketing.card.template.modify
  32. func (a *Client) MarketingCardTemplateModify(ctx context.Context, bm gopay.BodyMap) (aliRsp *MarketingCardTemplateModifyRsp, err error) {
  33. err = bm.CheckEmptyError("request_id", "template_id", "template_style_info")
  34. if err != nil {
  35. return nil, err
  36. }
  37. var bs []byte
  38. if bs, err = a.doAliPay(ctx, bm, "alipay.marketing.card.template.modify"); err != nil {
  39. return nil, err
  40. }
  41. aliRsp = new(MarketingCardTemplateModifyRsp)
  42. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  43. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  44. }
  45. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  46. return aliRsp, err
  47. }
  48. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  49. aliRsp.SignData = signData
  50. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  51. }
  52. // alipay.marketing.card.template.query(会员卡模板查询接口)
  53. // 文档地址:https://opendocs.alipay.com/open/690f3d16_alipay.marketing.card.template.query
  54. func (a *Client) MarketingCardTemplateQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *MarketingCardTemplateQueryRsp, err error) {
  55. err = bm.CheckEmptyError("template_id")
  56. if err != nil {
  57. return nil, err
  58. }
  59. var bs []byte
  60. if bs, err = a.doAliPay(ctx, bm, "alipay.marketing.card.template.query"); err != nil {
  61. return nil, err
  62. }
  63. aliRsp = new(MarketingCardTemplateQueryRsp)
  64. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  65. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  66. }
  67. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  68. return aliRsp, err
  69. }
  70. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  71. aliRsp.SignData = signData
  72. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  73. }
  74. // alipay.marketing.card.update(会员卡更新)
  75. // 文档地址:https://opendocs.alipay.com/open/89b55b6d_alipay.marketing.card.update
  76. func (a *Client) MarketingCardUpdate(ctx context.Context, bm gopay.BodyMap) (aliRsp *MarketingCardUpdateRsp, err error) {
  77. err = bm.CheckEmptyError("target_card_no", "target_card_no_type", "occur_time", "card_info")
  78. if err != nil {
  79. return nil, err
  80. }
  81. var bs []byte
  82. if bs, err = a.doAliPay(ctx, bm, "alipay.marketing.card.update"); err != nil {
  83. return nil, err
  84. }
  85. aliRsp = new(MarketingCardUpdateRsp)
  86. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  87. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  88. }
  89. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  90. return aliRsp, err
  91. }
  92. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  93. aliRsp.SignData = signData
  94. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  95. }
  96. // alipay.marketing.card.query(会员卡查询)
  97. // 文档地址:https://opendocs.alipay.com/open/023c20c1_alipay.marketing.card.query
  98. func (a *Client) MarketingCardQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *MarketingCardQueryRsp, err error) {
  99. err = bm.CheckEmptyError("target_card_no", "target_card_no_type")
  100. if err != nil {
  101. return nil, err
  102. }
  103. var bs []byte
  104. if bs, err = a.doAliPay(ctx, bm, "alipay.marketing.card.query"); err != nil {
  105. return nil, err
  106. }
  107. aliRsp = new(MarketingCardQueryRsp)
  108. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  109. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  110. }
  111. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  112. return aliRsp, err
  113. }
  114. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  115. aliRsp.SignData = signData
  116. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  117. }
  118. // alipay.marketing.card.delete(会员卡删卡)
  119. // 文档地址:https://opendocs.alipay.com/open/8efddab3_alipay.marketing.card.delete
  120. func (a *Client) MarketingCardDelete(ctx context.Context, bm gopay.BodyMap) (aliRsp *MarketingCardDeleteRsp, err error) {
  121. err = bm.CheckEmptyError("out_serial_no", "target_card_no", "target_card_no_type", "reason_code")
  122. if err != nil {
  123. return nil, err
  124. }
  125. var bs []byte
  126. if bs, err = a.doAliPay(ctx, bm, "alipay.marketing.card.delete"); err != nil {
  127. return nil, err
  128. }
  129. aliRsp = new(MarketingCardDeleteRsp)
  130. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  131. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  132. }
  133. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  134. return aliRsp, err
  135. }
  136. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  137. aliRsp.SignData = signData
  138. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  139. }
  140. // alipay.marketing.card.message.notify(会员卡消息通知)
  141. // 文档地址:https://opendocs.alipay.com/open/4c052993_alipay.marketing.card.message.notify
  142. func (a *Client) MarketingCardMessageNotify(ctx context.Context, bm gopay.BodyMap) (aliRsp *MarketingCardMessageNotifyRsp, err error) {
  143. err = bm.CheckEmptyError("target_card_no", "target_card_no_type", "occur_time")
  144. if err != nil {
  145. return nil, err
  146. }
  147. var bs []byte
  148. if bs, err = a.doAliPay(ctx, bm, "alipay.marketing.card.message.notify"); err != nil {
  149. return nil, err
  150. }
  151. aliRsp = new(MarketingCardMessageNotifyRsp)
  152. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  153. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  154. }
  155. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  156. return aliRsp, err
  157. }
  158. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  159. aliRsp.SignData = signData
  160. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  161. }
  162. // alipay.marketing.card.formtemplate.set(会员卡开卡表单模板配置)
  163. // 文档地址:https://opendocs.alipay.com/open/78c84d3f_alipay.marketing.card.formtemplate.set
  164. func (a *Client) MarketingCardFormTemplateSet(ctx context.Context, bm gopay.BodyMap) (aliRsp *MarketingCardFormTemplateSetRsp, err error) {
  165. err = bm.CheckEmptyError("template_id", "fields")
  166. if err != nil {
  167. return nil, err
  168. }
  169. var bs []byte
  170. if bs, err = a.doAliPay(ctx, bm, "alipay.marketing.card.formtemplate.set"); err != nil {
  171. return nil, err
  172. }
  173. aliRsp = new(MarketingCardFormTemplateSetRsp)
  174. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  175. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  176. }
  177. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  178. return aliRsp, err
  179. }
  180. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  181. aliRsp.SignData = signData
  182. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  183. }
  184. // alipay.offline.material.image.upload(上传门店照片和视频接口)
  185. // 文档地址:https://opendocs.alipay.com/open/0af852ff_alipay.offline.material.image.upload
  186. func (a *Client) OfflineMaterialImageUpload(ctx context.Context, bm gopay.BodyMap) (aliRsp *OfflineMaterialImageUploadRsp, err error) {
  187. err = bm.CheckEmptyError("image_type", "image_name", "image_content")
  188. if err != nil {
  189. return nil, err
  190. }
  191. var bs []byte
  192. if bs, err = a.FileUploadRequest(ctx, bm, "alipay.marketing.material.image.upload"); err != nil {
  193. return nil, err
  194. }
  195. aliRsp = new(OfflineMaterialImageUploadRsp)
  196. if err = json.Unmarshal(bs, aliRsp); err != nil {
  197. return nil, err
  198. }
  199. if aliRsp.Response != nil && aliRsp.Response.Code != "10000" {
  200. info := aliRsp.Response
  201. return aliRsp, fmt.Errorf(`{"code":"%s","msg":"%s","sub_code":"%s","sub_msg":"%s"}`, info.Code, info.Msg, info.SubCode, info.SubMsg)
  202. }
  203. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  204. aliRsp.SignData = signData
  205. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  206. }