package project import ( "encoding/json" "fmt" "io/ioutil" "log" "net/http" "net/url" "sfbase/utils" "strings" "sync" "testing" "time" ) var ( apiurl = "http://127.0.0.1:8080/sfis/api/v1/projectList" ) func Test_ProjectListApi(t *testing.T) { var wg = sync.WaitGroup{} for i := 0; i < 15; i++ { wg.Add(1) go func(i int) { defer wg.Done() getData1(i) }(i) } wg.Wait() c := make(chan int) c <- 2 } func Test_Project(t *testing.T) { //getData() m := &sync.Map{} m.Store("sfGSVYRQMAAgkGBAUBJg4f", &sync.Mutex{}) if v, ok := m.Load("sfGSVYRQMAAgkGBAUBJg4f"); ok { log.Println("取到值:", v) } } func getData1(n int) { appID := "sfGSVYRQMAAgkGBAUBJg4f" secretKey := "364xw909" projectName := "河南省地税局2021年信息化建设招标项目" winner := "河南拓普计算机" + fmt.Sprint(n) zbRq := "2020-12-02" data := make(url.Values) data["projectName"] = []string{projectName} data["winner"] = []string{winner} data["zbRq"] = []string{zbRq} data["app_id"] = []string{appID} now := time.Now().Unix() bs, _ := utils.HttpPostForm("http://localhost:8080/sfis/api/v1/projectList", map[string]string{ "token": utils.MD5(fmt.Sprintf("%s%d%s", appID, now, secretKey)), "timestamp": fmt.Sprint(now), }, data) log.Print(string(bs)) } func getData() { data := post(apiurl, map[string]string{ "name": "河南大学", "winner": "洛阳丹尼斯量贩有限公司", "time": "1545235200_1599014733", }) log.Println(data) } //获取项目详情测试用例 func Test_ProjectDetails(t *testing.T) { data := post("http://127.0.0.1:8080/sfis/api/v1/projectDetail", map[string]string{ "projectid": "5f6b4e12499cb0822d39c68f", }) res := map[string]interface{}{} s, _ := json.Marshal(data) json.Unmarshal(s, &res) log.Println("数据:", res) } 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 }