使用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)
具体流程请参考文档:获取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)
req := &waybill.LdopWaybillReceiveRequest{OrderID: "your orderid" ......}
cli := jd.GetClient()
res, err := cli.WaybillReceive(req)
cancelreq := &waybill.LdopDeliveryProviderCancelWayBillRequest{WaybillCode: "your waybillCode", CancelReason: "用户取消订单", OperatorName: "your name"}
cli := jd.GetClient()
res, err := cli.CancelWayBill(cancelreq)
Apache License, Version 2.0