yaoyaola

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountInfo

type AccountInfo struct {
	Balance   string `json:"balance"`   // remaining red pocket money that can be sent
	ExpiredAt Time   `json:"apiexpire"` // account expiration date/time
}

type Client

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

func NewClient

func NewClient(uid, apiKey string) *Client

NewClient creates a new client from UID and API key.

func (Client) GetAccountInfo

func (c Client) GetAccountInfo(ctx context.Context) (*AccountInfo, error)

GetAccountInfo gets balance and expiration date of current account.

func (Client) GetAuthURL

func (c Client) GetAuthURL(redirect string, getUserInfo bool) string

GetAuthURL generates authorization URL. Visit this URL in Wechat to get user's Open ID. To get user's name and image, set getUserInfo to true. Open ID and user info will be added as query string to the redirect URL provided. The URL can be verified by VerifyURL().

func (Client) SendRedPocket

func (c Client) SendRedPocket(ctx context.Context, redPocket RedPocket) error

SendRedPocket sends a Wechat red pocket.

func (Client) VerifyURL

func (c Client) VerifyURL(url string) (openId string, userInfo UserInfo, ok bool)

VerifyURL verifies the rediection URL from yaoyaola and, if URL is valid, returns the Open ID and user info (present if GetAuthURL's getUserInfo is true).

type Error

type Error struct {
	Code    string `json:"errcode"`
	Message string `json:"errmsg"`
}

func (Error) Error

func (e Error) Error() string

type RedPocket

type RedPocket struct {
	// Defaults to RedPocketTypePersonal, set to
	// RedPocketTypeEnterprise to send red pocket over 200 yuan
	Type RedPocketType

	// Money in cents of a red pocket, must not be less than 30
	Cents int

	// Once SendRedPocket() succeeds, you'll receive a new
	// Wechat message like this:
	//  你参与{Title},成功获得{SenderName}赠送的红包,
	//  点击消息打开,一起抢红包、拼手气吧!
	//  点击消息拆开红包即可获得现金
	// And on the details page, you'll see:
	//  {SenderName}的红包
	//  {Description}
	Title       string
	Description string
	SenderName  string

	// Open ID of the user who receives a red pocket, can be
	// obtained by the redirection URL from GetAuthURL
	ReceiverOpenId string

	// If Order ID is empty, random string will be used
	OrderId string
}

type RedPocketType

type RedPocketType int
const (
	RedPocketTypePersonal RedPocketType = iota
	RedPocketTypeEnterprise
)

type Time

type Time struct {
	time.Time
}

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(b []byte) error

type UserInfo

type UserInfo struct {
	OpenId   string `json:"openid"`
	NickName string `json:"nickname"`
	ImageUrl string `json:"headimgurl"`
}

Jump to

Keyboard shortcuts

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