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