sfexpress

package module
Version: v0.0.0-...-bfb03bf Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2020 License: MIT Imports: 9 Imported by: 0

README

Go Sf-Express

Welcome to use sf-express-go

Installation

go get -u -v github.com/IsCod/sf-express-go

Quickstart

package main

import (
	"fmt"
	"math/rand"
	sfexpress "sf-express-go"
	"time"
)

func main() {
	c := sfexpress.Config{CheckWord: "FBIqMkZjzxbsZgo7jTpeq7PD8CVzLT4Q", ClientCode: "NTL", Custid: "7553032834"}

	orderId := "SF-" + time.Now().Format("20060102150405") + string(rand.Intn(100))

	//order push
	o, err := c.Order(sfexpress.Order{
		OrderId:     orderId,
		ExpressType: 1,
		PayMethod:   1,
		JCompany:    "顺丰镖局",
		JContact:    "虾哥",
		JTel:        "15012345678",
		JMobile:     "",
		JProvince:   "广东省",
		JCity:       "深圳市",
		JCounty:     "南山区",
		JAddress:    "福田区新洲十一街万基商务大厦26楼",
		DCompany:    "顺丰镖局",
		DContact:    "虾哥",
		DTel:        "15012345678",
		DMobile:     "",
		DProvince:   "广东省",
		DCity:       "深圳市",
		DCounty:     "南山区",
		DAddress:    "福田区新洲十一街万基商务大厦26楼",
		AddedService: sfexpress.AddedService{
			Name:  "COD",
			Value: "1.01",
		},
		Cargo: "iphone x",
	})
	if err != nil {
		fmt.Printf("❌ Push: %s\n", err.Error())
	} else {
		fmt.Printf("✅ Push: orderId: %s, MailNo: %s\n", o.OrderId, o.MailNo)
	}

	//order query
	order, err := c.OrderQuery(sfexpress.OrderSearch{OrderId: o.OrderId, SearchType: 1})
	if err != nil {
		fmt.Printf("❌ query: %s\n", err)
	} else {
		fmt.Printf("✅ query: orderId: %s, MailNo: %s\n", order.OrderId, order.MailNo)
	}

	//order confirm&cancel
	oc, err := c.OrderConfirm(sfexpress.OrderConfirm{OrderId: o.OrderId, DealType: "2"})
	if err != nil {
		fmt.Printf("❌ Confirm: %s\n", err)
	} else {
		fmt.Printf("✅ Confirm:  orderId: %s, ResStatus: %d\n", oc.OrderId, oc.ResStatus)
	}

	//route Query By OrderNo
	oro, err := c.OrderRouteService(sfexpress.RouteRequest{TrackingType: 1, TrackingNumber: o.MailNo})
	if err != nil {
		fmt.Printf("❌ RouteQueryByOrderNo: %s", err)
	} else {
		for _, i := range oro {
			fmt.Printf("✅ RouteQueryByOrderNo:  orderId: %s, MailNo: %s, %v", i.OrderId, i.MailNo, i.Route)
		}
	}
}

Development

TODO:

Contributing

License

The sf-express-go is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the SfExpress project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Documentation

Index

Constants

View Source
const (
	HeadSuccess                         Head    = "OK"   //交易成功
	HeadERR                             Head    = "ERR"  //系统或业务异常,交易失败
	ErrCodeAddrRequired                 ErrCode = "010"  //寄件地址不能为空
	ErrCodeContractNameRequired         ErrCode = "1011" //寄件联系人不能为空
	ErrCodeTelPhoneRequired             ErrCode = "1012" //寄件电话不能为空
	ErrCodeReceiverAddrRequired         ErrCode = "1014" //到件地址不能为空
	ErrCodeReceiverContractNameRequired ErrCode = "1015" //到件联系人不能为空
	ErrCodeReceiverTelPhoneRequired     ErrCode = "1016" //到件联系人不能为空
	ErrCodeCargoRequired                ErrCode = "1017" //到件联系人不能为空
)

Variables

