12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?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='FgZJgH06B14FqD1DtiKiUYDQTTgMfOCsL05qWUXkU74'; //测试
- // $this->template_id='a9fxKufmVgDAxqMYz_RbiuII91vsJyyD7XRVGcONHk4';
- $this->url='http://api.app.cliu.cc/api/gzh';
- // $this->url='http://api.woaidakele.cn/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);
- }
- }
- }
|