123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950 |
- 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+"'"+","
- }
- }
- }
- delMobiles = strings.TrimSuffix(delMobiles, ",")
- delEmials = strings.TrimSuffix(delEmials, ",")
- 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
- }
|