蛋蛋星球-制度模式
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.

103 satır
2.7 KiB

  1. package wechat
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/go-pay/gopay"
  6. "github.com/go-pay/util"
  7. "github.com/go-pay/xlog"
  8. )
  9. func TestClient_EntrustPublic(t *testing.T) {
  10. // 初始化参数结构体
  11. bm := make(gopay.BodyMap)
  12. bm.Set("plan_id", "12535").
  13. Set("contract_code", "100000").
  14. Set("request_serial", "1000").
  15. Set("contract_display_account", "微信代扣").
  16. Set("notify_url", "https://www.igoogle.ink").
  17. Set("version", "1.0").
  18. Set("timestamp", time.Now().Unix())
  19. // 公众号纯签约
  20. wxRsp, err := client.EntrustPublic(ctx, bm)
  21. if err != nil {
  22. xlog.Errorf("client.EntrustPublic(%+v),error:%+v", bm, err)
  23. return
  24. }
  25. xlog.Debug("wxRsp:", wxRsp)
  26. }
  27. func TestClient_EntrustAppPre(t *testing.T) {
  28. // 初始化参数结构体
  29. bm := make(gopay.BodyMap)
  30. bm.Set("plan_id", "12535").
  31. Set("contract_code", "100000").
  32. Set("request_serial", "1000").
  33. Set("contract_display_account", "微信代扣").
  34. Set("notify_url", "https://www.igoogle.ink").
  35. Set("version", "1.0").
  36. Set("timestamp", time.Now().Unix())
  37. // APP纯签约
  38. wxRsp, err := client.EntrustAppPre(ctx, bm)
  39. if err != nil {
  40. xlog.Errorf("client.EntrustAppPre(%+v),error:%+v", bm, err)
  41. return
  42. }
  43. xlog.Debug("wxRsp:", wxRsp)
  44. }
  45. func TestClient_EntrustH5(t *testing.T) {
  46. // 初始化参数结构体
  47. bm := make(gopay.BodyMap)
  48. bm.Set("plan_id", "12535").
  49. Set("contract_code", "100000").
  50. Set("request_serial", "1000").
  51. Set("contract_display_account", "微信代扣").
  52. Set("notify_url", "https://www.igoogle.ink").
  53. Set("version", "1.0").
  54. Set("timestamp", time.Now().Unix()).
  55. Set("clientip", "127.0.0.1")
  56. // H5纯签约
  57. wxRsp, err := client.EntrustH5(ctx, bm)
  58. if err != nil {
  59. xlog.Errorf("client.EntrustH5(%+v),error:%+v", bm, err)
  60. return
  61. }
  62. xlog.Debug("wxRsp:", wxRsp)
  63. }
  64. func TestClient_EntrustPaying(t *testing.T) {
  65. number := util.RandomString(32)
  66. xlog.Info("out_trade_no:", number)
  67. // 初始化参数结构体
  68. bm := make(gopay.BodyMap)
  69. bm.Set("contract_mchid", mchId).
  70. Set("contract_appid", appId).
  71. Set("out_trade_no", number).
  72. Set("nonce_str", util.RandomString(32)).
  73. Set("body", "测试签约").
  74. Set("total_fee", 1).
  75. Set("spbill_create_ip", "127.0.0.1").
  76. Set("trade_type", TradeType_App).
  77. Set("plan_id", "12535").
  78. Set("contract_code", "100000").
  79. Set("request_serial", "1000").
  80. Set("contract_display_account", "微信代扣").
  81. Set("notify_url", "https://www.igoogle.ink").
  82. Set("contract_notify_url", "https://www.igoogle.ink")
  83. //bm.Set("openid", "o0Df70H2Q0fY8JXh1aFPIRyOBgu8")
  84. // 支付中签约
  85. wxRsp, err := client.EntrustPaying(ctx, bm)
  86. if err != nil {
  87. xlog.Errorf("client.EntrustPaying(%+v),error:%+v", bm, err)
  88. return
  89. }
  90. xlog.Debug("wxRsp:", wxRsp)
  91. }