Ejemplo n.º 1
0
 /**
  * 发送
  * @method send
  * @since 0.0.1
  * @param {string} $phone 手机号
  * @param {string} $content 短信内容
  * @param {number} $uid 操作者, 0系统, >0用户id
  * @return {boolean}
  * @example \Yii::$app->sms->send($phone, $content, $uid);
  */
 public function send($phone, $content, $uid = 0)
 {
     if (empty($phone) || empty($content)) {
         throw new ErrorException('Phone and content must be required');
     }
     $this->phone = $phone;
     $this->content = $content;
     $this->setContent();
     $status = false;
     switch (strtolower($this->mode)) {
         case 'luosimao':
             $result = Luosimao::sdk($this->config)->send($this->phone, $this->content);
             break;
     }
     if (isset($result) && !empty($result)) {
         $sms = new Sms();
         $sms->phone = $this->phone;
         $sms->content = $this->content;
         $sms->uid = $uid;
         $sms->status = $result['status'];
         $sms->message = $result['message'];
         $sms->created_at = time();
         if ($sms->save()) {
             $status = true;
         }
     }
     return $status;
 }
Ejemplo n.º 2
0
 /**
  * 发送
  * @method send
  * @since 0.0.1
  * @param {string} $mobile 移动号码, 多个以英文逗号隔开, <=10000个
  * @param {string} $content 内容, <=300个字(含签名)
  * @param {int} [$operator_id=0] 操作者, 0系统, >0用户id
  * @param {int} [$sent_at=0] 发送时间, 0立即, >0定时
  * @return {boolean}
  * @example \Yii::$app->sms->send($mobile, $content, $operator_id, $sent_at);
  */
 public function send($mobile, $content, $operator_id = 0, $sent_at = 0)
 {
     if (!$this->dev) {
         switch (strtolower($this->sp)) {
             case 'luosimao':
                 $sp = Luosimao::sdk($this->config);
                 break;
             default:
                 throw new ErrorException('The SP service provider does not supported');
                 break;
         }
     }
     $sms = new Sms();
     $sms->mobile = $this->formatMobile($mobile);
     $sms->content = $this->formatContent($content);
     $sms->sent_at = $sent_at;
     $sms->status = $this->dev || $sp->send($sms->mobile, $sms->content, $sms->sent_at) ? 1 : 0;
     $sms->message = $this->dev ? '发送成功' : $sp->errmsg;
     $sms->operator_id = $operator_id;
     $sms->created_at = time();
     $sms->save();
     return $sms->status;
 }