package svc import ( "applet/app/cfg" offical "applet/app/db/official" md2 "applet/app/es/md" "applet/app/task/md" "applet/app/utils" "applet/app/utils/cache" "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tik_tok" zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" "encoding/json" "fmt" "github.com/jinzhu/copier" "github.com/syyongx/php2go" "github.com/tidwall/gjson" "strings" "time" ) func TikTokTask() { //doc, _ := es.FirstDoc(md2.ZhiosTikTokTaskEsIndex, "tik_tok_task_tt99fdef4006c36ff001") //fmt.Println(string(doc.Source)) //return //es.CreateIndexIfNotExists(md2.ZhiosTikTokTaskEsIndex, md2.ZhiosTikTokTaskEsMapping) //es.CreateIndexIfNotExists(md2.ZhiosTikTokTaskDetailEsIndex, md2.ZhiosTikTokTaskDetailEsMapping) appidList := offical.MasterListCfgGetOneData("0", "tik_tok_task_appid") split := strings.Split(appidList, ";") for _, v := range split { endTime := time.Now().Unix() startTime := endTime - 7*86400 if endTime > time.Now().Unix() { endTime = time.Now().Unix() } param := map[string]interface{}{ "appid": v, "create_start_time": startTime, "create_end_time": endTime, } api, _ := tik_tok.TaskApi("query_app_task_id/", TikTokTaskToken(), zhios_third_party_utils.SerializeStr(param)) taskIds := gjson.Get(api, "data.task_ids").String() fmt.Println(taskIds) if taskIds == "" || taskIds == "[]" { fmt.Println(endTime) offical.MasterListCfgSave("0", "tik_tok_task_appid_time_"+v, utils.Int64ToStr(endTime)) continue } CommAddTask("tik_tok_task_"+v, taskIds) var tmp = make([]int64, 0) json.Unmarshal([]byte(taskIds), &tmp) GetTaskDetail(v, tmp) fmt.Println(endTime) offical.MasterListCfgSave("0", "tik_tok_task_appid_time_"+v, utils.Int64ToStr(endTime)) } } func GetTaskDetail(appId string, tmp []int64) { for _, v := range tmp { time.Sleep(time.Microsecond * 1000) param := map[string]interface{}{ "appid": appId, "query_params_type": "1", "query_params_content": utils.Int64ToStr(v), "page_no": "1", "page_size": "10", } api, _ := tik_tok.TaskApi("query_task_info/", TikTokTaskToken(), zhios_third_party_utils.SerializeStr(param)) detail := gjson.Get(api, "data.tasks").String() if detail == "" { fmt.Println("失败", v) continue } var tmpDetail = make([]md.TikTokTaskDetail, 0) json.Unmarshal([]byte(detail), &tmpDetail) for _, v1 := range tmpDetail { var tmpIn md.TikTokTaskDetailSecond err := copier.Copy(&tmpIn, &v1) fmt.Println(err) tmpIn.OrientedTalentRelList = utils.SerializeStr(v1.OrientedTalentRelList) tmpIn.ReferMaCaptures = utils.SerializeStr(v1.ReferMaCaptures) tmpIn.TaskTags = utils.SerializeStr(v1.TaskTags) tmpIn.ReferVideoCaptures = utils.SerializeStr(v1.ReferVideoCaptures) videoTmpStr := "bookId=" if tmpIn.Appid == "tt38e94e54a7d70c4601" { videoTmpStr = "cid=" } else if strings.Contains(tmpIn.StartPage, "novelid=") { videoTmpStr = "novelid=" } else if strings.Contains(tmpIn.StartPage, "video_id=") { videoTmpStr = "video_id=" } ex := strings.Split(tmpIn.StartPage, videoTmpStr) if len(ex) > 1 { exSecond := strings.Split(ex[1], "&") tmpIn.VideoId = exSecond[0] } if tmpIn.VideoId == "" { fmt.Println("失败", tmpIn) continue } if tmpIn.Status != 2 { tmpIn.TaskEndTime = int(time.Now().Unix() - 10) } for _, v2 := range md.TaskAddList { if tmpIn.Appid == v2["name"] { // tmp2 := md.Cinema5bmsData{ Description: "", ImageUrl: tmpIn.TaskIcon, Material: "", OnlineTime: time.Unix(int64(tmpIn.TaskStartTime), 0).Format("2006-01-02 15:04:05"), Type: v2["second_type"], Title: tmpIn.TaskName, UpdateTime: int(time.Now().Unix()), Time: tmpIn.TaskStartTime, Appid: v2["name"], Id: utils.StrToInt(tmpIn.VideoId), IsClose: 0, IsHot: 0, FirstCate: v2["type"], SecondCate: "", Platform: "tikTok", } if tmpIn.TaskEndTime < int(time.Now().Unix()) { tmp2.IsClose = 1 } uniqueId := php2go.Md5(tmp2.Appid + "_" + tmp2.Type + "_" + tmp2.FirstCate + "_" + utils.IntToStr(tmp2.Id)) fmt.Println(uniqueId) tmp2.Key = uniqueId commAddNew(uniqueId, tmp2) } } CommAddTaskDetail(utils.Int64ToStr(tmpIn.TaskId), tmpIn) } } } func CommAddTask(uniqueId string, taskIds string) { doc, _ := es.FirstDoc(md2.ZhiosTikTokTaskEsIndex, uniqueId) if doc == nil { var tmpData = map[string]string{ "task_ids": taskIds, } createDocRet, err := es.CreateDoc(md2.ZhiosTikTokTaskEsIndex, uniqueId, tmpData) if err != nil { return } fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet) } else { source := doc.Source tmpData := make(map[string]string) json.Unmarshal(source, &tmpData) var tmpOld = make([]int64, 0) json.Unmarshal([]byte(tmpData["task_ids"]), &tmpOld) var tmp = make([]int64, 0) json.Unmarshal([]byte(taskIds), &tmp) tmp = utils.MergeArr(tmpOld, tmp) tmp = utils.UniqueArr(tmp) tmpData = map[string]string{ "task_ids": utils.SerializeStr(tmp), } createDocRet, err := es.UpdateDoc(md2.ZhiosTikTokTaskEsIndex, uniqueId, tmpData) if err != nil { return } fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet) } } func CommAddTaskDetail(uniqueId string, tmp md.TikTokTaskDetailSecond) { doc, _ := es.FirstDoc(md2.ZhiosTikTokTaskDetailEsIndex, uniqueId) if doc == nil { createDocRet, err := es.CreateDoc(md2.ZhiosTikTokTaskDetailEsIndex, uniqueId, tmp) if err != nil { return } fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet) } else { createDocRet, err := es.UpdateDoc(md2.ZhiosTikTokTaskDetailEsIndex, uniqueId, tmp) if err != nil { return } fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet) } } func TikTokTaskToken() string { tikTokOpenAppkey := offical.MasterListCfgGetOneData("0", "tik_tok_task_open_appkey") tikTokOpenAppSecret := offical.MasterListCfgGetOneData("0", "tik_tok_task_open_app_secret") args := map[string]string{ "appkey": tikTokOpenAppkey, "appSecret": tikTokOpenAppSecret, } key := "tikTok_client_" + args["appkey"] tokeStr, err := cache.GetString(key) if cfg.Prd == false { return tokeStr } if tokeStr == "" || err != nil { token := tik_tok.GetClientToken(args) if token["tik_tok_acc_token"] != "" { tokeStr = token["tik_tok_acc_token"] cache.SetEx(key, token["tik_tok_acc_token"], utils.StrToInt(token["expires_in"])) } } return tokeStr }