jdskd

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

京东青龙系统 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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	AppKey    string
	AppSecret string
	ReturnURL string
	SalePlat  string
	Cache     cache.Cache
}

Config for user

type Jdsdk

type Jdsdk struct {
	Context *context.Context
}

Jdsdk struct

func NewJdsdk

func NewJdsdk(cfg *Config) *Jdsdk

NewJdsdk init

func (*Jdsdk) GetAccessToken

func (wc *Jdsdk) GetAccessToken(bizid string) (string, error)

GetAccessToken 获取access_token

func (*Jdsdk) GetClient

func (wc *Jdsdk) GetClient() *client.Client

GetClient client

func (*Jdsdk) GetOauth

func (wc *Jdsdk) GetOauth() *oauth.Oauth

GetOauth oauth2网页授权

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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