comein.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  1. package comein
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "hongze/hongze_task/models"
  8. "hongze/hongze_task/models/yb"
  9. "hongze/hongze_task/services/alarm_msg"
  10. "hongze/hongze_task/utils"
  11. "io/ioutil"
  12. "net/http"
  13. "net/url"
  14. "sort"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. // EventListResp 会议列表返回数据结构
  20. type EventListResp struct {
  21. Code string `json:"code"`
  22. Data []EventListDataResp `json:"data"`
  23. Errorcode string `json:"errorcode"`
  24. Errordesc string `json:"errordesc"`
  25. Extra struct {
  26. HasMore bool `json:"hasMore"`
  27. More string `json:"more"`
  28. Pagestart string `json:"pagestart"`
  29. Total string `json:"total"`
  30. } `json:"extra"`
  31. Msg string `json:"msg"`
  32. Total int64 `json:"total"`
  33. }
  34. // EventListDataResp 会议数据
  35. type EventListDataResp struct {
  36. Authtag string `json:"authtag"`
  37. ConferenceType int64 `json:"conferenceType"`
  38. ContentTypeTagName string `json:"contentTypeTagName"`
  39. DescURL string `json:"descUrl"`
  40. Etime int64 `json:"etime"`
  41. ID int64 `json:"id"`
  42. IndustryName string `json:"industryName"`
  43. IsDel int64 `json:"isDel"`
  44. Livemode int64 `json:"livemode"`
  45. Logo string `json:"logo"`
  46. Logoweb string `json:"logoweb"`
  47. Members []struct {
  48. Identity int64 `json:"identity"`
  49. PhoneNumber string `json:"phoneNumber"`
  50. Type int64 `json:"type"`
  51. Uname string `json:"uname"`
  52. } `json:"members"`
  53. PresentURL string `json:"presentUrl"`
  54. RecordSupport int64 `json:"recordSupport"`
  55. RoadshowID int64 `json:"roadshowId"`
  56. ShortURL string `json:"shortUrl"`
  57. Status string `json:"status"`
  58. Stime int64 `json:"stime"`
  59. Title string `json:"title"`
  60. WxminiProgramID string `json:"wxminiProgramId"`
  61. WxminiProgramPage string `json:"wxminiProgramPage"`
  62. }
  63. // GetEventList 获取会议列表
  64. func GetEventList(startTime, endTime time.Time) (respData EventListResp, err error) {
  65. defer func() {
  66. if err != nil {
  67. go alarm_msg.SendAlarmMsg("查询组织下所有的会议列表失败;ERR:"+err.Error(), 3)
  68. }
  69. }()
  70. logMsg := ``
  71. pageStart := 0
  72. pageNum := 10
  73. paramsMap := map[string]string{
  74. "mod": "roadshow", //模块名
  75. "act": "opensearch", //处理方法名
  76. //"btime": fmt.Sprint(startTime.Unix() * 1000), //开始时间,时间戳
  77. //"etime": fmt.Sprint(endTime.Unix() * 1000), //结束时间,时间戳
  78. //"ignoredel": "1", //忽略已删除的数据 (1 删除的数据也可查询出)
  79. "pagestart": strconv.Itoa(pageStart), //翻页数 (第一页传 0 )
  80. "pagenum": strconv.Itoa(pageNum), //每页总条数(默认10条)
  81. "ts": fmt.Sprint(time.Now().Unix() * 1000), //请求发起的时间戳,单位:毫秒
  82. }
  83. paramStr := GetUrlParams(paramsMap)
  84. //fmt.Println(paramStr)
  85. //App string `json:"app" description:"数据类型"`
  86. //Mod string `json:"mod" description:"模块名"`
  87. //Act string `json:"act" description:"处理方法名"`
  88. //Appid string `json:"appid" description:"合作方ID"`
  89. getUrl := utils.COMEIN_URL + "?" + paramStr
  90. resp, err := http.Get(getUrl)
  91. if err != nil {
  92. logMsg = fmt.Sprint("comein get err; request:", getUrl, "; errMsg:", err.Error())
  93. utils.FileLog.Info(logMsg)
  94. return
  95. }
  96. defer resp.Body.Close()
  97. body, err := ioutil.ReadAll(resp.Body)
  98. if err != nil {
  99. logMsg = fmt.Sprint("comein get err; request:", getUrl, "; errMsg:", err.Error())
  100. utils.FileLog.Info(logMsg)
  101. return
  102. }
  103. utils.FileLog.Info(fmt.Sprint("comein get Result", ";url:", getUrl, ";\nresponse:", string(body)))
  104. err = json.Unmarshal(body, &respData)
  105. if err != nil {
  106. utils.FileLog.Info("comein get Err:", err.Error(), ";url:", getUrl, ";response:", string(body))
  107. err = errors.New("Unmarshal Err:" + err.Error())
  108. return
  109. }
  110. if respData.Errorcode != "0" {
  111. utils.FileLog.Info("comein get Err:", err.Error(), ";url:", getUrl, ";response:", string(body))
  112. err = errors.New(respData.Errordesc)
  113. return
  114. }
  115. return
  116. }
  117. // RoadshowDataResp 用户参会数据返回
  118. type RoadshowDataResp struct {
  119. Code string `json:"code"`
  120. Data []RoadshowData `json:"data"`
  121. Errorcode string `json:"errorcode"`
  122. Errordesc string `json:"errordesc"`
  123. Msg string `json:"msg"`
  124. }
  125. type RoadshowData struct {
  126. AreaCode string `json:"areaCode"`
  127. AskCount int64 `json:"askCount"`
  128. AuthInfo string `json:"authInfo"`
  129. Company string `json:"company"`
  130. DataType int64 `json:"dataType"`
  131. DutySeller string `json:"dutySeller"`
  132. Email string `json:"email"`
  133. FirstWatchTime int64 `json:"firstWatchTime"`
  134. GuestUserNames string `json:"guestUserNames"`
  135. ID int64 `json:"id"`
  136. JoinTime int64 `json:"joinTime"`
  137. JoinType int64 `json:"joinType"`
  138. LastWatchTime int64 `json:"lastWatchTime"`
  139. MeetingType string `json:"meetingType"`
  140. Occupation string `json:"occupation"`
  141. OrgRemarks string `json:"orgRemarks"`
  142. ResearchArea string `json:"researchArea"`
  143. RoadshowBeginTime int64 `json:"roadshowBeginTime"`
  144. RoadshowEndTime int64 `json:"roadshowEndTime"`
  145. RoadshowID int64 `json:"roadshowId"`
  146. RoadshowTitle string `json:"roadshowTitle"`
  147. RoadshowType int64 `json:"roadshowType"`
  148. SpeakerID int64 `json:"speakerId"`
  149. SpeakerName string `json:"speakerName"`
  150. TelFixedID int64 `json:"telFixedId"`
  151. TeleconferenceID string `json:"teleconferenceId"`
  152. ThirdMeetingID string `json:"thirdMeetingId"`
  153. UniqueID string `json:"uniqueId"`
  154. UserIdentity int64 `json:"userIdentity"`
  155. UserInfoSource string `json:"userInfoSource"`
  156. UserName string `json:"userName"`
  157. UserPhone string `json:"userPhone"`
  158. }
  159. // GetRoadshowDataList 获取参会人员列表
  160. func GetRoadshowDataList(startTime, endTime int64) (respData RoadshowDataResp, err error) {
  161. defer func() {
  162. if err != nil {
  163. go alarm_msg.SendAlarmMsg("获取参会人员列表失败;ERR:"+err.Error(), 3)
  164. }
  165. }()
  166. logMsg := ``
  167. paramsMap := map[string]string{
  168. "mod": "open", //模块名
  169. "act": "roadshow-datas", //处理方法名
  170. "beginTime": fmt.Sprint(startTime), //开始时间,时间戳
  171. "endTime": fmt.Sprint(endTime), //结束时间,时间戳
  172. "ts": fmt.Sprint(time.Now().Unix() * 1000), //请求发起的时间戳,单位:毫秒
  173. }
  174. paramStr := GetUrlParams(paramsMap)
  175. paramsMap["dataType"] = "1" //数据类型,1:直播 2:回放 (该参数不参与签名算法)
  176. //fmt.Println(paramStr)
  177. //App string `json:"app" description:"数据类型"`
  178. //Mod string `json:"mod" description:"模块名"`
  179. //Act string `json:"act" description:"处理方法名"`
  180. //Appid string `json:"appid" description:"合作方ID"`
  181. getUrl := utils.COMEIN_URL + "?" + paramStr
  182. resp, err := http.Get(getUrl)
  183. if err != nil {
  184. logMsg = fmt.Sprint("获取参会人员列表 comein get err; request:", getUrl, "; errMsg:", err.Error())
  185. utils.FileLog.Info(logMsg)
  186. return
  187. }
  188. defer resp.Body.Close()
  189. body, err := ioutil.ReadAll(resp.Body)
  190. if err != nil {
  191. logMsg = fmt.Sprint("获取参会人员列表 comein get err; request:", getUrl, "; errMsg:", err.Error())
  192. utils.FileLog.Info(logMsg)
  193. return
  194. }
  195. utils.FileLog.Info(fmt.Sprint("获取参会人员列表 comein get Result", ";url:", getUrl, ";\nresponse:", string(body)))
  196. err = json.Unmarshal(body, &respData)
  197. if err != nil {
  198. utils.FileLog.Info("获取参会人员列表 comein get Err:", err.Error(), ";url:", getUrl, ";response:", string(body))
  199. err = errors.New("Unmarshal Err:" + err.Error())
  200. return
  201. }
  202. if respData.Errorcode != "0" {
  203. utils.FileLog.Info("获取参会人员列表 comein get Err:", err.Error(), ";url:", getUrl, ";response:", string(body))
  204. err = errors.New(respData.Errordesc)
  205. return
  206. }
  207. return
  208. }
  209. // GetUrlParams 获取url请求参数
  210. func GetUrlParams(params map[string]string) (paramStr string) {
  211. GetSign(params)
  212. // 待签名字符串
  213. for index, val := range params {
  214. paramStr += index + `=` + val + `&`
  215. }
  216. paramStr = paramStr[:len(paramStr)-1]
  217. return
  218. }
  219. // GetSign 获取签名
  220. func GetSign(params map[string]string) (paramStr string) {
  221. //获取map的下标切片,然后对下标进行排序
  222. keySlice := make([]string, 0)
  223. //基础参数
  224. params["appid"] = utils.COMEIN_APPID //签名用的是appid,实际请求用的appId
  225. params["app"] = "json"
  226. ignoreStr := []string{"app", "mod", "act"}
  227. for index := range params {
  228. //需要忽略的字符
  229. if utils.InArrayByStr(ignoreStr, index) {
  230. continue
  231. }
  232. keySlice = append(keySlice, index)
  233. }
  234. sort.Strings(keySlice)
  235. // 待签名字符串
  236. for _, index := range keySlice {
  237. paramStr += index + `=` + params[index] + `&`
  238. }
  239. // 获取签名
  240. signStr := utils.HmacMd5(utils.COMEIN_SECREKEY, paramStr[:len(paramStr)-1])
  241. signature := url.QueryEscape(signStr)
  242. params["signature"] = signature
  243. delete(params, "appid")
  244. params["appId"] = utils.COMEIN_APPID
  245. return
  246. }
  247. // InitAddWhiteList 初始化进门财经白名单
  248. func InitAddWhiteList() (err error) {
  249. defer func() {
  250. if err != nil {
  251. go alarm_msg.SendAlarmMsg("InitAddWhiteList;ERR:"+err.Error(), 3)
  252. }
  253. }()
  254. postUrl := utils.COMEIN_URL
  255. list, err := models.GetComeinWhiteUserMulti()
  256. if err != nil {
  257. fmt.Println("GetUserMobileFormal Err:", err.Error())
  258. return
  259. }
  260. whiteList := make([]yb.Whitelist, 0)
  261. for _, v := range list {
  262. whiteUser := yb.Whitelist{}
  263. if v.Mobile != "" {
  264. whiteUser.Phone = v.Mobile
  265. whiteUser.Areacode = v.CountryCode
  266. whiteUser.Guid = utils.MD5(strconv.Itoa(v.UserId))
  267. whiteList = append(whiteList, whiteUser)
  268. } else if v.Email != "" {
  269. whiteUser.Email = v.Email
  270. whiteUser.Guid = utils.MD5(strconv.Itoa(v.UserId))
  271. whiteList = append(whiteList, whiteUser)
  272. }
  273. }
  274. fmt.Println("共" + strconv.Itoa(len(whiteList)) + "条数据")
  275. // 分批发送请求
  276. var count int
  277. request := yb.SyncWhitelist{
  278. Opt: 1,
  279. AppID: utils.COMEIN_WHITELIST_APPID,
  280. }
  281. for i, v := range whiteList {
  282. //whiteItem := yb.Whitelist{
  283. // Guid: v.Guid,
  284. // Phone: v.Phone,
  285. // Email: v.Email,
  286. // Areacode: v.Areacode,
  287. //}
  288. request.Whitelist = append(request.Whitelist, v)
  289. if count < 10000 && (len(whiteList)-i-1) > 0 {
  290. count++
  291. continue
  292. }
  293. count = 0
  294. timestamp := fmt.Sprintf("%d", time.Now().UnixNano()/1e6)
  295. signature := GetSignature("1", timestamp)
  296. request.Signature = signature
  297. request.Timestamp = timestamp
  298. jsonData, e := json.Marshal(request)
  299. if e != nil {
  300. err = e
  301. return
  302. }
  303. headers := map[string]string{
  304. "app": "json",
  305. "mod": "channelopen",
  306. "act": "whitelist",
  307. }
  308. // 发起POST请求
  309. resp, e := utils.MakePostRequest(postUrl, jsonData, headers)
  310. if e != nil {
  311. err = e
  312. utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";url:", postUrl)
  313. return
  314. }
  315. defer resp.Body.Close()
  316. body, e := ioutil.ReadAll(resp.Body)
  317. if e != nil {
  318. err = e
  319. fmt.Println("reponse error", err)
  320. return
  321. }
  322. result := new(yb.ComeinResponse)
  323. err = json.Unmarshal(body, &result)
  324. if err != nil {
  325. fmt.Println("json.Unmarshal Err:" + err.Error())
  326. return
  327. }
  328. utils.FileLog.Info(fmt.Sprint("comein addWhitelist Result", ";url:", postUrl, ";\nrequest:", jsonData, ";\nresponse:", string(body)))
  329. err = json.Unmarshal(body, &result)
  330. if err != nil {
  331. utils.FileLog.Info(fmt.Sprint("comein addWhitelist Result", ";url:", postUrl, ";\nrequest:", jsonData, ";\nresponse:", string(body)))
  332. err = errors.New("Unmarshal Err:" + err.Error())
  333. return
  334. }
  335. if result.ErrorCode != "0" {
  336. utils.FileLog.Info(fmt.Sprint("comein addWhitelist Result", ";url:", postUrl, ";\nrequest:", request, ";\nresponse:", string(body)))
  337. err = errors.New(result.ErrorDesc)
  338. return
  339. }
  340. request.Whitelist = nil
  341. time.Sleep(110 * time.Second)
  342. fmt.Println("同步成功:" + strconv.Itoa(i+1) + "条数据")
  343. }
  344. return
  345. }
  346. func GetSignature(opt, timestamp string) (signature string) {
  347. //获取map的下标切片,然后对下标进行排序
  348. keySlice := make([]string, 0)
  349. //基础参数
  350. params := make(map[string]string, 0)
  351. params["appid"] = utils.COMEIN_WHITELIST_APPID //签名用的是appid,实际请求用的appId
  352. if opt != "" {
  353. params["opt"] = opt
  354. }
  355. params["timestamp"] = timestamp
  356. for index := range params {
  357. keySlice = append(keySlice, index)
  358. }
  359. sort.Strings(keySlice)
  360. var paramStr string
  361. // 待签名字符串
  362. for _, index := range keySlice {
  363. paramStr += index + `=` + params[index] + `&`
  364. }
  365. paramStr = paramStr[:len(paramStr)-1]
  366. // 获取签名
  367. signStr := utils.HmacMd5(utils.COMEIN_WHITELIST_SECREKEY, paramStr)
  368. signature = url.QueryEscape(signStr)
  369. return
  370. }
  371. func InitComeinWhiteList() (err error) {
  372. list := make([]*models.ComeinWhiteUser, 0)
  373. realList, err := models.GetUserMobileFormal()
  374. if err != nil {
  375. fmt.Println("GetUserMobileFormal Err:", err.Error())
  376. return
  377. }
  378. for _, v := range realList {
  379. user := models.ComeinWhiteUser{
  380. Email: v.Email,
  381. Mobile: v.Mobile,
  382. CountryCode: "+86",
  383. IsFake: 0,
  384. }
  385. list = append(list, &user)
  386. }
  387. for i := 0; i < 100000-len(realList); i++ {
  388. phone := utils.RandomPhone()
  389. user := models.ComeinWhiteUser{
  390. Mobile: phone,
  391. CountryCode: "+86",
  392. IsFake: 1,
  393. }
  394. list = append(list, &user)
  395. }
  396. err = models.AddComeinWhiteUserMulti(list)
  397. if err != nil {
  398. fmt.Println("添加随机手机号失败", err.Error())
  399. return
  400. }
  401. fmt.Println("添加随机手机号成功")
  402. return
  403. }
  404. // SyncWhiteList 同步进门财经白名单定时任务
  405. func SyncWhiteList(cont context.Context) (err error) {
  406. defer func() {
  407. if err != nil {
  408. go alarm_msg.SendAlarmMsg("SyncWhiteList;ERR:"+err.Error(), 3)
  409. }
  410. }()
  411. // 拿白名单表
  412. list, err := models.GetComeinWhiteUserMulti()
  413. if err != nil {
  414. fmt.Println("GetUserMobileFormal Err:", err.Error())
  415. return
  416. }
  417. syncedMap := make(map[string]bool, 0)
  418. for _, v := range list {
  419. syncedMap[v.Mobile+v.Email] = true
  420. }
  421. //拿联系人表,需要进白名单的
  422. needAddList, err := models.GetUserMobileFormal()
  423. if err != nil {
  424. fmt.Println("GetUserMobileFormal Err:", err.Error())
  425. return
  426. }
  427. addMobiles := ""
  428. addemails := ""
  429. addList := make([]*models.ComeinWhiteUser, 0)
  430. for _, v := range needAddList {
  431. if _, ok := syncedMap[v.Mobile+v.Email]; !ok {
  432. user := models.ComeinWhiteUser{
  433. Mobile: v.Mobile,
  434. CountryCode: "+"+v.CountryCode,
  435. Email: v.Email,
  436. IsFake: 0,
  437. }
  438. addList = append(addList, &user)
  439. if v.Mobile != "" {
  440. //addMobiles = append(addMobiles,"'"+ v.Mobile+"'")
  441. addMobiles += "'"+ v.Mobile+"'"+","
  442. } else if v.Email != "" {
  443. //addemails = append(addemails,"'"+ v.Email+"'")
  444. addemails += "'"+ v.Email+"'"+","
  445. }
  446. }
  447. }
  448. addMobiles = strings.TrimSuffix(addMobiles, ",")
  449. addemails = strings.TrimSuffix(addemails, ",")
  450. if len(addList) > 0 {
  451. err = models.AddComeinWhiteUserMulti(addList)
  452. if err != nil {
  453. fmt.Println("新增白名单失败,AddComeinWhiteUserMulti", err.Error())
  454. return
  455. }
  456. err = syncWhiteList(addMobiles,addemails, 1)
  457. if err != nil {
  458. fmt.Println("新增白名单失败", err.Error())
  459. return
  460. }
  461. }
  462. //拿联系人表,需要删除的
  463. needDelList, err := models.GetUserMobileNotFormal()
  464. if err != nil {
  465. fmt.Println("GetUserMobileFormal Err:", err.Error())
  466. return
  467. }
  468. delMobiles := ""
  469. delEmials := ""
  470. delList := make([]*models.ComeinWhiteUser, 0)
  471. for _, v := range needDelList {
  472. if _, ok := syncedMap[v.Mobile+v.Email]; ok {
  473. user := models.ComeinWhiteUser{
  474. UserId: v.UserId,
  475. Mobile: v.Mobile,
  476. CountryCode: "+"+v.CountryCode,
  477. Email: v.Email,
  478. IsFake: 0,
  479. }
  480. delList = append(delList, &user)
  481. if v.Mobile != "" {
  482. //delMobiles = append(delMobiles, "'"+v.Mobile+"'")
  483. delMobiles += "'"+v.Mobile+"'"+","
  484. } else if v.Email != "" {
  485. //delEmials = append(delEmials, "'"+v.Email+"'")
  486. delEmials += "'"+v.Email+"'"+","
  487. }
  488. }
  489. }
  490. delMobiles = strings.TrimSuffix(delMobiles, ",")
  491. delEmials = strings.TrimSuffix(delEmials, ",")
  492. if len(delList) > 0 {
  493. err = syncWhiteList(delMobiles, delEmials, 2)
  494. if err != nil {
  495. fmt.Println("删除白名单失败", err.Error())
  496. return
  497. }
  498. delIds := make([]int, 0)
  499. for _, v := range delList {
  500. delIds = append(delIds, v.UserId)
  501. }
  502. err = models.DelComeinWhiteUserMulti(delIds)
  503. if err != nil {
  504. fmt.Println("删除白名单失败,DelComeinWhiteUserMulti", err.Error())
  505. return
  506. }
  507. }
  508. return
  509. }
  510. func syncWhiteList(mobiles, emails string, opt int) (err error) {
  511. postUrl := utils.COMEIN_URL
  512. timestamp := fmt.Sprintf("%d", time.Now().UnixNano()/1e6)
  513. signature := GetSignature(strconv.Itoa(opt), timestamp)
  514. request := yb.SyncWhitelist{
  515. Opt: opt,
  516. Timestamp: timestamp,
  517. AppID: utils.COMEIN_WHITELIST_APPID,
  518. Signature: signature,
  519. }
  520. whiteList := make([]yb.Whitelist, 0)
  521. list, err := models.GetComeinWhiteUser(mobiles, emails)
  522. if err != nil {
  523. return
  524. }
  525. for _, v := range list {
  526. whiteUser := yb.Whitelist{}
  527. if v.Mobile != "" {
  528. whiteUser.Phone = v.Mobile
  529. whiteUser.Areacode = v.CountryCode
  530. whiteUser.Guid = utils.MD5(strconv.Itoa(v.UserId))
  531. whiteList = append(whiteList, whiteUser)
  532. } else if v.Email != "" {
  533. whiteUser.Email = v.Email
  534. whiteUser.Guid = utils.MD5(strconv.Itoa(v.UserId))
  535. whiteList = append(whiteList, whiteUser)
  536. }
  537. }
  538. request.Whitelist = whiteList
  539. jsonData, err := json.Marshal(request)
  540. if err != nil {
  541. return
  542. }
  543. headers := map[string]string{
  544. "app": "json",
  545. "mod": "channelopen",
  546. "act": "whitelist",
  547. }
  548. // 发起POST请求
  549. resp, err := utils.MakePostRequest(postUrl, jsonData, headers)
  550. if err != nil {
  551. utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";url:", postUrl)
  552. return
  553. }
  554. defer resp.Body.Close()
  555. body, err := ioutil.ReadAll(resp.Body)
  556. if err != nil {
  557. fmt.Println("reponse error", err)
  558. return
  559. }
  560. utils.FileLog.Info(fmt.Sprint("comein syncWhiteList Result", ";url:", postUrl, ";\nrequest:", request, ";\nresponse:", string(body)))
  561. result := new(yb.ComeinResponse)
  562. err = json.Unmarshal(body, &result)
  563. if err != nil {
  564. utils.FileLog.Info("comein syncWhiteList Err:", err.Error(), ";url:", postUrl, ";response:", string(body))
  565. err = errors.New("Unmarshal Err:" + err.Error())
  566. return
  567. }
  568. if result.ErrorCode != "0" {
  569. utils.FileLog.Info("comein syncWhiteList Err:", err.Error(), ";url:", postUrl, ";response:", string(body))
  570. err = errors.New(result.ErrorDesc)
  571. return
  572. }
  573. return
  574. }
  575. // CheckWhiteList
  576. func CheckComeinWhiteList() (err error) {
  577. defer func() {
  578. if err != nil {
  579. go alarm_msg.SendAlarmMsg("InitAddWhiteList;ERR:"+err.Error(), 3)
  580. }
  581. }()
  582. logMsg := ``
  583. timestamp := fmt.Sprintf("%d", time.Now().UnixNano()/1e6)
  584. signature := GetSignature("", timestamp)
  585. headers := map[string]string{
  586. "app": "json", //模块名
  587. "mod": "channelopen", //模块名
  588. "act": "list-detail", //处理方法名
  589. }
  590. paramsMap := map[string]string{
  591. "appId": utils.COMEIN_WHITELIST_APPID,
  592. "signature": signature,
  593. "timestamp": timestamp,
  594. "phone": "138108810525",
  595. }
  596. paramStr := ``
  597. for index, val := range paramsMap {
  598. paramStr += index + `=` + val + `&`
  599. }
  600. paramStr = paramStr[:len(paramStr)-1]
  601. getUrl := utils.COMEIN_URL + "?" + paramStr
  602. // 创建一个新的请求
  603. req, err := http.NewRequest("GET", getUrl, nil)
  604. if err != nil {
  605. fmt.Println("Error creating request:", err)
  606. return
  607. }
  608. // 添加自定义的头部信息
  609. for k, v := range headers {
  610. req.Header.Add(k, v)
  611. }
  612. // 发送请求并获取响应
  613. client := http.Client{}
  614. resp, err := client.Do(req)
  615. if err != nil {
  616. fmt.Println("Error sending request:", err)
  617. return
  618. }
  619. defer resp.Body.Close()
  620. body, err := ioutil.ReadAll(resp.Body)
  621. if err != nil {
  622. logMsg = fmt.Sprint("获取参会人员列表 comein get err; request:", getUrl, "; errMsg:", err.Error())
  623. utils.FileLog.Info(logMsg)
  624. return
  625. }
  626. result := new(yb.ComeinResponse)
  627. err = json.Unmarshal(body, &result)
  628. if err != nil {
  629. fmt.Println("json.Unmarshal Err:" + err.Error())
  630. return
  631. }
  632. utils.FileLog.Info(fmt.Sprint("comein addWhitelist Result", ";\nresponse:", string(body)))
  633. err = json.Unmarshal(body, &result)
  634. if err != nil {
  635. utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";response:", string(body))
  636. err = errors.New("Unmarshal Err:" + err.Error())
  637. return
  638. }
  639. if result.ErrorCode != "0" {
  640. utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";response:", string(body))
  641. err = errors.New(result.ErrorDesc)
  642. return
  643. }
  644. return
  645. }
  646. func AddWhiteList() (err error) {
  647. defer func() {
  648. if err != nil {
  649. go alarm_msg.SendAlarmMsg("InitAddWhiteList;ERR:"+err.Error(), 3)
  650. }
  651. }()
  652. postUrl := utils.COMEIN_URL
  653. whiteUser := yb.Whitelist{}
  654. whiteUser.Phone = "188286375317"
  655. whiteUser.Areacode = "+86"
  656. whiteUser.Guid = "26968fa5f8753ffdbaaab97fbe092f4f"
  657. request := yb.SyncWhitelist{
  658. Opt: 1,
  659. AppID: utils.COMEIN_WHITELIST_APPID,
  660. }
  661. request.Whitelist = append(request.Whitelist, whiteUser)
  662. timestamp := fmt.Sprintf("%d", time.Now().UnixNano()/1e6)
  663. signature := GetSignature("1", timestamp)
  664. request.Signature = signature
  665. request.Timestamp = timestamp
  666. jsonData, e := json.Marshal(request)
  667. if e != nil {
  668. err = e
  669. return
  670. }
  671. headers := map[string]string{
  672. "app": "json",
  673. "mod": "channelopen",
  674. "act": "whitelist",
  675. }
  676. // 发起POST请求
  677. resp, e := utils.MakePostRequest(postUrl, jsonData, headers)
  678. if e != nil {
  679. err = e
  680. utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";url:", postUrl)
  681. return
  682. }
  683. defer resp.Body.Close()
  684. body, e := ioutil.ReadAll(resp.Body)
  685. if e != nil {
  686. err = e
  687. fmt.Println("reponse error", err)
  688. return
  689. }
  690. result := new(yb.ComeinResponse)
  691. err = json.Unmarshal(body, &result)
  692. if err != nil {
  693. fmt.Println("json.Unmarshal Err:" + err.Error())
  694. return
  695. }
  696. utils.FileLog.Info(fmt.Sprint("comein addWhitelist Result", ";url:", postUrl, ";\nresponse:", string(body)))
  697. err = json.Unmarshal(body, &result)
  698. if err != nil {
  699. utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";url:", postUrl, ";response:", string(body))
  700. err = errors.New("Unmarshal Err:" + err.Error())
  701. return
  702. }
  703. if result.ErrorCode != "0" {
  704. utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";url:", postUrl, ";response:", string(body))
  705. err = errors.New(result.ErrorDesc)
  706. return
  707. }
  708. request.Whitelist = nil
  709. return
  710. }
  711. // CheckWhiteList
  712. func CheckComeinWhiteListByJobId() (err error) {
  713. defer func() {
  714. if err != nil {
  715. go alarm_msg.SendAlarmMsg("InitAddWhiteList;ERR:"+err.Error(), 3)
  716. }
  717. }()
  718. logMsg := ``
  719. headers := map[string]string{
  720. "app": "json", //模块名
  721. "mod": "channelopen", //模块名
  722. "act": "get-result", //处理方法名
  723. }
  724. paramsMap := map[string]string{
  725. "jobId": "a180a8a4-a674-48ce-aa96-5a373c7dcc9c",
  726. }
  727. paramStr := ``
  728. for index, val := range paramsMap {
  729. paramStr += index + `=` + val + `&`
  730. }
  731. paramStr = paramStr[:len(paramStr)-1]
  732. getUrl := utils.COMEIN_URL + "?" + paramStr
  733. // 创建一个新的请求
  734. req, err := http.NewRequest("GET", getUrl, nil)
  735. if err != nil {
  736. fmt.Println("Error creating request:", err)
  737. return
  738. }
  739. // 添加自定义的头部信息
  740. for k, v := range headers {
  741. req.Header.Add(k, v)
  742. }
  743. // 发送请求并获取响应
  744. client := http.Client{}
  745. resp, err := client.Do(req)
  746. if err != nil {
  747. fmt.Println("Error sending request:", err)
  748. return
  749. }
  750. defer resp.Body.Close()
  751. body, err := ioutil.ReadAll(resp.Body)
  752. if err != nil {
  753. logMsg = fmt.Sprint("获取参会人员列表 comein get err; request:", getUrl, "; errMsg:", err.Error())
  754. utils.FileLog.Info(logMsg)
  755. return
  756. }
  757. result := new(yb.ComeinResponse)
  758. err = json.Unmarshal(body, &result)
  759. if err != nil {
  760. fmt.Println("json.Unmarshal Err:" + err.Error())
  761. return
  762. }
  763. utils.FileLog.Info(fmt.Sprint("comein addWhitelist Result", ";\nresponse:", string(body)))
  764. err = json.Unmarshal(body, &result)
  765. if err != nil {
  766. utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";response:", string(body))
  767. err = errors.New("Unmarshal Err:" + err.Error())
  768. return
  769. }
  770. if result.ErrorCode != "0" {
  771. utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";response:", string(body))
  772. err = errors.New(result.ErrorDesc)
  773. return
  774. }
  775. return
  776. }
  777. func GetWhiteList() (err error) {
  778. defer func() {
  779. if err != nil {
  780. go alarm_msg.SendAlarmMsg("InitAddWhiteList;ERR:"+err.Error(), 3)
  781. }
  782. }()
  783. postUrl := utils.COMEIN_URL
  784. timestamp := fmt.Sprintf("%d", time.Now().UnixNano()/1e6)
  785. signature := GetSignature("", timestamp)
  786. request := yb.GetWhitelist{
  787. Ts: timestamp,
  788. AppID: utils.COMEIN_WHITELIST_APPID,
  789. Signature: signature,
  790. }
  791. jsonData, e := json.Marshal(request)
  792. if e != nil {
  793. err = e
  794. return
  795. }
  796. headers := map[string]string{
  797. "app": "json",
  798. "mod": "channelopen",
  799. "act": "get-whitelist-v1",
  800. }
  801. // 发起POST请求
  802. resp, e := utils.MakePostRequest(postUrl, jsonData, headers)
  803. if e != nil {
  804. err = e
  805. utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";url:", postUrl)
  806. return
  807. }
  808. defer resp.Body.Close()
  809. body, e := ioutil.ReadAll(resp.Body)
  810. if e != nil {
  811. err = e
  812. fmt.Println("reponse error", err)
  813. return
  814. }
  815. result := new(yb.ComeinResponse)
  816. err = json.Unmarshal(body, &result)
  817. if err != nil {
  818. fmt.Println("json.Unmarshal Err:" + err.Error())
  819. return
  820. }
  821. utils.FileLog.Info(fmt.Sprint("comein addWhitelist Result", ";url:", postUrl, ";\nresponse:", string(body)))
  822. err = json.Unmarshal(body, &result)
  823. if err != nil {
  824. utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";url:", postUrl, ";response:", string(body))
  825. err = errors.New("Unmarshal Err:" + err.Error())
  826. return
  827. }
  828. if result.ErrorCode != "0" {
  829. utils.FileLog.Info("comein addWhitelist Err:", err.Error(), ";url:", postUrl, ";response:", string(body))
  830. err = errors.New(result.ErrorDesc)
  831. return
  832. }
  833. return
  834. }