Skip to content

lgs821/jdsdk-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

京东青龙系统 SDK for Go

使用Golang开发的京东青龙系统,目前只有下单接口和取消运单接口

基本配置

memcache := cache.NewMemcache("127.0.0.1:11211")

config := &jdsdk.Config{
		AppKey:       "your appkey",
		AppSecret:    "your appsecret",
		ReturnURL:    "your retrunurl",
		SalePlat:     "0030001",
		Cache:        memcache,
	}
	jd = jdsdk.NewJdsdk(config)

Cache 设置

Cache主要用来保存全局access_token以及js-sdk中的ticket: 默认采用memcache存储,建议采用redis长期存储。

redisopts := &cache.RedisOpts{
		Host:     "your redis host",
		Password: "your redis password",
	}
	RedisCache := cache.NewRedis(redisopts)
	config := &jdsdk.Config{
		AppKey:       "your appkey",
		AppSecret:    "your appsecret",
		ReturnURL:    "your retrunurl",
		SalePlat:     "0030001",
		Cache:        RedisCache,
	}
	jd = jdsdk.NewJdsdk(config)

基本API使用

Oauth2授权

具体流程请参考文档:获取accesstoken

1.发起授权

oauth := jd.GetOauth()
err := oauth.Redirect("跳转的绝对地址", "snsapi_userinfo", "123dd123")
if err != nil {
	fmt.Println(err)
}

如果不希望直接跳转,可通过 oauth.GetRedirectURL 获取跳转的url

2.通过code换取access_token

code := c.Query("code")
resToken, err := oauth.GetUserAccessToken(code)
if err != nil {
	fmt.Println(err)
	return
}

3.刷新access_token

func (oauth *Oauth) RefreshAccessToken(refreshToken string) (result ResAccessToken, err error)

青龙系统

下单接口

下单接口API

req := &waybill.LdopWaybillReceiveRequest{OrderID: "your orderid" ......}

cli := jd.GetClient()
res, err := cli.WaybillReceive(req)

取消运单接口

取消运单API

cancelreq := &waybill.LdopDeliveryProviderCancelWayBillRequest{WaybillCode: "your waybillCode", CancelReason: "用户取消订单", OperatorName: "your name"}

cli := jd.GetClient()
res, err := cli.CancelWayBill(cancelreq)

License

Apache License, Version 2.0

About

京东青龙系统sdk

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages