123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace App\Listeners;
- use App\Events\ChangeOrder;
- use App\Events\SignMessageEvent;
- use App\Jobs\SignMessage;
- use EasyWeChat\Factory;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Support\Facades\Log;
- class SignMessageListener
- {
- protected $template_id;
- protected $url;
- /**
- * Create the event listener.
- *
- * @return void
- */
- public function __construct()
- {
- // $this->template_id='pW9YlUaGe5-q5xQPKuaVs54FovoA4x-kEybaoKRFvK4';
- // $this->template_id='8e87LapU3zQRre7s2siWNYf-qZyx5wePJvvFta1zYqc';
- $this->template_id='zWSvr-xAV6eIQbqDnwiSfVAJiwwvI1tta0p4KMs0nug';
- // $this->url='http://api.app.jiuweiyun.cn/api/gzh';
- }
- /**
- * Handle the event.
- *
- * @param ChangeOrder $event
- * @return void
- */
- public function handle(SignMessageEvent $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,
- "miniprogram"=>[
- "appid"=>"wxcf821c17589a0ec8",
- "pagepath"=>"pages/sign_manage/sign_manage"
- ],
- // 'url' => $this->url,
- 'data' => $data['data']
- ]);
- }catch (\Exception $exception){
- Log::error('发送模板消息出错,出错内容为'.$exception);
- }
- }
- }
|