123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- package services
- import (
- "encoding/json"
- "fmt"
- "hongze/hongze_clpt/models"
- "hongze/hongze_clpt/utils"
- "io/ioutil"
- "net/http"
- "strings"
- "time"
- )
- // GetActivityTypeIdWithYiDong 根据易董同步过来的活动类型,自动匹配行业
- func GetActivityTypeIdWithYiDong(industrySwName string) (chartPermissionId int) {
- mapIndustrySwName := map[string]int{
- "家用电器": utils.XIAO_FEI_ID,
- "纺织服饰": utils.XIAO_FEI_ID,
- "休闲服务": utils.XIAO_FEI_ID,
- "食品饮料": utils.XIAO_FEI_ID,
- "美容护理": utils.XIAO_FEI_ID,
- //消费
- "汽车": utils.ZHI_ZAO_ID,
- "机械设备": utils.ZHI_ZAO_ID,
- "电力设备": utils.ZHI_ZAO_ID,
- //智造
- "电子": utils.KE_JI_ID,
- "计算机": utils.KE_JI_ID,
- "通信": utils.KE_JI_ID,
- //科技
- "医药生物": utils.YI_YAO_ID,
- //医药
- "策略": utils.CE_LUE_ID,
- //策略
- "非银金融": utils.CHART_PERMISSION_ID_YANXUAN,
- "建筑装饰": utils.CHART_PERMISSION_ID_YANXUAN,
- "基础化工": utils.CHART_PERMISSION_ID_YANXUAN,
- "农林牧渔": utils.CHART_PERMISSION_ID_YANXUAN,
- "传媒": utils.CHART_PERMISSION_ID_YANXUAN,
- "公用事业": utils.CHART_PERMISSION_ID_YANXUAN,
- "建筑材料": utils.CHART_PERMISSION_ID_YANXUAN,
- "房地产": utils.CHART_PERMISSION_ID_YANXUAN,
- "采掘": utils.CHART_PERMISSION_ID_YANXUAN,
- "轻工制造": utils.CHART_PERMISSION_ID_YANXUAN,
- "钢铁": utils.CHART_PERMISSION_ID_YANXUAN,
- "交通运输": utils.CHART_PERMISSION_ID_YANXUAN,
- "国防军工": utils.CHART_PERMISSION_ID_YANXUAN,
- "银行": utils.CHART_PERMISSION_ID_YANXUAN,
- "有色金属": utils.CHART_PERMISSION_ID_YANXUAN,
- "综合": utils.CHART_PERMISSION_ID_YANXUAN,
- "商业贸易": utils.CHART_PERMISSION_ID_YANXUAN,
- "宏观": utils.CHART_PERMISSION_ID_YANXUAN,
- "金融工程": utils.CHART_PERMISSION_ID_YANXUAN,
- "商贸零售": utils.CHART_PERMISSION_ID_YANXUAN,
- "社会服务": utils.CHART_PERMISSION_ID_YANXUAN,
- "煤炭": utils.CHART_PERMISSION_ID_YANXUAN,
- "石油石化": utils.CHART_PERMISSION_ID_YANXUAN,
- "环保": utils.CHART_PERMISSION_ID_YANXUAN,
- //研选
- }
- chartPermissionId = mapIndustrySwName[industrySwName]
- return
- }
- // GetActivityTypeIdWithYiDong 根据易董同步过来的活动类型,自动匹配行业
- func GetActivityTypeNameWithYiDong(industrySwName string) (chartPermissionName string) {
- mapIndustrySwName := map[string]string{
- "家用电器": utils.XIAO_FEI_NAME,
- "纺织服饰": utils.XIAO_FEI_NAME,
- "休闲服务": utils.XIAO_FEI_NAME,
- "食品饮料": utils.XIAO_FEI_NAME,
- "美容护理": utils.XIAO_FEI_NAME,
- //消费
- "汽车": utils.ZHI_ZAO_NAME,
- "机械设备": utils.ZHI_ZAO_NAME,
- "电力设备": utils.ZHI_ZAO_NAME,
- //智造
- "电子": utils.KE_JI_NAME,
- "计算机": utils.KE_JI_NAME,
- "通信": utils.KE_JI_NAME,
- //科技
- "医药生物": utils.YI_YAO_NAME,
- //医药
- "策略": utils.CE_LUE_NAME,
- //策略
- "非银金融": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "建筑装饰": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "基础化工": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "农林牧渔": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "传媒": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "公用事业": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "建筑材料": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "房地产": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "采掘": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "轻工制造": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "钢铁": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "交通运输": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "国防军工": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "银行": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "有色金属": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "综合": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "商业贸易": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "宏观": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "金融工程": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "商贸零售": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "社会服务": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "煤炭": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "石油石化": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- "环保": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
- //研选
- }
- chartPermissionName = mapIndustrySwName[industrySwName]
- return
- }
- // 获取易董token
- func GetYiDongToken() (token string, err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- utils.FileLog.Info(err.Error())
- }
- }()
- cacheKey := utils.YD_TOKEN
- ttlTime := utils.Rc.GetRedisTTL(cacheKey)
- if ttlTime > 0 {
- token, _ = utils.Rc.RedisString(cacheKey)
- }
- if token == "" {
- url := utils.YiDongZhengTongYunUrl + "oauth/token?grant_type=client_credentials&response_type=token&client_id=" + utils.YiDongZhengTongYunAppid + "&client_secret=" + utils.YiDongZhengTongYunSecret
- method := "GET"
- client := &http.Client{}
- req, errReq := http.NewRequest(method, url, nil)
- if errReq != nil {
- err = errReq
- return
- }
- res, errReq := client.Do(req)
- if errReq != nil {
- err = errReq
- return
- }
- defer res.Body.Close()
- type Ydtoklen struct {
- Success bool `json:"success"`
- ExpiresIn int `json:"expires_in"`
- AccessToken string `json:"access_token"`
- }
- var ydtoklen Ydtoklen
- body, errReq := ioutil.ReadAll(res.Body)
- if errReq != nil {
- err = errReq
- return
- }
- errReq = json.Unmarshal(body, &ydtoklen)
- if errReq != nil {
- err = errReq
- return
- }
- token = ydtoklen.AccessToken
- utils.Rc.Put(cacheKey, ydtoklen.AccessToken, time.Second*7000)
- }
- return
- }
- // 生成用户相关信息接口 获取用户tgc
- func GetYiDongCreateUserInfo(user *models.WxUserItem) (userTgc string, err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- //易董测试环境有问题,先屏蔽一段时间
- if utils.RunMode == "" {
- go utils.SendAlarmMsg("生成用户相关信息接口 获取用户tgc失败:"+err.Error(), 2)
- }
- utils.FileLog.Info(err.Error())
- }
- }()
- url := utils.YiDongHuaWeiYunUrl + "app/hz/createUserInfo"
- method := "POST"
- payload := strings.NewReader(`{
- "phone": "` + user.Mobile + `",
- "personName": "` + user.RealName + `",
- "companyName": "` + user.CompanyName + `",
- "jobName": "` + user.Position + `",
- "mobileCountryCode": "+` + user.CountryCode + `",
- "sourceFrom": "01"
- }`)
- client := &http.Client{}
- req, err := http.NewRequest(method, url, payload)
- if err != nil {
- fmt.Println(err)
- utils.FileLog.Info(err.Error())
- return
- }
- req.Header.Add("Content-Type", "application/json")
- res, err := client.Do(req)
- if err != nil {
- fmt.Println(err)
- utils.FileLog.Info(err.Error())
- return
- }
- defer res.Body.Close()
- var ApifoxModal *models.ApifoxModalUserTgc
- body, err := ioutil.ReadAll(res.Body)
- if err != nil {
- fmt.Println(err)
- utils.FileLog.Info(err.Error())
- return
- }
- err = json.Unmarshal(body, &ApifoxModal)
- if err != nil {
- fmt.Println("Getres.PublicGetDate Err:", err.Error())
- utils.FileLog.Info(err.Error())
- return
- }
- userTgc = ApifoxModal.Result.Tgc
- return
- }
- // GetYiDongOriginalLink 将易懂的短连接转为长链接
- func GetYiDongOriginalLink(item *models.ActivityDetail) (yidongLongLink string, err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg("将易懂的短连接转为长链接 失败:"+err.Error(), 2)
- utils.FileLog.Info(err.Error())
- }
- }()
- sliceYidongActivityUrl := strings.Split(item.YidongActivityUrl, "/")
- var shortLink string
- if len(sliceYidongActivityUrl) > 1 {
- shortLink = sliceYidongActivityUrl[len(sliceYidongActivityUrl)-1]
- }
- var token string
- token, err = GetYiDongToken()
- if err != nil {
- fmt.Println(err)
- return
- }
- url := utils.YiDonggetOriginalLink + shortLink + "&access_token=" + token
- fmt.Println(url)
- method := "GET"
- client := &http.Client{}
- req, err := http.NewRequest(method, url, nil)
- if err != nil {
- fmt.Println(err)
- return
- }
- res, err := client.Do(req)
- if err != nil {
- fmt.Println(err)
- return
- }
- defer res.Body.Close()
- var ApifoxModal *models.ApifoxgetOriginalLink
- body, err := ioutil.ReadAll(res.Body)
- if err != nil {
- fmt.Println(err)
- utils.FileLog.Info(err.Error())
- return
- }
- err = json.Unmarshal(body, &ApifoxModal)
- if err != nil {
- fmt.Println("Getres.PublicGetDate Err:", err.Error())
- utils.FileLog.Info(err.Error())
- return
- }
- lingLink := ApifoxModal.Result
- //fmt.Println(lingLink)
- //
- //slicelingLink := strings.Split(lingLink, "redirect_uri=")
- ////var shortLink string
- //if len(slicelingLink) > 1 {
- // lingLink = slicelingLink[len(slicelingLink)-1]
- //}
- yidongLongLink = lingLink
- return
- }
|