package comein import ( "encoding/json" "errors" "fmt" "hongze/hz_crm_api/services/alarm_msg" "hongze/hz_crm_api/utils" "io/ioutil" "net/http" "net/url" "sort" "strconv" "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 }