1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace App\Listeners;
- use App\Events\OrderPayInfoEvent;
- use Illuminate\Queue\Listener;
- use EasyWeChat\Factory;
- use Illuminate\Support\Facades\Log;
- class OrderPayInfoListener extends Listener{
- protected $template_id;
- protected $url;
- //订单结算
- public function __construct()
- {
- $this->template_id='pyQbBWlbLyUo_imjUTztBSPvDauNMZXNzqwkshx6bIo';
- $this->url='http://api.tongnianshijie.com/api/gzh';
- }
- /**
- * Handle the event.
- *
- * @param OrderPayInfoEvent $event
- * @return void
- */
- public function handle(OrderPayInfoEvent $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);
- }
- }
- }
|