蛋蛋星球-制度模式
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

116 satır
2.9 KiB

  1. package saobei
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/go-pay/gopay"
  6. "github.com/go-pay/xlog"
  7. )
  8. // 小程序支付接口
  9. func TestClient_MiniPay(t *testing.T) {
  10. // 请求参数
  11. bm := make(gopay.BodyMap)
  12. bm.Set("pay_type", "010").
  13. Set("terminal_ip", "127.0.0.1").
  14. Set("terminal_trace", "larry01").
  15. Set("terminal_time", time.Now().Format("20060102150405")).
  16. Set("total_fee", "1").
  17. Set("sub_appid", "wx91b9fee6ce0135c9").
  18. Set("open_id", "oXJQK5paQaKRhgrXm_ZzF_8azJj0")
  19. resp, err := client.MiniPay(ctx, bm)
  20. xlog.Debugf("saobeiRsp:%+v", resp)
  21. if err != nil {
  22. xlog.Errorf("%+v", err)
  23. return
  24. }
  25. }
  26. // 付款码支付(扫码支付)
  27. func TestClient_BarcodePay(t *testing.T) {
  28. terminalTrace := "larry02456" // 终端流水号,填写商户系统的支付订单号,不可重复
  29. terminalTime := time.Now().Format("20060102150405") // 终端交易时间,yyyyMMddHHmmss,全局统一时间格式
  30. // 请求参数
  31. bm := make(gopay.BodyMap)
  32. bm.Set("pay_type", "010").
  33. Set("terminal_ip", "127.0.0.1").
  34. Set("terminal_trace", terminalTrace).
  35. Set("terminal_time", terminalTime).
  36. Set("total_fee", "1").
  37. Set("auth_no", "132038911197761804")
  38. resp, err := client.BarcodePay(ctx, bm)
  39. xlog.Debugf("saobeiRsp:%+v", resp)
  40. if err != nil {
  41. xlog.Errorf("%+v", err)
  42. return
  43. }
  44. xlog.Debugf("terminal_trace:%s", terminalTrace)
  45. xlog.Debugf("terminal_time:%s", terminalTime)
  46. }
  47. // 支付查询
  48. func TestClient_Query(t *testing.T) {
  49. // out_trade_no 和 pay_trace|pay_time 两种方式二选一
  50. // 请求参数
  51. bm := make(gopay.BodyMap)
  52. bm.Set("pay_type", "010").
  53. Set("terminal_trace", "larry02456").
  54. Set("terminal_time", "20231008133303").
  55. Set("out_trade_no", "443505910021123100813330300001")
  56. //Set("pay_trace", "larry02456"). // terminal_trace
  57. //Set("pay_time", "20231008133303") // terminal_time
  58. resp, err := client.Query(ctx, bm)
  59. xlog.Debugf("saobeiRsp:%+v", resp)
  60. if err != nil {
  61. xlog.Errorf("%+v", err)
  62. return
  63. }
  64. }
  65. // 退款申请
  66. func TestClient_Refund(t *testing.T) {
  67. // out_trade_no 和 pay_trace|pay_time 两种方式二选一
  68. // 请求参数
  69. bm := make(gopay.BodyMap)
  70. bm.Set("pay_type", "010").
  71. Set("terminal_trace", "larry02456").
  72. Set("terminal_time", "20231008133303").
  73. Set("refund_fee", "1").
  74. Set("out_trade_no", "443505910021123100813330300001")
  75. //Set("pay_trace", "larry02456"). // terminal_trace
  76. //Set("pay_time", "20231008133303") // terminal_time
  77. resp, err := client.Refund(ctx, bm)
  78. xlog.Debugf("saobeiRsp:%+v", resp)
  79. if err != nil {
  80. xlog.Errorf("%+v", err)
  81. return
  82. }
  83. }
  84. // 退款订单查询
  85. func TestClient_QueryRefund(t *testing.T) {
  86. // 请求参数
  87. bm := make(gopay.BodyMap)
  88. bm.Set("pay_type", "010").
  89. Set("terminal_trace", "larry02456").
  90. Set("terminal_time", "20231008133303").
  91. Set("out_refund_no", "1111111")
  92. resp, err := client.QueryRefund(ctx, bm)
  93. xlog.Debugf("saobeiRsp:%+v", resp)
  94. if err != nil {
  95. xlog.Errorf("%+v", err)
  96. return
  97. }
  98. }