1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20   array( 'user1' => array( 'nick' => '用户1', 'mobileNo' => '15123456789' ), 'user3' => array( 'nick' => 'user3', 'mobileNo' => '13812345670' ) ), '大连' => array( 'user2' => array( 'nick' => '用户2', 'mobileNo' => '13800138000' ) ) ); ?> 

 1 2 3 4 5 6   '101050101', '大连' => '101070201' ); ?> 

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63   $Weah, 'Temp' =>$Temp ); return $tomo; } function _get_http_result($_url){// 发送http请求的函数，因为不想每一次都curl整个来一遍，所以分离出来了 if(empty($_url)){ return false; }$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "$_url"); curl_setopt($ch, CURLOPT_TIMEOUT, 8); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);$result = curl_exec($ch);$info = curl_getinfo($ch); curl_close($ch); if($result){ return 'Success'; } } foreach($to as $cityName =>$group){//外层循环，对于每个组查询一次天气信息 $cityId =$cityList[$cityName];// Get every city's id according to city's name.$groupUsers = $to[$cityName];// Get th users of current group. $tomorrow = getWeatherData($cityId);// Get current city's weather. foreach($group as$user){// Get users in current group.// 内层循环，针对每个用户生成不同短信内容 $msg =$user['nick'] . '，您好！' . $cityName . '明天' .$tomorrow['Weah'] . '，温度' . $tomorrow['Temp'] . '，关注天气变化，注意身体哦~' .$serviceIntro; $url =$sendBaseUrl . '?phone=' . $mobile . '&pwd=' .$mobilePwd . '&to=' . $user['mobileNo'] .'&u=1&msg=' .$msg;// 生成短信请求的URL $sendResult = _get_http_result($url); if(\$sendResult == 'Success'){ echo 'Success'; }else { echo 'Fail'; } sleep(1); } } ?>