{"id":19021997,"url":"https://github.com/smartwalle/apple","last_synced_at":"2025-10-25T22:49:24.264Z","repository":{"id":83293587,"uuid":"407528867","full_name":"smartwalle/apple","owner":"smartwalle","description":"苹果内购、登录、通知、StoreKit","archived":false,"fork":false,"pushed_at":"2024-07-23T00:35:53.000Z","size":110,"stargazers_count":44,"open_issues_count":1,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T23:04:29.375Z","etag":null,"topics":["apple","ios","ipa","purchase","storekit"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smartwalle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-17T12:16:57.000Z","updated_at":"2025-02-26T15:47:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"7f8d8938-2dcb-4439-baeb-7440feabce88","html_url":"https://github.com/smartwalle/apple","commit_stats":null,"previous_names":["smartwalle/inpay"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartwalle%2Fapple","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartwalle%2Fapple/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartwalle%2Fapple/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartwalle%2Fapple/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smartwalle","download_url":"https://codeload.github.com/smartwalle/apple/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249117158,"owners_count":21215343,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apple","ios","ipa","purchase","storekit"],"created_at":"2024-11-08T20:24:30.927Z","updated_at":"2025-10-25T22:49:19.228Z","avatar_url":"https://github.com/smartwalle.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"苹果支付\n\n## 鸣谢\n\n[![jetbrains.svg](jetbrains.svg)](https://www.jetbrains.com/?from=AliPay%20SDK%20for%20Go)\n\n## 安装\n\n```go\ngo get github.com/smartwalle/apple\n```\n\n```go\nimport github.com/smartwalle/apple\n```\n\n## 帮助\n\n在集成的过程中有遇到问题，欢迎加 QQ 群 203357977 讨论。\n\n## 其它支付\n\n支付宝 [https://github.com/smartwalle/alipay](https://github.com/smartwalle/alipay)\n\nPayPal [https://github.com/smartwalle/paypal](https://github.com/smartwalle/paypal)\n\n银联支付 [https://github.com/smartwalle/unionpay](https://github.com/smartwalle/unionpay)\n\n## 苹果内购验证（旧）\n\n```go\nvar summary, info, err = apple.VerifyReceipt(transactionId, receipt)\n```\n\n苹果内购验证支持**生产环境**和**沙箱环境**，**VerifyReceipt()** 函数内部会优先向苹果生产环境进行验证，然后根据获取到的数据判断是否要向沙箱环境进行验证。\n\n可以从 **VerifyReceipt()** 函数返回的数据中判断该支付所属的环境信息。\n\n## 苹果内购验证（新）\n\n根据苹果[官方文档](https://developer.apple.com/documentation/appstorereceipts/verifyreceipt)所示，原 verifyReceipt 接口已经标记为 Deprecated，新的接口已经整合到 [App Store Server API](https://developer.apple.com/documentation/appstoreserverapi/get_transaction_info)。\n\n新的验证需要参考本文档[其它接口](https://github.com/smartwalle/apple#%E5%85%B6%E5%AE%83%E6%8E%A5%E5%8F%A3)部分对 apple.Client 进行实例化，然后调用其 GetTransaction() 方法进行查询。\n\n## 苹果登录数据解析\n\n```go\nvar client = apple.NewAuthClient()\nvar user, err = client.DecodeToken(\"从客户端获取到的 IdentityToken\")\n```\n\n## 苹果登录数据验证\n\n如果要验证 Token 的合法性，在初始化 IdentityClient 的时候，需要设置 BundleId。\n\n```go\nvar client = apple.NewAuthClient(apple.WithBundleId(\"bundle id\"))\nvar user, err = client.VerifyToken(\"从客户端获取到的 IdentityToken\")\n```\n\n## 通知数据解析\n\n```go\nvar notification, err = apple.DecodeNotification([]byte(data))\n```\n\n业务服务器提供一个请求方法为 **POST** 的 HTTP 接口给苹果，苹果会在需要的时候推送一些通知消息到该接口。\n\n```go\nvar s = gin.Default()\ns.POST(\"/apple\", apple)\n\nfunc apple(c *gin.Context) {\n    var data, _ = io.ReadAll(c.Request.Body)\n    var notification, err = apple.DecodeNotification([]byte(data)) \n    // 关于这里如何返回数据参考 https://developer.apple.com/documentation/appstoreservernotifications/responding_to_app_store_server_notifications\n    // 简单来讲，返回 HTTP Status Code 200 表示我们成功处理该通知\n    // 如：c.Status(http.StatusOK)\n\t\n    // 返回 HTTP Status Code 50x 或者 40x 表示我们没有成功处理该通知，苹果会在一定时间后重新推送该通知\n    // 如：c.Status(http.StatusBadRequest)\n}\n\n```\n\n## 其它接口\n\n* **[Get Transaction Info](https://developer.apple.com/documentation/appstoreserverapi/get_transaction_info)**\n* **[Look Up Order ID](https://developer.apple.com/documentation/appstoreserverapi/look_up_order_id)**\n* **[Get Refund History](https://developer.apple.com/documentation/appstoreserverapi/get_refund_history)**\n* **[Get All Subscription Statuses](https://developer.apple.com/documentation/appstoreserverapi/get_all_subscription_statuses)**\n* **[Extend a Subscription Renewal Date](https://developer.apple.com/documentation/appstoreserverapi/extend_a_subscription_renewal_date)**\n* **[Get Transaction History](https://developer.apple.com/documentation/appstoreserverapi/get_transaction_history)**\n* **[Send Consumption Information](https://developer.apple.com/documentation/appstoreserverapi/send_consumption_information)**\n\n以上接口需要先初始化 apple.Client\n\n```go\nvar client, _ = apple.New(keyfile, keyId, issuer, bundleId, isProduction)\n```\n\n#### 关于 keyfile, keyId, issuer 如何获取？\n\n[Creating API Keys to Use With the App Store Server API\n](https://developer.apple.com/documentation/appstoreserverapi/creating_api_keys_to_use_with_the_app_store_server_api)\n\n## License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartwalle%2Fapple","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmartwalle%2Fapple","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartwalle%2Fapple/lists"}