SendSMSCommand.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * 批量发送短信
  4. * @author >
  5. * @param $args[0] 发送数量限制
  6. * @param /download/need_sms.txt 需要发送短信的用户信息
  7. */
  8. class SendSMSCommand extends CConsoleCommand{
  9. public function run($args) {
  10. if(isset($args[0])){
  11. $send_num = $args[0];
  12. }else{
  13. $send_num = 3000;
  14. }
  15. $file = file_get_contents(APP_PATH.'/download/need_sms.txt');
  16. $smsservice = Service::factory('SendSMSService');
  17. $info_arr = explode("\n",$file);
  18. $i = 1;
  19. foreach ($info_arr as $key => $value) {
  20. if($i>$send_num){
  21. break;
  22. }
  23. $user_info = explode("----", $value);
  24. if(preg_match("/\d{11}/", $user_info[1])){
  25. $user_info[1] = trim($user_info[1]);
  26. $result = $smsservice->send_sms('【壹管家】炎热酷暑,清凉一夏,下载壹管家APP即获248元优惠大礼包,猛戳 http://dwz.cn,回T退订',$user_info[1]);
  27. if($i==1000){
  28. $result = $smsservice->send_sms('【壹管家】炎热酷暑,清凉一夏,下载壹管家APP即获248元优惠大礼包,回T退订','18521093629');
  29. $result = $smsservice->send_sms('【壹管家】炎热酷暑,清凉一夏,下载壹管家APP即获248元优惠大礼包,','18817554864');
  30. }
  31. echo $i++;
  32. echo iconv('utf-8', 'gbk', $result);
  33. echo "\r\n";
  34. if($result){
  35. unset($info_arr[$key]);
  36. }
  37. }else{
  38. unset($info_arr[$key]);
  39. }
  40. }
  41. $result_str = implode("\n",$info_arr);
  42. file_put_contents(APP_PATH.'/download/need_sms.txt',$result_str);
  43. }
  44. }