Example #1
0
 /**
  * 短信内容发送总接口
  * 发发除了验证码之外的短信
  * @param String $phone   手机号码
  * @param int    $tid     模板ID:-1表示不使用模板,直接发送短信内容$content
  * @param Array  $params  模板参数:参数名param1、param2、param3、...
  * @param String $content 短信内容:模板ID为-1时才使用
  * @return Boolean true:发送成功  false:发送失败
  */
 public static function sendSmsContent($phone, $tid = -1, $params = array(), $content = null)
 {
     $result = false;
     if ($tid != -1) {
         // 按模板发送
         if (empty(self::TEMPLATE_SMS[$tid])) {
             return $result;
         }
         $contentArray = explode('【变量】', self::TEMPLATE_SMS[$tid]);
         if (count($contentArray) != count($params) + 1) {
             return $result;
         }
         $content_temp = '';
         foreach ($contentArray as $k => $v) {
             if ($k == 0) {
                 $content_temp = $v;
             } else {
                 $key = "param" . $k;
                 $content_temp .= $params[$key] . $v;
             }
         }
         // 优先调用互忆无线短信接口
         $result = HuyiSmsService::sendSmsContent($phone, $content_temp);
         self::recordSmsLog(2, $result, false);
         // 记录互亿无线发送情况
         if (!$result) {
             // 莫名短信发送接口
             $status = SMSService::sendSMS($phone, $content_temp);
             if ($status == 100) {
                 $result = true;
             }
             self::recordSmsLog(3, $result, false);
             // 记录莫名发送情况
         }
     } else {
         // 直接发送短信内容:$content
         if (empty($content)) {
             return $result;
         }
         $status = SMSService::sendSMS($phone, $content);
         if ($status == 100) {
             $result = true;
         }
         self::recordSmsLog(3, $result, false);
         // 记录莫名发送情况
     }
     return $result;
 }