PHP短信群发

群发短信记录 导入excel文件
PHP短信群发
文章图片

导入样式PHP短信群发
文章图片
HTML js代码


【PHP短信群发】PHP代码
//短信接口 public function group_sms($post_data,$url){ $o=''; foreach ($post_data as $k=>$v) { $o.="$k=".$v.'&'; } $post_data=https://www.it610.com/article/substr($o,0,-1); $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果需要将结果直接返回到变量里,那加上这句。 $postObj = simplexml_load_string(curl_exec($ch),'SimpleXMLElement', LIBXML_NOCDATA); $jsonStr = json_encode($postObj); return $jsonStr; }// 导入定制短信信息 public function dinzhisms(){ $phones = I('phones'); $content = I('content'); if($content != ''){ $strSubject = $content; $strPattern = "/(?<={)[^}]+/"; $arrMatches = []; preg_match_all($strPattern, $strSubject, $arrMatches); $arr = $arrMatches[0]; }import("Org.Util.PHPExcel"); import("Org.Util.PHPExcel.Writer.Excel5"); import("Org.Util.PHPExcel.IOFactory.php"); ini_set('memory_limit','1024M'); $id=1; if (!empty($_FILES)) { $config = array( 'exts' => array('xlsx','xls'), 'maxSize' => 3145728000, 'rootPath' =>"./Public/", 'savePath' => 'Uploads/', 'subName' => array('date','Ymd'), ); $upload = new \Think\Upload($config); if (!$info = $upload->upload()) { $this->error($upload->getError()); }$file_name=$upload->rootPath.$info['photo']['savepath'].$info['photo']['savename']; $extension = strtolower(pathinfo($file_name, PATHINFO_EXTENSION)); //判断导入表格后缀格式 if ($extension == 'xlsx') { $objReader =\PHPExcel_IOFactory::createReader('Excel2007'); $objPHPExcel =$objReader->load($file_name, $encode = 'utf-8'); } else if ($extension == 'xls'){ $objReader =\PHPExcel_IOFactory::createReader('Excel5'); $objPHPExcel =$objReader->load($file_name, $encode = 'utf-8'); } $sheet =$objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); //取得总行数 $highestColumn =$sheet->getHighestColumn(); //取得总列数 $list=array(); for ($i = 3; $i <= $highestRow; $i++) { //读取的$phones.$i表坐标 $phone_temp[$i] = trim($objPHPExcel->getActiveSheet()->getCell($phones.$i)->getValue()); if($phone_temp[$i] != ''){ foreach($arr as $k => $v){ $address=$v.$i; $cell = $objPHPExcel->getActiveSheet()->getCell($address); $cvalue = https://www.it610.com/article/$cell->getValue(); if($cell->getDataType()==\PHPExcel_Cell_DataType::TYPE_NUMERIC){ $cellstyleformat = $cell->getStyle($cell->getCoordinate())->getNumberFormat(); $formatcode = $cellstyleformat->getFormatCode(); //判断时间类型 if (preg_match('/^(\[\$[A-Z]*-[0-9A-F]*\])*[hmsdy]/i', $formatcode)) { $data[$v] = gmdate("Y-m-d H:i:s", \PHPExcel_Shared_Date::ExcelToPHP($cvalue)); }else{ $data[$v] = $cvalue; }}else{ $data[$v] = $objPHPExcel->getActiveSheet()->getCell($v.$i)->getValue(); } $list[$i] = $data; } } } $phonelist = array_filter($phone_temp); $phonestr = implode(',',$phonelist); $this->assign('phonestr',$phonestr); foreach($arr as $k => $v){ $specs[$k] = '{'.$v.'}'; } foreach($phonelist as $k => $v){ $contentlist[$k] = '【金宝缘】'.trim(str_replace($specs,$list[$k], $content)); $strlen += ceil(mb_strlen($contentlist[$k])/67); } $contentstr = implode(',',$contentlist); $this->assign('contentstr',$contentstr); $lena = count($list); $zongphone = '共计号码'.count($phonelist).'个;计费条数'.$strlen.'条'; $this->assign('zongphone',$zongphone); $this->assign('lena',$lena); $this->assign('list',$contentlist); } $arr = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); $this->assign('arr',$arr); $len = count($arr); $this->assign('len',$len); $this->display(); }//发送定制短信 public function dinzhi_post(){ if(!empty(I('phonestr'))){ $phonestr = I('phonestr'); }$phones = explode(',',$phonestr); if(!empty(I('content'))){ $content = I('content'); } $contents = explode(',',$content); if(!empty(I('sendtime'))){ $sendtime = I('sendtime'); }$post_data = https://www.it610.com/article/array(); $post_data['userid'] = 1425; $post_data['timestamp'] = date('YmdHis'); $post_data['sign'] = MD5('jrcs123456'.date('YmdHis')); $post_data['sendTime'] = $sendtime; //不定时发送,值为0,定时发送,输入格式YYYYMMDDHHmmss的日期值 $post_data['extno'] = ''; $url='http://60.205.151.174:8888/v2sms.aspx?action=send'; foreach($phones as $k => $v){ $post_data['mobile'] = trim($v); $post_data['content'] = trim($contents[$k]); $res[$k] = json_decode($this->group_sms($post_data,$url)); } echo json_encode($res); }

    推荐阅读