View Source
var (
	OrderService        ServiceName = "OrderService"        //下单接口
	OrderSearchService  ServiceName = "OrderSearchService"  //订单查询
	OrderConfirmService ServiceName = "OrderConfirmService" //订单确认和取消
	OrderFilterService  ServiceName = "OrderFilterService"  //订单筛选接口
	OrderRouteService   ServiceName = "RouteService"        //订单筛选接口
	RequestServiceLang              = "zh-CN"
	RequestServiceHead              = "SLKJ2019"
	ServiceURL                      = "http://bsp-oisp.sf-express.com/bsp-oisp/sfexpressService"
	ServiceURLHttps                 = "https://bsp-oisp.sf-express.com/bsp-oisp/sfexpressService"
)
View Source
var ExpressType = map[int]ExpressTypeCode{
	1:  {Id: 1, Code: "T4"},
	2:  {Id: 2, Code: "T6"},
	5:  {Id: 5, Code: "T8"},
	6:  {Id: 6, Code: "T1"},
	9:  {Id: 9, Code: "T13"},
	10: {Id: 10, Code: "T14"},
	12: {Id: 12, Code: "T4"},
	13: {Id: 13, Code: "T6"},
}

Functions

This section is empty.

Types

type AddedService

type AddedService struct {
	Name   string `xml:"name,attr"`
	Value  string `xml:"value,attr"`
	Value1 string `xml:"value1,attr"`
	Value2 string `xml:"value2,attr"`
	Value3 string `xml:"value3,attr"`
	Value4 string `xml:"value4,attr"`
	Value5 string `xml:"value5,attr"`
}

type Body

type Body interface {
	GetServiceName() ServiceName
}

type Config

type Config struct {
	ClientCode string `NTL`
	CheckWord  string `P9CUF8XuqBUH2ZaFpwjyqTusx12zr4uM`
	Custid     string
	Lang       string `zh-CN`
}

func (*Config) Order

func (c *Config) Order(order Order) (*OrderResponse, error)

Order 下订单接口

func (*Config) OrderConfirm

func (c *Config) OrderConfirm(orderConfirm OrderConfirm) (*OrderConfirmResponse, error)

OrderConfirm 订单确认/取消接口 客户在确定将货物交付给顺丰托运后,将面单上的一些重要信息,如快件重量通过此接口发送给顺丰。 客户在发货前取消订单 订单取消之后,订单号也是不能重复利用的。

func (*Config) OrderFilterService

func (c *Config) OrderFilterService(orderFilter OrderFilter) (*OrderFilterResponse, error)

OrderFilterService 客户系统通过此接口向顺丰系统发送主动的筛单请求,用于判断客户的收、派地址是否属于顺丰的收派范围。

func (*Config) OrderQuery

func (c *Config) OrderQuery(orderSearch OrderSearch) (*OrderResponse, error)

OrderQuery 订单查询 因Internet环境下,网络不是绝对可靠,用户系统下订单到顺丰后,不一定可以收到顺丰系统返回的数据,此接口用于在未收到返回数据时,查询下订单(含筛选)接口客户订单当前的处理情况。

func (*Config) OrderRouteService

func (c *Config) OrderRouteService(routeRequest RouteRequest) ([]RouteResponse, error)

OrderRouteService 路由查询接口 客户可通过此接口查询顺丰运单路由,系统将返回当前时间点已发生的路由信息。 路由查询接口支持三种查询方式: 根据通过丰桥接口下单的订单号查询,系统校验信息匹配将返回对应运单路由信息。 根据运单号+月结卡号(需与传入的顾客编码绑定)查询,系统校验信息归属关系正确将返回对应运单路由信息。 根据运单号+运单对应的收寄人任一方电话号码后4位(参数check_phoneNo中传入)查询,系统校验信息匹配将返回对应运单路由信息。

type Err

type Err struct {
	ErrCode ErrCode `xml:"code,attr"`
	ErrMsg  ErrMsg  `xml:",chardata"`
}

func (Err) Error

func (e Err) Error() string

type ErrCode

type ErrCode string

type ErrMsg

type ErrMsg string

type ExpressTypeCode

type ExpressTypeCode struct {
	Id   int
	Code string
}
type Head string

func (Head) IsSuccess

func (c Head) IsSuccess() bool

type Order

