54 lines
2.5 KiB
Go
54 lines
2.5 KiB
Go
package mtwmapi
|
||
|
||
import (
|
||
"fmt"
|
||
"git.rosy.net.cn/baseapi/utils"
|
||
"strings"
|
||
)
|
||
|
||
type InvoiceCallback struct {
|
||
Timestamp string `json:"timestamp"` // 时间戳
|
||
AppId string `json:"app_id"` // 美团分配给APP方的id
|
||
Sig string `json:"sig"` // 输入参数计算后的签名结果
|
||
MtRequestId string `json:"mt_request_id"` // 平台请求id,由平台自动生成并保证唯一性,不参与业务逻辑,在接口响应时返回给商家系统
|
||
OrderId string `json:"order_id"` // 订单ID
|
||
InvoiceTaskId string `json:"invoice_task_id"` // 开票任务id
|
||
PushType string `json:"push_type"` // 消息类型,1-开发票,3-催发票
|
||
InvoiceTitle string `json:"invoice_title"` // 发票的抬头。
|
||
TaxpayerId string `json:"taxpayer_id"` // 纳税人识别号
|
||
NeedInvoiceByCategory int `json:"need_invoice_by_category"` // 1-需要按大类开票;2-需要商品明细开
|
||
CompanyAddress string `json:"company_address"` // 公司地址
|
||
CompanyPhone string `json:"company_phone"` // 电话
|
||
AccountBank string `json:"account_bank"` // 开户银行
|
||
AccountNumber string `json:"account_number"` // 开户账号
|
||
Email string `json:"email"` // 邮箱
|
||
EmailExpireTime int64 `json:"email_expire_time"` // 邮箱有效期
|
||
ItemTotalInvoiceAmount int64 `json:"item_total_invoice_amount"` // 商家开票金额
|
||
}
|
||
|
||
// UploadInvoice 上传发票给用户
|
||
func (a *API) UploadInvoice(orderId, invoiceUrl, invoiceId, taskId string) (err error) {
|
||
resp, err := a.AccessAPI2("ecommerce/invoice/upload", false, map[string]interface{}{
|
||
KeyOrderID: orderId,
|
||
"invoice_url": invoiceUrl,
|
||
"invoice_id": invoiceId,
|
||
"invoice_task_id": taskId,
|
||
}, "", "")
|
||
|
||
if err != nil {
|
||
return err
|
||
}
|
||
|
||
if utils.MustInterface2Int64(resp.(map[string]interface{})["result_code"]) == 1 {
|
||
return nil
|
||
}
|
||
|
||
errMsg := make([]string, 0, 0)
|
||
if resp.(map[string]interface{})["error_list"] != nil {
|
||
for _, v := range resp.(map[string]interface{})["error_list"].([]interface{}) {
|
||
errMsg = append(errMsg, v.(map[string]interface{})["msg"].(string))
|
||
}
|
||
}
|
||
return fmt.Errorf("%s", strings.Join(errMsg, ","))
|
||
}
|