蛋蛋星球-制度模式
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

135 rindas
3.3 KiB

  1. package wechat
  2. import (
  3. "context"
  4. "os"
  5. "testing"
  6. "github.com/go-pay/gopay"
  7. "github.com/go-pay/util"
  8. "github.com/go-pay/xlog"
  9. )
  10. var (
  11. client *Client
  12. appId = "wxdaa2ab9ef87b5497"
  13. mchId = "1368139502"
  14. apiKey = "GFDS8j98rewnmgl45wHTt980jg543wmg"
  15. ctx = context.Background()
  16. )
  17. func TestMain(m *testing.M) {
  18. // 初始化微信客户端
  19. // appId:应用ID
  20. // mchId:商户ID
  21. // apiKey:API秘钥值
  22. // isProd:是否是正式环境
  23. client = NewClient(appId, mchId, apiKey, false)
  24. // 打开Debug开关,输出日志
  25. client.DebugSwitch = gopay.DebugOn
  26. // 设置国家,不设置默认就是 China
  27. client.SetCountry(China)
  28. // 不使用证书接口,可以不添加证书
  29. // 添加pkcs12内容
  30. //err = client.AddCertPkcs12FilePath("apiclient_cert.p12")
  31. //if err != nil {
  32. // panic(err)
  33. //}
  34. // 或
  35. // 添加pem证书路径
  36. //err := client.AddCertPemFilePath("apiclient_cert.pem", "apiclient_key.pem")
  37. //if err != nil {
  38. // panic(err)
  39. //}
  40. os.Exit(m.Run())
  41. }
  42. func TestClient_AuthCodeToOpenId(t *testing.T) {
  43. // 初始化参数Map
  44. bm := make(gopay.BodyMap)
  45. bm.Set("nonce_str", util.RandomString(32)).
  46. Set("auth_code", "134753997737645794")
  47. wxRsp, err := client.AuthCodeToOpenId(ctx, bm)
  48. if err != nil {
  49. xlog.Errorf("client.AuthCodeToOpenId(%+v),error:%+v", bm, err)
  50. return
  51. }
  52. xlog.Debug("Response:", *wxRsp)
  53. }
  54. func TestClient_GetTransferInfo(t *testing.T) {
  55. // 初始化参数结构体
  56. bm := make(gopay.BodyMap)
  57. bm.Set("nonce_str", util.RandomString(32)).
  58. Set("partner_trade_no", util.RandomString(32))
  59. // 查询企业付款
  60. // body:参数Body
  61. wxRsp, err := client.GetTransferInfo(ctx, bm)
  62. if err != nil {
  63. xlog.Errorf("client.GetTransferInfo(%+v),error:%+v", bm, err)
  64. return
  65. }
  66. xlog.Debug("wxRsp:", *wxRsp)
  67. }
  68. func TestClient_DownloadBill(t *testing.T) {
  69. // 初始化参数结构体
  70. bm := make(gopay.BodyMap)
  71. bm.Set("nonce_str", util.RandomString(32)).
  72. Set("sign_type", SignType_MD5).
  73. Set("bill_date", "20190722").
  74. Set("bill_type", "ALL")
  75. // 请求下载对账单,成功后得到结果(string类型字符串)
  76. wxRsp, err := client.DownloadBill(ctx, bm)
  77. if err != nil {
  78. xlog.Errorf("client.DownloadBill(%+v),error:%+v", bm, err)
  79. return
  80. }
  81. xlog.Debug("wxRsp:", wxRsp)
  82. }
  83. func TestClient_DownloadFundFlow(t *testing.T) {
  84. // 初始化参数结构体
  85. bm := make(gopay.BodyMap)
  86. bm.Set("nonce_str", util.RandomString(32)).
  87. Set("sign_type", SignType_HMAC_SHA256).
  88. Set("bill_date", "20190122").
  89. Set("account_type", "Basic")
  90. // 请求下载资金账单,成功后得到结果,沙箱环境下,证书路径参数可传nil
  91. wxRsp, err := client.DownloadFundFlow(ctx, bm)
  92. if err != nil {
  93. xlog.Errorf("client.DownloadFundFlow(%+v),error:%+v", bm, err)
  94. return
  95. }
  96. xlog.Debug("wxRsp:", wxRsp)
  97. }
  98. func TestClient_BatchQueryComment(t *testing.T) {
  99. // 初始化参数结构体
  100. bm := make(gopay.BodyMap)
  101. bm.Set("nonce_str", util.RandomString(32)).
  102. Set("sign_type", SignType_HMAC_SHA256).
  103. Set("begin_time", "20190120000000").
  104. Set("end_time", "20190122174000").
  105. Set("offset", "0")
  106. // 请求拉取订单评价数据,成功后得到结果,沙箱环境下,证书路径参数可传nil
  107. wxRsp, err := client.BatchQueryComment(ctx, bm)
  108. if err != nil {
  109. xlog.Errorf("client.BatchQueryComment(%+v),error:%+v", bm, err)
  110. return
  111. }
  112. xlog.Debug("wxRsp:", wxRsp)
  113. }