12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace App\Listeners;
- use App\Events\DestoryOrder;
- use EasyWeChat\Factory;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Contracts\Queue\ShouldQueue;
- class DestoryOrderListener
- {
- protected $template_id;
- protected $url;
- /**
- * Create the event listener.
- *
- * @return void
- */
- public function __construct()
- {
- // $this->template_id='ROaNPNo__Le7G9b5CS58QbNsEwssvIdyOHEeI58ofyw';
- $this->template_id='a9fxKufmVgDAxqMYz_RbiuII91vsJyyD7XRVGcONHk4';
- $this->url='http://api.app.cliu.cc/api/gzh';
- // $this->template_id='ROaNPNo__Le7G9b5CS58QbNsEwssvIdyOHEeI58ofyw';
- // $this->url='http://api.woaidakele.cn/api/gzh';
- }
- /**
- * Handle the event.
- *
- * @param DestoryOrder $event
- * @return void
- */
- public function handle(DestoryOrder $event)
- {
- try{
- $data=$event->data;
- $openid=$data['openid'];
- $config=config('wechat.official_account.default');
- $app = Factory::officialAccount($config);
- $app->template_message->send([
- 'touser' => $openid,
- 'template_id' => $this->template_id,
- 'url' => $this->url,
- 'data' => $data['data']
- ]);
- }catch (\Exception $exception){
- Log::error('发送模板消息出错,出错内容为'.$exception);
- }
- }
- }
|