Skip to content

Commit

Permalink
传入参数自动转化为字符串格式
Browse files Browse the repository at this point in the history
  • Loading branch information
jaren-gu committed Jun 20, 2017
1 parent 84dd9d2 commit f516a26
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
4 changes: 0 additions & 4 deletions Lib/Alidayu/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ public function send($conf, $to, $param) {
if (!empty($param)) {
// 如果传入数据不是 json 字符串,将其转化为 json 字符串
if (is_array($param)) {
// 保证所有的参数都是字符串类型
foreach($param as $k => $v){
$param[$k] = $v . "";
}
$param = json_encode($param);
}

Expand Down
4 changes: 0 additions & 4 deletions Lib/Ucpaas/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ public function send($conf, $to, $param) {

// 如果传入数据不是 json 字符串,将其转化为 json 字符串
if (is_array($param)) {
// 保证所有的参数都是字符串类型
foreach($param as $k => $v){
$param[$k] = $v . "";
}
$param = json_encode($param);
}

Expand Down
42 changes: 24 additions & 18 deletions Service/SmsService.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class SmsService {
* 发送短信
*
* @param string $template 短信模板ID,从后台配置获取
* @param string $to 短信接收人,多个接收人号码之间使用英文半角逗号隔开
* @param array $param 短信模板变量,数组或者json字符串
* @param array $operator 短信平台,不传入时,使用后台配置的默认短信平台
* @param string $to 短信接收人,多个接收人号码之间使用英文半角逗号隔开
* @param array $param 短信模板变量,数组或者json字符串
* @param array $operator 短信平台,不传入时,使用后台配置的默认短信平台
*
* @return array operator => 发送平台,
* template => 短信模板数据,
Expand All @@ -26,19 +26,26 @@ class SmsService {
* result => 发送结果
*/
public static function sendSms($template, $to, $param = NULL, $operator = NULL) {


//如果没有传入短信平台,则使用后台配置的开启的短信平台发送
if (null == $operator){
$operator = M('smsOperator')->where("enable='1'")->find()['tablename'];
}
// 获取短信模板配置
if (null == $operator) {
$operator = M('smsOperator')->where("enable='1'")->find()['tablename'];
}

// 获取短信模板配置
$model = M('sms_' . $operator);
$conf = $model->find($template);

//检查是否存在指定的文件
$file = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "Lib" . DIRECTORY_SEPARATOR . ucfirst($operator) . DIRECTORY_SEPARATOR."Helper.php";
$file = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "Lib" . DIRECTORY_SEPARATOR . ucfirst($operator) . DIRECTORY_SEPARATOR . "Helper.php";

// 保证所有的参数都是字符串类型
if (is_array($param)) {
foreach ($param as $k => $v) {
$param[$k] = $v . "";
}
}

if (file_exists($file)) {
//导入当前模块下Lib目录下的指定文件
Expand All @@ -51,21 +58,20 @@ public static function sendSms($template, $to, $param = NULL, $operator = NULL)
$log = array(
'operator' => $operator,
'template' => json_encode($conf),
'recv' => $to,
'param' => is_array($param) ? json_encode($param): $param,
'recv' => $to,
'param' => is_array($param) ? json_encode($param) : $param,
'sendtime' => time(),
'result' => $result,
'result' => $result,
);

if (M('sms_log')->create($log)) {
M('sms_log')->add($log);
}

return json_decode($result,true);
return json_decode($result, true);

}
else {
return json_decode(['code' => -1,'sub_msg'=>'不支持的短信平台'],true);
} else {
return json_decode(['code' => -1, 'sub_msg' => '不支持的短信平台'], true);
}


Expand Down

0 comments on commit f516a26

Please sign in to comment.