<?php

namespace App\Console\Commands\ActionTrigger\BatchWechatMaterial;
use App\Http\Controllers\WechatController;
use Illuminate\Console\Command;

/**
 * 预览微信素材
 *
 */
class PreviewWechatMaterial extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'ActionTrigger:preview_zs_wechat_material  {data}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '预览微信素材';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        \Log::info('ActionTrigger::preview_wechat_material_start');
        $data = $this->argument('data');
        try{
            $this->start($data['data']);
        }catch(\Exception $e){
            \Log::error($e->getMessage());
        }
        \Log::info('ActionTrigger::preview_wechat_material_end:');
    }

    public function start($data){

    	\Log::info('$data');\Log::info($data);
        // 检查参数
        if(!($data['appid']&&$data['media_id']&&$data['openid'])){
            \Log::info('params_empty');
            return;
        }
        //调用预览接口
        try{
            $WechatController = new WechatController($data['appid']);
            $broadcast = $WechatController->app->broadcast;
            $res = $broadcast->previewNews($data['media_id'], $data['openid']);
            \Log::info('$res');\Log::info($res);
        }catch(\Exception $e){
            \Log::error($e->getMessage());
        }
        return;

    }
  
}
