1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace Modules\Finance\Listeners;
- use Modules\Finance\Events\AgentIncome;
- use EasyWeChat\Factory;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Contracts\Queue\ShouldQueue;
- class AgentIncomeListener
- {
- protected $template_id;
- protected $url;
- /**
- * Create the event listener.
- *
- * @return void
- */
- public function __construct()
- {
- $this->template_id='Y5bxIakuAeNkzj1ypnhmQBP4bs0086Z5hYgAtpMiQR8';
- $this->url='http://api.app.jiuweiyun.cn/api/gzh';
- // $this->template_id='dA1a7THXIf0Pt_WpCW235XV8mw8f0HF7JLgRyk_g8_I';
- // $this->url='http://api.woaidakele.cn/api/gzh';
- }
- /**
- * Handle the event.
- *
- * @param AgentIncome $event
- * @return void
- */
- public function handle(AgentIncome $event)
- {
- Log::error(json_encode($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);
- }
- }
- }
|