Example #1
0
 /**
  * 计时器(单位:秒)
  *
  * @return float
  */
 function webName()
 {
     $webName = '';
     if (!empty(config(conFile() . 'webName'))) {
         $webName = config(conFile() . 'webName');
     }
     return $webName;
 }
Example #2
0
 private static function getInfoForMobile($mobile, $type)
 {
     // 配置apiKey
     $apiKey = 'aeec72828c8a82f78b865e3c231afa31';
     if (!empty(config(conFile() . 'apiKey.baiDu.mobile'))) {
         $apiKey = config(conFile() . 'apiKey.baiDu.mobile');
     }
     if (!Mobile::isMobile($mobile)) {
         return null;
     }
     // 初始化一个cURL会话
     $ch = curl_init();
     $url = 'http://apis.baidu.com/apistore/mobilenumber/mobilenumber?phone=' . $mobile;
     $header = array('apikey: ' . $apiKey);
     // 添加apikey到header
     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
     // 将curl_exec()获取的信息以文件流的形式返回,而不是直接输出。
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     // 需要获取的URL地址,也可以在curl_init()函数中设置。
     curl_setopt($ch, CURLOPT_URL, $url);
     // 设置连接超时, 即服务器多少s无响应程序便会断开连接(官方说明:在发起连接前等待的时间,如果设置为0,则无限等待。)
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
     // 设置连接成功后cURL接收数据最长时间
     curl_setopt($ch, CURLOPT_TIMEOUT, 2);
     // 执行HTTP请求并将Json转换为对象
     $rst = json_decode(curl_exec($ch));
     // 出错处理
     if (!empty($rst->errNum) || empty($rst)) {
         // 给网站管理员发送邮件
         $err = '<h1>百度手机API接口没有成功返回地址信息!</h1>';
         if (!empty($rst->errNum)) {
             $err .= '<h5>错误代号:' . $rst->errNum . '</h5>';
         }
         if (!empty($rst->errMsg)) {
             $err .= '<h5>错误信息:' . $rst->errMsg . '</h5>';
         }
         Email::sendEmailForWebmaster('【故障】百度手机归属地API出错', $err);
         return null;
     }
     return $type == 'city' ? $rst->retData->city : $rst->retData->province;
 }
Example #3
0
File: IP.php Project: alpfish/alp
 private static function getAdd($ip, $type)
 {
     // 配置apiKey
     $apiKey = 'aeec72828c8a82f78b865e3c231afa31';
     if (!empty(config(conFile() . 'apiKey.baiDu.mobile'))) {
         $apiKey = config(conFile() . 'apiKey.baiDu.mobile');
     }
     // IP有效性
     if (!filter_var($ip, FILTER_VALIDATE_IP)) {
         return null;
     }
     $ch = curl_init();
     $url = 'http://apis.baidu.com/apistore/iplookupservice/iplookup?ip=' . $ip;
     $header = array('apikey: ' . $apiKey);
     // 添加apikey到header
     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
     // 设置curl_exec()获取的信息以文件流的形式返回,而不是直接输出。
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     // 需要获取的URL地址,也可以在curl_init()函数中设置。
     curl_setopt($ch, CURLOPT_URL, $url);
     // 设置连接超时, 即服务器多少s无响应程序便会断开连接(官方说明:在发起连接前等待的时间,如果设置为0,则无限等待。)
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
     // 设置连接成功后cURL接收数据最长时间
     curl_setopt($ch, CURLOPT_TIMEOUT, 2);
     // 执行HTTP请求并将Json转换为对象
     $rst = json_decode(curl_exec($ch));
     // 错误处理
     if (!empty($rst->errNum) || empty($rst)) {
         // 给网站管理员发送邮件
         $err = '<h1>百度IP接口没有成功返回地址信息!</h1>';
         if (!empty($rst->errNum)) {
             $err .= '<h5>错误代号:' . $rst->errNum . '</h5>';
         }
         if (!empty($rst->errMsg)) {
             $err .= '<h5>错误信息:' . $rst->errMsg . '</h5>';
         }
         Email::sendEmailForWebmaster('【故障】百度IP查询API出错', $err);
         return null;
     }
     return $type == 'city' ? $rst->retData->city : $rst->retData->province;
 }
Example #4
0
 private static function handleErrorsResponse($resp)
 {
     $err_title = '【紧急】网站SMS模块错误!';
     $err_content = '<h1>短信发送失败!</h1>';
     $err_content .= '<h5>代码:' . $resp->code . '</h5>';
     $err_content .= '<h5>提示:' . $resp->msg . '</h5>';
     $err_content .= empty($resp->sub_code) ? '' : '<h5>子码:' . $resp->sub_code . '</h5>';
     $err_content .= empty($resp->sub_msg) ? '' : '<h5>提示:' . $resp->sub_msg . '</h5>';
     // 通知站长
     if (config(conFile('sms') . 'sms.isSendErrEmail')) {
         Email::sendEmailForWebmaster($err_title, $err_content);
     }
     return false;
 }