type Order struct {
	OrderId        string       `xml:"orderid,attr"` //必填
	ExpressType    int          `xml:"express_type,attr"`
	JCompany       string       `xml:"j_company,attr"`
	JContact       string       `xml:"j_contact,attr"`
	JTel           string       `xml:"j_tel,attr"`
	JMobile        string       `xml:"j_mobile,attr"`
	JProvince      string       `xml:"j_province,attr"`
	JCity          string       `xml:"j_city,attr"`
	JCounty        string       `xml:"j_county,attr"`
	JAddress       string       `xml:"j_address,attr"`
	DCompany       string       `xml:"d_company,attr"`
	DContact       string       `xml:"d_contact,attr"`
	DTel           string       `xml:"d_tel,attr"`
	DMobile        string       `xml:"d_mobile,attr"`
	DProvince      string       `xml:"d_province,attr"`
	DCity          string       `xml:"d_city,attr"`
	DCounty        string       `xml:"d_county,attr"`
	DAddress       string       `xml:"d_address,attr"`
	ParcelQuantity string       `xml:"parcel_quantity,attr"`
	PayMethod      int          `xml:"pay_method,attr"`
	CustId         string       `xml:"custid,attr"`
	CustomsBatchs  string       `xml:"customs_batchs,attr"`
	Cargo          string       `xml:"cargo,attr"`
	AddedService   AddedService `xml:"AddedService"`
}

type OrderConfirm

type OrderConfirm struct {
	OrderId        string `xml:"orderid,attr"`          //客户订单号
	MailNo         string `xml:"mailno,attr"`           //顺丰母运单号如果dealtype=1,必填
	DealType       string `xml:"dealtype,attr"`         //可选,客户订单操作标识: 1:确认 2:取消
	CustomsBatchs  string `xml:"customs_batchs,attr"`   //可选,报关批次
	AgentNo        string `xml:"agent_no,attr"`         //可选,代理单号
	ConsignEmpCode string `xml:"consign_emp_code,attr"` //可选,收派员工号
}

type OrderConfirmRequestBody

type OrderConfirmRequestBody struct {
	OrderConfirm OrderConfirm `xml:"OrderConfirm"`
}

func (OrderConfirmRequestBody) GetServiceName

func (o OrderConfirmRequestBody) GetServiceName() ServiceName

type OrderConfirmResponse

type OrderConfirmResponse struct {
	OrderId   string `xml:"orderid,attr"`
	ResStatus int    `xml:"res_status,attr"`
}

type OrderConfirmResponseBody

type OrderConfirmResponseBody struct {
	Response OrderResponse `xml:"OrderResponse"`
}

type OrderFilter

type OrderFilter struct {
	FilterType int    `xml:"filter_type,attr"` //可选筛单类别: 1:自动筛单(系统根据地址库进行判断,并返回结果,系统无法检索到可派送的将返回不可派送) 2:可人工筛单(系统首先根据地址库判断,如果无法自动判断是否收派,系统将生成需要人工判断的任务,后续由人工处理,处理结束后,顺丰可主动推送给客户系统)
	OrderId    string `xml:"orderid,attr"`     //客户订单号,filter_type=2则必须提供
	Daddress   string `xml:"d_address,attr"`   //到件方详细地址,需要包括省市区,如:广东省深圳市福田区新洲十一街万基商务大厦。
}

type OrderFilterRequestBody

type OrderFilterRequestBody struct {
	OrderFilter OrderFilter `xml:"OrderFilter"`
}

func (OrderFilterRequestBody) GetServiceName

func (o OrderFilterRequestBody) GetServiceName() ServiceName

type OrderFilterResponse

type OrderFilterResponse struct {
	OrderId      string `xml:"orderid,attr"`
	FilterResult string `xml:"filter_result,attr"`
	OriginCode   string `xml:"origincode,attr"`
	Remark       string `xml:"remark,attr"`
}

type OrderFilterResponseBody

type OrderFilterResponseBody struct {
	Response OrderFilterResponse `xml:"OrderResponse"`
}

type OrderRequestBody

type OrderRequestBody struct {
	Order Order `xml:"Order"`
}

func (OrderRequestBody) GetServiceName

func (o OrderRequestBody) GetServiceName() ServiceName

type OrderResponse

type OrderResponse struct {
	OrderId      string `xml:"orderid,attr"`
	MailNo       string `xml:"mailno,attr"`
	OriginCode   string `xml:"origincode,attr"`
	DestCode     string `xml:"destcode,attr"`
	FilterResult string `xml:"filter_result,attr"`
	Remark       string `xml:"remark,attr"`
	ResStatus    string `xml:"res_status,attr"`
}

