1 function send_sms_all(){echo 0;die; //向所有实名认证用户群发,每次100 2 3 $sql = 'SELECT username FROM ych_user WHERE real_status!=0 and user_id not in(466,2,3,6,7)'; 4 //$sql = 'SELECT username FROM ych_user WHERE real_status!=0 and user_id in(466,2,3,6,7)';//先用自己人的手机号测试 5 $r = $this->db->query($sql); 6 $r2 = $r->result_array(); 7 8 foreach($r2 as $k=>$v){ 9 $arr[] = $v['username']; 10 if(count($arr)%100 == 0){//每次只能发100个 11 $send_arr[] = $arr;//将满足100的数组放到新数组中 12 $arr = ''; 13 } 14 } 15 16 $total_phone = count($r2); 17 $x = $total_phone%100; 18 $mod_list = array_slice($r2,'-'.$x);//从数组中倒数第x取值,这个值是不足100的情况 19 20 foreach($mod_list as $k=>$v){ 21 $mod_arr[] = $v['username'];//将不足100的合并为一维数组 22 } 23 24 $send_arr[] = $mod_arr;//至此已把所有数据每100条放到$send_arr中 25 //print_r($send_arr);die; 26 27 foreach($send_arr as $k=>$v){ 28 $send_phone = implode(',',$v); //'18645666555,15919700177'; 29 //echo $send_phone;die; 30 $this->load->library('phone'); 31 $res = $this->phone->sendSMS($send_phone,$msg,"98653"); 32 print_r($res); 33 } 34 print_r($send_arr);die; 35 }