Example #1
0
 public function testGetDocComment()
 {
     $this->assertEquals('测试常量1', $this->constDocHelper->getDocComment('TEST_CONSTANT_1'));
     $this->assertEquals('测试常量2', $this->constDocHelper->getDocComment('TEST_CONSTANT_2'));
 }
Example #2
0
 /**
  * 发送短信
  *
  * 群发时最多只能发 100 条,所以我们这里最多发 90 条,多出来的用回调解决
  *
  * @param string|array $mobile
  * @param string $text
  * @return array|boolean
  */
 public function sendSms($mobile, $text)
 {
     if ($this->useFileTransport) {
         return $this->saveSms($mobile, $text);
     }
     if (!is_array($mobile)) {
         $mobile = explode(',', $mobile);
     }
     if (empty($mobile)) {
         return false;
     }
     $mobileArr = array_chunk($mobile, 90);
     $mobile = array_pop($mobileArr);
     foreach ($mobileArr as $val) {
         self::sendSms($val, $text);
     }
     $mobile = array_filter($mobile, function ($val) {
         $isPhoneNumber = strlen($val) === 11;
         if ($isPhoneNumber) {
             return true;
         } else {
             Yii::error("Error phone number: " . $val);
             return false;
         }
     });
     $body = ['mobile' => implode(',', $mobile), 'text' => $text];
     $url = sprintf($this->urlFormat, static::RESOURCE_SMS, static::FUNCTION_SEND);
     if (($body = $this->post($url, $body)) === false) {
         return false;
     }
     $code = $body['code'];
     if ($code != static::CODE_0) {
         $n = new ConstDocHelper(__CLASS__);
         if ($code < 0) {
             $const = 'CODE_N' . -$code;
         } else {
             $const = 'CODE_' . $code;
         }
         $str = $n->getDocComment($const);
         Yii::error($str);
         return false;
     }
     return $body;
 }