core

package
v0.0.0-...-1ea5772 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2019 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//URLSKUState    = "http://c0.3.cn/stock"
	URLSKUState    = "https://c0.3.cn/stocks"
	URLGoodsDets   = "http://item.jd.com/%s.html"
	URLGoodsPrice  = "http://p.3.cn/prices/mgets"
	URLAdd2Cart    = "https://cart.jd.com/gate.action"
	URLChangeCount = "http://cart.jd.com/changeNum.action"
	URLCartInfo    = "https://cart.jd.com/cart.action"
	URLOrderInfo   = "http://trade.jd.com/shopping/order/getOrderInfo.action"
	URLSubmitOrder = "http://trade.jd.com/shopping/order/submitOrder.action"
)

Variables

View Source
var (
	// URLForQR is the login related URL
	//
	URLForQR = [...]string{
		"https://passport.jd.com/new/login.aspx",
		"https://qr.m.jd.com/show",
		"https://qr.m.jd.com/check",
		"https://passport.jd.com/uc/qrCodeTicketValidation",
		"http://home.jd.com/getUserVerifyRight.action",
	}

	DefaultHeaders = map[string]string{
		"User-Agent":      "Chrome/51.0.2704.103",
		"ContentType":     "application/json",
		"Connection":      "keep-alive",
		"Accept-Encoding": "gzip, deflate",
		"Accept-Language": "zh-CN,zh;q=0.8",
	}
)

Functions

This section is empty.

Types

type CookieJarType

type CookieJarType int8
const (
	JarMemory CookieJarType = iota
	JarJson
	JarGob
)

type JDConfig

type JDConfig struct {
	Period     time.Duration // refresh period
	ShipArea   string        // shipping area
	AutoRush   bool          // continue rush when out of stock
	AutoSubmit bool          // whether submit the order
}

JDConfig ...

type JarOption

type JarOption struct {
	// JarType specify the which way used to save the cookies
	//  JarMemory : just in memory without persist
	//	JarGob: persist by module encoding/gob
	JarType CookieJarType

	// Filename holds the file to use for storage of the cookies.
	// If it is empty, JarMemory will be used.
	Filename string
}

JarOption used to configure how cookies data saved

type JingDong

type JingDong struct {
	JDConfig
	// contains filtered or unexported fields
}

JingDong wrap jing dong operation

func NewJingDong

func NewJingDong(option JDConfig) *JingDong

NewJingDong create an object to wrap JingDong related operation

func (*JingDong) CartDetails

func (jd *JingDong) CartDetails() error

CartDetails get the shopping cart details

func (*JingDong) Login

func (jd *JingDong) Login(args ...interface{}) error

Login used to login JD by QR code. if the cookies file exits, will try cookies first.

func (*JingDong) OrderInfo

func (jd *JingDong) OrderInfo() error

OrderInfo shows the order detail information

func (*JingDong) Release

func (jd *JingDong) Release()

Release the resource opened

func (*JingDong) RushBuy

func (jd *JingDong) RushBuy(skuLst map[string]int)

支持多件商品抢购直接下单

func (*JingDong) SubmitOrder

func (jd *JingDong) SubmitOrder() (string, error)

SubmitOrder ... submit order to JingDong, return orderID or error

type SKUInfo

type SKUInfo struct {
	ID        string
	Price     string
	Count     int    // buying count
	State     string // stock state 33 : on sale, 34 : out of stock
	StateName string // "现货" / "无货"
	Name      string
	Link      string
}

SKUInfo ...

type SimpleJar

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

SimpleJar implement http.CookieJar to handle cookies

func NewSimpleJar

func NewSimpleJar(option JarOption) *SimpleJar

NewSimpleJar return SimpleJar object with sepecified option example:

   jar := NewSimpleJar(JarOption{
		JarType:  JarMemory,
		Filename: "d:\\cookies.jar",
	  })

func (*SimpleJar) Clean

func (jar *SimpleJar) Clean()

Clean cookies if not valid anymore

func (*SimpleJar) Cookies

func (jar *SimpleJar) Cookies(u *url.URL) []*http.Cookie

Cookies returns the cookies to send in a request for the given URL. It is up to the implementation to honor the standard cookie use restrictions such as in RFC 6265.

func (*SimpleJar) Get

func (jar *SimpleJar) Get(name string) string

Get cookie vlue by name

func (*SimpleJar) Load

func (jar *SimpleJar) Load() error

Load used to deserialization cookies data from file

func (*SimpleJar) Persist

func (jar *SimpleJar) Persist() error

Persist used to serialization cookies data into file

func (*SimpleJar) SetCookies

func (jar *SimpleJar) SetCookies(u *url.URL, cookies []*http.Cookie)

SetCookies handles the receipt of the cookies in a reply for the given URL. It may or may not choose to save the cookies, depending on the jar's policy and implementation.

Jump to

Keyboard shortcuts

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