open_taobao

package module
v0.0.0-...-a55b7e0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2019 License: MIT Imports: 15 Imported by: 2

README

open_taobao

淘宝开放平台的 go 语言 SDK, MIT许可。 自带web小工具: 可测试基本流程, 可根据 ApiMetadata.xml 重新生成SDK源码并编译, 保持与淘宝同步 只保留了自己生成的电子码商相关接口,其他请参考源项目 https://github.com/yaofangou/open_taobao

版本说明

  • 主包: 0.0.1
  • 子包: 根据淘宝 20131207 的 ApiMetadata.xml 生成
  • 工具程序: 0.0.1

运行环境

  • 操作系统: 由于使用Go原始功能,没有使用cgo,理论上go支持的操作系统都支持,当前只测试了win7
  • 测试环境 win7 go1.2

安装说明

安装主包

  • go get github.com/yaofangou/open_taobao

安装子包

  • go get github.com/yaofangou/open_taobao/api/user

更多子包

  • 用户API: github.com/yaofangou/open_taobao/api/user
  • 类目API: github.com/yaofangou/open_taobao/api/item
  • 商品API: github.com/yaofangou/open_taobao/api/product
  • 交易API: github.com/yaofangou/open_taobao/api/trade
  • 评价API: github.com/yaofangou/open_taobao/api/pinjia
  • 物流API: github.com/yaofangou/open_taobao/api/delivery
  • 店铺API: github.com/yaofangou/open_taobao/api/shop
  • 分销API: github.com/yaofangou/open_taobao/api/fenxiao
  • 旺旺API: github.com/yaofangou/open_taobao/api/wangwang
  • 淘客API: github.com/yaofangou/open_taobao/api/taobaoke
  • 主动通知业务API: github.com/yaofangou/open_taobao/api/notice
  • 工具类API: github.com/yaofangou/open_taobao/api/tools
  • 物流宝API: github.com/yaofangou/open_taobao/api/wlb
  • 直通车API: github.com/yaofangou/open_taobao/api/simba
  • 收藏夹API: github.com/yaofangou/open_taobao/api/favorite
  • 机票API: github.com/yaofangou/open_taobao/api/jipiao
  • 营销API: github.com/yaofangou/open_taobao/api/marketing
  • 数据API: github.com/yaofangou/open_taobao/api/udp
  • 酒店API: github.com/yaofangou/open_taobao/api/hotel
  • 店铺会员管理API: github.com/yaofangou/open_taobao/api/crm
  • 多媒体平台API: github.com/yaofangou/open_taobao/api/dmt
  • 子账号管理API: github.com/yaofangou/open_taobao/api/subuser
  • 服务平台API: github.com/yaofangou/open_taobao/api/fuwu
  • 退款API: github.com/yaofangou/open_taobao/api/refund
  • 关联推荐API: github.com/yaofangou/open_taobao/api/recommend
  • 组件API: github.com/yaofangou/open_taobao/api/widget
  • 支付宝API: github.com/yaofangou/open_taobao/api/alipy
  • 天猫精品库API: github.com/yaofangou/open_taobao/api/jp
  • 聚石塔API: github.com/yaofangou/open_taobao/api/rds
  • 旅行度假API: github.com/yaofangou/open_taobao/api/trvael
  • 彩票API: github.com/yaofangou/open_taobao/api/caipiao
  • 账务API: github.com/yaofangou/open_taobao/api/bill
  • 天猫退款退货API: github.com/yaofangou/open_taobao/api/eai

测试说明

运行如下命令, 执行web小工具

  • cd tools
  • go build .
  • tools

启动后,默认通过80端口访问, 提供如下功能:

  • 参数修改保存
  • 授权登陆测试
  • 用户信息获取测试
  • 根据淘宝最新 ApiMetadata.xml 重新生成SDK源码并编译, 保证代码最新
  • ApiMetadata.xml 在 tools/conf 目录下,可从 淘宝这里 下载最新配置

界面图片

auth test make

代码样例

  • 获取授权url(供用户访问、授权)
