wx_Refund.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package wechat
  2. import (
  3. "fmt"
  4. "github.com/iGoogle-ink/gopay"
  5. "github.com/iGoogle-ink/gopay/wechat"
  6. )
  7. func Refund() {
  8. //初始化微信客户端
  9. // appId:应用ID
  10. // MchID:商户ID
  11. // ApiKey:Key值
  12. // isProd:是否是正式环境
  13. client := wechat.NewClient("wxdaa2ab9ef87b5497", "1368139502", "GFDS8j98rewnmgl45wHTt980jg543abc", false)
  14. // 初始化参数结构体
  15. bm := make(gopay.BodyMap)
  16. bm.Set("out_trade_no", "SdZBAqJHBQGKVwb7aMR2mUwC588NG2Sd")
  17. bm.Set("nonce_str", gopay.GetRandomString(32))
  18. bm.Set("sign_type", wechat.SignType_MD5)
  19. s := gopay.GetRandomString(64)
  20. fmt.Println("out_refund_no:", s)
  21. bm.Set("out_refund_no", s)
  22. bm.Set("total_fee", 1)
  23. bm.Set("refund_fee", 1)
  24. bm.Set("notify_url", "https://www.gopay.ink")
  25. //请求申请退款(沙箱环境下,证书路径参数可传空)
  26. // body:参数Body
  27. // certFilePath:cert证书路径
  28. // keyFilePath:Key证书路径
  29. // pkcs12FilePath:p12证书路径
  30. wxRsp, err := client.Refund(bm, "iguiyu_cert/apiclient_cert.pem", "iguiyu_cert/apiclient_key.pem", "iguiyu_cert/apiclient_cert.p12")
  31. if err != nil {
  32. fmt.Println("Error:", err)
  33. return
  34. }
  35. fmt.Println("wxRsp:", *wxRsp)
  36. }