userRecharge_test.go 969 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package userRecharge
  2. import (
  3. "encoding/json"
  4. "io/ioutil"
  5. "log"
  6. "net/http"
  7. "strings"
  8. "testing"
  9. )
  10. var (
  11. // apiurl = "http://127.0.0.1:8081/sfis/api/v1/user/moneyRecharge"
  12. apiurl = "http://127.0.0.1:8081/sfis/api/v1/user/productRecharge"
  13. )
  14. func Test_Project(t *testing.T) {
  15. getData()
  16. }
  17. func getData() {
  18. data := post(apiurl, map[string]string{
  19. "appid": "sfGSVYRQMAAgkGBAUBJg4f",
  20. "money": "1000",
  21. "productId": "1000",
  22. "rechargeNum": "100",
  23. "endTime": "2022-01-01",
  24. })
  25. log.Println(data)
  26. }
  27. func post(url string, form map[string]string) (data map[string]interface{}) {
  28. str := ""
  29. for k, v := range form {
  30. str += "&" + k + "=" + v
  31. }
  32. log.Println(str)
  33. res, err := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(str))
  34. if err != nil {
  35. log.Println("post err:", err.Error())
  36. } else if res.Body != nil {
  37. defer res.Body.Close()
  38. bs, _ := ioutil.ReadAll(res.Body)
  39. json.Unmarshal(bs, &data)
  40. }
  41. return
  42. }