Skip to content

Commit

Permalink
更改参数传入方式
Browse files Browse the repository at this point in the history
  • Loading branch information
jaren-gu committed Jun 19, 2017
1 parent a6aeff7 commit 9c8f3b7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
9 changes: 9 additions & 0 deletions Lib/Alidayu/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions Lib/BaseHelper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions Lib/Ucpaas/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 1 addition & 10 deletions Service/SmsService.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
);
Expand Down

0 comments on commit 9c8f3b7

Please sign in to comment.