Beispiel #1
0
 /**
  * 生成发送手机验证码(未采用任何验证),历史版本方法,等待私有化
  * $mobile 手机号
  *
  * 返回
  * success
  */
 public function send_sms()
 {
     $app_id = intval($this->input['app_id']);
     $appName = $this->input['app_name'];
     if ($this->settings['closesms']) {
         $this->errorOutput($this->settings['error_text']['closesms']);
     }
     $mobile = trim($this->input['mobile']);
     if (!$mobile) {
         $this->errorOutput(MOBILE_NOT_NUMBER);
     }
     if ($this->mSmslog->check_max_limits($mobile)) {
         $this->errorOutput($this->settings['error_text']['sms_max_limits']);
     }
     //简单验证手机号格式
     if (!hg_verify_mobile($mobile)) {
         $this->errorOutput(MOBILE_NUMBER_FORMAT_ERROR);
     }
     /*******************************增加可以指定短信配置进行发短信*************************************/
     if ($this->input['m_server_id']) {
         $condition = " AND status = 1 AND id = '" . $this->input['m_server_id'] . "' ";
     } else {
         $condition = " AND status = 1 ORDER BY over DESC LIMIT 1";
     }
     /*******************************增加可以指定短信配置进行发短信*************************************/
     //限制应用的发送短信条数
     if ($app_id) {
         $app_sms_record = $this->app_sms_count->detail($app_id);
         if ($app_sms_record) {
             //判断时间是否是上个月  如果是,把total清零
             $last_sms_time = $app_sms_record['last_send_time'];
             if (date('Y-m', TIMENOW) > date('Y-m', $last_sms_time)) {
                 $this->app_sms_count->update($app_id, array('total' => 0, 'last_send_time' => TIMENOW));
                 //重新获取计数
                 $app_sms_record = $this->app_sms_count->detail($app_id);
             }
             $balance = $app_sms_record['total'];
             $limit_count = MAX_SENDSMS_COUNT_LIMITS + $app_sms_record['recharge'];
             if ($balance >= $limit_count) {
                 $this->errorOutput(SMS_BALANCE_NOT_ENOUGH);
             }
         }
     }
     $sms_server = $this->mSmsServer->get_sms_server_info($condition);
     $sms_server = $sms_server[0];
     if (empty($sms_server)) {
         $this->errorOutput(SMS_NOT);
     }
     $verifycode_length = $sms_server['verifycode_length'];
     $verifycode_content = $sms_server['verifycode_content'];
     $content = $sms_server['content'];
     if ($verifycode = $this->db->query_first("SELECT * FROM " . DB_PREFIX . "mobile_verifycode WHERE mobile='" . $mobile . "' AND create_time >= " . intval(TIMENOW - VERIFYCODE_EXPIRED_TIME) . " ORDER BY create_time DESC")) {
         $verifycode = $verifycode['verifycode'];
     } else {
         $verifycode = hg_set_verifycode($verifycode_length, $verifycode_content);
     }
     if (!$verifycode) {
         $this->errorOutput(VERIFY_MAKE_FAILED);
     }
     if (strstr($content, '{$c}')) {
         $content = str_replace('{$c}', $verifycode, $content);
     } else {
         if (strstr($content, ''{$c}'')) {
             $content = str_replace(''{$c}'', $verifycode, $content);
         }
     }
     //为应用名称处理短信发送接口
     if (strstr($content, '{$app}')) {
         if (strstr($content, '{$app}')) {
             $content = str_replace('{$app}', $appName, $content);
         } else {
             if (strstr($content, ''{$app}'')) {
                 $content = str_replace(''{$app}'', $appName, $content);
             }
         }
     }
     if ($sms_server['charset'] != 'UTF-8') {
         $content = iconv('UTF-8', $sms_server['charset'], $content);
     }
     //替换相关变量
     $url = $sms_server['send_url'];
     if (strstr($url, '{$mobile}')) {
         $url = str_replace('{$mobile}', $mobile, $url);
     }
     if (strstr($url, '{$content}')) {
         $url = str_replace('{$content}', $content, $url);
     }
     /*
     $data = array(
     'mobile'		=> $mobile,
     'verifycode'	=> $verifycode,
     'create_time'	=> TIMENOW,
     );
     if ($this->settings['closesms'])
     {
     $ret = $this->mSmsServer->mobile_verifycode_create($data);
     $this->addItem($data);
     $this->output();
     }
     */
     if (!$sms_server['return_type']) {
         $type = 'json';
     } else {
         $type = $sms_server['return_type'];
     }
     $return = $this->mSmsServer->curl_get($url, $type);
     if (isset($return['return']) && $return['return'] || $return['result'] == '01' || isset($return['result']['err_code']) && $return['result']['err_code'] == '0') {
         //入手机验证码库
         $data = array('mobile' => $mobile, 'verifycode' => $verifycode, 'create_time' => TIMENOW);
         $ret = $this->mSmsServer->mobile_verifycode_create($data);
         //纪录发送记录和次数
         $this->mSmslog->replace($mobile);
         //记录app发送的次数和最后的时间
         if ($app_id) {
             $this->record_app_count($app_id);
         }
         if (!$ret) {
             $this->errorOutput(VERIFY_ADD_FAILED);
         }
         $this->addItem('success');
         $this->output();
     } else {
         $this->errorOutput(VERIFY_SEND_FAILED);
     }
 }
Beispiel #2
0
 private function makeToken($length = 16)
 {
     $token = hg_set_verifycode($length = 16, $chars = '0123456789abcdefghijjklmnopqrstuvwxyzABCDEFGHIIJKLMNOPQRSTUVWXYZ');
     //获取随机数
     return $token;
 }