package svc import ( "applet/app/cfg" offical "applet/app/db/official" md2 "applet/app/es/md" md3 "applet/app/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) { data := md3.KujiangData var kujiang []md.KuJiang json.Unmarshal([]byte(data), &kujiang) kujiangMap := make(map[string]md.KuJiang) for _, v := range kujiang { kujiangMap[utils.IntToStr(v.BookId)] = v } xinghes := map[string]string{ "7367316323904372772": "https://pan.baidu.com/s/1kf58ZCgI0BgCLQapMfrTbQ?pwd=cceg", "7367710375317520399": "https://pan.baidu.com/s/1aEaDUhSM-4VDTxn40wXm3A?pwd=6e8b", "7368329261691961371": "https://pan.baidu.com/s/171ZRDKRRU3aP7ZMBDy0vsQ?pwd=sipq", "7366906746314555404": "https://pan.baidu.com/s/1MNfbPba3Nt2pTnHTfBUEBA?pwd=ew3v", "7366102746245726248": "https://pan.baidu.com/s/1WzXSrkemz0Hm0DTNcmTpxA?pwd=y2j0", "7365004815451062312": "https://pan.baidu.com/s/1q2XYO3GraSEvdX2F3JcX4Q?pwd=glby", "7363157598629068819": "https://pan.baidu.com/s/1NPtnl5EBK7jRRgk7kSStPg?pwd=86p6", "7362021099053383714": "https://pan.baidu.com/s/19mqfaAt5zovNO1sb0e-bxw?pwd=qae9", "7361659856501129279": "https://pan.baidu.com/s/1XtOabN5ZGsxG9x_CjF2Aig?pwd=ztet", "7361209400553521167": "https://pan.baidu.com/s/10BSo8P9wcxgYa-Li3dUiGA?pwd=6vlf", "7360937011936510006": "https://pan.baidu.com/s/1WlN5HLmcaADy0jGdiCaGFQ?pwd=tiwb", "7358322670871576616": "https://pan.baidu.com/s/13RET87iAbgZlj-jn5mUwUg?pwd=y9rd", "7357194974695391268": "https://pan.baidu.com/s/1cBU9PIXW99Y5W1XhvdPIpA?pwd=uxc6", "7356840659325583414": "https://pan.baidu.com/s/1znMbDDAnIRQ7PwtiznOvTQ?pwd=9nj7", "7356392523553636364": "https://pan.baidu.com/s/17YWBPOVbIi1QR-uKAAJEvQ?pwd=pph1", "7355357328834658319": "https://pan.baidu.com/s/1uoDFjFm9iWt5eXGCYwx0Sg?pwd=9i8p", "7353386971026309183": "https://pan.baidu.com/s/1LCgvkFblrE43e4JtxSOR4Q?pwd=svb5", "7350898126372323369": "https://pan.baidu.com/s/1P6E4vYl-2x0s_qw1X5oviQ?pwd=84xz", "7350859162219184139": "https://pan.baidu.com/s/1mUHucK0x5af8G40hJbLzqw?pwd=0dh1", "7349282971213512754": "https://pan.baidu.com/s/18QgGyqjzW7aImhQ8a2_SJQ?pwd=aswx", "7348970835950043147": "https://pan.baidu.com/s/1JEL9kvkrvzcZUKwexlhPhw?pwd=gadt", "7348684759972724745": "https://pan.baidu.com/s/1sqnsG74rqE8vKVz4-mibgw?pwd=q7us", "7348649376765460531": "https://pan.baidu.com/s/18AIW_J7XHGZFbEsa4zbEZw?pwd=akgy", "7348320058776502322": "https://pan.baidu.com/s/1RImOhdsbwT-d58U8x9Cl7g?pwd=5oy1", "7348220904138227746": "https://pan.baidu.com/s/1WL1ZCM5w9opVJRHq2_tQkg?pwd=08gs", "7347939532555304972": "https://pan.baidu.com/s/1A3vmJaRPU9YFmNZje9ttDw?pwd=2vjp", "7347576656296443941": "https://pan.baidu.com/s/106MDSCSM7BCTx_1kex65gA?pwd=t1gm", "7346064108011257897": "https://pan.baidu.com/s/1NY7JuB-2KUlvtbKZqI7vew?pwd=kpt4", "7345229086283055156": "https://pan.baidu.com/s/1mkkF_bhOh3E7sZf6ymIv0g?pwd=zl3m", "7344970667663589410": "https://pan.baidu.com/s/17e5bb0dGQ183zHWkO49cmg?pwd=l193", "7343744932248600616": "https://pan.baidu.com/s/1vL1g1aGhgXMtNEah4TQFxw?pwd=ub0r", "7342692698744193063": "https://pan.baidu.com/s/1MOaSBkuHGzvv9n1GPc-B3Q?pwd=69fg", "7340706698497212455": "https://pan.baidu.com/s/1vB8aG2U3kserxWsm3bR1Zg?pwd=qszf", "7340019974860914715": "https://pan.baidu.com/s/1bykE9LVcNCePutJ4Rmz14A?pwd=dvrx", "7338982451538133026": "https://pan.baidu.com/s/10GqBT2oBHTdIrtLvm7C3Mg?pwd=203x", "7336393071648587816": "https://pan.baidu.com/s/1Zl0zxZg3dcTuGsge8pD-SA?pwd=este", "7335313319047315456": "https://pan.baidu.com/s/1QQZQlgy-WN9hXKjSe59smg?pwd=klno", "7334158528300482571": "https://pan.baidu.com/s/1DuWh9nZwec3uTAoqwLzIEA?pwd=qs0v", "7333417334876454949": "https://pan.baidu.com/s/1l5FvB35F9YPnwllSpYPvSA?pwd=ogdy", "7333416896286507044": "https://pan.baidu.com/s/1S2E0DXe1w6z5kU5r9fGGoQ?pwd=k0br", "7332303743809011739": "https://pan.baidu.com/s/1S4I4smzV8I3-jytmua1kLg?pwd=2zhv", "7331643707597864997": "https://pan.baidu.com/s/1WWMY8bWnNLSxCaD0x_Gv0Q?pwd=scm5", "7331637776204480575": "https://pan.baidu.com/s/1PAYJUrYhZ71XivTZFSxw5Q?pwd=v1n7", "7330834016368623657": "https://pan.baidu.com/s/1yB46HJtIjjffc0w8RmeRTQ?pwd=x1v3", "7330529933564919823": "https://pan.baidu.com/s/1PzKUtgetU8bVTILFYxSrNQ?pwd=ul4a", "7330518079224512550": "https://pan.baidu.com/s/1I1o9UV89oYCVmzJc5bCe1g?pwd=5nxe", "7327911477510209548": "https://pan.baidu.com/s/1ebMtvlMV2UCCvTOx7znFsA?pwd=d00o", "7326049857058177024": "https://pan.baidu.com/s/1WtKwzdeiPQz0AjKzieU_6w?pwd=prkh", "7324972262531153959": "https://pan.baidu.com/s/1qZCfNogUvYWWlkJ225qNQQ?pwd=l0ui", "7324518583126753314": "https://pan.baidu.com/s/1yf7X6iI6bPYcJNLKTdd8QQ?pwd=kyvc", "7324525415568015411": "https://pan.baidu.com/s/1ZxrZMbySTtMX_5F0eW24Aw?pwd=2hht", "7324518767126429734": "https://pan.baidu.com/s/1J7CJYI76-I-9APIq1pzE5A?pwd=ai6t", "7324518642941476905": "https://pan.baidu.com/s/1t3tcaGhCjsTwRSTXQJ4_-g?pwd=s9d9", "7324518215852228644": "https://pan.baidu.com/s/1w7qG9kSfpZD1hCohnU8vUQ?pwd=0a3w", "7324510965024751650": "https://pan.baidu.com/s/1bzzIqBftk030n8ZRddnnRA?pwd=6k6e", "7320876050387353611": "https://pan.baidu.com/s/1Y6oe-upHqA72ivDp4MWBUA?pwd=04th", "7318971545959170058": "https://pan.baidu.com/s/1jEOgXAR7e5Oqd3KZ2e1zyg?pwd=wvb9", "7313727507914686476": "https://pan.baidu.com/s/1awg3uiLk5t1EJPGiUXhxyQ?pwd=ppwu", "7313751212422201379": "https://pan.baidu.com/s/1awg3uiLk5t1EJPGiUXhxyQ?pwd=ppwu", "7312337908660437004": "https://pan.baidu.com/s/1Q-6nsaWTmj3UWCdSdOQErw?pwd=4sl3", "7312292128947257383": "https://pan.baidu.com/s/1D71HmPOWkAeBmVk9ujU8dQ?pwd=ta3n", "7312294620745056267": "https://pan.baidu.com/s/1CI0fC50UWsxKLcQ4AIlUhQ?pwd=pi51", "7312295241607790643": "https://pan.baidu.com/s/1-8w4R1ypihnHw-djYQHXcg?pwd=p5h8", "7312292122370031670": "https://pan.baidu.com/s/1pZM-FzOQQrZjhgQ_Kn1nAQ?pwd=ryu0", "7312291614532599843": "https://pan.baidu.com/s/16794mteTYOn6nzu8k1gIBg?pwd=xdsg", "7312007303753957395": "https://pan.baidu.com/s/1hEyBrPTm0Rtkl1mP-1myxQ?pwd=di9v", } 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, "book_id=") { videoTmpStr = "book_id=" } 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: "", } if v2["second_type"] == "xinghe" { tmp2.Material = xinghes[utils.Int64ToStr(tmpIn.TaskId)] } uniqueId := php2go.Md5(tmp2.Appid + "_" + tmp2.Type + "_" + tmp2.FirstCate + "_" + utils.IntToStr(tmp2.Id)) if tmp2.Appid == "ttbed9c86421e54c8501" { doc, _ := es.FirstDoc(md2.ZhiosNewVideo, uniqueId) if tmpIn.TaskEndTime > int(time.Now().Unix()) { tmp2.Platform = "tikTok" } if doc != nil && strings.Contains(gjson.Get(string(doc.Source), "platform").String(), "kuaishou") { if tmpIn.TaskEndTime > int(time.Now().Unix()) { tmp2.Platform = "tikTok,kuaishou" } else { tmp2.Platform = "kuaishou" } } jiang, ok := kujiangMap[tmpIn.VideoId] if ok { tmp2.Material = jiang.WebDiskUrl } } else { tmp2.Platform = "tikTok" if tmpIn.TaskEndTime < int(time.Now().Unix()) { tmp2.IsClose = 1 } } if tmp2.Platform == "" { tmp2.IsClose = 1 } 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 }