123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace App\Listeners;
- use App\Events\WechatMessageEvent;
- use Illuminate\Queue\Listener;
- use Illuminate\Support\Facades\Log;
- class WechatMessageListener {
- /**
- * Create the event listener.
- *
- * @return void
- */
- public function __construct()
- {
- // $this->data=$data;
- }
- /**
- * Handle the event.
- *
- * @param WechatMessageEvent $event
- * @return void
- */
- public function handle(WechatMessageEvent $event)
- {
- Log::error(1);
- Log::error(json_encode($event));
- try{
- $data=$event->data;
- $openid=$data['openid'];
- $template_id='gfaNWrBCALMcS-SzguP5aaDzYQHxoHs_doejgMFZIr4';
- // $template_id='MfqZmLlo0LqD2cq6HvIkc9LRTO-8V2p7Bqzbvp9vBA8';
- $url='http://api.app.jiuweiyun.cn/api/gzh';
- $app=app('wechat.official_account');
- $app->template_message->send([
- 'touser' => $openid,
- 'template_id' => $template_id,
- 'url' => $url,
- 'data' => $data['data']
- ]);
- }catch (\Exception $exception){
- Log::error('发送模板消息出错,出错内容为'.$exception);
- }
- }
- }
|