public static function send($msg, $detail, $level = self::USER, $mobile = null) { //判断是否定义需要发送短信 if (!in_array($level, explode(',', C('SMS_LEVEL')))) { return; } //判断发送频率 $mc = memcache_init(); $is_send = $mc->get('think_sms_send'); //如果已经发送,则不发送 if ($is_send === 'true') { $status = 'not send'; } else { //TODU,如果apibus类调整,此类也得调整 $sms = apibus::init('sms'); if (is_null($mobile)) { $mobile = C('SMS_MOBILE'); } $mc = memcache_init(); $obj = $sms->send($mobile, mb_substr(C('SMS_SIGN') . $msg, 0, 65, 'utf-8'), "UTF-8"); if ($sms->isError($obj)) { $status = 'failed'; } else { $status = 'success'; $mc->set('think_sms_send', 'true', 0, C('SMS_INTERVAL')); } } //记录日志 if (C('LOG_RECORD')) { Log::record($msg . ';detail:' . $detail . '【status:' . $status . '】', 'SEND_SMS', true); } else { Log::write($msg . ';detail:' . $detail . '【status:' . $status . '】', 'SEND_SMS'); } }
/** * (non-PHPdoc) * @see SMS::set() */ public function set($options) { $this->sms = apibus::init("sms"); //创建短信服务对象 }