afdian

package module
v0.0.0-...-0a8110c Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: MIT Imports: 9 Imported by: 0

README

AFDIAN-GO 爱发电

爱发电SDK

golang 1.18 以上

使用方法

import (
    "github.com/niuhuan/afdian-go"
)

// 创建客户端
client := &afdian.Client{
    UserId: "uid",
    Token: "token",
}
// 查看配置是否正常(成功时err为nil)
err := client.Ping()
// 查询订单
orderRsp, err := client.QueryOrder(1)
// 查询赞助者
sponsorRsp, err := client.QuerySponsor(1)

// 解析爱发电调用服务器
orderRsp, err := client.ParseOrder(body)

// 给爱发电的调用返回json
client.CallResponseString()

Documentation

Index

Constants

View Source
const AfDianOpenApiUri = "https://afdian.net/api/open"

Variables

This section is empty.

Functions

func CallResponseString

func CallResponseString() string

func QueryAfdian

func QueryAfdian[T any, R any](c *Client, requestPath string, params *T) (*R, error)

QueryAfdian Go1.18 暂不支持成员函数使用泛型

Types

type AfdianCall

type AfdianCall AfdianResponse[AfdianCallData]

type AfdianCallData

type AfdianCallData struct {
	Type  string `json:"type"`
	Order Order  `json:"order"`
}

type AfdianCallResponse

type AfdianCallResponse struct {
	Ec int    `json:"ec"`
	Em string `json:"em"`
}

AfdianCallResponse 爱发电回调返回 {"ec":200,"em":""}

func CallResponseStruct

func CallResponseStruct() *AfdianCallResponse

type AfdianResponse

type AfdianResponse[T any] struct {
	Ec   int    `json:"ec"`
	Em   string `json:"em"`
	Data T      `json:"data"`
}

type Client

type Client struct {
	http.Client
	UserId string `json:"user_id"`
	Token  string `json:"token"`
}

func (*Client) Ping

func (c *Client) Ping() error

Ping 就很蠢, 非要有参数

func (*Client) QueryOrder

func (c *Client) QueryOrder(page int64) (*PageData[Order], error)

QueryOrder 查订单

func (*Client) QuerySponsor

func (c *Client) QuerySponsor(page int64) (*PageData[Sponsor], error)

QuerySponsor 查赞助者

type Order

type Order struct {
	OutTradeNo     string  `json:"out_trade_no"`
	UserId         string  `json:"user_id"`
	PlanId         string  `json:"plan_id"`
	Month          int     `json:"month"`
	TotalAmount    float64 `json:"total_amount"`
	ShowAmount     float64 `json:"show_amount"`
	Status         int     `json:"status"`
	Remark         string  `json:"remark"`
	RedeemId       string  `json:"redeem_id"`
	ProductType    int     `json:"product_type"`
	Discount       float64 `json:"discount"`
	SkuDetail      []Sku   `json:"sku_detail"`
	PlanTitle      string  `json:"plan_title"`
	UserPrivateId  string  `json:"user_private_id"`
	AddressPerson  string  `json:"address_person"`
	AddressPhone   string  `json:"address_phone"`
	AddressAddress string  `json:"address_address"`
}

func ParseOrder

func ParseOrder(body []byte) (*Order, error)

ParseOrder 爱发电调服务器的请求内容, 解析成Order

func ParseOrderInterface

func ParseOrderInterface(body interface{}) (*Order, error)

ParseOrderInterface 爱发电调服务器的请求内容, 解析成Order (AWS无法使用json模糊解析)

type PageData

type PageData[T any] struct {
	List       []T     `json:"list"`
	TotalCount int     `json:"total_count"`
	TotalPage  int     `json:"total_page"`
	Request    Request `json:"request"`
}

type Plan

type Plan struct {
	BundleSkuSelectCount int           `json:"bundle_sku_select_count"`
	BundleStock          int           `json:"bundle_stock"`
	CanBuyHide           int           `json:"can_buy_hide"`
	Coupon               []interface{} `json:"coupon"`
	Desc                 string        `json:"desc"`
	ExpireTime           int           `json:"expire_time"`
	FavorablePrice       int           `json:"favorable_price"`
	HasCoupon            int           `json:"has_coupon"`
	Independent          int           `json:"independent"`
	Name                 string        `json:"name"`
	NeedAddress          int           `json:"need_address"`
	NeedInviteCode       bool          `json:"need_invite_code"`
	PayMonth             int           `json:"pay_month"`
	Permanent            int           `json:"permanent"`
	Pic                  string        `json:"pic"`
	PlanId               string        `json:"plan_id"`
	Price                float64       `json:"price"`
	ProductType          int           `json:"product_type"`
	Rank                 int           `json:"rank"`
	RankType             int           `json:"rankType"`
	SaleLimitCount       int           `json:"sale_limit_count"`
	ShowPrice            float64       `json:"show_price"`
	ShowPriceAfterAdjust string        `json:"show_price_after_adjust"`
	SkuProcessed         []interface{} `json:"sku_processed"`
	Status               int           `json:"status"`
	Timing               Timing        `json:"timing"`
	UpdateTime           int           `json:"update_time"`
	UserId               string        `json:"user_id"`
}

type Request

type Request struct {
	UserId string `json:"user_id"`
	Params string `json:"params"`
	Ts     int    `json:"ts"`
	Sign   string `json:"sign"`
}

type Sku

type Sku struct {
	SkuId   string `json:"sku_id"`
	Count   int    `json:"count"`
	Name    string `json:"name"`
	AlbumId string `json:"album_id"`
	Pic     string `json:"pic"`
}
type Sponsor struct {
	AllSumAmount float64 `json:"all_sum_amount"`
	CurrentPlan  Plan    `json:"current_plan"`
	FirstPayTime int     `json:"first_pay_time"`
	LastPayTime  int     `json:"last_pay_time"`
	SponsorPlans []Plan  `json:"sponsor_plans"`
	User         User    `json:"user"`
}

type Timing

type Timing struct {
	TimingOff int `json:"timing_off"`
	TimingOn  int `json:"timing_on"`
}

type User

type User struct {
	Avatar        string `json:"avatar"`
	Name          string `json:"name"`
	UserId        string `json:"user_id"`
	UserPrivateId string `json:"user_private_id"`
}

Jump to

Keyboard shortcuts

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