weixin.go 1.1 KB

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