package lib import ( "Cold_Api/conf" "github.com/beego/beego/v2/core/logs" "encoding/json" "fmt" "github.com/go-resty/resty/v2" ) // {"Code".200,"CodeUrl":"weixin://wxpay/bizpayurl?pr=NtLrWvBzz","Message":"成功"} type WeixinRes struct { Code int `json:"Code"` CodeUrl string `json:"CodeUrl"` Message string `json:"Message"` OrderNo string `json:"OrderNo"` } func PayTransactionNative(title string, total float64) (WeixinRes, error) { type Vars struct { PwdKey string Title string Total float32 Notify string } client := resty.New() resp, err := client.R(). SetHeader("Content-Type", "application/x-www-form-urlencoded"). SetFormData(map[string]string{ "PwdKey": conf.Weixin_PwdKey, "Notify": conf.Weixin_Notify, "Title": title, "Total": fmt.Sprintf("%f", total), }). Post("https://cold.coldbaozhida.com/wxpay_wxb5b2c9147ae0b9db/PayTransactionNative") if err != nil { return WeixinRes{}, err } temp := WeixinRes{} if err = json.Unmarshal(resp.Body(), &temp); err != nil { logs.Error(FuncName(), err) return WeixinRes{}, err } return temp, nil }