智盟项目
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

207 wiersze
6.4 KiB

  1. package svc
  2. import (
  3. "applet/app/cfg"
  4. offical "applet/app/db/official"
  5. md2 "applet/app/es/md"
  6. "applet/app/task/md"
  7. "applet/app/utils"
  8. "applet/app/utils/cache"
  9. "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
  10. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tik_tok"
  11. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  12. "encoding/json"
  13. "fmt"
  14. "github.com/jinzhu/copier"
  15. "github.com/syyongx/php2go"
  16. "github.com/tidwall/gjson"
  17. "strings"
  18. "time"
  19. )
  20. func TikTokTask() {
  21. //doc, _ := es.FirstDoc(md2.ZhiosTikTokTaskEsIndex, "tik_tok_task_tt99fdef4006c36ff001")
  22. //fmt.Println(string(doc.Source))
  23. //return
  24. //es.CreateIndexIfNotExists(md2.ZhiosTikTokTaskEsIndex, md2.ZhiosTikTokTaskEsMapping)
  25. //es.CreateIndexIfNotExists(md2.ZhiosTikTokTaskDetailEsIndex, md2.ZhiosTikTokTaskDetailEsMapping)
  26. appidList := offical.MasterListCfgGetOneData("0", "tik_tok_task_appid")
  27. split := strings.Split(appidList, ";")
  28. for _, v := range split {
  29. endTime := time.Now().Unix()
  30. startTime := endTime - 7*86400
  31. if endTime > time.Now().Unix() {
  32. endTime = time.Now().Unix()
  33. }
  34. param := map[string]interface{}{
  35. "appid": v,
  36. "create_start_time": startTime,
  37. "create_end_time": endTime,
  38. }
  39. api, _ := tik_tok.TaskApi("query_app_task_id/", TikTokTaskToken(), zhios_third_party_utils.SerializeStr(param))
  40. taskIds := gjson.Get(api, "data.task_ids").String()
  41. fmt.Println(taskIds)
  42. if taskIds == "" || taskIds == "[]" {
  43. fmt.Println(endTime)
  44. offical.MasterListCfgSave("0", "tik_tok_task_appid_time_"+v, utils.Int64ToStr(endTime))
  45. continue
  46. }
  47. CommAddTask("tik_tok_task_"+v, taskIds)
  48. var tmp = make([]int64, 0)
  49. json.Unmarshal([]byte(taskIds), &tmp)
  50. GetTaskDetail(v, tmp)
  51. fmt.Println(endTime)
  52. offical.MasterListCfgSave("0", "tik_tok_task_appid_time_"+v, utils.Int64ToStr(endTime))
  53. }
  54. }
  55. func GetTaskDetail(appId string, tmp []int64) {
  56. for _, v := range tmp {
  57. param := map[string]interface{}{
  58. "appid": appId,
  59. "query_params_type": "1",
  60. "query_params_content": utils.Int64ToStr(v),
  61. "page_no": "1",
  62. "page_size": "10",
  63. }
  64. api, _ := tik_tok.TaskApi("query_task_info/", TikTokTaskToken(), zhios_third_party_utils.SerializeStr(param))
  65. detail := gjson.Get(api, "data.tasks").String()
  66. if detail == "" {
  67. fmt.Println("失败", v)
  68. continue
  69. }
  70. var tmpDetail = make([]md.TikTokTaskDetail, 0)
  71. json.Unmarshal([]byte(detail), &tmpDetail)
  72. for _, v1 := range tmpDetail {
  73. var tmpIn md.TikTokTaskDetailSecond
  74. err := copier.Copy(&tmpIn, &v1)
  75. fmt.Println(err)
  76. tmpIn.OrientedTalentRelList = utils.SerializeStr(v1.OrientedTalentRelList)
  77. tmpIn.ReferMaCaptures = utils.SerializeStr(v1.ReferMaCaptures)
  78. tmpIn.TaskTags = utils.SerializeStr(v1.TaskTags)
  79. tmpIn.ReferVideoCaptures = utils.SerializeStr(v1.ReferVideoCaptures)
  80. if tmpIn.Appid == "tt38e94e54a7d70c4601" {
  81. ex := strings.Split(tmpIn.StartPage, "cid=")
  82. if len(ex) > 1 {
  83. exSecond := strings.Split(ex[1], "&")
  84. tmpIn.VideoId = exSecond[0]
  85. }
  86. if tmpIn.VideoId == "" {
  87. fmt.Println("失败", tmpIn)
  88. continue
  89. }
  90. } else {
  91. ex := strings.Split(tmpIn.StartPage, "bookId=")
  92. if len(ex) > 1 {
  93. exSecond := strings.Split(ex[1], "&")
  94. tmpIn.VideoId = exSecond[0]
  95. }
  96. if tmpIn.VideoId == "" {
  97. fmt.Println("失败", tmpIn)
  98. continue
  99. }
  100. }
  101. if tmpIn.Status != 2 {
  102. tmpIn.TaskEndTime = int(time.Now().Unix() - 10)
  103. }
  104. if tmpIn.Appid == "tt8a93fc2e15affaaa01" {
  105. tmp2 := md.Cinema5bmsData{
  106. Description: "",
  107. ImageUrl: tmpIn.TaskIcon,
  108. Material: "",
  109. OnlineTime: time.Unix(int64(tmpIn.TaskStartTime), 0).Format("2006-01-02 15:04:05"),
  110. Type: "fenghuang",
  111. Title: tmpIn.TaskName,
  112. UpdateTime: int(time.Now().Unix()),
  113. Time: tmpIn.TaskStartTime,
  114. Appid: "tt8a93fc2e15affaaa01",
  115. Id: utils.StrToInt(tmpIn.VideoId),
  116. IsClose: 0,
  117. IsHot: 0,
  118. FirstCate: "story",
  119. SecondCate: "",
  120. Platform: "tikTok",
  121. }
  122. if tmpIn.TaskEndTime < int(time.Now().Unix()) {
  123. tmp2.IsClose = 1
  124. }
  125. uniqueId := php2go.Md5(tmp2.Appid + "_" + tmp2.Type + "_" + tmp2.FirstCate + "_" + utils.IntToStr(tmp2.Id))
  126. fmt.Println(uniqueId)
  127. commAddNew(uniqueId, tmp2)
  128. }
  129. CommAddTaskDetail(utils.Int64ToStr(tmpIn.TaskId), tmpIn)
  130. }
  131. }
  132. }
  133. func CommAddTask(uniqueId string, taskIds string) {
  134. doc, _ := es.FirstDoc(md2.ZhiosTikTokTaskEsIndex, uniqueId)
  135. if doc == nil {
  136. var tmpData = map[string]string{
  137. "task_ids": taskIds,
  138. }
  139. createDocRet, err := es.CreateDoc(md2.ZhiosTikTokTaskEsIndex, uniqueId, tmpData)
  140. if err != nil {
  141. return
  142. }
  143. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  144. } else {
  145. source := doc.Source
  146. tmpData := make(map[string]string)
  147. json.Unmarshal(source, &tmpData)
  148. var tmpOld = make([]int64, 0)
  149. json.Unmarshal([]byte(tmpData["task_ids"]), &tmpOld)
  150. var tmp = make([]int64, 0)
  151. json.Unmarshal([]byte(taskIds), &tmp)
  152. tmp = utils.MergeArr(tmpOld, tmp)
  153. tmp = utils.UniqueArr(tmp)
  154. tmpData = map[string]string{
  155. "task_ids": utils.SerializeStr(tmp),
  156. }
  157. createDocRet, err := es.UpdateDoc(md2.ZhiosTikTokTaskEsIndex, uniqueId, tmpData)
  158. if err != nil {
  159. return
  160. }
  161. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  162. }
  163. }
  164. func CommAddTaskDetail(uniqueId string, tmp md.TikTokTaskDetailSecond) {
  165. doc, _ := es.FirstDoc(md2.ZhiosTikTokTaskDetailEsIndex, uniqueId)
  166. if doc == nil {
  167. createDocRet, err := es.CreateDoc(md2.ZhiosTikTokTaskDetailEsIndex, uniqueId, tmp)
  168. if err != nil {
  169. return
  170. }
  171. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  172. } else {
  173. createDocRet, err := es.UpdateDoc(md2.ZhiosTikTokTaskDetailEsIndex, uniqueId, tmp)
  174. if err != nil {
  175. return
  176. }
  177. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  178. }
  179. }
  180. func TikTokTaskToken() string {
  181. tikTokOpenAppkey := offical.MasterListCfgGetOneData("0", "tik_tok_task_open_appkey")
  182. tikTokOpenAppSecret := offical.MasterListCfgGetOneData("0", "tik_tok_task_open_app_secret")
  183. args := map[string]string{
  184. "appkey": tikTokOpenAppkey,
  185. "appSecret": tikTokOpenAppSecret,
  186. }
  187. key := "tikTok_client_" + args["appkey"]
  188. tokeStr, err := cache.GetString(key)
  189. if cfg.Prd == false {
  190. return tokeStr
  191. }
  192. if tokeStr == "" || err != nil {
  193. token := tik_tok.GetClientToken(args)
  194. if token["tik_tok_acc_token"] != "" {
  195. tokeStr = token["tik_tok_acc_token"]
  196. cache.SetEx(key, token["tik_tok_acc_token"], utils.StrToInt(token["expires_in"]))
  197. }
  198. }
  199. return tokeStr
  200. }