afdian

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

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

Go to latest
Published: Feb 26, 2025 License: MIT Imports: 12 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 AfDianAppUrl = "https://ifdian.net/api"
View Source
const AfDianOpenApiUri = "https://ifdian.net/api/open"

Variables

This section is empty.

Functions

func CallResponseString

func CallResponseString() string

func DeserializeCookies

func DeserializeCookies(data []byte) ([]*http.Cookie, error)

将序列化后的 JSON 恢复为 []*http.Cookie

func QueryAfdian

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

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

func RequestApp

func RequestApp[R any](c *AppClient, method, path string, form url.Values) (*R, error)

func SerializeCookies

func SerializeCookies(cookies []*http.Cookie) ([]byte, error)

将 []*http.Cookie 转换为 []SerializableCookie

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 AppClient

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

func NewAppClient

func NewAppClient() *AppClient

func (*AppClient) DumpCookies

func (c *AppClient) DumpCookies()

func (*AppClient) Login

func (c *AppClient) Login(username, password string) (*AuthToken, error)

func (*AppClient) MyAccount

func (c *AppClient) MyAccount() (*MyAccount, error)

func (*AppClient) PlanSkus

func (c *AppClient) PlanSkus(planId string) (*PlanSkus, error)

func (*AppClient) Plans

func (c *AppClient) Plans(userId string) (*Plans, error)

func (*AppClient) SetAuthToken

func (c *AppClient) SetAuthToken(token string)

type AuthToken

type AuthToken struct {
	AuthToken string `json:"auth_token"`
}

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

func (c *Client) QueryOrderByNo(outTradeNo string) (*Order, error)

QueryOrderByNo 查订单

func (*Client) QuerySponsor

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

QuerySponsor 查赞助者

type CreatorPlan

type CreatorPlan struct {
	CanAliAgreement      int               `json:"can_ali_agreement"`
	PlanId               string            `json:"plan_id"`
	Rank                 int               `json:"rank"`
	UserId               string            `json:"user_id"`
	Status               int               `json:"status"`
	Name                 string            `json:"name"`
	Pic                  string            `json:"pic"`
	Desc                 string            `json:"desc"`
	Price                string            `json:"price"`
	UpdateTime           int               `json:"update_time"`
	Timing               CreatorPlanTiming `json:"timing"`
	PayMonth             int               `json:"pay_month"`
	ShowPrice            string            `json:"show_price"`
	ShowPriceAfterAdjust string            `json:"show_price_after_adjust"`
	HasCoupon            int               `json:"has_coupon"`
	FavorablePrice       int               `json:"favorable_price"`
	Independent          int               `json:"independent"`
	Permanent            int               `json:"permanent"`
	CanBuyHide           int               `json:"can_buy_hide"`
	NeedAddress          int               `json:"need_address"`
	ProductType          int               `json:"product_type"`
	SaleLimitCount       int               `json:"sale_limit_count"`
	NeedInviteCode       bool              `json:"need_invite_code"`
	BundleStock          int               `json:"bundle_stock"`
	BundleSkuSelectCount int               `json:"bundle_sku_select_count"`
	HasPlanConfig        int               `json:"has_plan_config"`
	HasBadge             int               `json:"has_badge"`
	SponsorCount         string            `json:"sponsor_count"`
	HasVip               int               `json:"has_vip"`
}

type CreatorPlanTiming

type CreatorPlanTiming struct {
	TimingOn      int `json:"timing_on"`
	TimingOff     int `json:"timing_off"`
	TimingSellOn  int `json:"timing_sell_on"`
	TimingSellOff int `json:"timing_sell_off"`
}

type MyAccount

type MyAccount struct {
	Login         MyAccountLogin `json:"login"`
	UserPrivateId string         `json:"user_private_id"`
}

type MyAccountLogin

