Git Product home page Git Product logo

apple_pay's Introduction

苹果支付

鸣谢

jetbrains.svg

安装

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

帮助

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

其它支付

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

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

银联支付 https://github.com/smartwalle/unionpay

苹果内购验证(旧)

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

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

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

苹果内购验证(新)

根据苹果官方文档所示,原 verifyReceipt 接口已经标记为 Deprecated,新的接口已经整合到 App Store Server API

新的验证需要参考本文档其它接口部分对 apple.Client 进行实例化,然后调用其 GetTransaction() 方法进行查询。

苹果登录数据解析

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

苹果登录数据验证

如果要验证 Token 的合法性,在初始化 IdentityClient 的时候,需要设置 BundleId。

var client = apple.NewAuthClient(apple.WithBundleId("bundle id"))
var user, err = client.VerifyToken("从客户端获取到的 IdentityToken")

通知数据解析

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.

apple_pay's People

Contributors

smartwalle avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.