// 上报用户卡片信息变更 package growingio import ( "fpdxfeed/helpers" "net/http" "encoding/json" "strings" "fmt" "time" ) const AI = "826fb1882511d92d" const SECRETKEY = "fa0d997b177040da9d83a435f6af87b2" const ACCESSTOKEN = "8809c8b595e946b383e55392e31b2719" type HttpBody struct { CS1 string `json:"cs1"` TM string `json:"tm"` T string `json:"t"` N string `json:"n"` Var []ReportData `json:"var"` } // 上报数据 type ReportData struct { PartnerLevel string `json:"partner_level"` CanNotice string `json:"can_notice"` PartnerSell string `json:"partner_sell"` LoginUserId string `json:"loginUserId"` } type ReportPartnerInfo struct { AI string secretkey string accessToken string loginUserId string ReportData ReportData } func NewReportPartnerInfo(loginUserId string) (reportPartnerInfo *ReportPartnerInfo) { reportPartnerInfo = &ReportPartnerInfo{ AI:AI, secretkey:SECRETKEY, accessToken:ACCESSTOKEN, loginUserId: loginUserId, } reportPartnerInfo.ReportData.LoginUserId = loginUserId return reportPartnerInfo } func (report *ReportPartnerInfo) authToken(projectKetId string, secretKey string, keyArray string) string { message := "ai=" + projectKetId + "&loginUserId=" + keyArray return helpers.HmacSha256(message, secretKey) } func (report *ReportPartnerInfo) SetPartnerLevel (value string) { report.ReportData.PartnerLevel = value } func (report *ReportPartnerInfo) SetCanNotice (value string) { report.ReportData.CanNotice = value } func (report *ReportPartnerInfo) SetPartnerSell (value string) { report.ReportData.PartnerSell = value } func (report *ReportPartnerInfo) DoSend() { var api = "https://api.growingio.com/v3/" + report.AI + "/s2s/cstm?stm=" + string(time.Now().Unix()) byte, _ := json.Marshal(report.ReportData) body := make(map[string]string) json.Unmarshal(byte, &body) reqBody := make(map[string]string) for k, v := range body { if v != "" { reqBody[k] = v } } jsonBody, _ := json.Marshal(reqBody) //fmt.Println(string(jsonBody)) req, _ := http.NewRequest("POST", api, strings.NewReader(string(jsonBody))) req.Header.Set("Access-Token", ACCESSTOKEN) req.Header.Set("Content-Type", "application/json") client := http.Client{} resp, _ := client.Do(req) //fmt.Println(resp) fmt.Sprint(resp) }