SyncSmsResultCodeListen.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace ln\listens;
  3. use app\common\repositories\system\sms\SmsRecordRepository;
  4. use ln\interfaces\ListenerInterface;
  5. use ln\services\TimerService;
  6. use ln\services\YunxinSmsService;
  7. use Swoole\Timer;
  8. class SyncSmsResultCodeListen extends TimerService implements ListenerInterface
  9. {
  10. public function handle($event): void
  11. {
  12. $this->tick(1000 * 60 * 5, function () {
  13. $smsRecordRepository = app()->make(SmsRecordRepository::class);
  14. $time = date('Y-m-d H:i:s', strtotime("- 10 minutes"));
  15. $ids = $smsRecordRepository->getTimeOutIds($time);
  16. if (count($ids)) return;
  17. $list = (array)YunxinSmsService::create()->getStatus($ids);
  18. foreach ($list as $item) {
  19. if (isset($item['id'])) {
  20. if ($item['resultcode'] == '' || $item['resultcode'] == null) $item['resultcode'] = 134;
  21. $smsRecordRepository->updateRecordStatus($item['id'], $item['resultcode']);
  22. }
  23. }
  24. });
  25. }
  26. }