WxPush.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\txx\listener;
  4. use app\txx\model\Act;use think\facade\Cache;
  5. class WxPush
  6. {
  7. protected $appid;
  8. protected $appsecret;
  9. protected $wechat;
  10. /**
  11. * 事件监听处理
  12. *
  13. * @return mixed
  14. */
  15. public function __construct()
  16. {
  17. $this->appid = env('WECHAT.APPID');
  18. $this->appsecret = env('WECHAT.APPSECRET');
  19. $this->wechat = new \Wechat(['appid' => $this->appid, 'appsecret' => $this->appsecret]);
  20. }
  21. public function handle($event)
  22. {
  23. if($event==null)return;
  24. if($event['status']==3){
  25. $act = Act::where(['actCode'=>$event['actCode']])->findOrEmpty();
  26. if(!$act->isEmpty()){
  27. $this->push($act->toArray());
  28. }
  29. }
  30. }
  31. public function push($data){
  32. $temps=[
  33. 'code'=>$data['actCode'],
  34. 'belong'=>1,
  35. 'openId'=>'oOpc26OhvWzdO0JlL9Q37rXyu69I',
  36. 'template_id'=>'oUFsqOfVNgavlzQKs9bT1as1miFNJ5-Q-h68eFiiQ0Q',
  37. 'template_name'=>'系统单据处理通知',
  38. 'action_name'=>'泰行销活动审批推送',
  39. 'template_data'=>['thing8' => ['value' => '泰行销直播'],
  40. 'thing4' => ['value' => $data['actCode']],
  41. 'thing5' =>['value' => Act::$statusCn[$data['status']]??'未知'],
  42. 'thing17' =>['value' => $data['contactor']],
  43. 'thing20' =>['value' => $data['depart']]
  44. ],
  45. 'uid'=>106,
  46. 'uname'=>'魏莉',
  47. ];
  48. Cache::store('redis')->handler()->lPush('wxpush_queue',json_encode($temps));
  49. }
  50. }