user_test.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package manage
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io/ioutil"
  6. "log"
  7. "net/http"
  8. "net/url"
  9. sutil "sfbase/utils"
  10. "sfis/utils"
  11. "strings"
  12. "testing"
  13. "time"
  14. )
  15. /*var (
  16. product1 = &model.Product{
  17. BaseModel: model.BaseModel{ID: 1003},
  18. Name: "行业招标数据",
  19. Path: "/path1",
  20. UnitPrice: 50, //单价精确到分 5毛
  21. MinUnit: 1, //最小单位1,即 5毛/条
  22. ProductType: 1, //产品类型 0-按次 1-按条
  23. TestNum: 100,
  24. }
  25. product2 = &model.Product{
  26. Name: "中国移动招标数据",
  27. Path: "/path2",
  28. UnitPrice: 1500, //单价精确到分 15快
  29. MinUnit: 1, //最小单位1,即 15快/次
  30. ProductType: 0, //产品类型 0-按次 1-按条
  31. TestNum: 500,
  32. }
  33. )*/
  34. func init() {
  35. //todo init connection db operation
  36. }
  37. func Test_CreateUser(t *testing.T) {
  38. //log.Println("devUserCreate testing......")
  39. appID := utils.GetAppID(time.Now().Unix())
  40. secretKey := sutil.GetComplexRandom(8, 3, 5)
  41. log.Printf("create successful appID:[%s],secretKey:[%s]", appID, secretKey)
  42. //创建用户、给用户开通接口产品时候有以下几种情况
  43. //1.线上给账户充值10000块(user_account),不去实际购买产品,无购买记录,用户产品表无剩余量(left_num为0).此时又分两种情况
  44. //1.1 按次扣账户余额
  45. //1.2 按量扣账户余额
  46. //appID := ""
  47. //tradeMoney := 1 * 100 * 10000 //充值1万块钱
  48. }
  49. func Test_UserProductChoose(t *testing.T) {
  50. appId := "sfPQRYRQMAAwcGBwYBCgcA"
  51. projectIds := "1009"
  52. startTime := "2021-01-11 00:00:00"
  53. endTime := "2022-01-11 00:00:00"
  54. leftNum := "10000"
  55. costModel := "0"
  56. interfaceStatus := "0"
  57. callTimesLimitDay := "100"
  58. dataNumOneTimes := "100"
  59. data := make(url.Values)
  60. data["appId"] = []string{appId}
  61. data["projectIds"] = []string{projectIds}
  62. data["startTime"] = []string{startTime}
  63. data["endTime"] = []string{endTime}
  64. data["leftNum"] = []string{leftNum}
  65. data["costModel"] = []string{costModel}
  66. data["interfaceStatus"] = []string{interfaceStatus}
  67. data["callTimesLimitDay"] = []string{callTimesLimitDay}
  68. data["dataNumOneTimes"] = []string{dataNumOneTimes}
  69. data["tradeMoney"] = []string{"1000"}
  70. data["buyType"] = []string{"1"}
  71. data["historyUnitPrice"] = []string{"18"}
  72. now := time.Now().Unix()
  73. bs, _ := sutil.HttpPostForm("http://localhost:8080/manage/user/userProjectChoose", map[string]string{
  74. "timestamp": fmt.Sprint(now),
  75. }, data)
  76. log.Print(string(bs))
  77. }
  78. func Test_UserProjectList(t *testing.T) {
  79. appId := "sfPQRYRQMAAwcGBwYBCgcA"
  80. data := make(url.Values)
  81. data["appId"] = []string{appId}
  82. now := time.Now().Unix()
  83. bs, _ := sutil.HttpPostForm("http://localhost:8080/manage/user/userProjectList", map[string]string{
  84. "timestamp": fmt.Sprint(now),
  85. }, data)
  86. log.Print(string(bs))
  87. }
  88. func post(url string, form map[string]string) (data map[string]interface{}) {
  89. str := ""
  90. for k, v := range form {
  91. str += "&" + k + "=" + v
  92. }
  93. log.Println(str)
  94. res, err := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(str))
  95. if err != nil {
  96. log.Println("post err:", err.Error())
  97. } else if res.Body != nil {
  98. defer res.Body.Close()
  99. bs, _ := ioutil.ReadAll(res.Body)
  100. json.Unmarshal(bs, &data)
  101. }
  102. return
  103. }