type MyAccountLogin struct {
	Email string `json:"email"`
	Phone string `json:"phone"`
}

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      []OrderSku `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 OrderPlan

type OrderPlan 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 OrderSku

type OrderSku struct {
	SkuId   string `json:"sku_id"`
	Count   int    `json:"count"`
	Name    string `json:"name"`
	AlbumId string `json:"album_id"`
	Pic     string `json:"pic"`
}

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 PlanSkus

type PlanSkus struct {
	Plan       CreatorPlan   `json:"plan"`
	List       []Sku         `json:"list"`
	BoughtSkus []interface{} `json:"bought_skus"`
}

type Plans

type Plans struct {
	List                  []CreatorPlan `json:"list"`
	SaleHasMore           int           `json:"sale_has_more"`
	SaleList              []CreatorPlan `json:"sale_list"`
	LimitShowProductCount int           `json:"limit_show_product_count"`
}

type Request

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

type SerializableCookie

type SerializableCookie struct {
	Name       string `json:"name"`
	Value      string `json:"value"`
	Path       string `json:"path,omitempty"`
	Domain     string `json:"domain,omitempty"`
	Expires    string `json:"expires,omitempty"`
	RawExpires string `json:"raw_expires,omitempty"`
	HttpOnly   bool   `json:"http_only,omitempty"`
	Secure     bool   `json:"secure,omitempty"`
}

Cookie 的中间序列化结构

type Sku

type Sku struct {
	SkuId               string    `json:"sku_id"`
	PlanId              string    `json:"plan_id"`
	UserId              string    `json:"user_id"`
	Status              int       `json:"status"`
	Name                string    `json:"name"`
	Pic                 string    `json:"pic"`
	Desc                string    `json:"desc"`
	Stock               string    `json:"stock"`
	SponsorCount        string    `json:"sponsor_count"`
	Price               string    `json:"price"`
	ReplyContent        string    `json:"reply_content"`
	ReplyRandomContent  string    `json:"reply_random_content"`
	ReplyRandomNum      int       `json:"reply_random_num"`
	ReplySwitch         bool      `json:"reply_switch"`
	ReplyRandomSwitch   bool      `json:"reply_random_switch"`
	PurchasedRichText   string    `json:"purchased_rich_text"`
	Redeem              SkuRedeem `json:"redeem"`
	Plan                SkuPlan   `json:"plan"`
	HasSkuPurchaseLimit int       `json:"has_sku_purchase_limit"`
	CanBuyCount         int       `json:"can_buy_count"`
}

type SkuPlan

type SkuPlan struct {
	Id                   int    `json:"id"`
	PlanId               string `json:"plan_id"`
	UserId               string `json:"user_id"`
	Status               int    `json:"status"`
	Rank                 int    `json:"rank"`
	Name                 string `json:"name"`
	Pic                  string `json:"pic"`
	Desc                 string `json:"desc"`
	Price                string `json:"price"`
	PayMonth             int    `json:"pay_month"`
	ReplySwitch          int    `json:"reply_switch"`
	ReplyContent         string `json:"reply_content"`
	ReplyRandomSwitch    int    `json:"reply_random_switch"`
	ReplyRandomContent   string `json:"reply_random_content"`
	Independent          int    `json:"independent"`
	Permanent            int    `json:"permanent"`
	ProductType          int    `json:"product_type"`
	CanBuyHide           int    `json:"can_buy_hide"`
	NeedAddress          int    `json:"need_address"`
	CreateTime           int    `json:"create_time"`
	UpdateTime           int    `json:"update_time"`
	BundleSkuSelectCount int    `json:"bundle_sku_select_count"`
	BundleStock          int    `json:"bundle_stock"`
	CanAliAgreement      int    `json:"can_ali_agreement"`
}

type SkuRedeem

type SkuRedeem struct {
	TotalCount   int `json:"total_count"`
	PendingCount int `json:"pending_count"`
	UsedCount    int `json:"used_count"`
}
type Sponsor struct {
	AllSumAmount float64     `json:"all_sum_amount"`
	CurrentPlan  OrderPlan   `json:"current_plan"`
	FirstPayTime int         `json:"first_pay_time"`
	LastPayTime  int         `json:"last_pay_time"`
	SponsorPlans []OrderPlan `json:"sponsor_plans"`
	User         User        `json:"user"`
}

type Timing

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

type TransportWithUA

type TransportWithUA struct {
	Transport http.RoundTripper
	UA        string
}

自定义 Transport 设置统一的 User-Agent

func (*TransportWithUA) RoundTrip

func (t *TransportWithUA) RoundTrip(req *http.Request) (*http.Response, error)

实现 RoundTripper 接口,添加统一 User-Agent

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