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

607 rivejä
24 KiB

  1. package alipay
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "net/url"
  8. "strings"
  9. "github.com/go-pay/gopay"
  10. )
  11. // alipay.system.oauth.token(换取授权访问令牌)
  12. // 文档地址:https://opendocs.alipay.com/open/02ailc
  13. func (a *Client) SystemOauthToken(ctx context.Context, bm gopay.BodyMap) (aliRsp *SystemOauthTokenResponse, err error) {
  14. if bm.GetString("code") == gopay.NULL && bm.GetString("refresh_token") == gopay.NULL {
  15. return nil, errors.New("code and refresh_token are not allowed to be null at the same time")
  16. }
  17. if err = bm.CheckEmptyError("grant_type"); err != nil {
  18. return nil, err
  19. }
  20. var (
  21. bs []byte
  22. aat string
  23. )
  24. if a.AppCertSN != gopay.NULL {
  25. bm.Set("app_cert_sn", a.AppCertSN)
  26. }
  27. if a.AliPayRootCertSN != gopay.NULL {
  28. bm.Set("alipay_root_cert_sn", a.AliPayRootCertSN)
  29. }
  30. // default use app_auth_token
  31. if a.AppAuthToken != gopay.NULL {
  32. aat = a.AppAuthToken
  33. }
  34. // if user set app_auth_token in body_map, use this
  35. if bmAt := bm.GetString("app_auth_token"); bmAt != gopay.NULL {
  36. aat = bmAt
  37. }
  38. if bs, err = systemOauthToken(ctx, a.AppId, a.privateKey, bm, "alipay.system.oauth.token", a.IsProd, a.SignType, aat); err != nil {
  39. return nil, err
  40. }
  41. aliRsp = new(SystemOauthTokenResponse)
  42. if err = json.Unmarshal(bs, aliRsp); err != nil {
  43. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  44. }
  45. if aliRsp.ErrorResponse != nil {
  46. info := aliRsp.ErrorResponse
  47. return aliRsp, fmt.Errorf(`{"code":"%s","msg":"%s","sub_code":"%s","sub_msg":"%s"}`, info.Code, info.Msg, info.SubCode, info.SubMsg)
  48. }
  49. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  50. aliRsp.SignData = signData
  51. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  52. }
  53. // alipay.open.auth.userauth.relationship.query(用户授权关系查询)
  54. // 文档地址:https://opendocs.alipay.com/open/6b97edd1_alipay.open.auth.userauth.relationship.query
  55. func (a *Client) UserAuthRelationshipQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserAuthRelationshipQueryRsp, err error) {
  56. err = bm.CheckEmptyError("scopes")
  57. if err != nil {
  58. return nil, err
  59. }
  60. var bs []byte
  61. if bs, err = a.doAliPay(ctx, bm, "alipay.open.auth.userauth.relationship.query"); err != nil {
  62. return nil, err
  63. }
  64. aliRsp = new(UserAuthRelationshipQueryRsp)
  65. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  66. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  67. }
  68. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  69. return aliRsp, err
  70. }
  71. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  72. aliRsp.SignData = signData
  73. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  74. }
  75. // alipay.user.deloauth.detail.query(查询解除授权明细)
  76. // 文档地址:https://opendocs.alipay.com/open/77e7fec5_alipay.user.deloauth.detail.query
  77. func (a *Client) UserDelOAuthDetailQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserDelOAuthDetailQueryRsp, err error) {
  78. err = bm.CheckEmptyError("date", "limit", "offset")
  79. if err != nil {
  80. return nil, err
  81. }
  82. var bs []byte
  83. if bs, err = a.doAliPay(ctx, bm, "alipay.user.deloauth.detail.query"); err != nil {
  84. return nil, err
  85. }
  86. aliRsp = new(UserDelOAuthDetailQueryRsp)
  87. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  88. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  89. }
  90. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  91. return aliRsp, err
  92. }
  93. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  94. aliRsp.SignData = signData
  95. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  96. }
  97. // alipay.user.info.share(支付宝会员授权信息查询接口)
  98. // body:此接口无需body参数
  99. // 文档地址:https://opendocs.alipay.com/open/02aild
  100. func (a *Client) UserInfoShare(ctx context.Context, authToken string) (aliRsp *UserInfoShareResponse, err error) {
  101. if authToken == "" {
  102. return nil, errors.New("auth_token can not be null")
  103. }
  104. var bs []byte
  105. if bs, err = a.doAliPay(ctx, nil, "alipay.user.info.share", authToken); err != nil {
  106. return nil, err
  107. }
  108. aliRsp = new(UserInfoShareResponse)
  109. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  110. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  111. }
  112. if aliRsp.ErrorResponse != nil {
  113. info := aliRsp.ErrorResponse
  114. return aliRsp, fmt.Errorf(`{"code":"%s","msg":"%s","sub_code":"%s","sub_msg":"%s"}`, info.Code, info.Msg, info.SubCode, info.SubMsg)
  115. }
  116. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  117. aliRsp.SignData = signData
  118. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  119. }
  120. // alipay.user.info.auth(用户登陆授权)
  121. // 注意:不支持自动验签
  122. // 文档地址:https://opendocs.alipay.com/open/02aile
  123. func (a *Client) UserInfoAuth(ctx context.Context, bm gopay.BodyMap) (html []byte, err error) {
  124. err = bm.CheckEmptyError("scopes", "state")
  125. if err != nil {
  126. return nil, err
  127. }
  128. var bs []byte
  129. if bs, err = a.doAliPay(ctx, bm, "alipay.user.info.auth"); err != nil {
  130. return nil, err
  131. }
  132. if strings.Contains(string(bs), "<head>") {
  133. return bs, nil
  134. }
  135. uiaErr := new(UserInfoAuthResponse)
  136. if err = json.Unmarshal(bs, uiaErr); err != nil {
  137. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  138. }
  139. return nil, bizErrCheck(*uiaErr.Response)
  140. }
  141. // alipay.user.certify.open.initialize(身份认证初始化服务)
  142. // 文档地址:https://opendocs.alipay.com/open/02ahjy
  143. func (a *Client) UserCertifyOpenInit(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserCertifyOpenInitResponse, err error) {
  144. err = bm.CheckEmptyError("outer_order_no", "biz_code", "identity_param", "merchant_config")
  145. if err != nil {
  146. return nil, err
  147. }
  148. var bs []byte
  149. if bs, err = a.doAliPay(ctx, bm, "alipay.user.certify.open.initialize"); err != nil {
  150. return nil, err
  151. }
  152. aliRsp = new(UserCertifyOpenInitResponse)
  153. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  154. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  155. }
  156. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  157. return aliRsp, err
  158. }
  159. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  160. aliRsp.SignData = signData
  161. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  162. }
  163. // alipay.user.certify.open.certify(身份认证开始认证)
  164. // API文档地址:https://opendocs.alipay.com/open/02ahk0
  165. func (a *Client) UserCertifyOpenCertify(ctx context.Context, bm gopay.BodyMap) (certifyUrl string, err error) {
  166. err = bm.CheckEmptyError("certify_id")
  167. if err != nil {
  168. return gopay.NULL, err
  169. }
  170. var bs []byte
  171. if bs, err = a.doAliPay(ctx, bm, "alipay.user.certify.open.certify"); err != nil {
  172. return gopay.NULL, err
  173. }
  174. certifyUrl = string(bs)
  175. return certifyUrl, nil
  176. }
  177. // alipay.user.certify.open.query(身份认证记录查询)
  178. // 文档地址:https://opendocs.alipay.com/open/02ahjw
  179. func (a *Client) UserCertifyOpenQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserCertifyOpenQueryResponse, err error) {
  180. err = bm.CheckEmptyError("certify_id")
  181. if err != nil {
  182. return nil, err
  183. }
  184. var bs []byte
  185. if bs, err = a.doAliPay(ctx, bm, "alipay.user.certify.open.query"); err != nil {
  186. return nil, err
  187. }
  188. aliRsp = new(UserCertifyOpenQueryResponse)
  189. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  190. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  191. }
  192. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  193. return aliRsp, err
  194. }
  195. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  196. aliRsp.SignData = signData
  197. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  198. }
  199. // alipay.user.agreement.page.sign(支付宝个人协议页面签约接口)
  200. // 文档地址:https://opendocs.alipay.com/open/8bccfa0b_alipay.user.agreement.page.sign
  201. func (a *Client) UserAgreementPageSign(ctx context.Context, bm gopay.BodyMap) (ret string, err error) {
  202. err = bm.CheckEmptyError("personal_product_code")
  203. if err != nil {
  204. return gopay.NULL, err
  205. }
  206. var bs []byte
  207. if bs, err = a.doAliPay(ctx, bm, "alipay.user.agreement.page.sign"); err != nil {
  208. return "", err
  209. }
  210. return string(bs), nil
  211. }
  212. // alipay.user.agreement.page.sign(APP 支付宝个人协议页面签约接口)
  213. // 文档地址:https://opendocs.alipay.com/open/00a05b 通过 App 唤起支付宝的签约页面
  214. func (a *Client) UserAgreementPageSignInApp(ctx context.Context, bm gopay.BodyMap) (ret string, err error) {
  215. err = bm.CheckEmptyError("personal_product_code")
  216. if err != nil {
  217. return gopay.NULL, err
  218. }
  219. var bs string
  220. // 参考官方示例
  221. // PageExecute get方式,生成url
  222. if bs, err = a.PageExecute(ctx, bm, "alipay.user.agreement.page.sign"); err != nil {
  223. return "", err
  224. }
  225. // / 生成的url地址去除 http://openapi.alipay.com/gateway.do
  226. replaceUrl := baseUrl + "?"
  227. if !a.IsProd {
  228. replaceUrl = sandboxBaseUrl + "?"
  229. }
  230. signParams := strings.Replace(bs, replaceUrl, "", 1)
  231. // 该链接里面的 APPID 为固定值,不可修改)
  232. // 生成唤起客户端。把signParams使用 UTF-8 字符集整体做一次 encode
  233. link := "alipays://platformapi/startapp?appId=60000157&appClearTop=false&startMultApp=YES&sign_params=" + url.QueryEscape(signParams)
  234. return link, nil
  235. }
  236. // alipay.user.agreement.unsign(支付宝个人代扣协议解约接口)
  237. // 文档地址:https://opendocs.alipay.com/open/b841da1f_alipay.user.agreement.unsign
  238. func (a *Client) UserAgreementPageUnSign(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserAgreementPageUnSignRsp, err error) {
  239. var bs []byte
  240. if bs, err = a.doAliPay(ctx, bm, "alipay.user.agreement.unsign"); err != nil {
  241. return nil, err
  242. }
  243. aliRsp = new(UserAgreementPageUnSignRsp)
  244. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  245. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  246. }
  247. if err = bizErrCheck(*aliRsp.Response); err != nil {
  248. return aliRsp, err
  249. }
  250. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  251. aliRsp.SignData = signData
  252. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  253. }
  254. // alipay.user.agreement.query(支付宝个人代扣协议查询接口)
  255. // 文档地址:https://opendocs.alipay.com/open/3dab71bc_alipay.user.agreement.query
  256. func (a *Client) UserAgreementQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserAgreementQueryRsp, err error) {
  257. var bs []byte
  258. if bs, err = a.doAliPay(ctx, bm, "alipay.user.agreement.query"); err != nil {
  259. return nil, err
  260. }
  261. aliRsp = new(UserAgreementQueryRsp)
  262. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  263. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  264. }
  265. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  266. return aliRsp, err
  267. }
  268. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  269. aliRsp.SignData = signData
  270. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  271. }
  272. // alipay.user.agreement.executionplan.modify(周期性扣款协议执行计划修改接口)
  273. // 文档地址:https://opendocs.alipay.com/apis/api_2/alipay.user.agreement.executionplan.modify
  274. func (a *Client) UserAgreementExecutionplanModify(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserAgreementExecutionplanModifyRsp, err error) {
  275. err = bm.CheckEmptyError("agreement_no", "deduct_time")
  276. if err != nil {
  277. return nil, err
  278. }
  279. var bs []byte
  280. if bs, err = a.doAliPay(ctx, bm, "alipay.user.agreement.executionplan.modify"); err != nil {
  281. return nil, err
  282. }
  283. aliRsp = new(UserAgreementExecutionplanModifyRsp)
  284. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  285. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  286. }
  287. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  288. return aliRsp, err
  289. }
  290. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  291. aliRsp.SignData = signData
  292. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  293. }
  294. // alipay.user.agreement.transfer(协议由普通通用代扣协议产品转移到周期扣协议产品)
  295. // 文档地址:https://opendocs.alipay.com/apis/api_2/alipay.user.agreement.transfer
  296. func (a *Client) UserAgreementTransfer(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserAgreementTransferRsp, err error) {
  297. err = bm.CheckEmptyError("agreement_no", "target_product_code", "period_rule_params")
  298. if err != nil {
  299. return nil, err
  300. }
  301. var bs []byte
  302. if bs, err = a.doAliPay(ctx, bm, "alipay.user.agreement.transfer"); err != nil {
  303. return nil, err
  304. }
  305. aliRsp = new(UserAgreementTransferRsp)
  306. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  307. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  308. }
  309. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  310. return aliRsp, err
  311. }
  312. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  313. aliRsp.SignData = signData
  314. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  315. }
  316. // alipay.user.twostage.common.use(通用当面付二阶段接口)
  317. // 文档地址:https://opendocs.alipay.com/apis/api_2/alipay.user.twostage.common.use
  318. func (a *Client) UserTwostageCommonUse(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserTwostageCommonUseRsp, err error) {
  319. err = bm.CheckEmptyError("dynamic_id", "sence_no", "pay_pid")
  320. if err != nil {
  321. return nil, err
  322. }
  323. var bs []byte
  324. if bs, err = a.doAliPay(ctx, bm, "alipay.user.twostage.common.use"); err != nil {
  325. return nil, err
  326. }
  327. aliRsp = new(UserTwostageCommonUseRsp)
  328. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  329. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  330. }
  331. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  332. return aliRsp, err
  333. }
  334. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  335. aliRsp.SignData = signData
  336. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  337. }
  338. // alipay.user.auth.zhimaorg.identity.apply(芝麻企业征信基于身份的协议授权)
  339. // 文档地址:https://opendocs.alipay.com/apis/api_2/alipay.user.auth.zhimaorg.identity.apply
  340. func (a *Client) UserAuthZhimaorgIdentityApply(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserAuthZhimaorgIdentityApplyRsp, err error) {
  341. err = bm.CheckEmptyError("cert_type", "cert_no", "name")
  342. if err != nil {
  343. return nil, err
  344. }
  345. var bs []byte
  346. if bs, err = a.doAliPay(ctx, bm, "alipay.user.auth.zhimaorg.identity.apply"); err != nil {
  347. return nil, err
  348. }
  349. aliRsp = new(UserAuthZhimaorgIdentityApplyRsp)
  350. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  351. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  352. }
  353. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  354. return aliRsp, err
  355. }
  356. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  357. aliRsp.SignData = signData
  358. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  359. }
  360. // alipay.user.charity.recordexist.query(查询是否在支付宝公益捐赠的接口)
  361. // 文档地址:https://opendocs.alipay.com/apis/api_2/alipay.user.charity.recordexist.query
  362. func (a *Client) UserCharityRecordexistQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserCharityRecordexistQueryRsp, err error) {
  363. err = bm.CheckEmptyError("partner_id", "user_id")
  364. if err != nil {
  365. return nil, err
  366. }
  367. var bs []byte
  368. if bs, err = a.doAliPay(ctx, bm, "alipay.user.charity.recordexist.query"); err != nil {
  369. return nil, err
  370. }
  371. aliRsp = new(UserCharityRecordexistQueryRsp)
  372. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  373. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  374. }
  375. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  376. return aliRsp, err
  377. }
  378. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  379. aliRsp.SignData = signData
  380. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  381. }
  382. // alipay.user.alipaypoint.send(集分宝发放接口)
  383. // 文档地址:https://opendocs.alipay.com/apis/api_2/alipay.user.alipaypoint.send
  384. func (a *Client) UserAlipaypointSend(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserAlipaypointSendRsp, err error) {
  385. err = bm.CheckEmptyError("budget_code", "partner_biz_no", "point_amount")
  386. if err != nil {
  387. return nil, err
  388. }
  389. var bs []byte
  390. if bs, err = a.doAliPay(ctx, bm, "alipay.user.alipaypoint.send"); err != nil {
  391. return nil, err
  392. }
  393. aliRsp = new(UserAlipaypointSendRsp)
  394. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  395. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  396. }
  397. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  398. return aliRsp, err
  399. }
  400. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  401. aliRsp.SignData = signData
  402. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  403. }
  404. // koubei.member.data.isv.create(isv 会员CRM数据回流)
  405. // 文档地址:https://opendocs.alipay.com/apis/api_2/koubei.member.data.isv.create
  406. func (a *Client) MemberDataIsvCreate(ctx context.Context, bm gopay.BodyMap) (aliRsp *MemberDataIsvCreateRsp, err error) {
  407. err = bm.CheckEmptyError("member_card_id", "member_source", "member_status", "gmt_merber_card_create", "parter_id")
  408. if err != nil {
  409. return nil, err
  410. }
  411. var bs []byte
  412. if bs, err = a.doAliPay(ctx, bm, "koubei.member.data.isv.create"); err != nil {
  413. return nil, err
  414. }
  415. aliRsp = new(MemberDataIsvCreateRsp)
  416. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  417. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  418. }
  419. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  420. return aliRsp, err
  421. }
  422. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  423. aliRsp.SignData = signData
  424. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  425. }
  426. // alipay.user.family.archive.query(查询家人信息档案(选人授权)组件已选的家人档案信息)
  427. // 文档地址:https://opendocs.alipay.com/apis/api_2/alipay.user.family.archive.query
  428. func (a *Client) UserFamilyArchiveQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserFamilyArchiveQueryRsp, err error) {
  429. err = bm.CheckEmptyError("archive_token")
  430. if err != nil {
  431. return nil, err
  432. }
  433. var bs []byte
  434. if bs, err = a.doAliPay(ctx, bm, "alipay.user.family.archive.query"); err != nil {
  435. return nil, err
  436. }
  437. aliRsp = new(UserFamilyArchiveQueryRsp)
  438. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  439. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  440. }
  441. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  442. return aliRsp, err
  443. }
  444. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  445. aliRsp.SignData = signData
  446. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  447. }
  448. // alipay.user.family.archive.initialize(初始化家人信息档案(选人授权)组件)
  449. // 文档地址:https://opendocs.alipay.com/apis/api_2/alipay.user.family.archive.initialize
  450. func (a *Client) UserFamilyArchiveInitialize(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserFamilyArchiveInitializeRsp, err error) {
  451. err = bm.CheckEmptyError("out_biz_no", "template_id", "redirect_uri")
  452. if err != nil {
  453. return nil, err
  454. }
  455. var bs []byte
  456. if bs, err = a.doAliPay(ctx, bm, "alipay.user.family.archive.initialize"); err != nil {
  457. return nil, err
  458. }
  459. aliRsp = new(UserFamilyArchiveInitializeRsp)
  460. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  461. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  462. }
  463. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  464. return aliRsp, err
  465. }
  466. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  467. aliRsp.SignData = signData
  468. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  469. }
  470. // alipay.user.certdoc.certverify.preconsult(实名证件信息比对验证预咨询)
  471. // 文档地址:https://opendocs.alipay.com/apis/api_2/alipay.user.certdoc.certverify.preconsult
  472. func (a *Client) UserCertdocCertverifyPreconsult(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserCertdocCertverifyPreconsultRsp, err error) {
  473. err = bm.CheckEmptyError("user_name", "cert_type", "cert_no")
  474. if err != nil {
  475. return nil, err
  476. }
  477. var bs []byte
  478. if bs, err = a.doAliPay(ctx, bm, "alipay.user.certdoc.certverify.preconsult"); err != nil {
  479. return nil, err
  480. }
  481. aliRsp = new(UserCertdocCertverifyPreconsultRsp)
  482. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  483. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  484. }
  485. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  486. return aliRsp, err
  487. }
  488. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  489. aliRsp.SignData = signData
  490. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  491. }
  492. // alipay.user.certdoc.certverify.consult(实名证件信息比对验证咨询)
  493. // 文档地址:https://opendocs.alipay.com/apis/api_2/alipay.user.certdoc.certverify.consult
  494. func (a *Client) UserCertdocCertverifyConsult(ctx context.Context, bm gopay.BodyMap, authToken string) (aliRsp *UserCertdocCertverifyConsultRsp, err error) {
  495. var bs []byte
  496. if bs, err = a.doAliPay(ctx, bm, "alipay.user.certdoc.certverify.consult", authToken); err != nil {
  497. return nil, err
  498. }
  499. aliRsp = new(UserCertdocCertverifyConsultRsp)
  500. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  501. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  502. }
  503. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  504. return aliRsp, err
  505. }
  506. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  507. aliRsp.SignData = signData
  508. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  509. }
  510. // alipay.user.family.share.zmgo.initialize(初始化家庭芝麻GO共享组件)
  511. // 文档地址:https://opendocs.alipay.com/apis/01n4yx
  512. func (a *Client) UserFamilyShareZmgoInitialize(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserFamilyShareZmgoInitializeRsp, err error) {
  513. err = bm.CheckEmptyError("user_id", "scene_id", "template_id", "out_request_no")
  514. if err != nil {
  515. return nil, err
  516. }
  517. var bs []byte
  518. if bs, err = a.doAliPay(ctx, bm, "alipay.user.family.share.zmgo.initialize"); err != nil {
  519. return nil, err
  520. }
  521. aliRsp = new(UserFamilyShareZmgoInitializeRsp)
  522. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  523. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  524. }
  525. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  526. return aliRsp, err
  527. }
  528. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  529. aliRsp.SignData = signData
  530. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  531. }
  532. // alipay.user.dtbank.qrcodedata.query(数字分行银行码明细数据查询)
  533. // 文档地址:https://opendocs.alipay.com/apis/01ozks
  534. func (a *Client) UserDtbankQrcodedataQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserDtbankQrcodedataQueryRsp, err error) {
  535. err = bm.CheckEmptyError("data_date", "qrcode_id", "qrcode_out_id")
  536. if err != nil {
  537. return nil, err
  538. }
  539. var bs []byte
  540. if bs, err = a.doAliPay(ctx, bm, "alipay.user.dtbank.qrcodedata.query"); err != nil {
  541. return nil, err
  542. }
  543. aliRsp = new(UserDtbankQrcodedataQueryRsp)
  544. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  545. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  546. }
  547. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  548. return aliRsp, err
  549. }
  550. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  551. aliRsp.SignData = signData
  552. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  553. }
  554. // alipay.user.alipaypoint.budgetlib.query(查询集分宝预算库详情)
  555. // 文档地址:https://opendocs.alipay.com/apis/01zrby
  556. func (a *Client) UserAlipaypointBudgetlibQuery(ctx context.Context, bm gopay.BodyMap) (aliRsp *UserAlipaypointBudgetlibQueryRsp, err error) {
  557. err = bm.CheckEmptyError("budget_code")
  558. if err != nil {
  559. return nil, err
  560. }
  561. var bs []byte
  562. if bs, err = a.doAliPay(ctx, bm, "alipay.user.alipaypoint.budgetlib.query"); err != nil {
  563. return nil, err
  564. }
  565. aliRsp = new(UserAlipaypointBudgetlibQueryRsp)
  566. if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
  567. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  568. }
  569. if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
  570. return aliRsp, err
  571. }
  572. signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
  573. aliRsp.SignData = signData
  574. return aliRsp, a.autoVerifySignByCert(aliRsp.Sign, signData, signDataErr)
  575. }