gaodeng

package module
v0.2.1-0...-41c2e7d Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2020 License: MIT Imports: 4 Imported by: 0

README

gaodeng

Latest Tag

用Golang封装了高灯电子发票SDK。

文档地址:http://developer-doc.fapiaoer.cn/

简介
  • 支持全局配置AppKeyAppSecret
  • 全部参数和返回值均使用struct类型传递,而不是map类型。
  • 调用时,按struct传入参数,内部自动将其转换为原生SDK支持的map类型。
  • 返回时,先按通用类型解析:
    • 异常时,记录日志;
    • 正常后,仅返回业务部分数据(即data部分)的字节流,需要在具体的业务内转为对应的struct类型。
术语清单
术语 对应 使用的系统
服务商 布谷 服务商平台
销货方 车场 商家平台 
购买方 车主 微信
代码简介
  • constant.go:常数定义。
  • model.go:通用返回类型定义。
  • config.go:HTTP请求客户端的环境配置。
  • client.go:HTTP请求客户端。
  • gd_*.go:相关的业务接口。
  • gd_*_test.go:业务接口对应的单元测试类。
接口
  • gd_invoice_blue.go:发票开具接口。
  • gd_invoice_red.go:发票冲红接口(批量查询,但一次最多20张)。
  • gd_invoice_status.go:查询发票信息接口(单张发票的查询)。
  • gd_invoice_amount.go:查询发票余量接口(todo)。
  • gd_invoice_verify.go:发票查验接口。

开票结果异步通知接口,将写在云端服务中

Documentation

Index

Constants

