Apple

Apple Pay 支付校验收据

url 请选择 apple.UrlSandbox 或 apple.UrlProd

  • apple.VerifyReceipt() => 苹果支付校验收据API

校验示例

  1. import (
  2. "github.com/go-pay/gopay/apple"
  3. "github.com/go-pay/gopay/pkg/xlog"
  4. )
  5. pwd := ""
  6. receipt := ""
  7. rsp, err := apple.VerifyReceipt(UrlSandbox, pwd, receipt)
  8. if err != nil {
  9. xlog.Error(err)
  10. return
  11. }
  12. /**
  13. response body:
  14. {"receipt":{"original_purchase_date_pst":"2021-08-14 05:28:17 America/Los_Angeles", "purchase_date_ms":"1628944097586", "unique_identifier":"13f339a765b706f8775f729723e9b889b0cbb64e", "original_transaction_id":"1000000859439868", "bvrs":"10", "transaction_id":"1000000859439868", "quantity":"1", "in_app_ownership_type":"PURCHASED", "unique_vendor_identifier":"6DFDEA8B-38CE-4710-A1E1-BAEB8B66FEBD", "item_id":"1581250870", "version_external_identifier":"0", "bid":"com.huochai.main", "is_in_intro_offer_period":"false", "product_id":"10002", "purchase_date":"2021-08-14 12:28:17 Etc/GMT", "is_trial_period":"false", "purchase_date_pst":"2021-08-14 05:28:17 America/Los_Angeles", "original_purchase_date":"2021-08-14 12:28:17 Etc/GMT", "original_purchase_date_ms":"1628944097586"}, "status":0}
  15. */
  16. if rsp.Receipt != nil {
  17. xlog.Infof("receipt:%+v", rsp.Receipt)
  18. }

苹果支付服务服务端通知数据解析 对应App下 [App 信息] --> [App Store 服务器通知] --> [版本 2] 配置对应的服务器地址,支付状态发生变化时Apple 将通过POST请求推送消息至配置的地址

示例

  • 请参考 notification_v2_test.go
  1. import (
  2. "github.com/go-pay/gopay/apple"
  3. "github.com/go-pay/gopay/pkg/xlog"
  4. )
  5. // decode signedPayload
  6. payload, err := apple.DecodeSignedPayload(signedPayload)
  7. if err != nil {
  8. xlog.Error(err)
  9. return
  10. }
  11. xlog.Debugf("payload.NotificationType: %s", payload.NotificationType)
  12. xlog.Debugf("payload.Subtype: %s", payload.Subtype)
  13. xlog.Debugf("payload.NotificationUUID: %s", payload.NotificationUUID)
  14. xlog.Debugf("payload.NotificationVersion: %s", payload.NotificationVersion)
  15. xlog.Debugf("payload.Data: %+v", payload.Data)
  16. bs1, _ := json.Marshal(payload)
  17. xlog.Color(xlog.RedBright).Info(string(bs1))
  18. /*
  19. {
  20. "notificationType":"DID_RENEW",
  21. "subtype":"",
  22. "notificationUUID":"469bf30e-7715-4f9f-aae3-a7bfc12aea77",
  23. "notificationVersion":"",
  24. "data":{
  25. "appAppleId":0,
  26. "bundleId":"com.audaos.audarecorder",
  27. "bundleVersion":"7",
  28. "environment":"Sandbox",
  29. "signedRenewalInfo":"xxxxxxxxxx",
  30. "signedTransactionInfo":"xxxxxxxxxxx"
  31. }
  32. }
  33. */
  34. // decode renewalInfo
  35. renewalInfo, err := payload.DecodeRenewalInfo()
  36. if err != nil {
  37. xlog.Error(err)
  38. return
  39. }
  40. xlog.Debugf("data.renewalInfo: %+v", renewalInfo)
  41. bs, _ := json.Marshal(renewalInfo)
  42. xlog.Color(xlog.GreenBright).Info(string(bs))
  43. /*
  44. {
  45. "autoRenewProductId":"com.audaos.audarecorder.vip.m2",
  46. "autoRenewStatus":1,
  47. "expirationIntent":0,
  48. "gracePeriodExpiresDate":0,
  49. "isInBillingRetryPeriod":false,
  50. "offerIdentifier":"",
  51. "offerType":0,
  52. "originalTransactionId":"2000000000842607",
  53. "priceIncreaseStatus":0,
  54. "productId":"com.audaos.audarecorder.vip.m2",
  55. "signedDate":1646387008228
  56. }
  57. */
  58. // decode transactionInfo
  59. transactionInfo, err := payload.DecodeTransactionInfo()
  60. if err != nil {
  61. xlog.Error(err)
  62. return
  63. }
  64. xlog.Debugf("data.transactionInfo: %+v", transactionInfo)
  65. bs2, _ := json.Marshal(transactionInfo)
  66. xlog.Color(xlog.YellowBright).Info(string(bs2))
  67. /*
  68. {
  69. "appAccountToken":"",
  70. "bundleId":"com.audaos.audarecorder",
  71. "expiresDate":1646387196000,
  72. "inAppOwnershipType":"PURCHASED",
  73. "isUpgraded":false,
  74. "offerIdentifier":"",
  75. "offerType":0,
  76. "originalPurchaseDate":1646046037000,
  77. "originalTransactionId":"2000000000842607",
  78. "productId":"com.audaos.audarecorder.vip.m2",
  79. "purchaseDate":1646387016000,
  80. "quantity":1,
  81. "revocationDate":0,
  82. "revocationReason":"",
  83. "signedDate":1646387008254,
  84. "subscriptionGroupIdentifier":"20929536",
  85. "transactionId":"2000000004047119",
  86. "type":"Auto-Renewable Subscription",
  87. "webOrderLineItemId":"2000000000302832"
  88. }
  89. */