url, err := open_taobao.GetUrlForAuth(AppKey, RedirectUri, "")
// 可参考 tools/CtrlAuth.go 的 do 方法
  • 获取用户授权后的处理(接收淘宝回调信息)
var req open_taobao.TokenGetRequest
req.SetAppKey(AppKey)
req.SetAppSecret(AppSecret)
req.SetRedirectUri(RedirectUri)
req.SetCode(code)
req.SetState("")
resp, _, err := req.GetResponse()
// 成功后 resp.AccessToken 就是访问令牌,可以用来调用功能API了
// 可参考 tools/CtrlAuth.go 的 callback 方法
  • 调用功能API
var req user.UserBuyerGetRequest
req.SetFields("user_id, nick")
resp, data, err := req.GetResponse(AccessToken)
// 成功后 resp 是结果对象, data 是返回的原始json串
// 可参考 tools/CtrlTest.go 的 userBuyerGet 或 userSellerGet 方法
  • 使用TOP授权方式调用功能API 需要对taobao进行配置初始化,设置appKey和secret,增加以下代码:
func init() {
	open_taobao.Init("taobao.appkey", "taobao.secret", true)
	// 如果没有使用代理可以不设置request url
	open_taobao.SetRequestUrl("http://api.XXXXXX.com:30005/")
}

技术说明

  • 调用方式: 支持 https 免签调用方式和TOP调用方式

  • 业务字段: 为了调用方便, 都生成相关字段或方法, 而不是 map 或 json 对象, 缺点是代码多, 包大

  • 子包分拆: 由于生成完整的Go包, 有20多M, 太大了,因此按淘宝官方的分类分拆成子包

    • API分类淘宝没有给出配置文件, 是根据淘宝API列表, 手工维护的配置表, 原理根据 api 前缀分类
    • 配置文件是 tools/conf/package.json, 若分类有问题,可修改该配置文件, 然后重新生成SDK
  • 调用参数: 所有调用参数,只支持字符串类型

  • 返回结果: 做了 string bool int float struct 的判断转型, 调用方便

  • 淘宝错误: 对淘宝返回错误做了包装, 都会通过 error 对象返回

  • 对象命名: 尽量参照淘宝官方其他SDK的命名方式, 例如:

    • 获取卖家信息的淘宝API是 taobao.user.seller.get
    • open_taobao 中对应 user 子包的 UserSellerGetRequest 对象的 GetResponse 方法
  • 前端框架: bootstrap jquery

  • **后端框架:**直接使用 go 自带功能

可以完善

  • 加密配置文件
  • 演示环境支持
  • 通用调用接口
  • 更多授权信息分辨
  • 直接下载配置文件
  • 编译进度
  • 分类包的自动检测
  • 更多测试

(^_^)

LICENSE

open_taobao is licensed under the MIT

Documentation

Overview

淘宝开放平台的 go 语言 SDK, MIT许可。 自带web小工具: 可测试基本流程, 可根据 ApiMetadata.xml 重新生成SDK源码并编译, 保持与淘宝同步

Index

Constants

View Source
const VersionNo = "0.0.1"

Variables

View Source
var (
	InsecureSkipVerify = true  // 相信淘宝服务器,跳过对其检查,减少客户端配置问题
	DisableCompression = false // 默认压缩数据

)

Functions

func GetUrlForAuth

func GetUrlForAuth(appKey, redirectUri, state string) (*url.URL, error)

func Init

func Init(key string, secret string, isTop bool)

func SetRequestUrl

func SetRequestUrl(requestUrl string)

Types

type ErrResponse

type ErrResponse struct {
	Code      int    `json:"code"`
	Msg       string `json:"msg"`
	SubCode   string `json:"sub_code"`
	SubMsg    string `json:sub_msg`
	RequestId string `json:request_id`
}

type TaobaoConfig

type TaobaoConfig struct {
	// contains filtered or unexported fields
}

type TaobaoMethodRequest

type TaobaoMethodRequest struct {
	TaobaoRequest
}

func (*TaobaoMethodRequest) GetResponse

func (t *TaobaoMethodRequest) GetResponse(accessToken, apiMethodName string, resp interface{}) ([]byte, error)

