-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit edd45ea
Showing
21 changed files
with
1,916 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
return array( | ||
//模块名称 | ||
'modulename' => '短信模块', | ||
//图标 | ||
'icon' => 'https://dn-coding-net-production-pp.qbox.me/e57af720-f26c-4f3b-90b9-88241b680b7b.png', | ||
//模块简介 | ||
'introduce' => '短信模块', | ||
//模块介绍地址 | ||
'address' => 'http://ztbcms.com', | ||
//模块作者 | ||
'author' => 'ZtbCMS', | ||
//作者地址 | ||
'authorsite' => 'http://ztbcms.com', | ||
//作者邮箱 | ||
'authoremail' => '[email protected]', | ||
//版本号,请不要带除数字外的其他字符 | ||
'version' => '2.0.0.2', | ||
//适配最低CMS版本, | ||
'adaptation' => '3.0.0.0', | ||
//签名 | ||
'sign' => 'b5ff336fe067fad96cbed5e140187171', | ||
//依赖模块 | ||
'depend' => array(), | ||
//行为注册 | ||
'tags' => array(), | ||
//缓存,格式:缓存key=>array('module','model','action') | ||
'cache' => array(), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
// +---------------------------------------------------------------------- | ||
// | Copyright (c) Zhutibang.Inc 2016 http://zhutibang.cn All rights reserved. | ||
// +---------------------------------------------------------------------- | ||
// | Author: Jayin Ton <[email protected]> | ||
// +---------------------------------------------------------------------- | ||
|
||
namespace Sms\Controller; | ||
|
||
use Common\Controller\Base; | ||
|
||
class ApiController extends Base { | ||
|
||
protected $operator; | ||
protected $conf; | ||
|
||
protected function _initialize() { | ||
parent::_initialize(); | ||
|
||
//获取默认短信平台,如果没有传入短信平台,则使用次短信平台发送 | ||
$this->operator = M('smsOperator')->where("enable='1'")->find()['tablename']; | ||
} | ||
|
||
/** | ||
* 发送短信 | ||
* | ||
* @param string $template 短信模板ID,从后台配置获取 | ||
* @param string $to 短信接收人,多个接收人号码之间使用英文半角逗号隔开 | ||
* @param array $param 短信模板变量,数组或者json字符串 | ||
* @param array $operator 短信平台,不传入时,使用后台配置的默认短信平台 | ||
* | ||
* @return array operator => 发送平台, | ||
* template => 短信模板数据, | ||
* recv => 短信接收人 | ||
* param => 短信模版参数 | ||
* sendtime => 发送时间 | ||
* result => 发送结果 | ||
*/ | ||
public function sendSms($template, $to, $param = NULL, $operator = NULL) { | ||
|
||
$operator = NULL == $operator ? $this->operator : $operator; | ||
|
||
if (is_array($param)) { | ||
$param = json_encode($param); | ||
} | ||
|
||
$model = M('sms_' . $operator); | ||
$conf = $model->find($template); | ||
|
||
//检查是否存在指定的文件 | ||
$file = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "Lib" . DIRECTORY_SEPARATOR . ucfirst($operator) . DIRECTORY_SEPARATOR."helper.php"; | ||
|
||
if (file_exists($file)) { | ||
//导入当前模块下Lib目录下的指定文件 | ||
require_once(PROJECT_PATH . "Application/Sms/Lib/" . ucfirst($operator) . "/helper.php"); | ||
$className = "\\Sms\\Lib\\" . ucfirst($operator) . "\\helper"; | ||
$helper = new $className(); | ||
$result = json_encode($helper->send($conf, $to, $param)); | ||
|
||
//发送结果存入数据库 | ||
$log = array( | ||
'operator' => $operator, | ||
'template' => json_encode($conf), | ||
'recv' => $to, | ||
'param' => $param, | ||
'sendtime' => time(), | ||
'result' => $result, | ||
); | ||
|
||
if (M('sms_log')->create($log)) { | ||
M('sms_log')->add($log); | ||
} | ||
|
||
return json_decode($result,true); | ||
|
||
} | ||
else { | ||
$this->error("所选短信平台暂不支持"); | ||
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.