package comein import ( "context" "encoding/json" "errors" "fmt" "hongze/hongze_task/models" "hongze/hongze_task/models/yb" "hongze/hongze_task/services/alarm_msg" "hongze/hongze_task/utils" "io/ioutil" "net/http" "net/url" "sort" "strconv" "strings" "time" ) // EventListResp 会议列表返回数据结构 type EventListResp struct { Code string `json:"code"` Data []EventListDataResp `json:"data"` Errorcode string `json:"errorcode"` Errordesc string `json:"errordesc"` Extra struct { HasMore bool `json:"hasMore"` More string `json:"more"` Pagestart string `json:"pagestart"` Total string `json:"total"` } `json:"extra"` Msg string `json:"msg"` Total int64 `json:"total"` } // EventListDataResp 会议数据 type EventListDataResp struct { Authtag string `json:"authtag"` ConferenceType int64 `json:"conferenceType"` ContentTypeTagName string `json:"contentTypeTagName"` DescURL string `json:"descUrl"` Etime int64 `json:"etime"` ID int64 `json:"id"` IndustryName string `json:"industryName"` IsDel int64 `json:"isDel"` Livemode int64 `json:"livemode"` Logo string `json:"logo"` Logoweb string `json:"logoweb"` Members []struct { Identity int64 `json:"identity"` PhoneNumber string `json:"phoneNumber"` Type int64 `json:"type"` Uname string `json:"uname"` } `json:"members"` PresentURL string `json:"presentUrl"` RecordSupport int64 `json:"recordSupport"` RoadshowID int64 `json:"roadshowId"` ShortURL string `json:"shortUrl"` Status string `json:"status"` Stime int64 `json:"stime"` Title string `json:"title"` WxminiProgramID string `json:"wxminiProgramId"` WxminiProgramPage string `json:"wxminiProgramPage"` } // GetEventList 获取会议列表 func GetEventList(startTime, endTime time.Time) (respData EventListResp, err error) { defer func() { if err != nil { go alarm_msg.SendAlarmMsg("查询组织下所有的会议列表失败;ERR:"+err.Error(), 3) } }() logMsg := `` pageStart := 0 pageNum := 10 paramsMap := map[string]string{ "mod": "roadshow", //模块名 "act": "opensearch", //处理方法名 //"btime": fmt.Sprint(startTime.Unix() * 1000), //开始时间,时间戳 //"etime": fmt.Sprint(endTime.Unix() * 1000), //结束时间,时间戳 //"ignoredel": "1", //忽略已删除的数据 (1 删除的数据也可查询出) "pagestart": strconv.Itoa(pageStart), //翻页数 (第一页传 0 ) "pagenum": strconv.Itoa(pageNum), //每页总条数(默认10条) "ts": fmt.Sprint(time.Now().Unix() * 1000), //请求发起的时间戳,单位:毫秒 } paramStr := GetUrlParams(paramsMap) //fmt.Println(paramStr) //App string `json:"app" description:"数据类型"` //Mod string `json:"mod" description:"模块名"` //Act string `json:"act" description:"处理方法名"` //Appid string `json:"appid" description:"合作方ID"` getUrl := utils.COMEIN_URL + "?" + paramStr resp, err := http.Get(getUrl) if err != nil { logMsg = fmt.Sprint("comein get err; request:", getUrl, "; errMsg:", err.Error()) utils.FileLog.Info(logMsg) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { logMsg = fmt.Sprint("comein get err; request:", getUrl, "; errMsg:", err.Error()) utils.FileLog.Info(logMsg) return } utils.FileLog.Info(fmt.Sprint("comein get Result", ";url:", getUrl, ";\nresponse:", string(body))) err = json.Unmarshal(body, &respData) if err != nil { utils.FileLog.Info("comein get Err:", err.Error(), ";url:", getUrl, ";response:", string(body)) err = errors.New("Unmarshal Err:" + err.Error()) return } if respData.Errorcode != "0" { utils.FileLog.Info("comein get Err:", err.Error(), ";url:", getUrl, ";response:", string(body)) err = errors.New(respData.Errordesc) return } return } // RoadshowDataResp 用户参会数据返回 type RoadshowDataResp struct { Code string `json:"code"` Data []RoadshowData `json:"data"` Errorcode string `json:"errorcode"` Errordesc string `json:"errordesc"` Msg string `json:"msg"` } type RoadshowData struct { AreaCode string `json:"areaCode"` AskCount int64 `json:"askCount"` AuthInfo string `json:"authInfo"` Company string `json:"company"` DataType int64 `json:"dataType"` DutySeller string `json:"dutySeller"` Email string `json:"email"` FirstWatchTime int64 `json:"firstWatchTime"` GuestUserNames string `json:"guestUserNames"` ID int64 `json:"id"` JoinTime int64 `json:"joinTime"` JoinType int64 `json:"joinType"` LastWatchTime int64 `json:"lastWatchTime"` MeetingType string `json:"meetingType"` Occupation string `json:"occupation"` OrgRemarks string `json:"orgRemarks"` ResearchArea string `json:"researchArea"` RoadshowBeginTime int64 `json:"roadshowBeginTime"` RoadshowEndTime int64 `json:"roadshowEndTime"` RoadshowID int64 `json:"roadshowId"` RoadshowTitle string `json:"roadshowTitle"` RoadshowType int64 `json:"roadshowType"` SpeakerID int64 `json:"speakerId"` SpeakerName string `json:"speakerName"` TelFixedID int64 `json:"telFixedId"` TeleconferenceID string `json:"teleconferenceId"` ThirdMeetingID string `json:"thirdMeetingId"` UniqueID string `json:"uniqueId"` UserIdentity int64 `json:"userIdentity"` UserInfoSource string `json:"userInfoSource"` UserName string `json:"userName"` UserPhone string `json:"userPhone"` } // GetRoadshowDataList 获取参会人员列表 func GetRoadshowDataList(startTime, endTime int64) (respData RoadshowDataResp, err error) { defer func() { if err != nil { go alarm_msg.SendAlarmMsg("获取参会人员列表失败;ERR:"+err.Error(), 3) } }() logMsg := `` paramsMap := map[string]string{ "mod": "open", //模块名 "act": "roadshow-datas", //处理方法名 "beginTime": fmt.Sprint(startTime), //开始时间,时间戳 "endTime": fmt.Sprint(endTime), //结束时间,时间戳 "ts": fmt.Sprint(time.Now().Unix() * 1000), //请求发起的时间戳,单位:毫秒 } paramStr := GetUrlParams(paramsMap) paramsMap["dataType"] = "1" //数据类型,1:直播 2:回放 (该参数不参与签名算法) //fmt.Println(paramStr) //App string `json:"app" description:"数据类型"` //Mod string `json:"mod" description:"模块名"` //Act string `json:"act" description:"处理方法名"` //Appid string `json:"appid" description:"合作方ID"` getUrl := utils.COMEIN_URL + "?" + paramStr resp, err := http.Get(getUrl) if err != nil { logMsg = fmt.Sprint("获取参会人员列表 comein get err; request:", getUrl, "; errMsg:", err.Error()) utils.FileLog.Info(logMsg) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { logMsg = fmt.Sprint("获取参会人员列表 comein get err; request:", getUrl, "; errMsg:", err.Error()) utils.FileLog.Info(logMsg) return } utils.FileLog.Info(fmt.Sprint("获取参会人员列表 comein get Result", ";url:", getUrl, ";\nresponse:", string(body))) err = json.Unmarshal(body, &respData) if err != nil { utils.FileLog.Info("获取参会人员列表 comein get Err:", err.Error(), ";url:", getUrl, ";response:", string(body)) err = errors.New("Unmarshal Err:" + err.Error()) return } if respData.Errorcode != "0" { utils.FileLog.Info("获取参会人员列表 comein get Err:", err.Error(), ";url:", getUrl, ";response:", string(body)) err = errors.New(respData.Errordesc) return } return } // GetUrlParams 获取url请求参数 func GetUrlParams(params map[string]string) (paramStr string) { GetSign(params) // 待签名字符串 for index, val := range params { paramStr += index + `=` + val + `&` } paramStr = paramStr[:len(paramStr)-1] return } // GetSign 获取签名 func GetSign(params map[string]string) (paramStr string) { //获取map的下标切片,然后对下标进行排序 keySlice := make([]string, 0) //基础参数 params["appid"] = utils.COMEIN_APPID //签名用的是appid,实际请求用的appId params["app"] = "json" ignoreStr := []string{"app", "mod", "act"} for index := range params { //需要忽略的字符 if utils.InArrayByStr(ignoreStr, index) { continue } keySlice = append(keySlice, index) } sort.Strings(keySlice) // 待签名字符串 for _, index := range keySlice { paramStr += index + `=` + params[index] + `&` } // 获取签名 signStr := utils.HmacMd5(utils.COMEIN_SECREKEY, paramStr[:len(paramStr)-1]) signature := url.QueryEscape(signStr) params["signature"] = signature delete(params, "appid") params["appId"] = utils.COMEIN_APPID return } // InitAddWhiteList 初始化进门财经白名单 func InitAddWhiteList() (err error) { defer func() { if err != nil { go alarm_msg.SendAlarmMsg("InitAddWhiteList;ERR:"+err.Error(), 3) } }() postUrl := utils.COMEIN_URL list, err := models.GetComeinWhiteUserMulti() if err != nil { fmt.Println("GetUserMobileFormal Err:", err.Error()) return } whiteList := make([]yb.Whitelist, 0) for _, v := range list { whiteUser := yb.Whitelist{} if v.Mobile != "" { whiteUser.Phone = v.Mobile whiteUser.Areacode = v.CountryCode whiteUser.Guid = utils.MD5(strconv.Itoa(v.UserId)) whiteList = append(whiteList, whiteUser) } else if v.Email != "" { whiteUser.Email = v.Email whiteUser.Guid = utils.MD5(strconv.Itoa(v.UserId)) whiteList = append(whiteList, whiteUser) } } fmt.Println("共" + strconv.Itoa(len(whiteList)) + "条数据") // 分批发送请求 var count int request := yb.SyncWhitelist{ Opt: 1, AppID: utils.COMEIN_WHITELIST_APPID, } for i, v := range whiteList { //whiteItem := yb.Whitelist{ // Guid: v.Guid, // Phone: v.Phone, // Email: v.Email, // Areacode: v.Areacode, //} request.Whitelist = append(request.Whitelist, v) if count < 10000 && (len(whiteList)-i-1) > 0 { count++ continue } count = 0 timestamp := fmt.Sprintf("%d", time.Now().UnixNano()/1e6) signature := GetSignature("1", timestamp) request.Signature = signature request.Timestamp = timestamp jsonData, e := json.Marshal(request) if e != nil { err = e return } headers := map[string]string{ "app": "json", "mod": "channelopen", "act": "whitelist", } // 发起POST请求 resp, e := utils.MakePostRequest(postUrl, jsonData, headers) if e != nil { err = e utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";url:", postUrl) return } defer resp.Body.Close() body, e := ioutil.ReadAll(resp.Body) if e != nil { err = e fmt.Println("reponse error", err) return } result := new(yb.ComeinResponse) err = json.Unmarshal(body, &result) if err != nil { fmt.Println("json.Unmarshal Err:" + err.Error()) return } utils.FileLog.Info(fmt.Sprint("comein addWhitelist Result", ";url:", postUrl, ";\nrequest:", jsonData, ";\nresponse:", string(body))) err = json.Unmarshal(body, &result) if err != nil { utils.FileLog.Info(fmt.Sprint("comein addWhitelist Result", ";url:", postUrl, ";\nrequest:", jsonData, ";\nresponse:", string(body))) err = errors.New("Unmarshal Err:" + err.Error()) return } if result.ErrorCode != "0" { utils.FileLog.Info(fmt.Sprint("comein addWhitelist Result", ";url:", postUrl, ";\nrequest:", request, ";\nresponse:", string(body))) err = errors.New(result.ErrorDesc) return } request.Whitelist = nil time.Sleep(110 * time.Second) fmt.Println("同步成功:" + strconv.Itoa(i+1) + "条数据") } return } func GetSignature(opt, timestamp string) (signature string) { //获取map的下标切片,然后对下标进行排序 keySlice := make([]string, 0) //基础参数 params := make(map[string]string, 0) params["appid"] = utils.COMEIN_WHITELIST_APPID //签名用的是appid,实际请求用的appId if opt != "" { params["opt"] = opt } params["timestamp"] = timestamp for index := range params { keySlice = append(keySlice, index) } sort.Strings(keySlice) var paramStr string // 待签名字符串 for _, index := range keySlice { paramStr += index + `=` + params[index] + `&` } paramStr = paramStr[:len(paramStr)-1] // 获取签名 signStr := utils.HmacMd5(utils.COMEIN_WHITELIST_SECREKEY, paramStr) signature = url.QueryEscape(signStr) return } func InitComeinWhiteList() (err error) { list := make([]*models.ComeinWhiteUser, 0) realList, err := models.GetUserMobileFormal() if err != nil { fmt.Println("GetUserMobileFormal Err:", err.Error()) return } for _, v := range realList { user := models.ComeinWhiteUser{ Email: v.Email, Mobile: v.Mobile, CountryCode: "+86", IsFake: 0, } list = append(list, &user) } for i := 0; i < 100000-len(realList); i++ { phone := utils.RandomPhone() user := models.ComeinWhiteUser{ Mobile: phone, CountryCode: "+86", IsFake: 1, } list = append(list, &user) } err = models.AddComeinWhiteUserMulti(list) if err != nil { fmt.Println("添加随机手机号失败", err.Error()) return } fmt.Println("添加随机手机号成功") return } // SyncWhiteList 同步进门财经白名单定时任务 func SyncWhiteList(cont context.Context) (err error) { defer func() { if err != nil { go alarm_msg.SendAlarmMsg("SyncWhiteList;ERR:"+err.Error(), 3) } }() // 拿白名单表 list, err := models.GetComeinWhiteUserMulti() if err != nil { fmt.Println("GetUserMobileFormal Err:", err.Error()) return } syncedMap := make(map[string]bool, 0) for _, v := range list { syncedMap[v.Mobile+v.Email] = true } //拿联系人表,需要进白名单的 needAddList, err := models.GetUserMobileFormal() if err != nil { fmt.Println("GetUserMobileFormal Err:", err.Error()) return } addMobiles := "" addemails := "" addList := make([]*models.ComeinWhiteUser, 0) for _, v := range needAddList { if _, ok := syncedMap[v.Mobile+v.Email]; !ok { user := models.ComeinWhiteUser{ Mobile: v.Mobile, CountryCode: "+"+v.CountryCode, Email: v.Email, IsFake: 0, } addList = append(addList, &user) if v.Mobile != "" { //addMobiles = append(addMobiles,"'"+ v.Mobile+"'") addMobiles += "'"+ v.Mobile+"'"+"," } else if v.Email != "" { //addemails = append(addemails,"'"+ v.Email+"'") addemails += "'"+ v.Email+"'"+"," } } } addMobiles = strings.TrimSuffix(addMobiles, ",") addemails = strings.TrimSuffix(addemails, ",") if len(addList) > 0 { err = models.AddComeinWhiteUserMulti(addList) if err != nil { fmt.Println("新增白名单失败,AddComeinWhiteUserMulti", err.Error()) return } err = syncWhiteList(addMobiles,addemails, 1) if err != nil { fmt.Println("新增白名单失败", err.Error()) return } } //拿联系人表,需要删除的 needDelList, err := models.GetUserMobileNotFormal() if err != nil { fmt.Println("GetUserMobileFormal Err:", err.Error()) return } delMobiles := "" delEmials := "" delList := make([]*models.ComeinWhiteUser, 0) for _, v := range needDelList { if _, ok := syncedMap[v.Mobile+v.Email]; ok { user := models.ComeinWhiteUser{ UserId: v.UserId, Mobile: v.Mobile, CountryCode: "+"+v.CountryCode, Email: v.Email, IsFake: 0, } delList = append(delList, &user) if v.Mobile != "" { //delMobiles = append(delMobiles, "'"+v.Mobile+"'") delMobiles += "'"+v.Mobile+"'"+"," } else if v.Email != "" { //delEmials = append(delEmials, "'"+v.Email+"'") delEmials += "'"+v.Email+"'"+"," } } } if len(delList) > 0 { err = syncWhiteList(delMobiles, delEmials, 2) if err != nil { fmt.Println("删除白名单失败", err.Error()) return } delIds := make([]int, 0) for _, v := range delList { delIds = append(delIds, v.UserId) } err = models.DelComeinWhiteUserMulti(delIds) if err != nil { fmt.Println("删除白名单失败,DelComeinWhiteUserMulti", err.Error()) return } } return } func syncWhiteList(mobiles, emails string, opt int) (err error) { postUrl := utils.COMEIN_URL timestamp := fmt.Sprintf("%d", time.Now().UnixNano()/1e6) signature := GetSignature(strconv.Itoa(opt), timestamp) request := yb.SyncWhitelist{ Opt: opt, Timestamp: timestamp, AppID: utils.COMEIN_WHITELIST_APPID, Signature: signature, } whiteList := make([]yb.Whitelist, 0) list, err := models.GetComeinWhiteUser(mobiles, emails) if err != nil { return } for _, v := range list { whiteUser := yb.Whitelist{} if v.Mobile != "" { whiteUser.Phone = v.Mobile whiteUser.Areacode = v.CountryCode whiteUser.Guid = utils.MD5(strconv.Itoa(v.UserId)) whiteList = append(whiteList, whiteUser) } else if v.Email != "" { whiteUser.Email = v.Email whiteUser.Guid = utils.MD5(strconv.Itoa(v.UserId)) whiteList = append(whiteList, whiteUser) } } request.Whitelist = whiteList jsonData, err := json.Marshal(request) if err != nil { return } headers := map[string]string{ "app": "json", "mod": "channelopen", "act": "whitelist", } // 发起POST请求 resp, err := utils.MakePostRequest(postUrl, jsonData, headers) if err != nil { utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";url:", postUrl) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println("reponse error", err) return } utils.FileLog.Info(fmt.Sprint("comein syncWhiteList Result", ";url:", postUrl, ";\nrequest:", request, ";\nresponse:", string(body))) result := new(yb.ComeinResponse) err = json.Unmarshal(body, &result) if err != nil { utils.FileLog.Info("comein syncWhiteList Err:", err.Error(), ";url:", postUrl, ";response:", string(body)) err = errors.New("Unmarshal Err:" + err.Error()) return } if result.ErrorCode != "0" { utils.FileLog.Info("comein syncWhiteList Err:", err.Error(), ";url:", postUrl, ";response:", string(body)) err = errors.New(result.ErrorDesc) return } return } // CheckWhiteList func CheckComeinWhiteList() (err error) { defer func() { if err != nil { go alarm_msg.SendAlarmMsg("InitAddWhiteList;ERR:"+err.Error(), 3) } }() logMsg := `` timestamp := fmt.Sprintf("%d", time.Now().UnixNano()/1e6) signature := GetSignature("", timestamp) headers := map[string]string{ "app": "json", //模块名 "mod": "channelopen", //模块名 "act": "list-detail", //处理方法名 } paramsMap := map[string]string{ "appId": utils.COMEIN_WHITELIST_APPID, "signature": signature, "timestamp": timestamp, "phone": "138108810525", } paramStr := `` for index, val := range paramsMap { paramStr += index + `=` + val + `&` } paramStr = paramStr[:len(paramStr)-1] getUrl := utils.COMEIN_URL + "?" + paramStr // 创建一个新的请求 req, err := http.NewRequest("GET", getUrl, nil) if err != nil { fmt.Println("Error creating request:", err) return } // 添加自定义的头部信息 for k, v := range headers { req.Header.Add(k, v) } // 发送请求并获取响应 client := http.Client{} resp, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { logMsg = fmt.Sprint("获取参会人员列表 comein get err; request:", getUrl, "; errMsg:", err.Error()) utils.FileLog.Info(logMsg) return } result := new(yb.ComeinResponse) err = json.Unmarshal(body, &result) if err != nil { fmt.Println("json.Unmarshal Err:" + err.Error()) return } utils.FileLog.Info(fmt.Sprint("comein addWhitelist Result", ";\nresponse:", string(body))) err = json.Unmarshal(body, &result) if err != nil { utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";response:", string(body)) err = errors.New("Unmarshal Err:" + err.Error()) return } if result.ErrorCode != "0" { utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";response:", string(body)) err = errors.New(result.ErrorDesc) return } return } func AddWhiteList() (err error) { defer func() { if err != nil { go alarm_msg.SendAlarmMsg("InitAddWhiteList;ERR:"+err.Error(), 3) } }() postUrl := utils.COMEIN_URL whiteUser := yb.Whitelist{} whiteUser.Phone = "188286375317" whiteUser.Areacode = "+86" whiteUser.Guid = "26968fa5f8753ffdbaaab97fbe092f4f" request := yb.SyncWhitelist{ Opt: 1, AppID: utils.COMEIN_WHITELIST_APPID, } request.Whitelist = append(request.Whitelist, whiteUser) timestamp := fmt.Sprintf("%d", time.Now().UnixNano()/1e6) signature := GetSignature("1", timestamp) request.Signature = signature request.Timestamp = timestamp jsonData, e := json.Marshal(request) if e != nil { err = e return } headers := map[string]string{ "app": "json", "mod": "channelopen", "act": "whitelist", } // 发起POST请求 resp, e := utils.MakePostRequest(postUrl, jsonData, headers) if e != nil { err = e utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";url:", postUrl) return } defer resp.Body.Close() body, e := ioutil.ReadAll(resp.Body) if e != nil { err = e fmt.Println("reponse error", err) return } result := new(yb.ComeinResponse) err = json.Unmarshal(body, &result) if err != nil { fmt.Println("json.Unmarshal Err:" + err.Error()) return } utils.FileLog.Info(fmt.Sprint("comein addWhitelist Result", ";url:", postUrl, ";\nresponse:", string(body))) err = json.Unmarshal(body, &result) if err != nil { utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";url:", postUrl, ";response:", string(body)) err = errors.New("Unmarshal Err:" + err.Error()) return } if result.ErrorCode != "0" { utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";url:", postUrl, ";response:", string(body)) err = errors.New(result.ErrorDesc) return } request.Whitelist = nil return } // CheckWhiteList func CheckComeinWhiteListByJobId() (err error) { defer func() { if err != nil { go alarm_msg.SendAlarmMsg("InitAddWhiteList;ERR:"+err.Error(), 3) } }() logMsg := `` headers := map[string]string{ "app": "json", //模块名 "mod": "channelopen", //模块名 "act": "get-result", //处理方法名 } paramsMap := map[string]string{ "jobId": "a180a8a4-a674-48ce-aa96-5a373c7dcc9c", } paramStr := `` for index, val := range paramsMap { paramStr += index + `=` + val + `&` } paramStr = paramStr[:len(paramStr)-1] getUrl := utils.COMEIN_URL + "?" + paramStr // 创建一个新的请求 req, err := http.NewRequest("GET", getUrl, nil) if err != nil { fmt.Println("Error creating request:", err) return } // 添加自定义的头部信息 for k, v := range headers { req.Header.Add(k, v) } // 发送请求并获取响应 client := http.Client{} resp, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { logMsg = fmt.Sprint("获取参会人员列表 comein get err; request:", getUrl, "; errMsg:", err.Error()) utils.FileLog.Info(logMsg) return } result := new(yb.ComeinResponse) err = json.Unmarshal(body, &result) if err != nil { fmt.Println("json.Unmarshal Err:" + err.Error()) return } utils.FileLog.Info(fmt.Sprint("comein addWhitelist Result", ";\nresponse:", string(body))) err = json.Unmarshal(body, &result) if err != nil { utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";response:", string(body)) err = errors.New("Unmarshal Err:" + err.Error()) return } if result.ErrorCode != "0" { utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";response:", string(body)) err = errors.New(result.ErrorDesc) return } return } func GetWhiteList() (err error) { defer func() { if err != nil { go alarm_msg.SendAlarmMsg("InitAddWhiteList;ERR:"+err.Error(), 3) } }() postUrl := utils.COMEIN_URL timestamp := fmt.Sprintf("%d", time.Now().UnixNano()/1e6) signature := GetSignature("", timestamp) request := yb.GetWhitelist{ Ts: timestamp, AppID: utils.COMEIN_WHITELIST_APPID, Signature: signature, } jsonData, e := json.Marshal(request) if e != nil { err = e return } headers := map[string]string{ "app": "json", "mod": "channelopen", "act": "get-whitelist-v1", } // 发起POST请求 resp, e := utils.MakePostRequest(postUrl, jsonData, headers) if e != nil { err = e utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";url:", postUrl) return } defer resp.Body.Close() body, e := ioutil.ReadAll(resp.Body) if e != nil { err = e fmt.Println("reponse error", err) return } result := new(yb.ComeinResponse) err = json.Unmarshal(body, &result) if err != nil { fmt.Println("json.Unmarshal Err:" + err.Error()) return } utils.FileLog.Info(fmt.Sprint("comein addWhitelist Result", ";url:", postUrl, ";\nresponse:", string(body))) err = json.Unmarshal(body, &result) if err != nil { utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";url:", postUrl, ";response:", string(body)) err = errors.New("Unmarshal Err:" + err.Error()) return } if result.ErrorCode != "0" { utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";url:", postUrl, ";response:", string(body)) err = errors.New(result.ErrorDesc) return } return }