ylyOpenApi

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

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

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 10 Imported by: 1

README

Golang SDK 接入指南

接入指南

  1. Go version >= 1.8
  2. 通过 go get 命令安装 SDK
  3. 使用 SDK 提供的接口进行开发调试

安装

    go get github.com/Qzm6826/yly-go-sdk

基本用法

    import openapi "github.com/Qzm6826/yly-go-sdk"

    // 新建一个配置实例
    conf := openApi.NewConfig(cid, secret)
    
    // 获取 token 并设置
    oauth := openApi.NewAuthClient(conf)
    tokenData := oauth.GetAccessToken()
    conf.SetToken(tokenData)
    
    // 新建一个 API 实例
    client := openApi.NewClient(conf)
    
    // 添加一个打印机。未绑定打印机,需先调用此方法
    res, _ := client.SetPrinter.AddPrinter(machineCode, mSign, printName)
    fmt.Println(res)
    
    // 调用服务 API
    res, _ := client.PrintService.TextPrint(machineCode, content, originId)
    fmt.Println(res)

Token获取

开放型应用与自有型应用的 token 获取方法略有不同。

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

开放型应用
    import openapi "github.com/Qzm6826/yly-go-sdk"
    
    // 新建一个配置实例
    conf := openApi.NewConfig(cid, secret)

    // 新建 oauth 客户端实例
    oauth := openApi.NewAuthClient(conf)
    
    // 根据 OAuth 2.0 中的对应 state 和 redirectUri,获取授权 URL, 跳转访问,通过回调获取AuthCode
    authURL := oauth.GetAuthUrl(redirectUri, state)
   

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

    ...
    // 通过授权得到的 code,获取token
    tokenData := oauth.GetAccessTokenByAuthCode(code)
    conf.SetToken(tokenData)
    ...

自有型应用可以看看基本用法

Demo使用方法

该 demo 主要用来演示自有型应用的授权流程和打印

  1. 在开发者中心创建自有型应用

  2. 在 demo 的同一目录clientApplication.go文件中 配置应用信息和redis信息,否则无法运行 demo。

  3. 运行 demo。

更新日志

[v2.0.3]
  • Release Date : 2023-11-01
  1. [Feature]v2新增K8推送开关设置接口。
  2. [Feature]v2新增K8高级设置接口。
[v2.0.1]
  1. [Feature]v2新增K8关键词设置接口。
[v2.0]
  • Release Date : 2023-06-07
  1. [Feature]更新接口v2.0版本,文档
  2. [Feature]v2新增订单重打(单订单)接口。
  3. [Feature]v2新增面单取消

Documentation

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)

func GetUUID4

func GetUUID4() string

获取UUID4

func RequestUrl

func RequestUrl() string

Types

type APIError

type APIError struct {
	Code    string
	Message string
}

func (APIError) Error

func (e APIError) Error() string

type ApiClient

type ApiClient struct {
	PrintService PrintService
	SetPrinter   SetPrinter
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config Config) ApiClient

func (*ApiClient) SetConfig

func (client *ApiClient) SetConfig(config Config)

type Config

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

func NewConfig

func NewConfig(cid string, secret string) Config

func (*Config) GetHost

func (conf *Config) GetHost() string

func (*Config) GetSign

func (conf *Config) GetSign(timestamp string) string

func (*Config) SetClientId

func (conf *Config) SetClientId(cid string)

func (*Config) SetClientSecret

func (conf *Config) SetClientSecret(secret string)

func (*Config) SetLogger

func (conf *Config) SetLogger(logger YlySdkLogger)

func (*Config) SetRequestUrl

func (conf *Config) SetRequestUrl(reqUrl string)

func (*Config) SetToken

func (conf *Config) SetToken(token Token)

type OAuthClient

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

func NewAuthClient

func NewAuthClient(conf Config) OAuthClient

func (*OAuthClient) GetAccessToken

func (oauth *OAuthClient) GetAccessToken() Token

自有应用获取调用凭证API

func (*OAuthClient) GetAccessTokenByAuthCode

func (oauth *OAuthClient) GetAccessTokenByAuthCode(code string) Token

开放型应用获取调用凭API code 授权码

func (*OAuthClient) GetAccessTokenByRefreshToken

func (oauth *OAuthClient) GetAccessTokenByRefreshToken(refreshToken string) Token

自有应用&开放型应用刷新调用凭证API 需刷新令牌refresh_token

func (*OAuthClient) GetAccessTokenBySecret

func (oauth *OAuthClient) GetAccessTokenBySecret(machineCode string, secret string, secretType int) Token

