Documentation
¶
Index ¶
- Constants
- Variables
- func GetCourierCode(alias string) string
- type AutoNumberResponse
- type CourierInfo
- type DeliveryTimeData
- type DeliveryTimeParam
- type DeliveryTimeResponse
- type Kuaidi100Config
- type Kuaidi100Tracker
- func (t *Kuaidi100Tracker) AutoNumber(trackingNumber string) ([]AutoNumberResponse, error)
- func (t *Kuaidi100Tracker) EstimateDeliveryTime(param DeliveryTimeParam) (*DeliveryTimeResponse, error)
- func (t *Kuaidi100Tracker) SetSecret(secret string)
- func (t *Kuaidi100Tracker) Track(courierCode, trackingNumber string) (*TrackingResponse, error)
- func (t *Kuaidi100Tracker) TrackWithPhone(courierCode, trackingNumber, phone string) (*TrackingResponse, error)
- type QueryParam
- type TrackingData
- type TrackingResponse
Constants ¶
const ( Kuaidi100APIURL = "https://poll.kuaidi100.com/poll/query.do" Kuaidi100AutoNumberURL = "http://www.kuaidi100.com/autonumber/auto" Kuaidi100DeliveryTimeURL = "https://api.kuaidi100.com/label/order?method=time" )
Variables ¶
var CourierCodes = map[string]CourierInfo{
"sf": {Code: "shunfeng", Name: "顺丰速运"},
"shunfeng": {Code: "shunfeng", Name: "顺丰速运"},
"顺丰": {Code: "shunfeng", Name: "顺丰速运"},
"yt": {Code: "yuantong", Name: "圆通速递"},
"yuantong": {Code: "yuantong", Name: "圆通速递"},
"圆通": {Code: "yuantong", Name: "圆通速递"},
"sto": {Code: "shentong", Name: "申通快递"},
"shentong": {Code: "shentong", Name: "申通快递"},
"申通": {Code: "shentong", Name: "申通快递"},
"zto": {Code: "zhongtong", Name: "中通快递"},
"zhongtong": {Code: "zhongtong", Name: "中通快递"},
"中通": {Code: "zhongtong", Name: "中通快递"},
"yd": {Code: "yunda", Name: "韵达快递"},
"yunda": {Code: "yunda", Name: "韵达快递"},
"韵达": {Code: "yunda", Name: "韵达快递"},
"jt": {Code: "jtexpress", Name: "极兔速递"},
"jitu": {Code: "jtexpress", Name: "极兔速递"},
"jtexpress": {Code: "jtexpress", Name: "极兔速递"},
"极兔": {Code: "jtexpress", Name: "极兔速递"},
"jd": {Code: "jd", Name: "京东物流"},
"京东": {Code: "jd", Name: "京东物流"},
"ems": {Code: "ems", Name: "EMS"},
"yzgn": {Code: "youzhengguonei", Name: "邮政国内"},
"youzheng": {Code: "youzhengguonei", Name: "邮政国内"},
"邮政": {Code: "youzhengguonei", Name: "邮政国内"},
"dbwl": {Code: "debangwuliu", Name: "德邦物流"},
"debang": {Code: "debangwuliu", Name: "德邦物流"},
"debangwuliu": {Code: "debangwuliu", Name: "德邦物流"},
"德邦": {Code: "debangwuliu", Name: "德邦物流"},
"anneng": {Code: "annengwuliu", Name: "安能物流"},
"annengwuliu": {Code: "annengwuliu", Name: "安能物流"},
"安能": {Code: "annengwuliu", Name: "安能物流"},
"best": {Code: "huitongkuaidi", Name: "百世快递"},
"huitong": {Code: "huitongkuaidi", Name: "百世快递"},
"huitongkuaidi": {Code: "huitongkuaidi", Name: "百世快递"},
"百世": {Code: "huitongkuaidi", Name: "百世快递"},
"kuayue": {Code: "kuayue", Name: "跨越速运"},
"跨越": {Code: "kuayue", Name: "跨越速运"},
"ups": {Code: "ups", Name: "UPS"},
"fedex": {Code: "fedex", Name: "FedEx"},
"dhl": {Code: "dhl", Name: "DHL"},
"tnt": {Code: "tnt", Name: "TNT"},
"usps": {Code: "usps", Name: "USPS"},
"cainiao": {Code: "cainiao", Name: "菜鸟"},
"菜鸟": {Code: "cainiao", Name: "菜鸟"},
}
CourierCodes maps aliases/codes to kuaidi100 courier info Source: https://github.com/simman/Kuaidi100 and https://www.kuaidi100.com/all/
Functions ¶
func GetCourierCode ¶
GetCourierCode returns the kuaidi100 courier code for an alias
Types ¶
type AutoNumberResponse ¶
type AutoNumberResponse struct {
ComCode string `json:"comCode"` // Courier company code
NoCount int `json:"noCount"` // Match count
NoPre string `json:"noPre"` // Number prefix
StartTime string `json:"startTime"` // Start time
}
AutoNumberResponse represents the auto number detection API response
type CourierInfo ¶
CourierInfo contains courier code and name
func GetCourierInfo ¶
func GetCourierInfo(alias string) *CourierInfo
GetCourierInfo returns the courier info for an alias, or nil if not found
func ListCouriers ¶
func ListCouriers() []CourierInfo
ListCouriers returns a list of common courier codes for display
type DeliveryTimeData ¶
type DeliveryTimeData struct {
ArriveTime string `json:"arriveTime"` // Estimated arrival time
SortingName string `json:"sortingName"` // Sorting center name
PickupTime string `json:"pickupTime"` // Estimated pickup time
Hour string `json:"hour"` // Estimated hours
Day string `json:"day"` // Estimated days
ExpectTime string `json:"expectTime"` // Expected delivery time range
SecondDayArrive bool `json:"secondDayArrive"` // Whether arrives next day
}
DeliveryTimeData contains the estimated delivery time info
type DeliveryTimeParam ¶
type DeliveryTimeParam struct {
Kuaidicom string `json:"kuaidicom"` // Courier company code
From string `json:"from"` // Origin address (must include 3+ levels, e.g., 广东深圳市南山区)
To string `json:"to"` // Destination address (must include 3+ levels)
OrderTime string `json:"orderTime"` // Order time, format: yyyy-MM-dd HH:mm:ss
ExpType string `json:"expType,omitempty"` // Product type (e.g., 特惠送, 标快)
}
DeliveryTimeParam represents the parameters for delivery time estimation
type DeliveryTimeResponse ¶
type DeliveryTimeResponse struct {
Result bool `json:"result"` // Whether successful
ReturnCode string `json:"returnCode"` // Return code
Message string `json:"message"` // Error message if any
Data *DeliveryTimeData `json:"data,omitempty"`
}
DeliveryTimeResponse represents the delivery time estimation API response
type Kuaidi100Config ¶
type Kuaidi100Config struct {
Key string // Authorization key (授权key)
Customer string // Customer ID (查询公司编号)
Secret string // Secret for delivery time API (授权secret)
}
Kuaidi100Config holds the API credentials
type Kuaidi100Tracker ¶
type Kuaidi100Tracker struct {
// contains filtered or unexported fields
}
Kuaidi100Tracker implements package tracking via kuaidi100.com API
func NewKuaidi100Tracker ¶
func NewKuaidi100Tracker(key, customer string) *Kuaidi100Tracker
NewKuaidi100Tracker creates a new tracker instance
func NewKuaidi100TrackerWithSecret ¶
func NewKuaidi100TrackerWithSecret(key, customer, secret string) *Kuaidi100Tracker
NewKuaidi100TrackerWithSecret creates a new tracker instance with secret for delivery time API
func (*Kuaidi100Tracker) AutoNumber ¶
func (t *Kuaidi100Tracker) AutoNumber(trackingNumber string) ([]AutoNumberResponse, error)
AutoNumber detects the courier company from a tracking number Returns a list of possible courier codes
func (*Kuaidi100Tracker) EstimateDeliveryTime ¶
func (t *Kuaidi100Tracker) EstimateDeliveryTime(param DeliveryTimeParam) (*DeliveryTimeResponse, error)
EstimateDeliveryTime estimates the delivery time for a shipment Requires secret to be configured
func (*Kuaidi100Tracker) SetSecret ¶
func (t *Kuaidi100Tracker) SetSecret(secret string)
SetSecret sets the secret for delivery time API
func (*Kuaidi100Tracker) Track ¶
func (t *Kuaidi100Tracker) Track(courierCode, trackingNumber string) (*TrackingResponse, error)
Track queries the tracking info for a package
func (*Kuaidi100Tracker) TrackWithPhone ¶
func (t *Kuaidi100Tracker) TrackWithPhone(courierCode, trackingNumber, phone string) (*TrackingResponse, error)
TrackWithPhone queries tracking info with phone number (required for some couriers like SF Express)
type QueryParam ¶
type QueryParam struct {
Com string `json:"com"` // Courier company code (e.g., "yuantong", "shunfeng")
Num string `json:"num"` // Tracking number
Phone string `json:"phone,omitempty"` // Phone number (required for some couriers like SF)
From string `json:"from,omitempty"` // Origin city
To string `json:"to,omitempty"` // Destination city
Resultv2 string `json:"resultv2"` // Enable district parsing (1=enabled)
Show string `json:"show"` // Response format: 0=json, 1=xml, 2=html, 3=text
Order string `json:"order"` // Sort order: desc (newest first), asc (oldest first)
}
QueryParam represents the query parameters for kuaidi100 API
type TrackingData ¶
type TrackingData struct {
Context string `json:"context"` // Event description
Time string `json:"time"` // Event time (formatted)
Ftime string `json:"ftime"` // Event time (formatted, alternative)
Status string `json:"status"` // Status at this point
AreaCode string `json:"areaCode"` // Area code
AreaName string `json:"areaName"` // Area name
AreaCenter string `json:"areaCenter"` // Area center coordinates
Location string `json:"location"` // Location description
}
TrackingData represents a single tracking event
type TrackingResponse ¶
type TrackingResponse struct {
Message string `json:"message"` // Error message if any
State string `json:"state"` // Tracking state code
Status string `json:"status"` // Status code (200=success)
Condition string `json:"condition"` // Current condition
IsCheck string `json:"ischeck"` // Whether delivered (1=yes)
Com string `json:"com"` // Courier company code
Nu string `json:"nu"` // Tracking number
Data []TrackingData `json:"data"` // Tracking events
}
TrackingResponse represents the API response
func (*TrackingResponse) IsDelivered ¶
func (r *TrackingResponse) IsDelivered() bool
IsDelivered returns true if package has been delivered
func (*TrackingResponse) StateDescription ¶
func (r *TrackingResponse) StateDescription() string
StateDescription returns human-readable state description