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