package userRecharge import ( "encoding/json" "io/ioutil" "log" "net/http" "strings" "testing" ) var ( // apiurl = "http://127.0.0.1:8081/sfis/api/v1/user/moneyRecharge" apiurl = "http://127.0.0.1:8081/sfis/api/v1/user/productRecharge" ) func Test_Project(t *testing.T) { getData() } func getData() { data := post(apiurl, map[string]string{ "appid": "sfGSVYRQMAAgkGBAUBJg4f", "money": "1000", "productId": "1000", "rechargeNum": "100", "endTime": "2022-01-01", }) log.Println(data) } func post(url string, form map[string]string) (data map[string]interface{}) { str := "" for k, v := range form { str += "&" + k + "=" + v } log.Println(str) res, err := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(str)) if err != nil { log.Println("post err:", err.Error()) } else if res.Body != nil { defer res.Body.Close() bs, _ := ioutil.ReadAll(res.Body) json.Unmarshal(bs, &data) } return }