123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace Modules\Order\Listeners;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Support\Facades\Log;
- use EasyWeChat\Factory;
- class SendMessageOrderSendListener
- {
- /**
- * Create the event listener.
- *
- * @return void
- */
- public function __construct()
- {
- $this->template_id='uJW_mg0A42MDNwutgaoe7R4kNjYQNwwClP8ru5rbo9o';//测试
- // $this->template_id='3PGRr84zGsleaJYLqQjgr6G9XAmCLjC2YmardI6RBAo';
- $this->url='http://api.app.jiuweiyun.cn/api/gzh';
- // $this->url='http://api.woaidakele.cn/api/gzh';//测试
- }
- /**
- * Handle the event.
- *
- * @param object $event
- * @return void
- */
- public function handle($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);
- }
- }
- }
|