billing

package module
v0.0.0-...-f51f4f7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

billing

GoDoc

Android billing服务端校验,Golang实现

Usage
go get github.com/swxctx/billing
Doc
Android
https://developer.android.com/google/play/billing/integrate?hl=zh-cn#java
Server
https://developers.google.com/android-publisher?hl=zh-cn#subscriptions
https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.products/get?hl=zh-cn
Refresh Token
https://developers.google.com/android-publisher/authorization?hl=zh-cn
Example
package main

import (
	"fmt"
	"github.com/swxctx/billing"
	"github.com/xiaoenai/xmodel/redis"
)

func main() {
	err := billing.Init(&billing.Config{
		ClientId:     "",
		ClientSecret: "",
		PackageName:  "",
		RefreshToken: "",
		Debug:        true,
		Redis: &redis.Config{
			DeployType: "single",
			ForSingle: redis.SingleConfig{
				Addr: "127.0.0.1:6379",
			},
		},
	})
	if err != nil {
		fmt.Println("init err")
		return
	}

	// 获取token
	accessToken, err := billing.GetAccessToken()
	if err != nil {
		fmt.Printf("err-> %v", err)
		return
	}
	fmt.Printf("accessToken-> %v\n", accessToken)

	// 查询订单
	orderInfo, err := billing.Verify("", "")
	if err != nil {
		fmt.Printf("err-> %v", err)
		return
	}
	fmt.Printf("orderInfo-> %v", orderInfo)
}

Documentation

Index

Constants

View Source
const (
	// 支付成功
	ORDER_STATUS_SUCCESS = 0
	// 支付取消
	ORDER_STATUS_CANCEL = 1
	// 支付待处理
	ORDER_STATUS_PENDING = 2
)
View Source
const (
	// 消耗状态未确认
	CONSUME_STATE_UNCONFIRMED = 0
	// 消耗状态已确认
	CONSUME_STATE_CONFIRMED = 1
)
View Source
const (
	// 非消耗商品未确认
	ACKNOWLERDGE_STATE_UNCONFIRMED = 0
	// 非小号商品已确认
	ACKNOWLERDGE_STATE_CONFIRMED = 1
)

Variables

This section is empty.

Functions

func Acknowledge

func Acknowledge(productId, purchaseToken string) error

Acknowledge

func Consume

func Consume(productId, purchaseToken string) error

Consume

func Init

func Init(cfg *Config) error

Init

Types

type AccessToken

type AccessToken struct {
	// token
	AccessToken string `json:"access_token"`
	// 有效时间[单位为秒,默认一小时]
	ExpiresIn int64 `json:"expires_in"`
	// 授权范围
	Scope string `json:"scope"`
	// token 类型[Bearer]
	TokenType string `json:"token_type"`
}

AccessToken

func GetAccessToken

func GetAccessToken() (*AccessToken, error)

GetAccessToken

type Client

type Client struct {
	// contains filtered or unexported fields
}

type Config

type Config struct {
	// client id
	ClientId string `yaml:"client_id"`
	// client secret
	ClientSecret string `yaml:"client_secret"`
	// 包名
	PackageName string `yaml:"package_name"`
	// 刷新token
	RefreshToken string `yaml:"refresh_token"`
	// redis缓存token的key(选填)
	CacheKey string `yaml:"cache_key"`
	// Debug 是否调试模式
	Debug bool `yaml:"debug"`
	// TimeoutSecond 超时时间
	TimeoutSecond int64 `yaml:"timeout_second"`
	// Redis 缓存的redis配置[127.0.0.1:6379]
	RedisAddr string `yaml:"redis_addr"`
}

Config owechat配置中心

type OrderInfo

type OrderInfo struct {
	// 支付时间,毫秒
	PurchaseTimeMillis string `json:"purchaseTimeMillis"`
	// 支付状态[0: 已购买 1: 已取消 2: 待处理]
	PurchaseState int `json:"purchaseState"`
	// 应用内商品的消耗状态[0: 尚未消耗 1: 已使用]
	ConsumptionState int `json:"consumptionState"`
	// 开发者指定的字符串,其中包含关于订单的补充信息
	DeveloperPayload string `json:"developerPayload"`
	// 订单ID
	OrderID string `json:"orderId"`
	// 应用内商品的购买类型。
	// 仅当购买交易不是使用标准的应用内购买结算流程完成时,系统才会设置此字段。
	// 可能的值包括:0. 测试(即从许可测试帐号中购买的服务)1. 促销(即使用促销代码购买)2. 激励广告(即通过观看视频广告而不是付费)
	PurchaseType int `json:"purchaseType"`
	// 应用内商品的确认状态。可能的值包括:0. 尚未确认 1. 已确认
	AcknowledgementState int `json:"acknowledgementState"`
	// 表示 android publisher service 中的 inappPurchase 对象
	Kind string `json:"kind"`
	// 产品被授予时用户的 ISO 3166-1 alpha-2 结算区域代码
	RegionCode string `json:"regionCode"`
}

OrderInfo 订单查询信息

func Verify

func Verify(productId, purchaseToken string) (*OrderInfo, error)

Verify

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL