report_user_partner_info.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // 上报用户卡片信息变更
  2. package growingio
  3. import (
  4. "fpdxfeed/helpers"
  5. "net/http"
  6. "encoding/json"
  7. "strings"
  8. "fmt"
  9. "time"
  10. )
  11. const AI = "826fb1882511d92d"
  12. const SECRETKEY = "fa0d997b177040da9d83a435f6af87b2"
  13. const ACCESSTOKEN = "8809c8b595e946b383e55392e31b2719"
  14. type HttpBody struct {
  15. CS1 string `json:"cs1"`
  16. TM string `json:"tm"`
  17. T string `json:"t"`
  18. N string `json:"n"`
  19. Var []ReportData `json:"var"`
  20. }
  21. // 上报数据
  22. type ReportData struct {
  23. PartnerLevel string `json:"partner_level"`
  24. CanNotice string `json:"can_notice"`
  25. PartnerSell string `json:"partner_sell"`
  26. LoginUserId string `json:"loginUserId"`
  27. }
  28. type ReportPartnerInfo struct {
  29. AI string
  30. secretkey string
  31. accessToken string
  32. loginUserId string
  33. ReportData ReportData
  34. }
  35. func NewReportPartnerInfo(loginUserId string) (reportPartnerInfo *ReportPartnerInfo) {
  36. reportPartnerInfo = &ReportPartnerInfo{
  37. AI:AI,
  38. secretkey:SECRETKEY,
  39. accessToken:ACCESSTOKEN,
  40. loginUserId: loginUserId,
  41. }
  42. reportPartnerInfo.ReportData.LoginUserId = loginUserId
  43. return reportPartnerInfo
  44. }
  45. func (report *ReportPartnerInfo) authToken(projectKetId string, secretKey string, keyArray string) string {
  46. message := "ai=" + projectKetId + "&loginUserId=" + keyArray
  47. return helpers.HmacSha256(message, secretKey)
  48. }
  49. func (report *ReportPartnerInfo) SetPartnerLevel (value string) {
  50. report.ReportData.PartnerLevel = value
  51. }
  52. func (report *ReportPartnerInfo) SetCanNotice (value string) {
  53. report.ReportData.CanNotice = value
  54. }
  55. func (report *ReportPartnerInfo) SetPartnerSell (value string) {
  56. report.ReportData.PartnerSell = value
  57. }
  58. func (report *ReportPartnerInfo) DoSend() {
  59. var api = "https://api.growingio.com/v3/" + report.AI + "/s2s/cstm?stm=" + string(time.Now().Unix())
  60. byte, _ := json.Marshal(report.ReportData)
  61. body := make(map[string]string)
  62. json.Unmarshal(byte, &body)
  63. reqBody := make(map[string]string)
  64. for k, v := range body {
  65. if v != "" {
  66. reqBody[k] = v
  67. }
  68. }
  69. jsonBody, _ := json.Marshal(reqBody)
  70. //fmt.Println(string(jsonBody))
  71. req, _ := http.NewRequest("POST", api, strings.NewReader(string(jsonBody)))
  72. req.Header.Set("Access-Token", ACCESSTOKEN)
  73. req.Header.Set("Content-Type", "application/json")
  74. client := http.Client{}
  75. resp, _ := client.Do(req)
  76. //fmt.Println(resp)
  77. fmt.Sprint(resp)
  78. }