Check the purchase status of Android, but failed to return the purchase token.

I reviewed the google play android api to check the purchase and consumption status of an item in the app. For some orders, I can get the correct result, but some return an error, as shown below:

error: {
errors: [
{
domain: "global",
reason: "purchaseTokenNotFound",
message: "The purchase token was not found.",
locationType: "parameter",
location: "token"
}
],
code: 404,
message: "The purchase token was not found."
}

Commodity token provided by google, can it be fake?

I found that if I canceled a Google order, then check the purchase status, it will return the purchase marker was not found. if not, I will receive the correct purchase status.

Hope someone can help.

+4
source share
2 answers

INAPP , , , , 404.

:

john@example.com com.example.test.product , ( Google ) Merchant account), .

, , :

{
kind: "androidpublisher#inappPurchase",
purchaseTime: "1409823171827",
purchaseState: "0",
consumptionState: "1",
developerPayload: "My Product | Ref | 1409823162466"
}

, , , 404!

- ( , ), , , inapp google. , "" , .

, . , API Google . , - :)

+5

. API .

INAPP_PURCHASE_DATA INAPP_DATA_SIGNATURE getBuyIntent.

https://developer.android.com/google/play/billing/billing_reference.html#getBuyIntent

Google Play Developer Console β†’ YOUR_APP β†’ service and API

package main

import (
        "crypto"
        "crypto/rsa"
        "crypto/sha1"
        "crypto/x509"
        "encoding/base64"
        "encoding/pem"
        "fmt"
)

//replace const below with your own.
const (
        pubKeyPEM=`-----BEGIN PUBLIC KEY-----
Some thing like this
-----END PUBLIC KEY-----`
        data = `purchase data from getBuyIntent API`
        sign = `purchase data signature from getBuyIntent API`

)

func Panic(err error) {
        if err != nil {
                panic(err)
        }
}

func main() {

        PEMBlock, _ := pem.Decode([]byte(pubKeyPEM))
        if PEMBlock == nil {
                Panic(fmt.Errorf("Could not parse Public Key PEM"))
        }
        if PEMBlock.Type != "PUBLIC KEY" {
                Panic(fmt.Errorf("Found wrong key type"))
        }
        pubkey, err := x509.ParsePKIXPublicKey(PEMBlock.Bytes)
        if err != nil {
                Panic(err)
        }

        // compute the sha1
        h := sha1.New()
        h.Write([]byte(data))

        // decode b64 signature
        signature, err := base64.StdEncoding.DecodeString(sign)
        Panic(err)

        // Verify
        err = rsa.VerifyPKCS1v15(pubkey.(*rsa.PublicKey), crypto.SHA1, h.Sum(nil), signature)
        Panic(err)

        // It verified!
        fmt.Println("OK")
}
+1

All Articles