View Source
const (
	EnvProd = "prod" // (生产环境)
	EnvTest = "test" // (沙盒环境)

	AppVersion = "1.0.0"

	InvoiceStatusDoing   uint8 = 1 // 开票中
	InvoiceStatusSuccess uint8 = 2 // 开票成功
	InvoiceStatusFailure uint8 = 3 // 开票失败

	InvoiceTitleTypePerson     uint8 = 1 // 个人
	InvoiceTitleTypeEnterprise uint8 = 2 // 企业

	TradeTypeElse             = "0" // 其他
	TradeTypeCommunication    = "1" // 通信
	TradeTypeFood             = "2" // 餐饮
	TradeTypeTransportation   = "3" // 交通
	TradeTypePayment          = "4" // 支付平台
	TradeTypeTicketAndTourist = "5" // 票务/旅游

	InvoiceTypeCodeZZSZY = "004" // 增值税专用发票
	InvoiceTypeCodeZZSPT = "007" // 增值税普通发票
	InvoiceTypeCodeZZSJS = "025" // 增值税卷式发票
	InvoiceTypeCodeZZSDZ = "026" // 增值税电子发票(默认)
	InvoiceTypeCodeQKL   = "032" // 区块链发票

	ZeroTaxNo     = ""  // 非零税率
	ZeroTaxExport = "0" // 出口零税
	ZeroTaxFree   = "1" // 免税
	ZeroTaxNone   = "2" // 不征税
	ZeroTaxCommon = "3" // 普通零税率

	PreferentialPolicyNo  = ""  // 不使用
	PreferentialPolicyUse = "1" // 使用

	RedStateSuccess uint8 = 1 // 调用成功
	RedStateFailure uint8 = 0 // 调用失败

	TicketDoing   = "1" // 开票中
	TicketSuccess = "2" // 开票成功
	TicketFailure = "3" // 开票失败

	VerifyCodeTrue uint8 = 0 // 成功(发票验证为真)
	VerifyCodeFail uint8 = 1 // 成功(发票验证为假)

	CallbackNotifyTypeBlue = "invoice.blue" // 蓝票通知类型
	CallbackNotifyTypeRed  = "invoice.red"  // 红票通知类型

	CallbackTicketStatusSuccess uint8 = 2 // 开票成功,其他都是失败

	StatusCodeNormal               uint16 = 0    // 正常
	StatusCodeRequestError         uint16 = 400  // 请求错误,服务器无法理解http请求
	StatusCodeNotPermission        uint16 = 403  // 禁止访问
	StatusCodeServerInnerError     uint16 = 500  // 服务器内部错误
	StatusCodeVersionError         uint16 = 1001 // 版本错误
	StatusCodeLackCommonParameters uint16 = 1002 // 缺少公共参数
	StatusCodeTimestampError       uint16 = 1003 // 时间戳错误
	StatusCodeAppKeyNotExists      uint16 = 1004 // appkey不存在
	StatusCodeAppClosed            uint16 = 1005 // app已关闭
	StatusCodeDeveloperClosed      uint16 = 1006 // 开发者已被关闭
	StatusCodeSignError            uint16 = 1007 // 签名错误
	StatusCodeDeveloperUnAudit     uint16 = 1008 // 开发者资质待审核
	StatusCodeDeveloperNoAudit     uint16 = 1009 // 开发者资质审核未通过
	StatusCodeParameterInValid     uint16 = 1010 // 参数检验错误
	StatusCodeDirtyData            uint16 = 1011 // 脏数据
	StatusCodeCallNumberNotEnough  uint16 = 1012 // 接口调用次数不足
	StatusCodeInterfaceFeeError    uint16 = 1013 // 接口计费错误
	StatusCodearameterError        uint16 = 1014 // 业务参数错误
	StatusCodeDependDeny           uint16 = 1015 // 依赖服务返回拒绝
	StatusCodeDependError          uint16 = 1016 // 依赖服务故障
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CallbackUrlBody

type CallbackUrlBody struct {
	AppKey                  string `json:"appkey"`                      // 服务商appkey
	Message                 string `json:"message"`                     // 返回结果详情
	NotifyType              string `json:"notify_type"`                 // 通知类型,参见constant.go
	NotifyTime              string `json:"notify_time"`                 // 通知时间 格式"2017-09-09 10:20:12"
	OrderId                 string `json:"order_id"`                    // 商户交易流水号(由商户维护唯一性)
	GlobalUniqueId          string `json:"g_unique_id"`                 // 平台交易流水号(由平台维护唯一性,同order_sn,兼容老平台用户)
	OrderSn                 string `json:"order_sn"`                    // 平台唯一交易订单号(由平台维护唯一性)
	TicketSn                string `json:"ticket_sn"`                   // 发票号码 开票失败时值为空
	TicketCode              string `json:"ticket_code"`                 // 发票代码 开票失败时值为空
	TicketDate              string `json:"ticket_date"`                 // 开票时间
	TicketStatus            uint8  `json:"ticket_status"`               // 发票状态,参见constant.go
	TicketTotalAmountHasTax string `json:"ticket_total_amount_has_tax"` // 发票含税总价 开票失败时值为空
	TicketTotalAmountNoTax  string `json:"ticket_total_amount_no_tax"`  // 发票去税总价 开票失败时值为空
	TicketTaxAmount         string `json:"ticket_tax_amount"`           // 发票税额 开票失败时值为空
	QrCode                  string `json:"qrcode"`                      // 发票二维码base64内容,最大10Kb。渠道不同可能返回为空
	CheckCode               string `json:"check_code"`                  // 发票校验码 开票失败时值为空
	CipherText              string `json:"cipher_text"`                 // 发票密文
	PdfUrl                  string `json:"pdf_url"`                     // 发票url地址 开票失败时值为空(纸票没有pdf)
}

type Client

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

func NewClient

func NewClient(env string, config Config) (client *Client)

高灯客户端的构造函数

func (*Client) InvoiceAmount

func (c *Client) InvoiceAmount(body InvoiceAmountRequest) (rsp InvoiceAmountResponse, err error)

查询发票信息

func (*Client) InvoiceBlue

func (c *Client) InvoiceBlue(body InvoiceBlueRequest) (rsp InvoiceBlueResponse, err error)

开具发票

func (*Client) InvoiceRed

func (c *Client) InvoiceRed(body InvoiceRedRequest) (rsp InvoiceRedResponse, err error)

发票冲红

func (*Client) InvoiceStatus

func (c *Client) InvoiceStatus(body InvoiceStatusRequest) (rsp InvoiceStatusResponse, err error)

查询发票信息

func (*Client) InvoiceVerify

func (c *Client) InvoiceVerify(body InvoiceVerifyRequest) (rsp InvoiceVerifyResponse, err error)

发票查验

type Config

type Config struct {
	AppKey    string // 高灯开放平台id
	AppSecret string // 高灯开放平台secret
}

高灯发票的整体配置

type Invoice

type Invoice struct {
	SellerTaxPayerNumber string `json:"seller_taxpayer_num"` // 销方税号
	CallbackUrl          string `json:"callback_url"`        // 红票接收地址
	OrderSn              string `json:"order_sn,omitempty"`  // 需要红冲的高灯订单号(蓝票开具时获得),和order_id不能同时为空
	OrderId              string `json:"order_id,omitempty"`  // 需要红冲的三方自有订单号(蓝票开具时传入),和order_sn不能同时为空
}

type InvoiceAmountRequest

type InvoiceAmountRequest struct {
	TaxPayerNumber  string `json:"taxpayer_num"`                // 开票商户的税号
	MachineNo       string `json:"machine_no,omitempty"`        // 税盘号,使用云票儿或百望税控服务器时必填
	TerminalCode    string `json:"terminal_code,omitempty"`     // 开票终端代码,使用百望税控服务器时必填
	InvoiceTypeCode string `json:"invoice_type_code,omitempty"` // 发票种类编码(见constant定义)
}

type InvoiceAmountResponse

type InvoiceAmountResponse struct {
	Result string `json:"result"` // 查询结果(见constant定义)
	Number int64  `json:"number"` // 剩余发票数量
}

type InvoiceBlueRequest

type InvoiceBlueRequest struct {
	SellerName           string `json:"seller_name,omitempty"`          // 销方名称
	SellerTaxPayerNumber string `json:"seller_taxpayer_num"`            // 销货方税号
	SellerAddress        string `json:"seller_address,omitempty"`       // 销货方地址
	SellerTel            string `json:"seller_tel,omitempty"`           // 销货方电话
	SellerBankName       string `json:"seller_bank_name,omitempty"`     // 销货方开户行
	SellerBankAccount    string `json:"seller_bank_account,omitempty"`  // 销货方银行账号
	TitleType            uint8  `json:"title_type"`                     // 发票抬头类型(见constant定义)
	BuyerTitle           string `json:"buyer_title"`                    // 购方抬头
	BuyerTaxPayerNumber  string `json:"buyer_taxpayer_num,omitempty"`   // 购方税号(企业类型的抬头必填)
	BuyerAddress         string `json:"buyer_address,omitempty"`        // 购方地址
	BuyerBankName        string `json:"buyer_bank_name,omitempty"`      // 购方开户行
	BuyerBankAccount     string `json:"buyer_bank_account,omitempty"`   // 购方银行账号
	BuyerPhone           string `json:"buyer_phone,omitempty"`          // 购方电话
	BuyerEmail           string `json:"buyer_email,omitempty"`          // 购方邮箱
	TakerPhone           string `json:"taker_phone,omitempty"`          // 收票人手机
	TakerName            string `json:"taker_name,omitempty"`           // 收票人名称
	OrderId              string `json:"order_id"`                       // 商户订单号
	InvoiceTypeCode      string `json:"invoice_type_code,omitempty"`    // 发票种类编码(见constant定义)
	CallbackUrl          string `json:"callback_url"`                   // 接收开票平台推送的消息地址
	Drawer               string `json:"drawer,omitempty"`               // 开票人
	Payee                string `json:"payee,omitempty"`                // 收款人
	Checker              string `json:"checker,omitempty"`              // 复核人
	TradeType            string `json:"trade_type,omitempty"`           // 行业分类(见constant定义)
	MachineNo            string `json:"machine_no,omitempty"`           // 税盘号
	UserOpenId           string `json:"user_openid,omitempty"`          // 三方用户id
	SpecialInvoiceKind   string `json:"special_invoice_kind,omitempty"` // 特殊票种标识(成品油票必传:08,其他票种可以为空)
	TerminalCode         string `json:"terminal_code,omitempty"`        // 开票终端代码,使用百望税控服务器时必填
	AmountHasTax         int64  `json:"amount_has_tax"`                 // 含税金额(单分)
	TaxAmount            int64  `json:"tax_amount"`                     // 税额(单分)
	AmountWithoutTax     int64  `json:"amount_without_tax"`             // 不含税金额(单分)
	Remark               string `json:"remark,omitempty"`               // 发票备注
	Items                []Item `json:"items"`                          // 商品数组
}

type InvoiceBlueResponse

type InvoiceBlueResponse struct {
	InvoiceId string `json:"invoice_id"` // 高灯发票唯一识别号
	OrderSn   string `json:"order_sn"`   // 高灯订单号(红冲需要用到)
	State     uint8  `json:"state"`      // 发票状态(见constant定义)
}

type InvoiceDetail

type InvoiceDetail struct {
	TicketCode         string       `json:"ticket_code"`          // 发票代码
	TicketSn           string       `json:"ticket_sn"`            // 发票号码
	TicketDate         string       `json:"ticket_date"`          // 开票日期
	BuyerName          string       `json:"buyer_name"`           // 销方名称
	BuyerTaxCode       string       `json:"buyer_tax_code"`       // 购方税号
	BuyerAddressPhone  string       `json:"buyer_address_phone"`  // 销方地址和电话
	BuyerBankAccount   string       `json:"buyer_bank_account"`   // 销方银行账号
	SellerName         string       `json:"seller_name"`          // 销方名称
	SellerTaxCode      string       `json:"seller_tax_code"`      // 购方税号
	SellerAddressPhone string       `json:"seller_address_phone"` // 销方地址和电话
	SellerBankAccount  string       `json:"seller_bank_account"`  // 销方银行账号
	Remark             string       `json:"remark"`               // 发票备注
	MachineNo          string       `json:"machine_no"`           // 税盘号
	InvoiceType        string       `json:"invoice_type"`         // 发票种类编码(见constant定义)
	CheckCode          string       `json:"check_code"`           // 发票校验码
	IsAbandoned        string       `json:"is_abandoned"`         // 是否作废(红冲)
	HasSellerList      string       `json:"has_seller_list"`      // 是否有销货清单
	SellerListTitle    string       `json:"seller_list_title"`    // 销货清单标题
	SellerListTax      string       `json:"seller_list_tax"`      // 销货清单税额
	AmountWithoutTax   string       `json:"amount_without_tax"`   // 不含税金额(元)
	TaxAmount          string       `json:"tax_amount"`           // 税额(元)
	AmountWithTax      string       `json:"amount_with_tax"`      // 含税金额(元)
	Items              []ItemDetail `json:"items"`                // 项目明细
}

type InvoiceNoRed

type InvoiceNoRed struct {
	Code      uint8  `json:"code"`       // 冲红状态(见constant定义)
	Message   string `json:"message"`    // 提交红冲描述
	OrderSn   string `json:"order_sn"`   // 高灯红票订单号(常与蓝票订单号一致)
	InvoiceId string `json:"invoice_id"` // 高灯发票唯一识别号
}

type InvoiceRedRequest

type InvoiceRedRequest struct {
	Invoices []Invoice `json:"invoices"` // 发票组
}

type InvoiceRedResponse

type InvoiceRedResponse = []InvoiceNoRed

type InvoiceStatusRequest

type InvoiceStatusRequest struct {
	SellerTaxPayerNumber string `json:"seller_taxpayer_num"` // 销货方税号
	OrderId              string `json:"order_id,omitempty"`  // 三方订单号(和order_sn二选一必填)
	OrderSn              string `json:"order_sn,omitempty"`  // 平台订单号(和order_id二选一必填)
}

type InvoiceStatusResponse

type InvoiceStatusResponse struct {
	OrderId          string `json:"order_id"`           // 三方订单号
	OrderSn          string `json:"order_sn,omitempty"` // 平台订单号
	Status           uint8  `json:"status"`             // 冲红状态(见constant定义)
	Message          string `json:"message"`            // 开票错误信息
	TicketDate       string `json:"ticket_date"`        // 开票日期
	TicketSn         string `json:"ticket_sn"`          // 发票号码
	TicketCode       string `json:"ticket_code"`        // 发票代码
	CheckCode        string `json:"check_code"`         // 发票校验码
	AmountWithTax    string `json:"amount_with_tax"`    // 含税金额(元)
	AmountWithoutTax string `json:"amount_without_tax"` // 不含税金额(元)
	TaxAmount        string `json:"tax_amount"`         // 税额(元)
	IsRed            uint8  `json:"is_red_washed"`      // 是否被红冲
	PdfUrl           string `json:"pdf_url"`            // 发票pdf文件url
}

type InvoiceVerifyRequest

type InvoiceVerifyRequest struct {
	TicketCode string `json:"ticket_code"`          // 发票代码
	TicketSn   string `json:"ticket_sn"`            // 发票号码
	TicketDate string `json:"ticket_date"`          // 开票日期
	Additional string `json:"additional,omitempty"` // 发票校验码后6位(增值税专用发票,增值税机动车发票,二手车统一发票可以不传)
}

type InvoiceVerifyResponse

type InvoiceVerifyResponse struct {
	Status       uint8         `json:"status"`        // 销方名称
	OriginStatus string        `json:"origin_status"` // 详细状态(详见附录)
	Message      string        `json:"message"`       // 查询描述
	Invoice      InvoiceDetail `json:"invoice"`       // 发票信息
}

type Item

type Item struct {
	Name                   string `json:"name"`                               // 商品名(见constant定义)
	TaxCode                string `json:"tax_code"`                           // 税目编码(见constant定义)
	TaxType                string `json:"tax_type,omitempty"`                 // 税目类别
	Models                 string `json:"models,omitempty"`                   // 商品规格
	Unit                   string `json:"unit,omitempty"`                     // 计量单位
	TotalPrice             int64  `json:"total_price"`                        // 不含税商品总金额(精确到2位)
	Total                  string `json:"total"`                              // 商品数量
	Price                  string `json:"price"`                              // 不含税商品单价
	TaxRate                int64  `json:"tax_rate"`                           // 税率(千分位,税率*1000)
	TaxAmount              int64  `json:"tax_amount"`                         // 税额(单分)
	Discount               int64  `json:"discount,omitempty"`                 // 总的折扣金额;金额必须是负数;无折扣时不传
	ZeroTaxFlag            string `json:"zero_tax_flag,omitempty"`            // 零税率标识,默认为空(见constant定义)
	PreferentialPolicyFlag string `json:"preferential_policy_flag,omitempty"` // 优惠政策标志(见constant定义)
	VatSpecialManagement   string `json:"vat_special_management,omitempty"`   // 增值税特殊管理
}

type ItemDetail

type ItemDetail struct {
	LineNo           string `json:"line_no"`            // 项目行号
	Name             string `json:"name"`               // 商品名
	Model            string `json:"model"`              // 商品规格
	Unit             string `json:"unit"`               // 计量单位
	Number           string `json:"num"`                // 商品数量
	Price            string `json:"per_price"`          // 商品单价
	AmountWithoutTax string `json:"amount_without_tax"` // 不含税金额
	TaxRate          string `json:"tax_rate"`           // 税率
	TaxAmount        string `json:"tax_amount"`         // 税额
}

type ResponseModel

type ResponseModel struct {
	Code uint16      `json:"code"`    // 状态码
	Msg  string      `json:"message"` // 错误信息
	Data interface{} `json:"data"`    // 业务逻辑返回
}

返回结果的通信标识

Directories

Path Synopsis
golden

Jump to

Keyboard shortcuts

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