Golang实现的In-App-Purchase(IAP)源码

Golang 归档:202004
普通
浏览:5118
2020-04-15 10:59:24
Golang实现的In-App-Purchase(IAP)源码,包括了apple iap和google pay iap

开源项目一:

https://github.com/kkdai/iap

介绍

Golang In-App-Purchase Package for Apple iTune and Google Play

安装

go get github.com/kkdai/iap

开源项目二:

https://github.com/Pallinder/go-iap

文档地址

https://godoc.org/github.com/Pallinder/go-iap

使用demo1,使用sandbox方式

package main

import (
    "fmt"
    "github.com/Pallinder/go-iap"
    "log"
)

func main() {
    receipt, err := goiap.VerifyReceipt("receipt",true) // Uses the sandbox environment

    if err != nil {
      log.Fatal(err)
    }

    fmt.Println("Got receipt", receipt)
}

实现demo2

package main

import (
    "fmt"
    "github.com/Pallinder/go-iap"
    "log"
)

func main() {
    receipt, err := goiap.VerifyReceipt("receipt",false)

    goiapErr, ok := err.(goiap.ErrorWithCode)

    if ok && goiapErr.Code() == goiap.SandboxReceiptOnProd {
        receipt, err = goiap.VerifyReceipt("receipt", true)
    }

    if err != nil {
      log.Fatal(err)
    }

    fmt.Println("Got receipt", receipt)
}
注意事项
  • 此文章对你有帮助,对作者表示感谢(微信):
  • 本文地址:https://22v.net/article/3254/
  • 转载本文时,请注明转载自“SamBlog”的字样。
  • 如此文章有损您的合法权益,请使用页面底部的邮箱与我取得联系。
分类目录
文章归档
友情站点