SyncSmsResultCodeListen.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\listens;
  12. use app\common\repositories\system\sms\SmsRecordRepository;
  13. use crmeb\interfaces\ListenerInterface;
  14. use crmeb\services\TimerService;
  15. use crmeb\services\YunxinSmsService;
  16. use Swoole\Timer;
  17. class SyncSmsResultCodeListen extends TimerService implements ListenerInterface
  18. {
  19. public function handle($event): void
  20. {
  21. $this->tick(1000 * 60 * 5, function () {
  22. $smsRecordRepository = app()->make(SmsRecordRepository::class);
  23. $time = date('Y-m-d H:i:s', strtotime("- 10 minutes"));
  24. $ids = $smsRecordRepository->getTimeOutIds($time);
  25. if (count($ids)) return;
  26. $list = (array)YunxinSmsService::create()->getStatus($ids);
  27. foreach ($list as $item) {
  28. if (isset($item['id'])) {
  29. if ($item['resultcode'] == '' || $item['resultcode'] == null) $item['resultcode'] = 134;
  30. $smsRecordRepository->updateRecordStatus($item['id'], $item['resultcode']);
  31. }
  32. }
  33. });
  34. }
  35. }