<?php

namespace App\Listeners;

use App\Events\CancelOrderEvent;
use Illuminate\Support\Facades\Log;

class CancelOrderListener {
    protected $template_id;
    protected $url;

    //支付
    public function __construct()
    {
        $this->template_id='Q3c9olbC-A9Un_uzNwwTrf1tY9YUD7B-mCndlB_td1c';
        $this->url='https://weidian.cliu.cc/web/user';
    }

    public function handle(CancelOrderEvent $event)
    {
        try{
            $data=$event->data;
            $openid=$data['openid'];
            $app=app('wechat.official_account.daweiboshi');
            $app->template_message->send([
                'touser' => $openid,
                'template_id' => $this->template_id,
                'url' => $this->url,
                'data' => $data['data']
            ]);
        }catch (\Exception $exception){
            Log::error('发送模板消息出错，出错内容为'.$exception);
        }
    }
}
