project_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package project
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io/ioutil"
  6. "log"
  7. "net/http"
  8. "net/url"
  9. "sfbase/utils"
  10. "strings"
  11. "sync"
  12. "testing"
  13. "time"
  14. )
  15. var (
  16. apiurl = "http://127.0.0.1:8080/sfis/api/v1/projectList"
  17. // apiurl = "http://127.0.0.1:8080/sfis/api/v1/projectListDetail"
  18. SE = utils.SimpleEncrypt{Key: "topJYBX2019"}
  19. )
  20. func Test_ProjectListApi(t *testing.T) {
  21. var wg = sync.WaitGroup{}
  22. for i := 0; i < 15; i++ {
  23. wg.Add(1)
  24. go func(i int) {
  25. defer wg.Done()
  26. getData1(i)
  27. }(i)
  28. }
  29. wg.Wait()
  30. c := make(chan int)
  31. c <- 2
  32. }
  33. func Test_Project(t *testing.T) {
  34. //getData()
  35. m := &sync.Map{}
  36. m.Store("sfGSVYRQMAAgkGBAUBJg4f", &sync.Mutex{})
  37. if v, ok := m.Load("sfGSVYRQMAAgkGBAUBJg4f"); ok {
  38. log.Println("取到值:", v)
  39. }
  40. }
  41. func getData1(n int) {
  42. appID := "sfGSVYRQMAAgkGBAUBJg4f"
  43. secretKey := "364xw909"
  44. projectName := "河南省地税局2021年信息化建设招标项目"
  45. winner := "河南拓普计算机" + fmt.Sprint(n)
  46. zbRq := "2020-12-02"
  47. data := make(url.Values)
  48. data["projectName"] = []string{projectName}
  49. data["winner"] = []string{winner}
  50. data["zbRq"] = []string{zbRq}
  51. data["app_id"] = []string{appID}
  52. now := time.Now().Unix()
  53. bs, _ := utils.HttpPostForm("http://localhost:8080/sfis/api/v1/projectList", map[string]string{
  54. "token": utils.MD5(fmt.Sprintf("%s%d%s", appID, now, secretKey)),
  55. "timestamp": fmt.Sprint(now),
  56. }, data)
  57. log.Print(string(bs))
  58. }
  59. func getData() {
  60. data := post(apiurl, map[string]string{
  61. "projectname": "河南大学",
  62. "s_winner": "洛阳丹尼斯量贩有限公司",
  63. "jgtime": "1545235200_1599014733",
  64. })
  65. log.Println(data)
  66. }
  67. //获取项目详情测试用例
  68. func Test_ProjectDetails(t *testing.T) {
  69. appID := "sfPQRYRQMAAwcGBwYBCgcA"
  70. secretKey := "a8Iws4mE"
  71. data := make(url.Values)
  72. projectId := SE.EncodeString("5f6b4e12499cb0822d39c68f")
  73. data["project_id"] = []string{projectId}
  74. data["app_id"] = []string{appID}
  75. now := time.Now().Unix()
  76. bs, _ := utils.HttpPostForm("http://localhost:8080/sfis/api/v1/projectDetail", map[string]string{
  77. "token": utils.MD5(fmt.Sprintf("%s%d%s", appID, now, secretKey)),
  78. "timestamp": fmt.Sprint(now),
  79. }, data)
  80. log.Print(string(bs))
  81. }
  82. func post(url string, form map[string]string) (data map[string]interface{}) {
  83. str := ""
  84. for k, v := range form {
  85. str += "&" + k + "=" + v
  86. }
  87. log.Println(str)
  88. res, err := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(str))
  89. if err != nil {
  90. log.Println("post err:", err.Error())
  91. } else if res.Body != nil {
  92. defer res.Body.Close()
  93. bs, _ := ioutil.ReadAll(res.Body)
  94. json.Unmarshal(bs, &data)
  95. }
  96. return
  97. }