This commit is contained in:
parent
f352a4349f
commit
f6e56fe462
|
|
@ -122,18 +122,18 @@ func (c *Client) doRequest(ctx context.Context, path string, request interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析通用响应
|
// 解析通用响应
|
||||||
var commonResp CommonResponse
|
//var commonResp CommonResponse
|
||||||
if err := json.Unmarshal(respBody, &commonResp); err != nil {
|
//if err := json.Unmarshal(respBody, &commonResp); err != nil {
|
||||||
return NewSDKError(ErrCodeUnknown, "响应解析失败", err)
|
// return NewSDKError(ErrCodeUnknown, "响应解析失败", err)
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
if commonResp.Code != 0 {
|
//if commonResp.Code != 0 {
|
||||||
return NewSDKError(commonResp.Code, commonResp.Msg, nil)
|
// return NewSDKError(commonResp.Code, commonResp.Msg, nil)
|
||||||
}
|
//}
|
||||||
|
|
||||||
// 如果response不为nil,将commonResp.Data反序列化到response
|
// 如果response不为nil,将commonResp.Data反序列化到response
|
||||||
if response != nil {
|
if response != nil {
|
||||||
if err := json.Unmarshal(commonResp.Data, response); err != nil {
|
if err := json.Unmarshal(respBody, response); err != nil {
|
||||||
return NewSDKError(ErrCodeUnknown, "响应数据解析失败", err)
|
return NewSDKError(ErrCodeUnknown, "响应数据解析失败", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -148,7 +148,7 @@ func (c *Client) doRequest(ctx context.Context, path string, request interface{}
|
||||||
// CreateInvoice 提交订单开票申请
|
// CreateInvoice 提交订单开票申请
|
||||||
// 文档:接口1 - 提交订单开票申请
|
// 文档:接口1 - 提交订单开票申请
|
||||||
func (c *Client) CreateInvoice(ctx context.Context, req *CreateInvoiceRequest) (*CreateInvoiceResponse, error) {
|
func (c *Client) CreateInvoice(ctx context.Context, req *CreateInvoiceRequest) (*CreateInvoiceResponse, error) {
|
||||||
path := "/api/v1/invoice/create"
|
path := "OZu"
|
||||||
var resp CreateInvoiceResponse
|
var resp CreateInvoiceResponse
|
||||||
if err := c.doRequest(ctx, path, req, &resp); err != nil {
|
if err := c.doRequest(ctx, path, req, &resp); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -163,7 +163,7 @@ func (c *Client) CreateInvoice(ctx context.Context, req *CreateInvoiceRequest) (
|
||||||
// QueryInvoiceStatus 查询订单开票状态
|
// QueryInvoiceStatus 查询订单开票状态
|
||||||
// 文档:接口2 - 查询订单开票状态
|
// 文档:接口2 - 查询订单开票状态
|
||||||
func (c *Client) QueryInvoiceStatus(ctx context.Context, req *QueryInvoiceStatusRequest) (*QueryInvoiceStatusResponse, error) {
|
func (c *Client) QueryInvoiceStatus(ctx context.Context, req *QueryInvoiceStatusRequest) (*QueryInvoiceStatusResponse, error) {
|
||||||
path := "/api/v1/invoice/query"
|
path := "OZv"
|
||||||
var resp QueryInvoiceStatusResponse
|
var resp QueryInvoiceStatusResponse
|
||||||
if err := c.doRequest(ctx, path, req, &resp); err != nil {
|
if err := c.doRequest(ctx, path, req, &resp); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import (
|
||||||
|
|
||||||
// GenerateTimestamp 生成秒级时间戳字符串
|
// GenerateTimestamp 生成秒级时间戳字符串
|
||||||
func GenerateTimestamp() string {
|
func GenerateTimestamp() string {
|
||||||
return fmt.Sprintf("%d", time.Now().Unix())
|
return fmt.Sprintf("%d", time.Now().UnixMilli())
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateNonce 生成指定长度的加密安全随机字符串
|
// GenerateNonce 生成指定长度的加密安全随机字符串
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,18 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strconv"
|
||||||
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ApiBaseURL = "https://bfl.jcsk100.com/webhook/"
|
||||||
|
tenantID = "142"
|
||||||
|
clientID = "webhook_lsxd"
|
||||||
|
clientSecret = "wNKmz2VrSTawWLG5CoYNP9HLbQ6I4Cei"
|
||||||
|
)
|
||||||
|
|
||||||
// ExampleNewClient 展示了如何创建SDK客户端
|
// ExampleNewClient 展示了如何创建SDK客户端
|
||||||
func ExampleNewClient() {
|
func ExampleNewClient() {
|
||||||
// 创建客户端
|
// 创建客户端
|
||||||
|
|
@ -24,21 +33,22 @@ func ExampleNewClient() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExampleClient_CreateInvoice 展示了如何提交订单开票申请
|
// ExampleClient_CreateInvoice 展示了如何提交订单开票申请
|
||||||
func ExampleClient_CreateInvoice() {
|
func Test_ExampleClient_CreateInvoice(t *testing.T) {
|
||||||
client := NewClient(
|
client := NewClient(
|
||||||
"https://api.example.com",
|
ApiBaseURL,
|
||||||
"your-tenant-id",
|
tenantID,
|
||||||
"dd-ai-table",
|
clientID,
|
||||||
"your-client-secret",
|
clientSecret,
|
||||||
|
WithDebug(true),
|
||||||
)
|
)
|
||||||
|
|
||||||
req := &CreateInvoiceRequest{
|
req := &CreateInvoiceRequest{
|
||||||
OrderID: "ORDER20240101001",
|
OrderID: "testOrder" + strconv.FormatInt(time.Now().Unix(), 10),
|
||||||
InvoiceType: 9, // 数电普票
|
InvoiceType: 9, // 数电普票
|
||||||
Purchaser: "测试购买方有限公司",
|
Purchaser: "测试购买方有限公司",
|
||||||
TaxNum: "91110108MA12345678",
|
TaxNum: "91110108MA12345678",
|
||||||
Phone: "13800138000",
|
Phone: "13800138000",
|
||||||
Email: "test@example.com",
|
Email: "",
|
||||||
Products: []InvoiceProduct{
|
Products: []InvoiceProduct{
|
||||||
{
|
{
|
||||||
ProductName: "办公用品",
|
ProductName: "办公用品",
|
||||||
|
|
@ -61,23 +71,26 @@ func ExampleClient_CreateInvoice() {
|
||||||
log.Fatalf("创建开票申请失败: %v", err)
|
log.Fatalf("创建开票申请失败: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("开票状态: %d, 错误信息: %s\n", resp.Status, resp.ErrorMsg)
|
fmt.Printf("开票状态: %d, 错误信息: %s\n", resp.Code, resp.Msg)
|
||||||
for i, inv := range resp.DataList {
|
if resp.Data == "true" {
|
||||||
fmt.Printf("发票%d: 代码=%s, 号码=%s, 金额(含税)=%s\n", i+1, inv.InvoiceCode, inv.InvoiceNo, inv.TotalIncludeTax)
|
fmt.Printf("开票成功")
|
||||||
|
} else {
|
||||||
|
fmt.Printf("开票失败")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExampleClient_QueryInvoiceStatus 展示了如何查询开票状态
|
// ExampleClient_QueryInvoiceStatus 展示了如何查询开票状态
|
||||||
func ExampleClient_QueryInvoiceStatus() {
|
func Test_ExampleClient_QueryInvoiceStatus(t *testing.T) {
|
||||||
client := NewClient(
|
client := NewClient(
|
||||||
"https://api.example.com",
|
ApiBaseURL,
|
||||||
"your-tenant-id",
|
tenantID,
|
||||||
"dd-ai-table",
|
clientID,
|
||||||
"your-client-secret",
|
clientSecret,
|
||||||
|
WithDebug(true),
|
||||||
)
|
)
|
||||||
|
|
||||||
req := &QueryInvoiceStatusRequest{
|
req := &QueryInvoiceStatusRequest{
|
||||||
OrderID: "ORDER20240101001",
|
OrderID: "testOrder1787018268",
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.QueryInvoiceStatus(context.Background(), req)
|
resp, err := client.QueryInvoiceStatus(context.Background(), req)
|
||||||
|
|
@ -85,7 +98,11 @@ func ExampleClient_QueryInvoiceStatus() {
|
||||||
log.Fatalf("查询开票状态失败: %v", err)
|
log.Fatalf("查询开票状态失败: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("开票状态: %d, 描述: %s\n", resp.Status, resp.Message)
|
fmt.Printf("开票状态查询: %d, 错误信息: %s,当前状态:%s\n", resp.Code, resp.Msg, resp.Data.Message)
|
||||||
|
if resp.Data.InvoiceDateList != nil {
|
||||||
|
invoce, _ := json.Marshal(resp.Data.InvoiceDateList)
|
||||||
|
fmt.Printf(string(invoce))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExampleClient_CreatePayment 展示了如何创建付款单据
|
// ExampleClient_CreatePayment 展示了如何创建付款单据
|
||||||
|
|
@ -187,14 +204,14 @@ func ExampleClient_CreateSupplier() {
|
||||||
CorpID: "dingXXXXXX",
|
CorpID: "dingXXXXXX",
|
||||||
Creator: "user123",
|
Creator: "user123",
|
||||||
SupplierInfo: &SupplierInfo{
|
SupplierInfo: &SupplierInfo{
|
||||||
Name: "测试供应商有限公司",
|
Name: "测试供应商有限公司",
|
||||||
CorpID: "dingXXXXXX",
|
CorpID: "dingXXXXXX",
|
||||||
Creator: "user123",
|
Creator: "user123",
|
||||||
UserDefineCode: "SUP-001",
|
UserDefineCode: "SUP-001",
|
||||||
ContactName: "张三",
|
ContactName: "张三",
|
||||||
ContactTelephone: "13800138000",
|
ContactTelephone: "13800138000",
|
||||||
ContactEmail: "contact@supplier.com",
|
ContactEmail: "contact@supplier.com",
|
||||||
ContactAddress: "北京市朝阳区XX路XX号",
|
ContactAddress: "北京市朝阳区XX路XX号",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -270,14 +287,14 @@ func ExampleClient_UpdateSupplier() {
|
||||||
)
|
)
|
||||||
|
|
||||||
bizData := UpdateSupplierBizData{
|
bizData := UpdateSupplierBizData{
|
||||||
SupplierID: "SUP_XXXXX",
|
SupplierID: "SUP_XXXXX",
|
||||||
Name: "更新后的供应商名称",
|
Name: "更新后的供应商名称",
|
||||||
CorpID: "dingXXXXXX",
|
CorpID: "dingXXXXXX",
|
||||||
UserID: "user123",
|
UserID: "user123",
|
||||||
ContactName: "李四",
|
ContactName: "李四",
|
||||||
ContactTelephone: "13900139000",
|
ContactTelephone: "13900139000",
|
||||||
ContactEmail: "new@supplier.com",
|
ContactEmail: "new@supplier.com",
|
||||||
Description: "长期合作供应商",
|
Description: "长期合作供应商",
|
||||||
}
|
}
|
||||||
|
|
||||||
bizDataBytes, _ := json.Marshal(bizData)
|
bizDataBytes, _ := json.Marshal(bizData)
|
||||||
|
|
|
||||||
|
|
@ -26,25 +26,25 @@ type NotificationRequest struct {
|
||||||
|
|
||||||
// CreateInvoiceRequest 提交订单开票申请请求
|
// CreateInvoiceRequest 提交订单开票申请请求
|
||||||
type CreateInvoiceRequest struct {
|
type CreateInvoiceRequest struct {
|
||||||
CompanyCode string `json:"companyCode,omitempty"`
|
CompanyCode string `json:"companyCode,omitempty"`
|
||||||
OrderID string `json:"orderId"`
|
OrderID string `json:"orderId"`
|
||||||
InvoiceType int `json:"invoiceType"`
|
InvoiceType int `json:"invoiceType"`
|
||||||
Products []InvoiceProduct `json:"products"`
|
Products []InvoiceProduct `json:"products"`
|
||||||
Remark string `json:"remark,omitempty"`
|
Remark string `json:"remark,omitempty"`
|
||||||
Purchaser string `json:"purchaser"`
|
Purchaser string `json:"purchaser"`
|
||||||
TaxNum string `json:"taxnum,omitempty"`
|
TaxNum string `json:"taxnum,omitempty"`
|
||||||
PurchaserAddr string `json:"purchaserAddress,omitempty"`
|
PurchaserAddr string `json:"purchaserAddress,omitempty"`
|
||||||
PurchaserTel string `json:"purchaserTel,omitempty"`
|
PurchaserTel string `json:"purchaserTel,omitempty"`
|
||||||
BankName string `json:"bankName,omitempty"`
|
BankName string `json:"bankName,omitempty"`
|
||||||
BankAccount string `json:"bankAccount,omitempty"`
|
BankAccount string `json:"bankAccount,omitempty"`
|
||||||
Phone string `json:"phone,omitempty"`
|
Phone string `json:"phone,omitempty"`
|
||||||
Email string `json:"email,omitempty"`
|
Email string `json:"email,omitempty"`
|
||||||
ApplyPerson string `json:"applyPerson,omitempty"`
|
ApplyPerson string `json:"applyPerson,omitempty"`
|
||||||
Payee string `json:"payee,omitempty"`
|
Payee string `json:"payee,omitempty"`
|
||||||
Reviewer string `json:"reviewer,omitempty"`
|
Reviewer string `json:"reviewer,omitempty"`
|
||||||
InvoiceRemark string `json:"invoiceRemark,omitempty"`
|
InvoiceRemark string `json:"invoiceRemark,omitempty"`
|
||||||
NaturalPerson string `json:"naturalPerson,omitempty"`
|
NaturalPerson string `json:"naturalPerson,omitempty"`
|
||||||
AdditionInfo string `json:"additionInfo,omitempty"`
|
AdditionInfo string `json:"additionInfo,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InvoiceProduct 货物/服务明细
|
// InvoiceProduct 货物/服务明细
|
||||||
|
|
@ -62,6 +62,13 @@ type InvoiceProduct struct {
|
||||||
|
|
||||||
// CreateInvoiceResponse 提交订单开票申请响应
|
// CreateInvoiceResponse 提交订单开票申请响应
|
||||||
type CreateInvoiceResponse struct {
|
type CreateInvoiceResponse struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Msg string `json:"msg"`
|
||||||
|
Data string `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开票回调
|
||||||
|
type CreateInvoiceNotify struct {
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
ErrorMsg string `json:"errorMsg,omitempty"`
|
ErrorMsg string `json:"errorMsg,omitempty"`
|
||||||
DataList []InvoiceData `json:"dataList"`
|
DataList []InvoiceData `json:"dataList"`
|
||||||
|
|
@ -138,11 +145,14 @@ type QueryInvoiceStatusRequest struct {
|
||||||
OrderID string `json:"orderId"`
|
OrderID string `json:"orderId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryInvoiceStatusResponse 查询订单开票状态响应
|
|
||||||
type QueryInvoiceStatusResponse struct {
|
type QueryInvoiceStatusResponse struct {
|
||||||
Status int `json:"status"`
|
Code int `json:"code"`
|
||||||
Message string `json:"message"`
|
Msg string `json:"msg"`
|
||||||
Data []InvoiceData `json:"data"`
|
Data struct {
|
||||||
|
InvoiceDateList []interface{} `json:"invoiceDateList"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Status int `json:"status"`
|
||||||
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
|
|
@ -275,26 +285,26 @@ type CreatePaymentResponse struct {
|
||||||
|
|
||||||
// PaymentNotification 支付完成通知数据结构
|
// PaymentNotification 支付完成通知数据结构
|
||||||
type PaymentNotification struct {
|
type PaymentNotification struct {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
InstanceID string `json:"instanceId"`
|
InstanceID string `json:"instanceId"`
|
||||||
CorpID string `json:"corpId"`
|
CorpID string `json:"corpId"`
|
||||||
PaymentStatus string `json:"paymentStatus"`
|
PaymentStatus string `json:"paymentStatus"`
|
||||||
PaymentTime string `json:"paymentTime"`
|
PaymentTime string `json:"paymentTime"`
|
||||||
UserID string `json:"userId"`
|
UserID string `json:"userId"`
|
||||||
FailReason string `json:"failReason,omitempty"`
|
FailReason string `json:"failReason,omitempty"`
|
||||||
PayerAccountInfo *PayerAccountInfo `json:"payerAccountInfo,omitempty"`
|
PayerAccountInfo *PayerAccountInfo `json:"payerAccountInfo,omitempty"`
|
||||||
PayeeAccountInfo *PayeeAccountInfo `json:"payeeAccountInfo,omitempty"`
|
PayeeAccountInfo *PayeeAccountInfo `json:"payeeAccountInfo,omitempty"`
|
||||||
RelatedRowNumberList []string `json:"relatedRowNumberList,omitempty"`
|
RelatedRowNumberList []string `json:"relatedRowNumberList,omitempty"`
|
||||||
Source string `json:"source,omitempty"`
|
Source string `json:"source,omitempty"`
|
||||||
Template string `json:"template,omitempty"`
|
Template string `json:"template,omitempty"`
|
||||||
Amount string `json:"amount,omitempty"`
|
Amount string `json:"amount,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PayerAccountInfo 付款账户信息
|
// PayerAccountInfo 付款账户信息
|
||||||
type PayerAccountInfo struct {
|
type PayerAccountInfo struct {
|
||||||
BankOpenDTO *BankOpenDTO `json:"bankOpenDTO,omitempty"`
|
BankOpenDTO *BankOpenDTO `json:"bankOpenDTO,omitempty"`
|
||||||
EnterpriseAccountCode string `json:"enterpriseAccountCode,omitempty"`
|
EnterpriseAccountCode string `json:"enterpriseAccountCode,omitempty"`
|
||||||
AccountType string `json:"accountType,omitempty"`
|
AccountType string `json:"accountType,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PayeeAccountInfo 收款账户信息
|
// PayeeAccountInfo 收款账户信息
|
||||||
|
|
@ -349,26 +359,26 @@ type CreateSupplierBizData struct {
|
||||||
|
|
||||||
// SupplierInfo 供应商数据
|
// SupplierInfo 供应商数据
|
||||||
type SupplierInfo struct {
|
type SupplierInfo struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
CorpID string `json:"corpId"`
|
CorpID string `json:"corpId"`
|
||||||
UserDefineCode string `json:"userDefineCode,omitempty"`
|
UserDefineCode string `json:"userDefineCode,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
ContactAddress string `json:"contactAddress,omitempty"`
|
ContactAddress string `json:"contactAddress,omitempty"`
|
||||||
ContactCompanyTelephone string `json:"contactCompanyTelephone,omitempty"`
|
ContactCompanyTelephone string `json:"contactCompanyTelephone,omitempty"`
|
||||||
ContactEmail string `json:"contactEmail,omitempty"`
|
ContactEmail string `json:"contactEmail,omitempty"`
|
||||||
ContactName string `json:"contactName,omitempty"`
|
ContactName string `json:"contactName,omitempty"`
|
||||||
ContactTelephone string `json:"contactTelephone,omitempty"`
|
ContactTelephone string `json:"contactTelephone,omitempty"`
|
||||||
Creator string `json:"creator"`
|
Creator string `json:"creator"`
|
||||||
InvoiceAccount string `json:"invoiceAccount,omitempty"`
|
InvoiceAccount string `json:"invoiceAccount,omitempty"`
|
||||||
InvoiceAddress string `json:"invoiceAddress,omitempty"`
|
InvoiceAddress string `json:"invoiceAddress,omitempty"`
|
||||||
InvoiceBankName string `json:"invoiceBankName,omitempty"`
|
InvoiceBankName string `json:"invoiceBankName,omitempty"`
|
||||||
InvoiceName string `json:"invoiceName,omitempty"`
|
InvoiceName string `json:"invoiceName,omitempty"`
|
||||||
InvoiceTaxNo string `json:"invoiceTaxNo,omitempty"`
|
InvoiceTaxNo string `json:"invoiceTaxNo,omitempty"`
|
||||||
PurchaserTel string `json:"purchaserTel,omitempty"`
|
PurchaserTel string `json:"purchaserTel,omitempty"`
|
||||||
BankName string `json:"bankName,omitempty"`
|
BankName string `json:"bankName,omitempty"`
|
||||||
InvoiceTelephone string `json:"invoiceTelephone,omitempty"`
|
InvoiceTelephone string `json:"invoiceTelephone,omitempty"`
|
||||||
AccountName string `json:"accountName,omitempty"`
|
AccountName string `json:"accountName,omitempty"`
|
||||||
AccountType string `json:"accountType,omitempty"`
|
AccountType string `json:"accountType,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateSupplierResponse 创建供应商响应
|
// CreateSupplierResponse 创建供应商响应
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue