智盟项目
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.

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