From 9c8f3b797bd0bd731b286800db6155d90819e60f Mon Sep 17 00:00:00 2001 From: jaren <13428282005@163.com> Date: Mon, 19 Jun 2017 10:02:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=8F=82=E6=95=B0=E4=BC=A0?= =?UTF-8?q?=E5=85=A5=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lib/Alidayu/Helper.php | 9 +++++++++ Lib/BaseHelper.class.php | 6 +++--- Lib/Ucpaas/Helper.php | 16 ++++++++++++++++ Service/SmsService.class.php | 11 +---------- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Lib/Alidayu/Helper.php b/Lib/Alidayu/Helper.php index b81695a..9529b32 100644 --- a/Lib/Alidayu/Helper.php +++ b/Lib/Alidayu/Helper.php @@ -18,6 +18,15 @@ public function send($conf, $to, $param) { $req->setSmsType($conf['type']); $req->setSmsFreeSignName($conf['sign']); if (!empty($param)) { + // 如果传入数据不是 json 字符串,将其转化为 json 字符串 + if (is_array($param)) { + // 保证所有的参数都是字符串类型 + foreach($param as $k => $v){ + $param[$k] = $v . ""; + } + $param = json_encode($param); + } + $req->setSmsParam($param); } $req->setRecNum($to); diff --git a/Lib/BaseHelper.class.php b/Lib/BaseHelper.class.php index 757b3a9..3403a17 100644 --- a/Lib/BaseHelper.class.php +++ b/Lib/BaseHelper.class.php @@ -6,9 +6,9 @@ abstract class BaseHelper { /** * 短信发送 * - * @param $conf array 配置 - * @param $to string 接受人 - * @param $param array 短信参数 + * @param $conf array 配置 + * @param $to string 短信接收人,多个接收人号码之间使用英文半角逗号隔开 + * @param $param array 短信参数 * @return mixed */ abstract function send($conf, $to, $param); diff --git a/Lib/Ucpaas/Helper.php b/Lib/Ucpaas/Helper.php index 6a3697b..4bba142 100644 --- a/Lib/Ucpaas/Helper.php +++ b/Lib/Ucpaas/Helper.php @@ -6,8 +6,24 @@ class Helper extends BaseHelper { + /** + * + * @param array $conf + * @param string $to + * @param array $param + * @return mixed|string + */ public function send($conf, $to, $param) { + // 如果传入数据不是 json 字符串,将其转化为 json 字符串 + if (is_array($param)) { + // 保证所有的参数都是字符串类型 + foreach($param as $k => $v){ + $param[$k] = $v . ""; + } + $param = json_encode($param); + } + $ucpass = new Ucpaas($conf); return $ucpass->templateSMS($to, $param); diff --git a/Service/SmsService.class.php b/Service/SmsService.class.php index 48e8563..7596575 100644 --- a/Service/SmsService.class.php +++ b/Service/SmsService.class.php @@ -32,15 +32,6 @@ public static function sendSms($template, $to, $param = NULL, $operator = NULL) if (null == $operator){ $operator = M('smsOperator')->where("enable='1'")->find()['tablename']; } - - // 如果传入数据不是 json 字符串,将其转化为 json 字符串 - if (is_array($param)) { - // 保证所有的参数都是字符串类型 - foreach($param as $k => $v){ - $param[$k] = $v . ""; - } - $param = json_encode($param); - } // 获取短信模板配置 $model = M('sms_' . $operator); @@ -61,7 +52,7 @@ public static function sendSms($template, $to, $param = NULL, $operator = NULL) 'operator' => $operator, 'template' => json_encode($conf), 'recv' => $to, - 'param' => $param, + 'param' => is_array($param) ? json_encode($param): $param, 'sendtime' => time(), 'result' => $result, );