private function _sendAsFile($mobile, $content)
{
$dir = Yii::getAlias('@app/runtime/smser');
try {
if (!FileHelper::createDirectory($dir)) {
throw new \Exception('无法创建目录:' . $dir);
}
$filename = $dir . DIRECTORY_SEPARATOR . time() . mt_rand(1000, 9999) . '.msg';
if (!touch($filename)) {
throw new \Exception('无法创建文件:' . $filename);
}
if (!file_put_contents($filename, "TO - {$mobile}" . PHP_EOL . "CONTENT - {$content}")) {
throw new \Exception('短信发送失败!');
}
return true;
} catch (\Exception $e) {
$this->message = $e->getMessage();
return false;
}
}