type OrderResponseBody

type OrderResponseBody struct {
	Response OrderResponse `xml:"OrderResponse"`
}

type OrderSearch

type OrderSearch struct {
	OrderId    string `xml:"orderid,attr"`
	SearchType int    `xml:"search_type,attr"` //可选 1,正向单查询,传入的orderid为正向定单号,2,退货单查询,传入的orderid 为退货原始订单号
}

type OrderSearchRequestBody

type OrderSearchRequestBody struct {
	OrderSearch OrderSearch `xml:"OrderSearch"`
}

func (OrderSearchRequestBody) GetServiceName

func (o OrderSearchRequestBody) GetServiceName() ServiceName

type OrderSearchResponseBody

type OrderSearchResponseBody struct {
	Response OrderResponse `xml:"OrderResponse"`
}

type RequestXml

type RequestXml struct {
	XMLName xml.Name    `xml:"Request"`
	Service ServiceName `xml:"service,attr"`
	Lang    string      `xml:"lang,attr"`
	Head    string      `xml:"Head"`
	Body    Body        `xml:"Body"`
}

type ResponseBody

type ResponseBody struct {
	OrderResponse        OrderResponse        `xml:"OrderResponse"`
	OrderConfirmResponse OrderConfirmResponse `xml:"OrderConfirmResponse"`
	RouteResponse        []RouteResponse      `xml:"RouteResponse"`
	OrderFilterResponse  OrderFilterResponse  `xml:"OrderFilterResponse"`
}

type ResponseXml

type ResponseXml struct {
	XMLName xml.Name     `xml:"Response"`
	Head    Head         `xml:"Head"`
	Err     Err          `xml:"ERROR"`
	Body    ResponseBody `xml:"Body"`
}

type Route

type Route struct {
	Remark        string `xml:"remark,attr"`
	AcceptTime    string `xml:"accept_time,attr"`
	AcceptAddress string `xml:"accept_address,attr"`
	Opcode        string `xml:"opcode,attr"`
}

type RouteRequest

type RouteRequest struct {
	TrackingType   int    `xml:"tracking_type,attr"`   //可选,查询号类别: 1:根据顺丰运单号查询,order节点中tracking_number将被当作顺丰运单号处理 2:根据客户订单号查询,order节点中tracking_number将被当作客户订单号处理 3:逆向单,根据客户原始订单号查询,order节点中tracking_number将被当作逆向单原始订单号处理
	TrackingNumber string `xml:"tracking_number,attr"` //查询号: 如果tracking_type=1,则此值为顺丰运单号 如果tracking_type=2,则此值为客户订单号 如果tracking_type=3,则此值为逆向单原始订单号 如果有多个单号,以逗号分隔,如"123,124,125"。
	MethodType     string `xml:"method_type,attr"`     //可选,路由查询类别: 1:标准路由查询
	CheckPhoneNo   string `xml:"check_phoneNo,attr"`   //可选,校验电话号码后四位值; 按运单号查询路由时,可通过该参数传入用于校验的电话号码后4位(寄方或收方都可以),如果涉及多个运单号,对应该值也需按顺序传入多个,并以英文逗号隔开。
}

type RouteRequestBody

type RouteRequestBody struct {
	RouteRequest RouteRequest `xml:"RouteRequest"`
}

func (RouteRequestBody) GetServiceName

func (r RouteRequestBody) GetServiceName() ServiceName

type RouteResponse

type RouteResponse struct {
	MailNo  string  `xml:"mailno,attr"`
	OrderId string  `xml:"orderid,attr"`
	Route   []Route `xml:"Route"`
}

type RouteResponseBody

type RouteResponseBody struct {
	Response []RouteResponse `xml:"OrderResponse"`
}

type ServiceName

type ServiceName string

type UserInfo

type UserInfo struct {
	Company  string `xml:"d_company,attr"`
	Contact  string `xml:"d_contact,attr"`
	Tel      string `xml:"d_tel,attr"`
	Mobile   string `xml:"d_mobile,attr"`
	Province string `xml:"d_province,attr"`
	City     string `xml:"d_city,attr"`
	County   string `xml:"d_county,attr"`
	Address  string `xml:"d_address,attr"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL