开源项目一:

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)
}