123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- namespace App\Listeners;
- use App\Events\NewOrder;
- use EasyWeChat\Factory;
- use Illuminate\Support\Facades\Log;
- class NewOrderListeners
- {
- protected $templateId;
- protected $url;
- /**
- * Create the event listener.
- *
- * @return void
- */
- public function __construct()
- {
- $this->templateId='uZLksk1kr2EcmRMz4ybWex14YHJ0M0qtrMWGOKeOgf8';
- $this->url='';
- }
- public function handle(NewOrder $event)
- {
- try{
- $data=$event->data;
- $openid=$data['openid'];
- $config=config('wechat.official_account.daweiboshi');
- $app = Factory::officialAccount($config);
- $app->template_message->send([
- 'touser' => $openid,
- 'template_id' => $this->templateId,
- 'url' => $this->url,
- 'data' => $data['data'],
- 'miniprogram' => [ //与公众号绑定的小程序(选传)
- 'appid' => config('wechat.mini_program.default.app_id'),//小程序id
- 'pagepath' => 'pages/order-manage/order-manage',//跳转页面
- ],
- ]);
- }catch (\Exception $exception){
- Log::error('发送模板消息出错,出错内容为'.$exception);
- }
- }
- }
|