Skip to content

Commit

Permalink
V1.15
Browse files Browse the repository at this point in the history
完成控制台命令程序
  • Loading branch information
michaelweixi committed Dec 4, 2016
1 parent 44e819a commit 2f680f1
Show file tree
Hide file tree
Showing 5 changed files with 643 additions and 0 deletions.
78 changes: 78 additions & 0 deletions console/controllers/HelloController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
namespace console\controllers;

use yii\console\Controller;
use common\models\Post;

class HelloController extends Controller
{
public $rev;

public function options()
{
return ['rev'];
}

public function optionAliases()
{
return['r'=>'rev'];
}

public function actionIndex()
{
if($this->rev == 1)
{
echo strrev("Hello World!")."\n";
}
else
{
echo "Hello World!\n";
}
}

/*
public function actionIndex() //index 是默认动作
{
echo "Hello World! \n";
}
*/
public function actionList()
{
$posts = Post::find()->all();

foreach ($posts as $aPost)
{
echo ($aPost['id']. " - ".$aPost['title'] ."\n");
}
}

public function actionWho($name)
{
echo ("Hello ". $name . "!\n");
}

public function actionBoth($name,$another)
{
echo ("Hello ".$name." and ". $another ."!\n");
}

public function actionAll(array $names)
{
var_dump($names);
}















}
61 changes: 61 additions & 0 deletions console/controllers/SmsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
namespace console\controllers;

use Yii;
use yii\console\Controller;
use common\models\Comment;

class SmsController extends Controller
{
public function actionSend()

//操作系统上的执行命令:
///Users/michaelweixi/WWWRoot/blogdemo2/yii sms/send >> /Users/michaelweixi/WWWRoot/blogdemo2/sms.log

{
$newCommentCount=Comment::find()->where(['remind'=>0,'status'=>1])->count();//看看有没有未提醒的新评论

if($newCommentCount>0)
{
$content=''.$newCommentCount.'条新评论待审核。';

$result = $this->vendorSmsService($content);

if($result['status']=='success')
{
Comment::updateAll(['remind'=>1]); //把提醒标志全部设为已提醒
echo '['.date("Y-m-d H:i:s",$result['dt']).'] '.$content.'['.$result['length'].']'."\r\n";//记录日志

}
return 0;
}
}

protected function vendorSmsService($content)
{
//实现第三方短信供应商提供的短信发送接口。

// $username = 'companyname'; //用户账号
// $password = 'pwdforsendsms'; //密码
// $apikey = '577d265efafd2d9a0a8c2ed2a3155ded7e01'; //密码
// $mobile = $adminuser->mobile; //号手机码

// $url = 'http://sms.vendor.com/api/send/?';
// $data = array
// (
// 'username'=>$username, //用户账号
// 'password'=>$password, //密码
// 'mobile'=>$mobile, //号码
// 'content'=>$content, //内容
// 'apikey'=>$apikey, //apikey
// );
// $result= $this->curlSend($url,$data); //POST方式提交
// return $result; //返回发送状态,发送时间,字节数等数据
// }

$result=array("status"=>"success","dt"=>time(),"length"=>43); //模拟数据
return $result;

}

}
10 changes: 10 additions & 0 deletions database/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

博客系统源码的不同版本需要导入的SQL文件的版本也不同,下表列出了他们的对应关系:

————————————————————————————————————————

源码版本:V1.1 ————— SQL文件版本:V1.1

源码版本:V1.2 ————— SQL文件版本:V1.2
Expand Down Expand Up @@ -29,3 +31,11 @@
源码版本:V1.13 ————— 同上

源码版本:V1.14 ————— 同上

源码版本:V1.15 ————— SQL文件版本:V1.5

————————————————————————————————————————

注:V1.5也可以在V1.4基础上执行下面这句SQL语句得到:

ALTER TABLE `comment` ADD `remind` INT(4) NULL DEFAULT '0' COMMENT '0:未提醒1:已提醒' ;
Loading

0 comments on commit 2f680f1

Please sign in to comment.