智盟项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

312 lines
13 KiB

  1. package svc
  2. import (
  3. "applet/app/cfg"
  4. offical "applet/app/db/official"
  5. md2 "applet/app/es/md"
  6. md3 "applet/app/md"
  7. "applet/app/task/md"
  8. "applet/app/utils"
  9. "applet/app/utils/cache"
  10. "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
  11. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tik_tok"
  12. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  13. "encoding/json"
  14. "fmt"
  15. "github.com/jinzhu/copier"
  16. "github.com/syyongx/php2go"
  17. "github.com/tidwall/gjson"
  18. "strings"
  19. "time"
  20. )
  21. func TikTokTask() {
  22. //doc, _ := es.FirstDoc(md2.ZhiosTikTokTaskEsIndex, "tik_tok_task_tt99fdef4006c36ff001")
  23. //fmt.Println(string(doc.Source))
  24. //return
  25. //es.CreateIndexIfNotExists(md2.ZhiosTikTokTaskEsIndex, md2.ZhiosTikTokTaskEsMapping)
  26. //es.CreateIndexIfNotExists(md2.ZhiosTikTokTaskDetailEsIndex, md2.ZhiosTikTokTaskDetailEsMapping)
  27. appidList := offical.MasterListCfgGetOneData("0", "tik_tok_task_appid")
  28. split := strings.Split(appidList, ";")
  29. for _, v := range split {
  30. endTime := time.Now().Unix()
  31. startTime := endTime - 7*86400
  32. if endTime > time.Now().Unix() {
  33. endTime = time.Now().Unix()
  34. }
  35. param := map[string]interface{}{
  36. "appid": v,
  37. "create_start_time": startTime,
  38. "create_end_time": endTime,
  39. }
  40. api, _ := tik_tok.TaskApi("query_app_task_id/", TikTokTaskToken(), zhios_third_party_utils.SerializeStr(param))
  41. taskIds := gjson.Get(api, "data.task_ids").String()
  42. fmt.Println(taskIds)
  43. if taskIds == "" || taskIds == "[]" {
  44. fmt.Println(endTime)
  45. offical.MasterListCfgSave("0", "tik_tok_task_appid_time_"+v, utils.Int64ToStr(endTime))
  46. continue
  47. }
  48. CommAddTask("tik_tok_task_"+v, taskIds)
  49. var tmp = make([]int64, 0)
  50. json.Unmarshal([]byte(taskIds), &tmp)
  51. GetTaskDetail(v, tmp)
  52. fmt.Println(endTime)
  53. offical.MasterListCfgSave("0", "tik_tok_task_appid_time_"+v, utils.Int64ToStr(endTime))
  54. }
  55. }
  56. func GetTaskDetail(appId string, tmp []int64) {
  57. data := md3.KujiangData
  58. var kujiang []md.KuJiang
  59. json.Unmarshal([]byte(data), &kujiang)
  60. kujiangMap := make(map[string]md.KuJiang)
  61. for _, v := range kujiang {
  62. kujiangMap[utils.IntToStr(v.BookId)] = v
  63. }
  64. xinghes := map[string]string{
  65. "7367316323904372772": "https://pan.baidu.com/s/1kf58ZCgI0BgCLQapMfrTbQ?pwd=cceg",
  66. "7367710375317520399": "https://pan.baidu.com/s/1aEaDUhSM-4VDTxn40wXm3A?pwd=6e8b",
  67. "7368329261691961371": "https://pan.baidu.com/s/171ZRDKRRU3aP7ZMBDy0vsQ?pwd=sipq",
  68. "7366906746314555404": "https://pan.baidu.com/s/1MNfbPba3Nt2pTnHTfBUEBA?pwd=ew3v",
  69. "7366102746245726248": "https://pan.baidu.com/s/1WzXSrkemz0Hm0DTNcmTpxA?pwd=y2j0",
  70. "7365004815451062312": "https://pan.baidu.com/s/1q2XYO3GraSEvdX2F3JcX4Q?pwd=glby",
  71. "7363157598629068819": "https://pan.baidu.com/s/1NPtnl5EBK7jRRgk7kSStPg?pwd=86p6",
  72. "7362021099053383714": "https://pan.baidu.com/s/19mqfaAt5zovNO1sb0e-bxw?pwd=qae9",
  73. "7361659856501129279": "https://pan.baidu.com/s/1XtOabN5ZGsxG9x_CjF2Aig?pwd=ztet",
  74. "7361209400553521167": "https://pan.baidu.com/s/10BSo8P9wcxgYa-Li3dUiGA?pwd=6vlf",
  75. "7360937011936510006": "https://pan.baidu.com/s/1WlN5HLmcaADy0jGdiCaGFQ?pwd=tiwb",
  76. "7358322670871576616": "https://pan.baidu.com/s/13RET87iAbgZlj-jn5mUwUg?pwd=y9rd",
  77. "7357194974695391268": "https://pan.baidu.com/s/1cBU9PIXW99Y5W1XhvdPIpA?pwd=uxc6",
  78. "7356840659325583414": "https://pan.baidu.com/s/1znMbDDAnIRQ7PwtiznOvTQ?pwd=9nj7",
  79. "7356392523553636364": "https://pan.baidu.com/s/17YWBPOVbIi1QR-uKAAJEvQ?pwd=pph1",
  80. "7355357328834658319": "https://pan.baidu.com/s/1uoDFjFm9iWt5eXGCYwx0Sg?pwd=9i8p",
  81. "7353386971026309183": "https://pan.baidu.com/s/1LCgvkFblrE43e4JtxSOR4Q?pwd=svb5",
  82. "7350898126372323369": "https://pan.baidu.com/s/1P6E4vYl-2x0s_qw1X5oviQ?pwd=84xz",
  83. "7350859162219184139": "https://pan.baidu.com/s/1mUHucK0x5af8G40hJbLzqw?pwd=0dh1",
  84. "7349282971213512754": "https://pan.baidu.com/s/18QgGyqjzW7aImhQ8a2_SJQ?pwd=aswx",
  85. "7348970835950043147": "https://pan.baidu.com/s/1JEL9kvkrvzcZUKwexlhPhw?pwd=gadt",
  86. "7348684759972724745": "https://pan.baidu.com/s/1sqnsG74rqE8vKVz4-mibgw?pwd=q7us",
  87. "7348649376765460531": "https://pan.baidu.com/s/18AIW_J7XHGZFbEsa4zbEZw?pwd=akgy",
  88. "7348320058776502322": "https://pan.baidu.com/s/1RImOhdsbwT-d58U8x9Cl7g?pwd=5oy1",
  89. "7348220904138227746": "https://pan.baidu.com/s/1WL1ZCM5w9opVJRHq2_tQkg?pwd=08gs",
  90. "7347939532555304972": "https://pan.baidu.com/s/1A3vmJaRPU9YFmNZje9ttDw?pwd=2vjp",
  91. "7347576656296443941": "https://pan.baidu.com/s/106MDSCSM7BCTx_1kex65gA?pwd=t1gm",
  92. "7346064108011257897": "https://pan.baidu.com/s/1NY7JuB-2KUlvtbKZqI7vew?pwd=kpt4",
  93. "7345229086283055156": "https://pan.baidu.com/s/1mkkF_bhOh3E7sZf6ymIv0g?pwd=zl3m",
  94. "7344970667663589410": "https://pan.baidu.com/s/17e5bb0dGQ183zHWkO49cmg?pwd=l193",
  95. "7343744932248600616": "https://pan.baidu.com/s/1vL1g1aGhgXMtNEah4TQFxw?pwd=ub0r",
  96. "7342692698744193063": "https://pan.baidu.com/s/1MOaSBkuHGzvv9n1GPc-B3Q?pwd=69fg",
  97. "7340706698497212455": "https://pan.baidu.com/s/1vB8aG2U3kserxWsm3bR1Zg?pwd=qszf",
  98. "7340019974860914715": "https://pan.baidu.com/s/1bykE9LVcNCePutJ4Rmz14A?pwd=dvrx",
  99. "7338982451538133026": "https://pan.baidu.com/s/10GqBT2oBHTdIrtLvm7C3Mg?pwd=203x",
  100. "7336393071648587816": "https://pan.baidu.com/s/1Zl0zxZg3dcTuGsge8pD-SA?pwd=este",
  101. "7335313319047315456": "https://pan.baidu.com/s/1QQZQlgy-WN9hXKjSe59smg?pwd=klno",
  102. "7334158528300482571": "https://pan.baidu.com/s/1DuWh9nZwec3uTAoqwLzIEA?pwd=qs0v",
  103. "7333417334876454949": "https://pan.baidu.com/s/1l5FvB35F9YPnwllSpYPvSA?pwd=ogdy",
  104. "7333416896286507044": "https://pan.baidu.com/s/1S2E0DXe1w6z5kU5r9fGGoQ?pwd=k0br",
  105. "7332303743809011739": "https://pan.baidu.com/s/1S4I4smzV8I3-jytmua1kLg?pwd=2zhv",
  106. "7331643707597864997": "https://pan.baidu.com/s/1WWMY8bWnNLSxCaD0x_Gv0Q?pwd=scm5",
  107. "7331637776204480575": "https://pan.baidu.com/s/1PAYJUrYhZ71XivTZFSxw5Q?pwd=v1n7",
  108. "7330834016368623657": "https://pan.baidu.com/s/1yB46HJtIjjffc0w8RmeRTQ?pwd=x1v3",
  109. "7330529933564919823": "https://pan.baidu.com/s/1PzKUtgetU8bVTILFYxSrNQ?pwd=ul4a",
  110. "7330518079224512550": "https://pan.baidu.com/s/1I1o9UV89oYCVmzJc5bCe1g?pwd=5nxe",
  111. "7327911477510209548": "https://pan.baidu.com/s/1ebMtvlMV2UCCvTOx7znFsA?pwd=d00o",
  112. "7326049857058177024": "https://pan.baidu.com/s/1WtKwzdeiPQz0AjKzieU_6w?pwd=prkh",
  113. "7324972262531153959": "https://pan.baidu.com/s/1qZCfNogUvYWWlkJ225qNQQ?pwd=l0ui",
  114. "7324518583126753314": "https://pan.baidu.com/s/1yf7X6iI6bPYcJNLKTdd8QQ?pwd=kyvc",
  115. "7324525415568015411": "https://pan.baidu.com/s/1ZxrZMbySTtMX_5F0eW24Aw?pwd=2hht",
  116. "7324518767126429734": "https://pan.baidu.com/s/1J7CJYI76-I-9APIq1pzE5A?pwd=ai6t",
  117. "7324518642941476905": "https://pan.baidu.com/s/1t3tcaGhCjsTwRSTXQJ4_-g?pwd=s9d9",
  118. "7324518215852228644": "https://pan.baidu.com/s/1w7qG9kSfpZD1hCohnU8vUQ?pwd=0a3w",
  119. "7324510965024751650": "https://pan.baidu.com/s/1bzzIqBftk030n8ZRddnnRA?pwd=6k6e",
  120. "7320876050387353611": "https://pan.baidu.com/s/1Y6oe-upHqA72ivDp4MWBUA?pwd=04th",
  121. "7318971545959170058": "https://pan.baidu.com/s/1jEOgXAR7e5Oqd3KZ2e1zyg?pwd=wvb9",
  122. "7313727507914686476": "https://pan.baidu.com/s/1awg3uiLk5t1EJPGiUXhxyQ?pwd=ppwu",
  123. "7313751212422201379": "https://pan.baidu.com/s/1awg3uiLk5t1EJPGiUXhxyQ?pwd=ppwu",
  124. "7312337908660437004": "https://pan.baidu.com/s/1Q-6nsaWTmj3UWCdSdOQErw?pwd=4sl3",
  125. "7312292128947257383": "https://pan.baidu.com/s/1D71HmPOWkAeBmVk9ujU8dQ?pwd=ta3n",
  126. "7312294620745056267": "https://pan.baidu.com/s/1CI0fC50UWsxKLcQ4AIlUhQ?pwd=pi51",
  127. "7312295241607790643": "https://pan.baidu.com/s/1-8w4R1ypihnHw-djYQHXcg?pwd=p5h8",
  128. "7312292122370031670": "https://pan.baidu.com/s/1pZM-FzOQQrZjhgQ_Kn1nAQ?pwd=ryu0",
  129. "7312291614532599843": "https://pan.baidu.com/s/16794mteTYOn6nzu8k1gIBg?pwd=xdsg",
  130. "7312007303753957395": "https://pan.baidu.com/s/1hEyBrPTm0Rtkl1mP-1myxQ?pwd=di9v",
  131. }
  132. for _, v := range tmp {
  133. time.Sleep(time.Microsecond * 1000)
  134. param := map[string]interface{}{
  135. "appid": appId,
  136. "query_params_type": "1",
  137. "query_params_content": utils.Int64ToStr(v),
  138. "page_no": "1",
  139. "page_size": "10",
  140. }
  141. api, _ := tik_tok.TaskApi("query_task_info/", TikTokTaskToken(), zhios_third_party_utils.SerializeStr(param))
  142. detail := gjson.Get(api, "data.tasks").String()
  143. if detail == "" {
  144. fmt.Println("失败", v)
  145. continue
  146. }
  147. var tmpDetail = make([]md.TikTokTaskDetail, 0)
  148. json.Unmarshal([]byte(detail), &tmpDetail)
  149. for _, v1 := range tmpDetail {
  150. var tmpIn md.TikTokTaskDetailSecond
  151. err := copier.Copy(&tmpIn, &v1)
  152. fmt.Println(err)
  153. tmpIn.OrientedTalentRelList = utils.SerializeStr(v1.OrientedTalentRelList)
  154. tmpIn.ReferMaCaptures = utils.SerializeStr(v1.ReferMaCaptures)
  155. tmpIn.TaskTags = utils.SerializeStr(v1.TaskTags)
  156. tmpIn.ReferVideoCaptures = utils.SerializeStr(v1.ReferVideoCaptures)
  157. videoTmpStr := "bookId="
  158. if tmpIn.Appid == "tt38e94e54a7d70c4601" {
  159. videoTmpStr = "cid="
  160. } else if strings.Contains(tmpIn.StartPage, "novelid=") {
  161. videoTmpStr = "novelid="
  162. } else if strings.Contains(tmpIn.StartPage, "book_id=") {
  163. videoTmpStr = "book_id="
  164. } else if strings.Contains(tmpIn.StartPage, "video_id=") {
  165. videoTmpStr = "video_id="
  166. }
  167. ex := strings.Split(tmpIn.StartPage, videoTmpStr)
  168. if len(ex) > 1 {
  169. exSecond := strings.Split(ex[1], "&")
  170. tmpIn.VideoId = exSecond[0]
  171. }
  172. if tmpIn.VideoId == "" {
  173. fmt.Println("失败", tmpIn)
  174. continue
  175. }
  176. if tmpIn.Status != 2 {
  177. tmpIn.TaskEndTime = int(time.Now().Unix() - 10)
  178. }
  179. for _, v2 := range md.TaskAddList {
  180. if tmpIn.Appid == v2["name"] { //
  181. tmp2 := md.Cinema5bmsData{
  182. Description: "",
  183. ImageUrl: tmpIn.TaskIcon,
  184. Material: "",
  185. OnlineTime: time.Unix(int64(tmpIn.TaskStartTime), 0).Format("2006-01-02 15:04:05"),
  186. Type: v2["second_type"],
  187. Title: tmpIn.TaskName,
  188. UpdateTime: int(time.Now().Unix()),
  189. Time: tmpIn.TaskStartTime,
  190. Appid: v2["name"],
  191. Id: utils.StrToInt(tmpIn.VideoId),
  192. IsClose: 0,
  193. IsHot: 0,
  194. FirstCate: v2["type"],
  195. SecondCate: "",
  196. Platform: "",
  197. }
  198. if v2["second_type"] == "xinghe" {
  199. tmp2.Material = xinghes[utils.Int64ToStr(tmpIn.TaskId)]
  200. }
  201. uniqueId := php2go.Md5(tmp2.Appid + "_" + tmp2.Type + "_" + tmp2.FirstCate + "_" + utils.IntToStr(tmp2.Id))
  202. if tmp2.Appid == "ttbed9c86421e54c8501" {
  203. doc, _ := es.FirstDoc(md2.ZhiosNewVideo, uniqueId)
  204. if tmpIn.TaskEndTime > int(time.Now().Unix()) {
  205. tmp2.Platform = "tikTok"
  206. }
  207. if doc != nil && strings.Contains(gjson.Get(string(doc.Source), "platform").String(), "kuaishou") {
  208. if tmpIn.TaskEndTime > int(time.Now().Unix()) {
  209. tmp2.Platform = "tikTok,kuaishou"
  210. } else {
  211. tmp2.Platform = "kuaishou"
  212. }
  213. }
  214. jiang, ok := kujiangMap[tmpIn.VideoId]
  215. if ok {
  216. tmp2.Material = jiang.WebDiskUrl
  217. }
  218. } else {
  219. tmp2.Platform = "tikTok"
  220. if tmpIn.TaskEndTime < int(time.Now().Unix()) {
  221. tmp2.IsClose = 1
  222. }
  223. }
  224. if tmp2.Platform == "" {
  225. tmp2.IsClose = 1
  226. }
  227. fmt.Println(uniqueId)
  228. tmp2.Key = uniqueId
  229. commAddNew(uniqueId, tmp2)
  230. }
  231. }
  232. CommAddTaskDetail(utils.Int64ToStr(tmpIn.TaskId), tmpIn)
  233. }
  234. }
  235. }
  236. func CommAddTask(uniqueId string, taskIds string) {
  237. doc, _ := es.FirstDoc(md2.ZhiosTikTokTaskEsIndex, uniqueId)
  238. if doc == nil {
  239. var tmpData = map[string]string{
  240. "task_ids": taskIds,
  241. }
  242. createDocRet, err := es.CreateDoc(md2.ZhiosTikTokTaskEsIndex, uniqueId, tmpData)
  243. if err != nil {
  244. return
  245. }
  246. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  247. } else {
  248. source := doc.Source
  249. tmpData := make(map[string]string)
  250. json.Unmarshal(source, &tmpData)
  251. var tmpOld = make([]int64, 0)
  252. json.Unmarshal([]byte(tmpData["task_ids"]), &tmpOld)
  253. var tmp = make([]int64, 0)
  254. json.Unmarshal([]byte(taskIds), &tmp)
  255. tmp = utils.MergeArr(tmpOld, tmp)
  256. tmp = utils.UniqueArr(tmp)
  257. tmpData = map[string]string{
  258. "task_ids": utils.SerializeStr(tmp),
  259. }
  260. createDocRet, err := es.UpdateDoc(md2.ZhiosTikTokTaskEsIndex, uniqueId, tmpData)
  261. if err != nil {
  262. return
  263. }
  264. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  265. }
  266. }
  267. func CommAddTaskDetail(uniqueId string, tmp md.TikTokTaskDetailSecond) {
  268. doc, _ := es.FirstDoc(md2.ZhiosTikTokTaskDetailEsIndex, uniqueId)
  269. if doc == nil {
  270. createDocRet, err := es.CreateDoc(md2.ZhiosTikTokTaskDetailEsIndex, uniqueId, tmp)
  271. if err != nil {
  272. return
  273. }
  274. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  275. } else {
  276. createDocRet, err := es.UpdateDoc(md2.ZhiosTikTokTaskDetailEsIndex, uniqueId, tmp)
  277. if err != nil {
  278. return
  279. }
  280. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  281. }
  282. }
  283. func TikTokTaskToken() string {
  284. tikTokOpenAppkey := offical.MasterListCfgGetOneData("0", "tik_tok_task_open_appkey")
  285. tikTokOpenAppSecret := offical.MasterListCfgGetOneData("0", "tik_tok_task_open_app_secret")
  286. args := map[string]string{
  287. "appkey": tikTokOpenAppkey,
  288. "appSecret": tikTokOpenAppSecret,
  289. }
  290. key := "tikTok_client_" + args["appkey"]
  291. tokeStr, err := cache.GetString(key)
  292. if cfg.Prd == false {
  293. return tokeStr
  294. }
  295. if tokeStr == "" || err != nil {
  296. token := tik_tok.GetClientToken(args)
  297. if token["tik_tok_acc_token"] != "" {
  298. tokeStr = token["tik_tok_acc_token"]
  299. cache.SetEx(key, token["tik_tok_acc_token"], utils.StrToInt(token["expires_in"]))
  300. }
  301. }
  302. return tokeStr
  303. }