抖音小程序

TemplateCallbackService.php 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace App\Service;
  3. use App\Log;
  4. use App\Models\Album;
  5. use App\Models\Material;
  6. use App\RedisModel;
  7. class TemplateCallbackService
  8. {
  9. public static function uoloadVideoCallBack($msg, $v) {
  10. /** {
  11. "ma_app_id":"tt498f3f32d6xxxxxxxx",
  12. "open_video_id":"7270100931638329856",
  13. "success":true
  14. } */
  15. $appId = $msg['ma_app_id'] ?? null;
  16. $openVideoId = $msg['open_video_id'] ?? null;
  17. $success = $msg['success'] ?? null;
  18. $successToDyCloud = $msg['success_to_dy_cloud'] ?? null;
  19. $dyCloudId = $msg['dy_cloud_id'] ?? null;
  20. if(is_null($appId) || is_null($openVideoId) || is_null($success)) {
  21. Log::logError('uoload_video_callback', ['msg_data' => $msg, 'err_msg' => '必要响应参数缺失']);
  22. return 500;
  23. }
  24. # 验证小程序appid
  25. $res = self::checkAppId($appId);
  26. if(!$res) {
  27. Log::logError('uoload_video_callback', ['msg_data' => $msg, 'err_msg' => '小程序app_id不合法']);
  28. return 500;
  29. }
  30. # 验证视频id是否存在
  31. $videoInfo = Material::getVideoInfo($appId, $openVideoId);
  32. if(empty($videoInfo)) {
  33. Log::logError('uoload_video_callback', ['msg_data' => $msg, 'err_msg' => '视频ID不在系统中']);
  34. return 500;
  35. }
  36. if($success && 2 != $videoInfo->status){
  37. $status = 2;
  38. # 更新视频状态
  39. $res = Material::updateVideoStatus($appId, $openVideoId, $status);
  40. if(!$res) {
  41. Log::logError('uoload_video_callback', ['msg_data' => $msg, 'err_msg' => '更新视频状态失败']);
  42. return 500;
  43. }
  44. }
  45. return 0;
  46. }
  47. public static function albumAuditCallBack($msg, $v) {
  48. /** {
  49. "ma_app_id":"tt498f3f32d6xxxxxxxx",
  50. "album_id":7270100931638329856,
  51. "version":1,
  52. "audit_status":1,
  53. "scope_list":"["可播放","可挂载"]",
  54. "audit_msg":"[23-24]错别字字幕"
  55. } */
  56. $appId = $msg['ma_app_id'] ?? null;
  57. $albumId = $msg['album_id'] ?? null;
  58. $version = $msg['version'] ?? null;
  59. $scopeList = $msg['scope_list'] ?? null;
  60. $auditStatus = $msg['audit_status'] ?? null;
  61. $auditMsg = $msg['audit_msg'] ?? null;
  62. if(is_null($appId) || is_null($albumId) || is_null($version) || is_null($scopeList) || is_null($auditStatus)) {
  63. Log::logError('album_audit_callback', ['msg_data' => $msg, 'err_msg' => '必要响应参数缺失']);
  64. return 500; # 参数异常
  65. }
  66. # 验证小程序appid
  67. $res = self::checkAppId($appId);
  68. if(!$res) {
  69. Log::logError('album_audit_callback', ['msg_data' => $msg, 'err_msg' => '小程序app_id不合法']);
  70. return 500;
  71. }
  72. # 验证短剧ID是否存在,不存在时需要通过脚本同步一遍短剧列表
  73. $albumInfo = Album::getInfo($appId, $albumId);
  74. if(empty($albumInfo)) {
  75. RedisModel::lPush(Album::SYNC_ALBUM_LIST, json_encode([
  76. 'app_id' => $appId, 'album_id' => $albumId
  77. ], 256));
  78. return 0;
  79. }
  80. # 审核状态格式化
  81. switch($auditStatus) {
  82. case 1:# 审核不通过
  83. $auditStatus = 3;
  84. break;
  85. case 2: # 审核通过
  86. $auditStatus = 4;
  87. break;
  88. default:
  89. return 500;
  90. }
  91. if($auditStatus != $albumInfo->audit_status) {
  92. # 判断审核状态,修改系统中短剧审核信息
  93. $res = Album::updateAuditStatus($appId, $albumId, $version, json_encode($scopeList), $auditStatus, $auditMsg);
  94. if(!$res) {
  95. return 500;
  96. }
  97. }
  98. return 0;
  99. }
  100. public static function postReviewCallBack($msg, $v) {
  101. /** {
  102. "review_id":"RT7358655xxxxxxxx",
  103. "album_id":"7358397726xxxxxxxx",
  104. "episode_id":"7358397751xxxxxxxx",
  105. "app_id":"tt19b56f0886xxxxxxxx",
  106. "review_type":"path重定向校验",
  107. "review_result":"REJECT",
  108. "tips":"绑定path存在重定向问题",
  109. "review_init_timestamp":1713322906
  110. } */
  111. $appId = $msg['app_id'] ?? null;
  112. $reviewId = $msg['review_id'] ?? null;
  113. $reviewType = $msg['review_type'] ?? null;
  114. $albumId = $msg['album_id'] ?? null;
  115. $episodeId = $msg['episode_id'] ?? null;
  116. $reviewResult = $msg['review_result'] ?? null;
  117. $failReason = $msg['fail_reason'] ?? null;
  118. $tips = $msg['tips'] ?? null;
  119. if(is_null($appId) || is_null($reviewId) || is_null($reviewType) || is_null($albumId) || is_null($reviewResult)) {
  120. return 500; # 参数异常
  121. }
  122. # 验证小程序appid
  123. $res = self::checkAppId($appId);
  124. if(!$res) {
  125. return 500;
  126. }
  127. }
  128. public static function checkAppId($appId) {
  129. $appConfig = config('douyin.app_info');
  130. $appIdList = array_keys($appConfig);
  131. if(!is_array($appId, $appIdList)) {
  132. return false;
  133. }
  134. return true;
  135. }
  136. }