You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-library/service/ejiaofei/check_cost.go

49 lines
1.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package ejiaofei
import (
"context"
"encoding/xml"
"fmt"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
)
type CheckCostResponse struct {
XMLName xml.Name `xml:"response"`
UserID string `xml:"userid"` // 用户账号
OrderID string `xml:"orderid"` // 用户提交订单号
Face float64 `xml:"face"` // 官方价格
Price float64 `xml:"price"` // 用户成本价
Error int64 `xml:"error"` // 错误提示
}
type CheckCostResult struct {
Result CheckCostResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
}
func newCheckCostResult(result CheckCostResponse, body []byte, http gorequest.Response) *CheckCostResult {
return &CheckCostResult{Result: result, Body: body, Http: http}
}
// CheckCost 会员订单成本价查询接口
// orderID 用户提交的订单号 用户提交的订单号最长32位用户保证其唯一性
func (c *Client) CheckCost(ctx context.Context, orderId string) (*CheckCostResult, error) {
// 参数
param := gorequest.NewParams()
param.Set("orderid", orderId)
params := gorequest.NewParamsWith(param)
// 签名
c.config.signStr = fmt.Sprintf("userid%vpwd%vorderid%v", c.GetUserId(), c.GetPwd(), orderId)
// 请求
request, err := c.request(ctx, apiUrl+"/checkCost.do", params, http.MethodGet)
if err != nil {
return newCheckCostResult(CheckCostResponse{}, request.ResponseBody, request), err
}
// 定义
var response CheckCostResponse
err = xml.Unmarshal(request.ResponseBody, &response)
return newCheckCostResult(response, request.ResponseBody, request), err
}