/** * 主动上报 * @param $code * @param string $content * @internal param $details * @internal param array $data */ static function report($code, $content = '') { $client = new YucRequest(YApp::getConfig('YUC_SERVICE_NAME'), YApp::getConfig('YUC_SERVICE_PORT')); $client->setTimeout(YApp::getConfig('YUC_CLIENT_TIMEOUT')); //设置超时 $client->post(YApp::getConfig('YUC_MONITOR_PATH'), array('site_key' => YApp::getConfig('YUC_SITE_KEY'), 'code' => $code, 'content' => $content, 'datetime' => date("Y-m-d H:i:s"), 'server' => $_SERVER)); $result = json_decode($client->getContent(), TRUE); YLog::Write(var_export($result, TRUE), YLog::DEBUG); if ($client->getStatus() == 200 && is_array($result) && count($result) == 2 && $result['result'] == 1) { YLog::Write('主动上报信息成功!Code:' . $code . ';Content:' . $content, YLog::DEBUG); } else { YLog::Write('主动上报信息失败!', YLog::DEBUG); } }
/** * 获取校验结果 * @param $ssid * @param $result * @param int $diff * @param array $extra * @return type */ public static function sendVerifyRemoteRequest($ssid, $result, $diff = 0, $extra = array()) { $client = new YucRequest(YApp::getConfig('YUC_SERVICE_NAME'), YApp::getConfig('YUC_SERVICE_PORT')); $client->setTimeout(YApp::getConfig('YUC_CLIENT_TIMEOUT')); //设置超时 $client->post(YApp::getConfig('YUC_VERIFY_PATH'), array('site_key' => YApp::getConfig('YUC_SITE_KEY'), 'secure_key' => YApp::getConfig('YUC_SECURE_KEY'), 'ssid' => $ssid, 'result' => $result, 'diffsec_client' => $diff, 'extra' => $extra)); $post_req = json_decode($client->getContent(), TRUE); YLog::Write('远程验证完成,输入结果为:' . $result . ',返回状态 :' . $client->getStatus() . ';' . 'POST 验证码正确性请求返回的数据:' . $client->getContent(), YLog::DEBUG); if ($client->getStatus() == 200 && is_array($post_req)) { self::$_code = $post_req['code']; self::$_details = $post_req['details']; self::$_result = $post_req['result']; } else { self::$_code = 'E_SEVERVALID_001'; self::$_details = '服务器请求失败!'; self::$_result = 0; } }
/** * POST发送请求数据 * @return array */ private function doPost() { $client = new YucRequest(YApp::getConfig('YUC_SERVICE_NAME'), YApp::getConfig('YUC_SERVICE_PORT')); $client->setTimeout(YApp::getConfig('YUC_CLIENT_TIMEOUT')); //设置超时 $client->post(YApp::getConfig('YUC_REQUEST_PATH'), $this->_local->getPostData()); YLog::Write('请求:' . YApp::getConfig('YUC_SERVICE_NAME') . YApp::getConfig('YUC_REQUEST_PATH') . ';返回状态 :' . $client->getStatus() . ';POST请求返回的数据:' . $client->getContent(), YLog::DEBUG); $ret_back = json_decode($client->getContent(), TRUE); if (!is_array($ret_back)) { YucMonitor::report("REPORT_0004", $client->getContent()); } return array('status' => $client->getStatus(), 'content' => $ret_back); }