elemeOpenApi

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2017 License: MIT Imports: 16 Imported by: 0

README

Golang SDK 接入指南

接入指南

  1. Go version == 1.8
  2. 通过 go get 命令安装 SDK
  3. 创建 Config 配置类,填入 key,secret 和 sandbox 参数
  4. 使用 SDK 提供的接口进行开发调试
  5. 上线前调用 Config.SetSandbox 为 false 以及填入正式环境的 key 和 secret
安装
    go get git.coding.net/napos_openapi/eleme-openapi-php-sdk.git
基本用法
    import openapi "git.coding.net/napos_openapi/eleme-openapi-go-sdk.git"

    // 新建一个配置实例
    config := openapi.NewConfig(false, app_key, app_secret)
    
    // 设置 token
    config.SetToken(token)
    
    // 新建一个 API 实例
    eleme := openapi.NewAPIClient(config)
    
    // 调用服务 API
    data := eleme.Shop.GetShop(shopId)

Token获取

企业应用与个人应用的 token 获取方法略有不同。

实际使用过程中,在 token 获取成功后,该 token 可以使用较长一段时间,需要缓存起来,请勿每次请求都重新获取 token。

企业应用
    import openapi "git.coding.net/napos_openapi/eleme-openapi-go-sdk.git"
    
    // 新建一个配置实例
    config := openapi.NewConfig(false, app_key, app_secret)

    // 新建 oauth 客户端实例
    oauth := openapi.NewAuthClient(config)

    // 获取 token
    token := oauth.GetClientToken()
    
    // 根据 OAuth 2.0 中的对应 state,scope 和 callback_url,获取授权 URL
    authURL := oauth.GenerateAuthUrl(state, scope, redirecrUri)

商家打开授权URL,同意授权后,跳转到您的回调页面,并返回code

    ...
    // 通过授权得到的 code,以及正确的 callback_url,获取token
    token := oauth.GetTokenByAuthCode(code, redirectURL)
    ...
个人应用
    import openapi "git.coding.net/napos_openapi/eleme-openapi-go-sdk.git"

    // 新建一个配置实例
    config := openapi.NewConfig(false, app_key, app_secret)

    // 新建 oauth 客户端实例
    oauth := openapi.NewAuthClient(config)

    // 获取 token
    token := oauth.GetClientToken()

    // 设置 token
    config.SetToken(token)

    ...

Demo使用方法

该 demo 主要用来演示企业应用的授权流程和展示应用信息

  1. 在开发者中心创建企业应用,记下沙箱环境店铺的账号和密码,并在沙箱环境中填入回调地址(该地址需要https)

  2. 在 demo 的同一目录创建 config.json 并配置沙箱环境,否则无法运行 demo。

    {"key":"yourkey","secret":"yoursecret","callbackUrl":"yourhost","userId":"","acessToken":"","refreshToken":""}
  1. 运行 demo。

  2. 打开SDK生成的授权URL,使用沙箱店铺的账号和密码进行授权,成功后调转回调接口,输出页面,展示店铺信息

  3. 使用沙箱店铺的账号密码在 napos 客户端登陆,会发现刚刚授权的应用已安装,并能够打开应用跳转回调页,展示店铺信息

Change Log

v1.1.0 增加接口确认订单送达 ReceivedOrder

Documentation

Overview

消息服务

订单服务

商品服务

店铺服务

商户服务

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIInterface

func APIInterface(config *Config, strAction string, params map[string]interface{}) (interface{}, error)

api 通用接口

Types

type APIClient

type APIClient struct {
	Message Message
	Order   Order
	Shop    Shop
	Product Product
	User    User
	File    File
	// contains filtered or unexported fields
}

func NewAPIClient

func NewAPIClient(config Config) APIClient

func (*APIClient) SetConfig

func (client *APIClient) SetConfig(config Config)

type APIError

type APIError struct {
	Code    string
	Message string
}

func (APIError) Error

func (e APIError) Error() string

type ApiBody

type ApiBody struct {
	Token     string                 `json:"token"`
	Nop       string                 `json:"nop"`
	Metas     map[string]interface{} `json:"metas"`
	Params    map[string]interface{} `json:"params"`
	Action    string                 `json:"action"`
	ID        string                 `json:"id"`
	Signature string                 `json:"signature"`
}

func (*ApiBody) Sign

func (body *ApiBody) Sign(secret string)

给 body 签名

type Category

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

func (*Category) CreateCategory

func (category *Category) CreateCategory(shopId_ int64, name_ string, description_ string) (interface{}, error)

添加商品分类 shopId 店铺Id name 商品分类名称,长度需在50字以内 description 商品分类描述,长度需在50字以内

func (*Category) GetCategory

func (category *Category) GetCategory(categoryId_ int64) (interface{}, error)

