README
open_taobao
淘宝开放平台的 go 语言 SDK, MIT许可。 自带web小工具: 可测试基本流程, 可根据 ApiMetadata.xml 重新生成SDK源码并编译, 保持与淘宝同步
版本说明
- 主包: 0.0.1
- 子包: 根据淘宝 20130808 的 ApiMetadata.xml 生成
- 工具程序: 0.0.1
运行环境
- 操作系统: 由于使用Go原始功能,没有使用cgo,理论上go支持的操作系统都支持,当前只测试了win7
- 测试环境 win7 go1.1.1
安装说明
安装主包
- go get github.com/changkong/open_taobao
安装子包
- go get github.com/changkong/open_taobao/api/user
更多子包
- 用户API: github.com/changkong/open_taobao/api/user
- 类目API: github.com/changkong/open_taobao/api/item
- 商品API: github.com/changkong/open_taobao/api/product
- 交易API: github.com/changkong/open_taobao/api/trade
- 评价API: github.com/changkong/open_taobao/api/pinjia
- 物流API: github.com/changkong/open_taobao/api/delivery
- 店铺API: github.com/changkong/open_taobao/api/shop
- 分销API: github.com/changkong/open_taobao/api/fenxiao
- 旺旺API: github.com/changkong/open_taobao/api/wangwang
- 淘客API: github.com/changkong/open_taobao/api/taobaoke
- 主动通知业务API: github.com/changkong/open_taobao/api/notice
- 工具类API: github.com/changkong/open_taobao/api/tools
- 物流宝API: github.com/changkong/open_taobao/api/wlb
- 直通车API: github.com/changkong/open_taobao/api/simba
- 收藏夹API: github.com/changkong/open_taobao/api/favorite
- 机票API: github.com/changkong/open_taobao/api/jipiao
- 营销API: github.com/changkong/open_taobao/api/marketing
- 数据API: github.com/changkong/open_taobao/api/udp
- 酒店API: github.com/changkong/open_taobao/api/hotel
- 店铺会员管理API: github.com/changkong/open_taobao/api/crm
- 多媒体平台API: github.com/changkong/open_taobao/api/dmt
- 子账号管理API: github.com/changkong/open_taobao/api/subuser
- 服务平台API: github.com/changkong/open_taobao/api/fuwu
- 退款API: github.com/changkong/open_taobao/api/refund
- 关联推荐API: github.com/changkong/open_taobao/api/recommend
- 组件API: github.com/changkong/open_taobao/api/widget
- 支付宝API: github.com/changkong/open_taobao/api/alipy
- 天猫精品库API: github.com/changkong/open_taobao/api/jp
- 聚石塔API: github.com/changkong/open_taobao/api/rds
- 旅行度假API: github.com/changkong/open_taobao/api/trvael
- 彩票API: github.com/changkong/open_taobao/api/caipiao
- 账务API: github.com/changkong/open_taobao/api/bill
- 天猫退款退货API: github.com/changkong/open_taobao/api/eai
测试说明
运行如下命令, 执行web小工具
- cd tools
- go build .
- tools
启动后,默认通过80端口访问, 提供如下功能:
- 参数修改保存
- 授权登陆测试
- 用户信息获取测试
- 根据淘宝最新 ApiMetadata.xml 重新生成SDK源码并编译, 保证代码最新
- ApiMetadata.xml 在 tools/conf 目录下,可从 淘宝这里 下载最新配置
界面图片
代码样例
- 获取授权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 方法
-
其他资源
- 淘宝API详细列表 可以API更详细的解释
- 对登陆授权的更多介绍,参见 https免签调用方式详解 OAuth2.0授权方式
技术说明
-
调用方式: 只支持 https 免签调用方式
-
业务字段: 为了调用方便, 都生成相关字段或方法, 而不是 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
- Variables
- func GetUrlForAuth(appKey, redirectUri, state string) (*url.URL, error)
- type ErrResponse
- type TaobaoMethodRequest
- type TaobaoRequest
- type TaobaoRequestI
- type TaobaoTopErrResponse
- type TokenGetRequest
- func (t *TokenGetRequest) GetResponse() (*TokenGetResponse, []byte, error)
- func (t *TokenGetRequest) SetAppKey(val string)
- func (t *TokenGetRequest) SetAppSecret(val string)
- func (t *TokenGetRequest) SetCode(val string)
- func (t *TokenGetRequest) SetRedirectUri(val string)
- func (t *TokenGetRequest) SetState(val string)
- type TokenGetResponse
Constants ¶
View Source
const VersionNo = "0.0.1"
Variables ¶
View Source
var ( InsecureSkipVerify = true // 相信淘宝服务器,跳过对其检查,减少客户端配置问题 DisableCompression = false // 默认压缩数据 )
Functions ¶
Types ¶
type ErrResponse ¶
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 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"` }
Source Files
Directories
Path | Synopsis |
---|---|
api/alipy | 提供查询商家支付宝财务流水功能 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/bill | 提供商家账务信息查询 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/caipiao | 支持营销活动赠送彩票功能实现 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/crm | API无需订购ecrm工具也可调用。 |
api/delivery | 提供了发货,物流单详情,区域地址和物流公司信息查询功能 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/dmt | 解决淘宝各种文件上传、管理维护、使用的统一解决方案平台 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/eai | 天猫逆向流程API auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/favorite | 提供了收藏夹添加和查询功能 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/fenxiao | 提供了分销商信息和采购单信息的查询以及分销产品的添加和更新等功能 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/fuwu | 提供服务平台相关API,包括用户应用订购关系相关查询,定向营销等功能 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/hotel | 淘宝酒店业务 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/item | 提供了标准类目,类目属性和类目属性值的查询功能 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/jipiao | auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/jp | 提供天猫精选的商品、店铺、活动等,方便合作伙伴做天猫导购 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/marketing | 提供淘宝营销工具的业务,包括店铺优惠券、会员关系管理等 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/notice | 配合主动通知业务,提供商品,交易,退款和评价等数据或状态变更的查询功能,使用:http://open.taobao.com/doc/category_list.htm?spm=0.0.0.0.maU6vt&id=87 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/pinjia | 提供了评价的添加和查询功能 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/product | 提供了商品以及商品相关的sku,邮费增加,修改功能 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/rds | 管理聚石塔DB实例 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/recommend | 通过商品、类目、用户等条件推荐优质商品 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/refund | 提供了卖家接收退款,退款留言等功能 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/shop | 提供了店铺查询,店铺自定义类目的查询和更新 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/simba | 提供卖家直通车投放管理功能,增值包现已开放申请 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/subuser | 提供子账号相关的帐号及角色的查询、授权等信息及操作 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/taobaoke | 提供了淘宝客商品列表和淘宝客单品详情推广,店铺推广,类目和关键字推广以及淘客报表查询等功能.常见的淘客问题,请看该文档的“功能介绍” auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/tools | 提供了系统时间查询、关键词过滤、定时任务管理、异步任务管理等功能的API auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/trade | 提供了订单下载,修改收货地址、修改交易备注等功能 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/trvael | 提供旅行商品发布管理功能 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/udp | 提供淘宝数据开放 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/user | 提供了用户基本信息查询功能 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/wangwang | 提供了旺旺聊天记录,平均等待时间,客服评价统计,客服未回复人数和客服接待数等绩效考核功能 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/widget | 组件API列表 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
api/wlb | 提供了物流宝库存,商品,订单和发货等功能 auto sdk from taobao ApiMetadata.xml version 20130808 auther: dz7changkong@qq.com |
tools | web 小工具, 测试淘宝GoSdk基本流程, 能根据淘宝 ApiMetadata.xml 重新生成SDK源码并编译 |