极速授权获取调用凭证API 注意:仅支持开放型应用 machineCode 终端号 secret 密钥(可能是msign或qr_key)

func (*OAuthClient) GetAuthUrl

func (oauth *OAuthClient) GetAuthUrl(redirectUri string, state string) string

获取授权url API redirectUri 回调地址 state 用于保持请求和回调的状态,在回调时,会回传该参数。开发者可以用这个参数验证请求有效性,也可以记录用户请求授权页前的位置。可防止CSRF攻击

func (*OAuthClient) GetUUID4

func (oauth *OAuthClient) GetUUID4() string

获取UUID4

func (*OAuthClient) SetConfig

func (oauth *OAuthClient) SetConfig(conf Config)

type PrintService

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

func (*PrintService) ExpressOrderCancel

func (PrintService *PrintService) ExpressOrderCancel(machineCode string, content string) (interface{}, error)

面单取消。参数(终端号machineCode,面单数据详情请看文档content

func (*PrintService) ExpressOrderPrint

func (PrintService *PrintService) ExpressOrderPrint(machineCode string, content string, originId string, sandbox int) (interface{}, error)

面单生成并打印。参数(终端号machineCode,面单数据详情请看文档content,商户订单号originId,sandbox沙箱环境:1 正式环境:0)

func (*PrintService) PicturePrint

func (PrintService *PrintService) PicturePrint(machineCode string, pictureUrl string, originId string, idempotence int) (interface{}, error)

图片打印。参数(终端号machineCode,图片链接pictureUrl,商户订单号originId)

func (*PrintService) TextPrint

func (PrintService *PrintService) TextPrint(machineCode string, content string, originId string, idempotence int) (interface{}, error)

文本打印。参数(终端号machineCode,打印内容content,商户订单号originId)

type SetPrinter

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

func (*SetPrinter) AddPrinter

func (SetPrinter *SetPrinter) AddPrinter(machineCode string, mSign string, printName string) (interface{}, error)

绑定打印机API machineCode 终端号 mSign 终端密钥 printName 打印机别名

func (*SetPrinter) CancelAPrintOrder

func (SetPrinter *SetPrinter) CancelAPrintOrder(machineCode string, orderId string) (interface{}, error)

取消单条未打印订单API machineCode 终端号 orderId 易联云打印id

func (*SetPrinter) CancelAllPrintOrders

func (SetPrinter *SetPrinter) CancelAllPrintOrders(machineCode string) (interface{}, error)

取消所有未打印订单API machineCode 终端号

func (*SetPrinter) DelIcon

func (SetPrinter *SetPrinter) DelIcon(machineCode string) (interface{}, error)

取消LOGO API machineCode 终端号

func (*SetPrinter) DelPrinter

func (SetPrinter *SetPrinter) DelPrinter(machineCode string) (interface{}, error)

删除已授权的打印机API machineCode 终端号

func (*SetPrinter) DelVoice

func (SetPrinter *SetPrinter) DelVoice(machineCode string, aId int) (interface{}, error)

删除内置语音API machineCode 终端号 aid 内置语音编号0~9

func (*SetPrinter) GetOrderList

func (SetPrinter *SetPrinter) GetOrderList(machineCode string, pageIndex int, pageSize int) (interface{}, error)

获取订单列表API machineCode 终端号 pageIndex 查询条件—当前页码,暂只提供前100页数据 pageSize 查询条件—每页显示条数,每页最大条数100

func (*SetPrinter) GetOrderStatus

func (SetPrinter *SetPrinter) GetOrderStatus(machineCode string, orderId string) (interface{}, error)

获取订单状态API machineCode 终端号 orderId 易联云打印id

func (*SetPrinter) GetPrintStatus

func (SetPrinter *SetPrinter) GetPrintStatus(machineCode string) (interface{}, error)

获取终端状态API machineCode 终端号

func (*SetPrinter) GetPrinterInfo

func (SetPrinter *SetPrinter) GetPrinterInfo(machineCode string) (interface{}, error)

获取机型打印宽度API machineCode 终端号

func (*SetPrinter) GetPrinterVersion

func (SetPrinter *SetPrinter) GetPrinterVersion(machineCode string) (interface{}, error)

获取机型软硬件版本API machineCode 终端号

func (*SetPrinter) PushSwitch

func (SetPrinter *SetPrinter) PushSwitch(machineCode string, status string) (interface{}, error)

K8推送开关设置API machineCode 终端号 status 开启"open",关闭"close"

func (*SetPrinter) Reprint

func (SetPrinter *SetPrinter) Reprint(machineCode string, orderId string) (interface{}, error)

订单重打(单订单)API machineCode 终端号 orderId 易联云打印id

func (*SetPrinter) SetIcon

func (SetPrinter *SetPrinter) SetIcon(machineCode string, imgUrl string) (interface{}, error)

设置LOGO API machineCode 终端号 imgUrl logo图标地址,图片宽度最大为350px,文件大小不能超过40Kb

func (*SetPrinter) SetKeywords

func (SetPrinter *SetPrinter) SetKeywords(machineCode string, keys string, keyType string, content string) (interface{}, error)

K8关键词设置API machineCode 终端号 keys 关键词-key type 黑白名单类型 content 关键词-value 数据类型 json数组

func (*SetPrinter) SetOrderConfirmation

func (SetPrinter *SetPrinter) SetOrderConfirmation(machineCode string, responseType string) (interface{}, error)

设置订单确认API machineCode 终端号 responseType 开启"open",关闭"close"

func (*SetPrinter) SetPrintMode

func (SetPrinter *SetPrinter) SetPrintMode(machineCode string, responseType string) (interface{}, error)

设置打印方式API machineCode 终端号 responseType 开启"btnopen",关闭"btnclose"

func (*SetPrinter) SetPrinterMenu

func (SetPrinter *SetPrinter) SetPrinterMenu(machineCode string, content string) (interface{}, error)

设置应用菜单API machineCode 终端号 content json字符串["菜单名","菜单url"]

func (*SetPrinter) SetPushUrlByAuth

func (SetPrinter *SetPrinter) SetPushUrlByAuth(machineCode string, cmd string, url string, status string) (interface{}, error)

设置推送url API (开放型) machineCode 终端号 cmd 打印完成标识"oauth_finish",接单拒单标识"oauth_getOrder",终端状态标识"oauth_printStatus", 按键请求标识"oauth_request" url 推送地址填写必须以http://或https://开头的地址。推送地址需要支持GET访问,当GET请求访问时,请直接返回{"data":"OK"},用于推送地址的可用性测试 status 开启"open",关闭"close"

func (*SetPrinter) SetPushUrlByClient

func (SetPrinter *SetPrinter) SetPushUrlByClient(cmd string, url string, status string) (interface{}, error)

设置推送url API (自有型) cmd 打印完成标识"oauth_finish",接单拒单标识"oauth_getOrder",终端状态标识"oauth_printStatus", 按键请求标识"oauth_request" url 推送地址填写必须以http://或https://开头的地址。推送地址需要支持GET访问,当GET请求访问时,请直接返回{"data":"OK"},用于推送地址的可用性测试 status 开启"open",关闭"close"

func (*SetPrinter) SetSound

func (SetPrinter *SetPrinter) SetSound(machineCode string, responseType string, voice string) (interface{}, error)

声音调节API machineCode 终端号 responseType 蜂鸣器"buzzer",喇叭"horn" voice 音量大小0~4

func (*SetPrinter) SetVoice

func (SetPrinter *SetPrinter) SetVoice(machineCode string, content string, isFile string, aId int) (interface{}, error)

设置内置语音API machineCode 终端号 content (播报内容,音量(1~9),声音类型(0,1,3,4)组成json字符串) 或者 (在线语音链接,语音内容请小于24kb) isFile "true" or "false" , 判断content是否为在线语音链接,格式MP3 aid 定义需设置的语音编号0~9

func (*SetPrinter) Setting

func (SetPrinter *SetPrinter) Setting(machineCode string, usbPrintMode int, usbInputMode int, cameraDecodeTxMode int) (interface{}, error)

K8高级设置API machineCode 终端号 usbPrintMode USB打印设置 直接打印:0 扫码支付后打印:1 usbInputMode USB输入方式设置 键盘输入:0 刷脸或扫码设备输入:1 cameraDecodeTxMode 扫码输出设置 输出到服务器:0 输出到收银机:1

func (*SetPrinter) ShutdownOrRestart

func (SetPrinter *SetPrinter) ShutdownOrRestart(machineCode string, responseType string) (interface{}, error)

关机重启API machineCode 终端号 responseType 重启"restart",关闭"shutdown" 仅支持k4机型,子版本中带字母A的机器

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 {
	Error             int
	Error_description string
	Body              TokenBody
}

type TokenBody

type TokenBody struct {
	Access_token  string
	Refresh_token string
	Expires_in    int
	Machine_code  string
}

type YlySdkLogger

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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