查询商品分类详情 categoryId 商品分类Id

func (*Category) GetShopCategories

func (category *Category) GetShopCategories(shopId_ int64) (interface{}, error)

查询店铺商品分类 shopId 店铺Id

func (*Category) RemoveCategory

func (category *Category) RemoveCategory(categoryId_ int64) (interface{}, error)

删除商品分类 categoryId 商品分类Id

func (*Category) SetCategoryPositions

func (category *Category) SetCategoryPositions(shopId_ int64, categoryIds_ interface{}) (interface{}, error)

设置分类排序 shopId 饿了么店铺Id categoryIds 需要排序的分类Id

func (*Category) UpdateCategory

func (category *Category) UpdateCategory(categoryId_ int64, name_ string, description_ string) (interface{}, error)

更新商品分类 categoryId 商品分类Id name 商品分类名称,长度需在50字以内 description 商品分类描述,长度需在50字以内

type Config

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

func NewConfig

func NewConfig(bSandbox bool, key string, secret string) Config

构造一个新的 openapi 配置

func (*Config) GetAPIHost

func (conf *Config) GetAPIHost() string

获取 openapi host

func (*Config) SetKey

func (conf *Config) SetKey(key string)

设置 openapi key

func (*Config) SetLogger

func (conf *Config) SetLogger(logger ElemeSdkLogger)

设置日志接口

func (*Config) SetSandbox

func (conf *Config) SetSandbox(b bool)

设置是否为沙箱环境

func (*Config) SetSecret

func (conf *Config) SetSecret(secret string)

设置 openapi secret

func (*Config) SetToken

func (conf *Config) SetToken(token Token)

设置 token

func (*Config) SetURL

func (conf *Config) SetURL(url string)

设置 openapi URL

type ElemeSdkLogger

type ElemeSdkLogger interface {
	Info(message string)
	Error(message string)
}

type File

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

func (*File) GetUploadedUrl

func (file *File) GetUploadedUrl(hash_ string) (interface{}, error)

获取上传文件的访问URL,返回文件的Url地址 hash 图片hash值

func (*File) UploadImage

func (file *File) UploadImage(image_ string) (interface{}, error)

上传图片,返回图片的hash值 image 文件内容base64编码值

func (*File) UploadImageWithRemoteUrl

func (file *File) UploadImageWithRemoteUrl(url_ string) (interface{}, error)

通过远程URL上传图片,返回图片的hash值 url 远程Url地址

type Item

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

func (*Item) BatchClearStock

func (item *Item) BatchClearStock(specIds_ interface{}) (interface{}, error)

批量沽清库存 specIds 商品及商品规格的列表

func (*Item) BatchCreateItems

func (item *Item) BatchCreateItems(categoryId_ int64, items_ interface{}) (interface{}, error)

批量添加商品 categoryId 商品分类Id items 商品属性的列表

func (*Item) BatchFillStock

func (item *Item) BatchFillStock(specIds_ interface{}) (interface{}, error)

批量置满库存 specIds 商品及商品规格的列表

func (*Item) BatchGetItems

func (item *Item) BatchGetItems(itemIds_ interface{}) (interface{}, error)

批量查询商品详情 itemIds 商品Id的列表

func (*Item) BatchOffShelf

func (item *Item) BatchOffShelf(specIds_ interface{}) (interface{}, error)

批量下架商品 specIds 商品及商品规格的列表

func (*Item) BatchOnShelf

func (item *Item) BatchOnShelf(specIds_ interface{}) (interface{}, error)

批量上架商品 specIds 商品及商品规格的列表

func (*Item) BatchRemoveItems

func (item *Item) BatchRemoveItems(itemIds_ interface{}) (interface{}, error)

批量删除商品 itemIds 商品Id的列表

func (*Item) BatchUpdateSpecStocks

func (item *Item) BatchUpdateSpecStocks(specStocks_ interface{}) (interface{}, error)

批量更新商品库存 specStocks 商品以及规格库存列表

func (*Item) CreateItem

func (item *Item) CreateItem(categoryId_ int64, properties_ interface{}) (interface{}, error)

添加商品 categoryId 商品分类Id properties 商品属性

func (*Item) GetItem

func (item *Item) GetItem(itemId_ int64) (interface{}, error)

查询商品详情 itemId 商品Id

func (*Item) GetItemsByCategoryId

func (item *Item) GetItemsByCategoryId(categoryId_ int64) (interface{}, error)

获取一个分类下的所有商品 categoryId 商品分类Id

func (*Item) RemoveItem

func (item *Item) RemoveItem(itemId_ int64) (interface{}, error)

删除商品 itemId 商品Id

func (*Item) SetItemPositions

func (item *Item) SetItemPositions(categoryId_ int64, itemIds_ interface{}) (interface{}, error)

