wxpay.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package lib
  2. import (
  3. "Cold_Api/conf"
  4. "github.com/beego/beego/v2/core/logs"
  5. "encoding/json"
  6. "fmt"
  7. "github.com/go-resty/resty/v2"
  8. )
  9. // {"Code".200,"CodeUrl":"weixin://wxpay/bizpayurl?pr=NtLrWvBzz","Message":"成功"}
  10. type WeixinRes struct {
  11. Code int `json:"Code"`
  12. CodeUrl string `json:"CodeUrl"`
  13. Message string `json:"Message"`
  14. OrderNo string `json:"OrderNo"`
  15. }
  16. func PayTransactionNative(title string, total float64) (WeixinRes, error) {
  17. type Vars struct {
  18. PwdKey string
  19. Title string
  20. Total float32
  21. Notify string
  22. }
  23. client := resty.New()
  24. resp, err := client.R().
  25. SetHeader("Content-Type", "application/x-www-form-urlencoded").
  26. SetFormData(map[string]string{
  27. "PwdKey": conf.Weixin_PwdKey,
  28. "Notify": conf.Weixin_Notify,
  29. "Title": title,
  30. "Total": fmt.Sprintf("%f", total),
  31. }).
  32. Post("https://cold.coldbaozhida.com/wxpay_wxb5b2c9147ae0b9db/PayTransactionNative")
  33. if err != nil {
  34. return WeixinRes{}, err
  35. }
  36. temp := WeixinRes{}
  37. if err = json.Unmarshal(resp.Body(), &temp); err != nil {
  38. logs.Error(FuncName(), err)
  39. return WeixinRes{}, err
  40. }
  41. return temp, nil
  42. }