load->driver('cache', array('adapter' => 'apc', 'backup' => 'file')); $this->load->helper(array('form', 'url', 'date', 'sms')); $this->load->model("setting_model"); $this->load->library('aliyunsms'); $this->assign("setting", $this->cache->get('setting')); } /** * 设置短信和邮件 */ public function setting() { if ($this->input->post()) { $data['setting_id'] = $this->input->post("setting_id", true); $data['is_sms'] = $this->input->post("is_sms", true); $data['sms_type'] = $this->input->post("sms_type", true); $data['serial_port'] = $this->input->post("serial_port", true); $data['baud_rate'] = $this->input->post("baud_rate", true); $data['sms_cneter_num'] = $this->input->post("sms_cneter_num", true); $data['test_phone'] = $this->input->post("test_phone", true); $data['product'] = $this->input->post("product", true); $data['access_key_id'] = $this->input->post("access_key_id", true); $data['access_key_secret'] = $this->input->post("access_key_secret", true); $data['sign_name'] = $this->input->post("sign_name", true); $data['template_codes'] = $this->input->post("template_codes", true); $data['is_email'] = $this->input->post("is_email", true); $data['server'] = $this->input->post("server", true); $data['smtp_secure'] = $this->input->post("smtp_secure", true); $data['port'] = $this->input->post("port", true); $data['sender'] = $this->input->post("sender", true); $data['secret_key'] = $this->input->post("secret_key", true); $data['tester'] = $this->input->post("tester", true); if ($data['setting_id']) { $this->setting_model->update_setting($data); } elseif($data['is_sms'] != null && $data['is_email'] != null) { $data['setting_id'] = $this->create_id(); $data['save_time'] = "180"; $this->setting_model->save_setting($data); } $this->update_cahce(); $this->response(array("code" => 1, "icon" => 1, "msg" => "配置信息保存成功!")); } else { $setting= $this->cache->get('setting'); if (!$setting) { $setting = $this->setting_model->get_model(); } $this->assign("setting", $setting); $this->display("setting/setting.html"); } } /** * 更新设置缓存 */ private function update_cahce(){ $setting = $this->setting_model->get_setting(); $this->cache->save('setting', $setting, 30000); } /** * 测试发送 */ public function test() { $setting = $this->setting_model->get_setting(); if ($setting) { $msg = ""; if ($setting['is_email']) { $this->load->library('mailer'); $this->mailer->set_config($setting); if ($this->mailer->send_email($setting['tester'], "邮件发送测试!", "邮件发送测试!如果收到这封邮件说明的邮箱配置已经成功!")) { $msg .= "邮件发送成功!"; } else { $msg .= "邮件发送失败!请检查配置!"; } } else { $msg .= "未启用邮件发送!"; } if ($setting['is_sms']) { if($setting['sms_type']=='10'){ if(send_by_modem($setting, $setting['test_phone'], "短息发送成!收到该短信说明短信发送已经配置成功!")) { $msg .= "短信发送成功!如未收到短信请检查配置!"; }else{ $msg .= "短信发送失败!端口被占用或者配置错误!"; } }elseif($setting['sms_type']=='20'){ $sms_content = array("sys_name"=> $this->config->item('sys_name')); $resp = $this->aliyunsms->sendSms($setting['test_phone'],$setting['template_codes'][6],$sms_content); if($resp['Code'] == 'OK'){ $msg .= "短信发送成功!如未收到短信请检查配置!"; }else{ $msg .= "短信发送失败!".$resp['Code'] ; } } } else { $msg .= "未启用短信发送!"; } $this->response(array("icon" => 1, "msg" => $msg)); } else { $this->response(array("icon" => 2, "msg" => "未配置短信和邮箱不能测试发送!")); } } /** * 配置向导 */ public function step(){ $setting= $this->cache->get('setting'); if (!$setting) { $setting = $this->setting_model->get_model(); } $this->assign("setting", $setting); $this->display("setting/step.html"); } /** * 设置已完成工单保存时间 */ public function savetime(){ if ($this->input->post()) { $save_time= $this->input->post("save_time", true); $setting = $this->setting_model->get_setting(); $setting['save_time'] = $save_time; $this->setting_model->update_setting($setting); $this->update_cahce(); $this->response(array("code" => 1, "icon" => 1, "msg" => "已完成工单保存时间修改成功!")); }else{ $this->response(array("code" => 2, "icon" => 2, "msg" => "请勿非法提交数据!")); } } /** * 清除缓存 */ public function clearcache(){ if($this->cache->clean()) { $this->ci_smarty->clearAllCache(); $this->response(array("code" => 1, "icon" => 1, "msg" => "缓存清除成功!")); }else{ $this->response(array("code" => 2, "icon" => 2, "msg" => "缓存清除失败!请检查application/cache目录是否有写权限!")); } } }