设置商品排序 categoryId 商品分类Id itemIds 商品Id列表

func (*Item) UpdateItem

func (item *Item) UpdateItem(itemId_ int64, categoryId_ int64, properties_ interface{}) (interface{}, error)

更新商品 itemId 商品Id categoryId 商品分类Id properties 商品属性

type Message

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

func (*Message) GetNonReachedMessages

func (message *Message) GetNonReachedMessages(appId_ int) (interface{}, error)

获取未到达的推送消息 appId 应用ID

func (*Message) GetNonReachedOMessages

func (message *Message) GetNonReachedOMessages(appId_ int) (interface{}, error)

获取未到达的推送消息实体 appId 应用ID

type OAuthClient

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

func NewAuthClient

func NewAuthClient(conf Config) OAuthClient

func (*OAuthClient) GenerateAuthUrl

func (oauth *OAuthClient) GenerateAuthUrl(state string, scope string, redirectUri string) string

获取授权 URL

func (*OAuthClient) GetClientToken

func (oauth *OAuthClient) GetClientToken() Token

获取 token 客户端模式

func (*OAuthClient) GetTokenByAuthCode

func (oauth *OAuthClient) GetTokenByAuthCode(code string, redirectURL string) Token

通过 auth code 获取 token

func (*OAuthClient) GetTokenByRefreshToken

func (oauth *OAuthClient) GetTokenByRefreshToken(refreshToken string, scope string) Token

通过刷新 token 获取 token

func (*OAuthClient) SetConfig

func (oauth *OAuthClient) SetConfig(conf Config)

设置配置

type Order

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

func (*Order) AgreeRefund

func (order *Order) AgreeRefund(orderId_ string) (interface{}, error)

同意退单/取消单 orderId 订单Id

func (*Order) BatchGetDeliveryStates

func (order *Order) BatchGetDeliveryStates(orderIds_ interface{}) (interface{}, error)

批量获取订单最新配送记录 orderIds 订单Id列表

func (*Order) CancelOrder

func (order *Order) CancelOrder(orderId_ string, type_ interface{}, remark_ string) (interface{}, error)

取消订单 orderId 订单Id type 取消原因 remark 备注说明

func (*Order) ConfirmOrder

func (order *Order) ConfirmOrder(orderId_ string) (interface{}, error)

确认订单 orderId 订单Id

func (*Order) DeliveryBySelf

func (order *Order) DeliveryBySelf(orderId_ string) (interface{}, error)

配送异常或者物流拒单后选择自行配送 orderId 订单Id

func (*Order) DisagreeRefund

func (order *Order) DisagreeRefund(orderId_ string, reason_ string) (interface{}, error)

不同意退单/取消单 orderId 订单Id reason 商家不同意退单原因

func (*Order) GetDeliveryStateRecord

func (order *Order) GetDeliveryStateRecord(orderId_ string) (interface{}, error)

获取订单配送记录 orderId 订单Id

func (*Order) GetOrder

func (order *Order) GetOrder(orderId_ string) (interface{}, error)

获取订单 orderId 订单Id

func (*Order) MgetOrders

func (order *Order) MgetOrders(orderIds_ interface{}) (interface{}, error)

批量获取订单 orderIds 订单Id的列表

func (*Order) NoMoreDelivery

func (order *Order) NoMoreDelivery(orderId_ string) (interface{}, error)

配送异常或者物流拒单后选择不再配送 orderId 订单Id

func (*Order) ReceivedOrder

func (order *Order) ReceivedOrder(orderId_ string) (interface{}, error)

订单确认送达 orderId 订单ID

type Product

type Product struct {
	Item     Item
	Category Category
	// contains filtered or unexported fields
}

type Shop

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

func (*Shop) GetShop

func (shop *Shop) GetShop(shopId_ int64) (interface{}, error)

查询店铺信息 shopId 店铺Id

func (*Shop) MgetShopStatus

func (shop *Shop) MgetShopStatus(shopIds_ interface{}) (interface{}, error)

批量获取店铺简要 shopIds 店铺Id的列表

func (*Shop) UpdateShop

func (shop *Shop) UpdateShop(shopId_ int64, properties_ interface{}) (interface{}, error)

更新店铺基本信息 shopId 店铺Id properties 店铺属性

type SimpleLogger

type SimpleLogger struct {
}

func (*SimpleLogger) Error

func (logger *SimpleLogger) Error(message string)

func (*SimpleLogger) Info

func (logger *SimpleLogger) Info(message string)

type Token

type Token struct {
	Access_token  string
	Token_type    string
	Expires_in    int
	Refresh_token string
}

type User

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

func (*User) GetUser

func (user *User) GetUser() (interface{}, error)

获取商户账号信息

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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