<?php

namespace App\Api\Controllers;

use App\Model\MoviePushLog;
use Storage;
use App\Http\Controllers\Controller;

class NotifyController extends Controller
{
	public function gxydyst()
	{
        $response_data['code'] = 400; 

        $raw_post_data = json_decode(file_get_contents('php://input', 'r'), true);
        
        //记录异步通知日志
        Storage::append(date('Ymd').'_pushlog.txt', json_encode($raw_post_data) . "\n");
		
        if(isset($raw_post_data['srcFiles'][0]['playUrl'])){
            //处理资源ID
            $movie_id_e = explode('_', $raw_post_data['mediaId']);
            $movie_id = $movie_id_e[3];
            
            $map[] = ['movie_id', $movie_id];
            $update_data['injection_status'] = 1;
            $update_data['view_url'] = $raw_post_data['srcFiles'][0]['playUrl'];
            //更新推送状态
            $rs = MoviePushLog::where($map)->update($update_data);
            if($rs){
                $response_data['msg'] = '成功';
                $response_data['code'] = 0; 
            }else{
                $response_data['msg'] = '失败或重复更新';
            }
        }else{
            $response_data['msg'] = '缺少CDN播放地址';
        }
        return response()->json($response_data);
	}

}