type TaobaoRequest

type TaobaoRequest struct {
	// contains filtered or unexported fields
}

func (*TaobaoRequest) GetReqUrl

func (t *TaobaoRequest) GetReqUrl() string

func (*TaobaoRequest) GetValue

func (t *TaobaoRequest) GetValue(key string) string

func (*TaobaoRequest) GetValues

func (t *TaobaoRequest) GetValues() url.Values

func (*TaobaoRequest) SetReqUrl

func (t *TaobaoRequest) SetReqUrl(resUrl string)

func (*TaobaoRequest) SetValue

func (t *TaobaoRequest) SetValue(key, value string)

type TaobaoRequestI

type TaobaoRequestI interface {
	GetValues() url.Values
	GetReqUrl() string
}

type TaobaoTopErrResponse

type TaobaoTopErrResponse struct {
	Error            string       `json:"error"`
	ErrorDescription string       `json:"error_description"`
	ErrResponse      *ErrResponse `json:"error_response"`
}

func (*TaobaoTopErrResponse) GetErr

func (t *TaobaoTopErrResponse) GetErr() string

type TokenGetRequest

type TokenGetRequest struct {
	TaobaoRequest
}

func (*TokenGetRequest) GetResponse

func (t *TokenGetRequest) GetResponse() (*TokenGetResponse, []byte, error)

func (*TokenGetRequest) SetAppKey

func (t *TokenGetRequest) SetAppKey(val string)

func (*TokenGetRequest) SetAppSecret

func (t *TokenGetRequest) SetAppSecret(val string)

func (*TokenGetRequest) SetCode

func (t *TokenGetRequest) SetCode(val string)

func (*TokenGetRequest) SetRedirectUri

func (t *TokenGetRequest) SetRedirectUri(val string)

func (*TokenGetRequest) SetState

func (t *TokenGetRequest) SetState(val string)

type TokenGetResponse

type TokenGetResponse struct {
	AccessToken       string `json:"access_token"`
	TokenType         string `json:"token_type"`
	ExpiresIn         int    `json:"expires_in"`
	RefreshToken      string `json:"refresh_token"`
	ReExpiresIn       int    `json:"re_expires_in"`
	R1ExpiresIn       int    `json:"r1_expires_in"`
	R2ExpiresIn       int    `json:"r2_expires_in"`
	W1ExpiresIn       int    `json:"w1_expires_in"`
	W2ExpiresIn       int    `json:"w2_expires_in"`
	TaobaoUserNick    string `json:"taobao_user_nick"`
	TaobaoUserId      string `json:"taobao_user_id"`
	SubTaobaoUserId   string `json:"sub_taobao_user_id"`
	SubTaobaoUserNick string `json:"sub_taobao_user_nick"`
}

type TokenRefreshRequest

type TokenRefreshRequest struct {
	TaobaoRequest
}

func (*TokenRefreshRequest) GetResponse

func (t *TokenRefreshRequest) GetResponse() (*TokenGetResponse, []byte, error)

func (*TokenRefreshRequest) SetRefreshToken

func (t *TokenRefreshRequest) SetRefreshToken(val string)

Directories

Path Synopsis
api
eticket
电子码商相关功能 auto sdk from taobao ApiMetadata.xml version 20170816 auther: dz7changkong@qq.com
电子码商相关功能 auto sdk from taobao ApiMetadata.xml version 20170816 auther: dz7changkong@qq.com
user
提供了用户基本信息查询功能 auto sdk from taobao ApiMetadata.xml version 20131207 auther: dz7changkong@qq.com
提供了用户基本信息查询功能 auto sdk from taobao ApiMetadata.xml version 20131207 auther: dz7changkong@qq.com
web 小工具, 测试淘宝GoSdk基本流程, 能根据淘宝 ApiMetadata.xml 重新生成SDK源码并编译
web 小工具, 测试淘宝GoSdk基本流程, 能根据淘宝 ApiMetadata.xml 重新生成SDK源码并编译

Jump to

Keyboard shortcuts

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