opvexe / apple

苹果内购、登录、通知、StoreKit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

苹果支付

鸣谢

jetbrains.svg

安装

go get github.com/smartwalle/apple
import github.com/smartwalle/apple

帮助

在集成的过程中有遇到问题,欢迎加 QQ 群 564704807 讨论。

其它支付

支付宝 https://github.com/smartwalle/alipay

PayPal https://github.com/smartwalle/paypal

苹果内购验证

var summary, info, err = apple.VerifyReceipt(transactionId, receipt)

苹果内购验证支持生产环境沙箱环境VerifyReceipt() 函数内部会优先向苹果生产环境进行验证,然后根据获取到的数据判断是否要向沙箱环境进行验证。

可以从 VerifyReceipt() 函数返回的数据中判断该支付所属的环境信息。

苹果登录数据解析

var client = apple.NewIdentityClient()
var user, err = client.DecodeToken("从客户端获取到的 IdentityToken")

DecodeToken() 方法只负责对数据进行解析,验证是否为当前应用的用户,需要自行验证该方法返回值 User 对象的 BundleId 属性。

通知数据解析

var notification, err = apple.DecodeNotification([]byte(data))

业务服务器提供一个请求方法为 POST 的 HTTP 接口给苹果,苹果会在需要的时候推送一些通知消息到该接口。

var s = gin.Default()
s.POST("/apple", apple)

func apple(c *gin.Context) {
    var data, _ = io.ReadAll(c.Request.Body)
    var notification, err = apple.DecodeNotification([]byte(data)) 
    // 关于这里如何返回数据参考 https://developer.apple.com/documentation/appstoreservernotifications/responding_to_app_store_server_notifications
    // 简单来讲,返回 HTTP Status Code 200 表示我们成功处理该通知
    // 如:c.Status(http.StatusOK)
	
    // 返回 HTTP Status Code 50x 或者 40x 表示我们没有成功处理该通知,苹果会在一定时间后重新推送该通知
    // 如:c.Status(http.StatusBadRequest)
}

其它接口

以上接口需要先初始化 apple.Client

var client, _ = apple.New(keyfile, keyId, issuer, bundleId, isProduction)

关于 keyfile, keyId, issuer 如何获取?

Creating API Keys to Use With the App Store Server API

License

This project is licensed under the MIT License.

About

苹果内购、登录、通知、StoreKit

License:MIT License


Languages

Language:Go 100.0%