12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- declare (strict_types = 1);
- namespace app\txx\listener;
- use app\txx\model\Act;use think\facade\Cache;
- class WxPush
- {
- protected $appid;
- protected $appsecret;
- protected $wechat;
- /**
- * 事件监听处理
- *
- * @return mixed
- */
- public function __construct()
- {
- $this->appid = env('WECHAT.APPID');
- $this->appsecret = env('WECHAT.APPSECRET');
- $this->wechat = new \Wechat(['appid' => $this->appid, 'appsecret' => $this->appsecret]);
- }
- public function handle($event)
- {
- if($event==null)return;
- if($event['status']==3){
- $act = Act::where(['actCode'=>$event['actCode']])->findOrEmpty();
- if(!$act->isEmpty()){
- $this->push($act->toArray());
- }
- }
- }
- public function push($data){
- $temps=[
- 'code'=>$data['actCode'],
- 'belong'=>1,
- 'openId'=>'oOpc26OhvWzdO0JlL9Q37rXyu69I',
- 'template_id'=>'oUFsqOfVNgavlzQKs9bT1as1miFNJ5-Q-h68eFiiQ0Q',
- 'template_name'=>'系统单据处理通知',
- 'action_name'=>'泰行销活动审批推送',
- 'template_data'=>['thing8' => ['value' => '泰行销直播'],
- 'thing4' => ['value' => $data['actCode']],
- 'thing5' =>['value' => Act::$statusCn[$data['status']]??'未知'],
- 'thing17' =>['value' => $data['contactor']],
- 'thing20' =>['value' => $data['depart']]
- ],
- 'uid'=>106,
- 'uname'=>'魏莉',
- ];
- Cache::store('redis')->handler()->lPush('wxpush_queue',json_encode($temps));
- }
- }
|