|
@@ -1,17 +1,11 @@
|
|
package resourceChannel
|
|
package resourceChannel
|
|
|
|
|
|
import (
|
|
import (
|
|
- "bytes"
|
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
|
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
|
"github.com/go-redis/redis"
|
|
"github.com/go-redis/redis"
|
|
"golang.org/x/net/context"
|
|
"golang.org/x/net/context"
|
|
- "io/ioutil"
|
|
|
|
"log"
|
|
"log"
|
|
- "net/http"
|
|
|
|
- "net/url"
|
|
|
|
- "path"
|
|
|
|
- "runtime"
|
|
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
@@ -96,42 +90,55 @@ func GetChannel(assessment ResourceAssessment) ChannelCategory {
|
|
// URL解析
|
|
// URL解析
|
|
if strings.Contains(assessment.URL, "link=") || strings.Contains(assessment.ReferPageURL, "link=") || strings.Contains(assessment.ChatURL, "link=") {
|
|
if strings.Contains(assessment.URL, "link=") || strings.Contains(assessment.ReferPageURL, "link=") || strings.Contains(assessment.ChatURL, "link=") {
|
|
log.Printf("解析URL")
|
|
log.Printf("解析URL")
|
|
- if len(strings.Split(assessment.URL, "_")) == 3 {
|
|
|
|
- var category, _ = strconv.Atoi(strings.Split(assessment.URL, "_")[1])
|
|
|
|
|
|
+ if strings.Contains(assessment.URL, "link=") && len(strings.Split(strings.Split(assessment.URL, "link=")[1], "_")) == 3 {
|
|
|
|
+ var category, _ = strconv.Atoi(strings.Split(strings.Split(assessment.URL, "link=")[1], "_")[1])
|
|
if category > 10000 {
|
|
if category > 10000 {
|
|
assessment.Channel = category
|
|
assessment.Channel = category
|
|
assessment.Category = category
|
|
assessment.Category = category
|
|
}
|
|
}
|
|
- }
|
|
|
|
- if strings.Contains(assessment.URL, "link=") {
|
|
|
|
- split := strings.Split(assessment.URL, "link")
|
|
|
|
- if strings.Contains(split[1], "form") || strings.Contains(split[1], "from") {
|
|
|
|
- assessment.Channel, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(assessment.URL, "link")[1], "form")[0], "_")[1])
|
|
|
|
- var category, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(assessment.URL, "link")[1], "form")[0], "_")[2])
|
|
|
|
- assessment.Category = getCategory(category)
|
|
|
|
- } else {
|
|
|
|
- assessment.Channel = 5
|
|
|
|
- assessment.Category = getCategory(11)
|
|
|
|
|
|
+ } else if strings.Contains(assessment.ReferPageURL, "link=") && len(strings.Split(strings.Split(assessment.ReferPageURL, "link=")[1], "_")) == 3 {
|
|
|
|
+ var category, _ = strconv.Atoi(strings.Split(strings.Split(assessment.ReferPageURL, "link=")[1], "_")[1])
|
|
|
|
+ if category > 10000 {
|
|
|
|
+ assessment.Channel = category
|
|
|
|
+ assessment.Category = category
|
|
}
|
|
}
|
|
- } else if strings.Contains(assessment.ReferPageURL, "link=") {
|
|
|
|
- split := strings.Split(assessment.ReferPageURL, "link")
|
|
|
|
- if strings.Contains(split[1], "form") || strings.Contains(split[1], "from") {
|
|
|
|
- assessment.Channel, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(assessment.ReferPageURL, "link")[1], "form")[0], "_")[1])
|
|
|
|
- var category, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(assessment.ReferPageURL, "link")[1], "form")[0], "_")[2])
|
|
|
|
- assessment.Category = getCategory(category)
|
|
|
|
- } else {
|
|
|
|
- assessment.Channel = 5
|
|
|
|
- assessment.Category = getCategory(11)
|
|
|
|
|
|
+ } else if strings.Contains(assessment.ChatURL, "link=") && len(strings.Split(strings.Split(assessment.ChatURL, "link=")[1], "_")) == 3 {
|
|
|
|
+ var category, _ = strconv.Atoi(strings.Split(strings.Split(assessment.ChatURL, "link=")[1], "_")[1])
|
|
|
|
+ if category > 10000 {
|
|
|
|
+ assessment.Channel = category
|
|
|
|
+ assessment.Category = category
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- split := strings.Split(assessment.ChatURL, "link")
|
|
|
|
- if strings.Contains(split[1], "form") || strings.Contains(split[1], "from") {
|
|
|
|
- assessment.Channel, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(assessment.ChatURL, "link")[1], "form")[0], "_")[1])
|
|
|
|
- var category, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(assessment.ChatURL, "link")[1], "form")[0], "_")[2])
|
|
|
|
- assessment.Category = getCategory(category)
|
|
|
|
|
|
+ if strings.Contains(assessment.URL, "link=") {
|
|
|
|
+ split := strings.Split(assessment.URL, "link")
|
|
|
|
+ if strings.Contains(split[1], "form") || strings.Contains(split[1], "from") {
|
|
|
|
+ assessment.Channel, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(assessment.URL, "link")[1], "form")[0], "_")[1])
|
|
|
|
+ var category, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(assessment.URL, "link")[1], "form")[0], "_")[2])
|
|
|
|
+ assessment.Category = getCategory(category)
|
|
|
|
+ } else {
|
|
|
|
+ assessment.Channel = 5
|
|
|
|
+ assessment.Category = getCategory(11)
|
|
|
|
+ }
|
|
|
|
+ } else if strings.Contains(assessment.ReferPageURL, "link=") {
|
|
|
|
+ split := strings.Split(assessment.ReferPageURL, "link")
|
|
|
|
+ if strings.Contains(split[1], "form") || strings.Contains(split[1], "from") {
|
|
|
|
+ assessment.Channel, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(assessment.ReferPageURL, "link")[1], "form")[0], "_")[1])
|
|
|
|
+ var category, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(assessment.ReferPageURL, "link")[1], "form")[0], "_")[2])
|
|
|
|
+ assessment.Category = getCategory(category)
|
|
|
|
+ } else {
|
|
|
|
+ assessment.Channel = 5
|
|
|
|
+ assessment.Category = getCategory(11)
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- assessment.Channel = 5
|
|
|
|
- assessment.Category = getCategory(11)
|
|
|
|
|
|
+ split := strings.Split(assessment.ChatURL, "link")
|
|
|
|
+ if strings.Contains(split[1], "form") || strings.Contains(split[1], "from") {
|
|
|
|
+ assessment.Channel, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(assessment.ChatURL, "link")[1], "form")[0], "_")[1])
|
|
|
|
+ var category, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(assessment.ChatURL, "link")[1], "form")[0], "_")[2])
|
|
|
|
+ assessment.Category = getCategory(category)
|
|
|
|
+ } else {
|
|
|
|
+ assessment.Channel = 5
|
|
|
|
+ assessment.Category = getCategory(11)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 百度惠生活渠道合并
|
|
// 百度惠生活渠道合并
|
|
@@ -209,25 +216,39 @@ func GetChatChannel(chat SemJsChatRecord) ChannelCategory {
|
|
// URL解析
|
|
// URL解析
|
|
if strings.Contains(chat.ChatURL, "link=") || strings.Contains(chat.ReferPage, "link=") {
|
|
if strings.Contains(chat.ChatURL, "link=") || strings.Contains(chat.ReferPage, "link=") {
|
|
log.Printf("解析CHATURL")
|
|
log.Printf("解析CHATURL")
|
|
- if strings.Contains(chat.ChatURL, "link=") {
|
|
|
|
- split := strings.Split(chat.ChatURL, "link=")
|
|
|
|
- if strings.Contains(split[1], "form") || strings.Contains(split[1], "from") {
|
|
|
|
- chat.ChannleID, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(chat.ChatURL, "link")[1], "form")[0], "_")[1])
|
|
|
|
- var category, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(chat.ChatURL, "link")[1], "form")[0], "_")[2])
|
|
|
|
- chat.CategoryID = getCategory(category)
|
|
|
|
- } else {
|
|
|
|
- chat.ChannleID = 5
|
|
|
|
- chat.CategoryID = getCategory(11)
|
|
|
|
|
|
+ if strings.Contains(chat.ChatURL, "link=") && len(strings.Split(strings.Split(chat.ChatURL, "link=")[1], "_")) == 3 {
|
|
|
|
+ var category, _ = strconv.Atoi(strings.Split(strings.Split(chat.ChatURL, "link=")[1], "_")[1])
|
|
|
|
+ if category > 10000 {
|
|
|
|
+ chat.ChannleID = category
|
|
|
|
+ chat.CategoryID = category
|
|
|
|
+ }
|
|
|
|
+ } else if strings.Contains(chat.ReferPage, "link=") && len(strings.Split(strings.Split(chat.ReferPage, "link=")[1], "_")) == 3 {
|
|
|
|
+ var category, _ = strconv.Atoi(strings.Split(strings.Split(chat.ReferPage, "link=")[1], "_")[1])
|
|
|
|
+ if category > 10000 {
|
|
|
|
+ chat.ChannleID = category
|
|
|
|
+ chat.CategoryID = category
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- split := strings.Split(chat.ReferPage, "link=")
|
|
|
|
- if strings.Contains(split[01], "form") || strings.Contains(split[1], "from") {
|
|
|
|
- chat.ChannleID, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(chat.ReferPage, "link")[1], "form")[0], "_")[1])
|
|
|
|
- var category, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(chat.ReferPage, "link")[1], "form")[0], "_")[2])
|
|
|
|
- chat.CategoryID = getCategory(category)
|
|
|
|
|
|
+ if strings.Contains(chat.ChatURL, "link=") {
|
|
|
|
+ split := strings.Split(chat.ChatURL, "link=")
|
|
|
|
+ if strings.Contains(split[1], "form") || strings.Contains(split[1], "from") {
|
|
|
|
+ chat.ChannleID, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(chat.ChatURL, "link")[1], "form")[0], "_")[1])
|
|
|
|
+ var category, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(chat.ChatURL, "link")[1], "form")[0], "_")[2])
|
|
|
|
+ chat.CategoryID = getCategory(category)
|
|
|
|
+ } else {
|
|
|
|
+ chat.ChannleID = 5
|
|
|
|
+ chat.CategoryID = getCategory(11)
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- chat.ChannleID = 5
|
|
|
|
- chat.CategoryID = getCategory(11)
|
|
|
|
|
|
+ split := strings.Split(chat.ReferPage, "link=")
|
|
|
|
+ if strings.Contains(split[01], "form") || strings.Contains(split[1], "from") {
|
|
|
|
+ chat.ChannleID, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(chat.ReferPage, "link")[1], "form")[0], "_")[1])
|
|
|
|
+ var category, _ = strconv.Atoi(strings.Split(strings.Split(strings.Split(chat.ReferPage, "link")[1], "form")[0], "_")[2])
|
|
|
|
+ chat.CategoryID = getCategory(category)
|
|
|
|
+ } else {
|
|
|
|
+ chat.ChannleID = 5
|
|
|
|
+ chat.CategoryID = getCategory(11)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 百度惠生活渠道合并
|
|
// 百度惠生活渠道合并
|
|
@@ -280,48 +301,11 @@ type SensorsData struct {
|
|
Url string `json:"url"`
|
|
Url string `json:"url"`
|
|
}
|
|
}
|
|
|
|
|
|
-// 访问神策API
|
|
|
|
-func getSensorsData(sql string) string {
|
|
|
|
- sensorsUrl := "http://10.0.6.35:8107/api/sql/query?token=128d837f466684101710cfb308e7556de975b717c6c2465ba5fc2836d57a64c8&project=production&type=impala&q=" + url.QueryEscape(sql) + "&format=json"
|
|
|
|
- data := []byte("")
|
|
|
|
- log.Printf("REQ_URL:%s", sensorsUrl)
|
|
|
|
- req, err := http.NewRequest("POST", sensorsUrl, bytes.NewBuffer(data))
|
|
|
|
- if err != nil {
|
|
|
|
- log.Printf("ERROR:%s", err.Error())
|
|
|
|
- return err.Error()
|
|
|
|
- }
|
|
|
|
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
- client := &http.Client{}
|
|
|
|
- resp, err := client.Do(req)
|
|
|
|
- if err != nil {
|
|
|
|
- return err.Error()
|
|
|
|
- }
|
|
|
|
- defer resp.Body.Close()
|
|
|
|
- respBody, err := ioutil.ReadAll(resp.Body)
|
|
|
|
- if err != nil {
|
|
|
|
- return err.Error()
|
|
|
|
- }
|
|
|
|
- var sensors Sensors
|
|
|
|
- json.Unmarshal([]byte(string(respBody)), &sensors)
|
|
|
|
- return sensors.LatestReferrer
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// Sensors 神策数据结构体
|
|
|
|
-type Sensors struct {
|
|
|
|
- Url string `json:"$url"`
|
|
|
|
- LatestReferrer string `json:"$latest_referrer"`
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
type SysChannel struct {
|
|
type SysChannel struct {
|
|
OriginalCategory string `json:"original_category"` // 主键ID
|
|
OriginalCategory string `json:"original_category"` // 主键ID
|
|
CategoryId string `json:"category_id"` // 备注
|
|
CategoryId string `json:"category_id"` // 备注
|
|
}
|
|
}
|
|
|
|
|
|
-func getCurrentPath() string {
|
|
|
|
- _, filename, _, _ := runtime.Caller(1)
|
|
|
|
- return path.Dir(filename)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
func getCategory(OriginalCategory int) int {
|
|
func getCategory(OriginalCategory int) int {
|
|
endpoint := "oss-cn-beijing.aliyuncs.com" // 例如 "oss-cn-hangzhou.aliyuncs.com"
|
|
endpoint := "oss-cn-beijing.aliyuncs.com" // 例如 "oss-cn-hangzhou.aliyuncs.com"
|
|
accessKeyID := "LTAI5t7iAtrYaUgGgK8ws54e"
|
|
accessKeyID := "LTAI5t7iAtrYaUgGgK8ws54e"
|