comein.go 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. package comein
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "hongze/hz_crm_api/services/alarm_msg"
  7. "hongze/hz_crm_api/utils"
  8. "io/ioutil"
  9. "net/http"
  10. "net/url"
  11. "sort"
  12. "strconv"
  13. "time"
  14. )
  15. // EventListResp 会议列表返回数据结构
  16. type EventListResp struct {
  17. Code string `json:"code"`
  18. Data []EventListDataResp `json:"data"`
  19. Errorcode string `json:"errorcode"`
  20. Errordesc string `json:"errordesc"`
  21. Extra struct {
  22. HasMore bool `json:"hasMore"`
  23. More string `json:"more"`
  24. Pagestart string `json:"pagestart"`
  25. Total string `json:"total"`
  26. } `json:"extra"`
  27. Msg string `json:"msg"`
  28. Total int64 `json:"total"`
  29. }
  30. // EventListDataResp 会议数据
  31. type EventListDataResp struct {
  32. Authtag string `json:"authtag"`
  33. ConferenceType int64 `json:"conferenceType"`
  34. ContentTypeTagName string `json:"contentTypeTagName"`
  35. DescURL string `json:"descUrl"`
  36. Etime int64 `json:"etime"`
  37. ID int64 `json:"id"`
  38. IndustryName string `json:"industryName"`
  39. IsDel int64 `json:"isDel"`
  40. Livemode int64 `json:"livemode"`
  41. Logo string `json:"logo"`
  42. Logoweb string `json:"logoweb"`
  43. Members []struct {
  44. Identity int64 `json:"identity"`
  45. PhoneNumber string `json:"phoneNumber"`
  46. Type int64 `json:"type"`
  47. Uname string `json:"uname"`
  48. } `json:"members"`
  49. PresentURL string `json:"presentUrl"`
  50. RecordSupport int64 `json:"recordSupport"`
  51. RoadshowID int64 `json:"roadshowId"`
  52. ShortURL string `json:"shortUrl"`
  53. Status string `json:"status"`
  54. Stime int64 `json:"stime"`
  55. Title string `json:"title"`
  56. WxminiProgramID string `json:"wxminiProgramId"`
  57. WxminiProgramPage string `json:"wxminiProgramPage"`
  58. }
  59. // GetEventList 获取会议列表
  60. func GetEventList(startTime, endTime time.Time) (respData EventListResp, err error) {
  61. defer func() {
  62. if err != nil {
  63. go alarm_msg.SendAlarmMsg("查询组织下所有的会议列表失败;ERR:"+err.Error(), 3)
  64. }
  65. }()
  66. logMsg := ``
  67. pageStart := 0
  68. pageNum := 10
  69. paramsMap := map[string]string{
  70. "mod": "roadshow", //模块名
  71. "act": "opensearch", //处理方法名
  72. //"btime": fmt.Sprint(startTime.Unix() * 1000), //开始时间,时间戳
  73. //"etime": fmt.Sprint(endTime.Unix() * 1000), //结束时间,时间戳
  74. //"ignoredel": "1", //忽略已删除的数据 (1 删除的数据也可查询出)
  75. "pagestart": strconv.Itoa(pageStart), //翻页数 (第一页传 0 )
  76. "pagenum": strconv.Itoa(pageNum), //每页总条数(默认10条)
  77. "ts": fmt.Sprint(time.Now().Unix() * 1000), //请求发起的时间戳,单位:毫秒
  78. }
  79. paramStr := GetUrlParams(paramsMap)
  80. //fmt.Println(paramStr)
  81. //App string `json:"app" description:"数据类型"`
  82. //Mod string `json:"mod" description:"模块名"`
  83. //Act string `json:"act" description:"处理方法名"`
  84. //Appid string `json:"appid" description:"合作方ID"`
  85. getUrl := utils.COMEIN_URL + "?" + paramStr
  86. resp, err := http.Get(getUrl)
  87. if err != nil {
  88. logMsg = fmt.Sprint("comein get err; request:", getUrl, "; errMsg:", err.Error())
  89. utils.FileLog.Info(logMsg)
  90. return
  91. }
  92. defer resp.Body.Close()
  93. body, err := ioutil.ReadAll(resp.Body)
  94. if err != nil {
  95. logMsg = fmt.Sprint("comein get err; request:", getUrl, "; errMsg:", err.Error())
  96. utils.FileLog.Info(logMsg)
  97. return
  98. }
  99. utils.FileLog.Info(fmt.Sprint("comein get Result", ";url:", getUrl, ";\nresponse:", string(body)))
  100. err = json.Unmarshal(body, &respData)
  101. if err != nil {
  102. utils.FileLog.Info("comein get Err:", err.Error(), ";url:", getUrl, ";response:", string(body))
  103. err = errors.New("Unmarshal Err:" + err.Error())
  104. return
  105. }
  106. if respData.Errorcode != "0" {
  107. utils.FileLog.Info("comein get Err:", err.Error(), ";url:", getUrl, ";response:", string(body))
  108. err = errors.New(respData.Errordesc)
  109. return
  110. }
  111. return
  112. }
  113. // RoadshowDataResp 用户参会数据返回
  114. type RoadshowDataResp struct {
  115. Code string `json:"code"`
  116. Data []RoadshowData `json:"data"`
  117. Errorcode string `json:"errorcode"`
  118. Errordesc string `json:"errordesc"`
  119. Msg string `json:"msg"`
  120. }
  121. type RoadshowData struct {
  122. AreaCode string `json:"areaCode"`
  123. AskCount int64 `json:"askCount"`
  124. AuthInfo string `json:"authInfo"`
  125. Company string `json:"company"`
  126. DataType int64 `json:"dataType"`
  127. DutySeller string `json:"dutySeller"`
  128. Email string `json:"email"`
  129. FirstWatchTime int64 `json:"firstWatchTime"`
  130. GuestUserNames string `json:"guestUserNames"`
  131. ID int64 `json:"id"`
  132. JoinTime int64 `json:"joinTime"`
  133. JoinType int64 `json:"joinType"`
  134. LastWatchTime int64 `json:"lastWatchTime"`
  135. MeetingType string `json:"meetingType"`
  136. Occupation string `json:"occupation"`
  137. OrgRemarks string `json:"orgRemarks"`
  138. ResearchArea string `json:"researchArea"`
  139. RoadshowBeginTime int64 `json:"roadshowBeginTime"`
  140. RoadshowEndTime int64 `json:"roadshowEndTime"`
  141. RoadshowID int64 `json:"roadshowId"`
  142. RoadshowTitle string `json:"roadshowTitle"`
  143. RoadshowType int64 `json:"roadshowType"`
  144. SpeakerID int64 `json:"speakerId"`
  145. SpeakerName string `json:"speakerName"`
  146. TelFixedID int64 `json:"telFixedId"`
  147. TeleconferenceID string `json:"teleconferenceId"`
  148. ThirdMeetingID string `json:"thirdMeetingId"`
  149. UniqueID string `json:"uniqueId"`
  150. UserIdentity int64 `json:"userIdentity"`
  151. UserInfoSource string `json:"userInfoSource"`
  152. UserName string `json:"userName"`
  153. UserPhone string `json:"userPhone"`
  154. }
  155. // GetRoadshowDataList 获取参会人员列表
  156. func GetRoadshowDataList(startTime, endTime int64) (respData RoadshowDataResp, err error) {
  157. defer func() {
  158. if err != nil {
  159. go alarm_msg.SendAlarmMsg("获取参会人员列表失败;ERR:"+err.Error(), 3)
  160. }
  161. }()
  162. logMsg := ``
  163. paramsMap := map[string]string{
  164. "mod": "open", //模块名
  165. "act": "roadshow-datas", //处理方法名
  166. "beginTime": fmt.Sprint(startTime), //开始时间,时间戳
  167. "endTime": fmt.Sprint(endTime), //结束时间,时间戳
  168. "ts": fmt.Sprint(time.Now().Unix() * 1000), //请求发起的时间戳,单位:毫秒
  169. }
  170. paramStr := GetUrlParams(paramsMap)
  171. paramsMap["dataType"] = "1" //数据类型,1:直播 2:回放 (该参数不参与签名算法)
  172. //fmt.Println(paramStr)
  173. //App string `json:"app" description:"数据类型"`
  174. //Mod string `json:"mod" description:"模块名"`
  175. //Act string `json:"act" description:"处理方法名"`
  176. //Appid string `json:"appid" description:"合作方ID"`
  177. getUrl := utils.COMEIN_URL + "?" + paramStr
  178. resp, err := http.Get(getUrl)
  179. if err != nil {
  180. logMsg = fmt.Sprint("获取参会人员列表 comein get err; request:", getUrl, "; errMsg:", err.Error())
  181. utils.FileLog.Info(logMsg)
  182. return
  183. }
  184. defer resp.Body.Close()
  185. body, err := ioutil.ReadAll(resp.Body)
  186. if err != nil {
  187. logMsg = fmt.Sprint("获取参会人员列表 comein get err; request:", getUrl, "; errMsg:", err.Error())
  188. utils.FileLog.Info(logMsg)
  189. return
  190. }
  191. utils.FileLog.Info(fmt.Sprint("获取参会人员列表 comein get Result", ";url:", getUrl, ";\nresponse:", string(body)))
  192. err = json.Unmarshal(body, &respData)
  193. if err != nil {
  194. utils.FileLog.Info("获取参会人员列表 comein get Err:", err.Error(), ";url:", getUrl, ";response:", string(body))
  195. err = errors.New("Unmarshal Err:" + err.Error())
  196. return
  197. }
  198. if respData.Errorcode != "0" {
  199. utils.FileLog.Info("获取参会人员列表 comein get Err:", err.Error(), ";url:", getUrl, ";response:", string(body))
  200. err = errors.New(respData.Errordesc)
  201. return
  202. }
  203. return
  204. }
  205. // GetUrlParams 获取url请求参数
  206. func GetUrlParams(params map[string]string) (paramStr string) {
  207. GetSign(params)
  208. // 待签名字符串
  209. for index, val := range params {
  210. paramStr += index + `=` + val + `&`
  211. }
  212. paramStr = paramStr[:len(paramStr)-1]
  213. return
  214. }
  215. // GetSign 获取签名
  216. func GetSign(params map[string]string) (paramStr string) {
  217. //获取map的下标切片,然后对下标进行排序
  218. keySlice := make([]string, 0)
  219. //基础参数
  220. params["appid"] = utils.COMEIN_APPID //签名用的是appid,实际请求用的appId
  221. params["app"] = "json"
  222. ignoreStr := []string{"app", "mod", "act"}
  223. for index := range params {
  224. //需要忽略的字符
  225. if utils.InArrayByStr(ignoreStr, index) {
  226. continue
  227. }
  228. keySlice = append(keySlice, index)
  229. }
  230. sort.Strings(keySlice)
  231. // 待签名字符串
  232. for _, index := range keySlice {
  233. paramStr += index + `=` + params[index] + `&`
  234. }
  235. // 获取签名
  236. signStr := utils.HmacMd5(utils.COMEIN_SECREKEY, paramStr[:len(paramStr)-1])
  237. signature := url.QueryEscape(signStr)
  238. params["signature"] = signature
  239. delete(params, "appid")
  240. params["appId"] = utils.COMEIN_APPID
  241. return
  242. }