/** * 验证用户信息并种cookie * @param $access_token */ private function _user_login($access_token) { if (empty($access_token)) { $this->_apf->get_response()->redirect('/'); exit; } $data = array("oauth_token" => $access_token, "getinfo" => true); $oauth = $this->_apf->get_config('oauth2'); $curlObj = new APF_Http_Client_Curl('post'); $curlObj->set_url($oauth['oauth_login_url']); $curlObj->set_attribute(CURLOPT_POST, TRUE); $curlObj->set_attribute(CURLOPT_POSTFIELDS, $data); //不需要验证CURL证书 $curlObj->set_attribute(CURLOPT_SSL_VERIFYPEER, false); $curlObj->set_attribute(CURLOPT_SSL_VERIFYHOST, false); if ($curlObj->execute()) { $user_info = $curlObj->get_response_text(); if (empty($user_info)) { $this->_check_error(); exit; } $cookie_cfg = $this->_apf->get_config('cookie'); $cookie_value = Util_AuthorCrypt::encrypt($user_info, $cookie_cfg['key']); $this->_apf->get_response()->set_cookie($cookie_cfg['name'], $cookie_value, time() + $cookie_cfg['expires'], $cookie_cfg['path'], $cookie_cfg['domain']); $this->_apf->get_response()->redirect('/'); exit; } else { $this->_check_error(); exit; } }
/** * 检查手机是否被用户使用 * @param $mobile 手机号 * @return bool true已被占用 false 没有被占用 */ public static function checkUserMobile($params) { $userAPIDomain = APF::get_instance()->get_config("user_api_url"); $url = $userAPIDomain . "/memberapi/m"; $postData = array("act" => "check_user_phone", "phone" => $params['mobile']); $postData = http_build_query($postData); //curl 获取结果 apf_require_class("APF_Http_Client_Curl"); $curl_client = new APF_Http_Client_Curl('post'); //创建http客户端实例 $curl_client->set_url($url); //设置URL $curl_client->set_attribute(CURLOPT_POSTFIELDS, $postData); $curl_client->set_attribute(CURLOPT_HTTPHEADER, array()); $curl_client->set_attribute(CURLOPT_POST, 1); $curl_client->execute(); $res = $curl_client->get_response_text(); //从romar的http接口中获取推荐的数据 if (isset($res)) { $res = json_decode($res); } if ($res->status == 'ok' && $res->result > 0) { return true; } else { return false; } }
public function post($url, array $param, $ifJson = true) { $baseHost = $this->host; $postUrl = "http://" . $baseHost . "/" . $url; if ($ifJson) { $postData = json_encode($param); } else { $postData = http_build_query($param); } //curl 获取结果 apf_require_class("APF_Http_Client_Curl"); $curl_client = new APF_Http_Client_Curl('post'); //创建http客户端实例 $curl_client->set_url($postUrl); //设置URL $curl_client->set_attribute(CURLOPT_POST, 1); $curl_client->set_attribute(CURLOPT_POSTFIELDS, $postData); $curl_client->execute(); $res = $curl_client->get_response_text(); //从romar的http接口中获取推荐的数据 unset($curl_client); if (isset($res)) { $res = json_decode($res); return $res; } else { return false; } }
/** * 发送短信 * @param string $mobile 手机号 * @param string $content 短信内容 * @param int $business_id 业务ID * @param string $broker_id 经纪人ID * @param string $user_id 用户ID * @return bool 是否已放入短信发送队列 * */ public function send($mobile, $content, $business_id, $broker_id, $user_id) { $data = array('num' => $mobile, 'content' => $content, 'biz_id' => $business_id, 'bid' => $broker_id, 'uid' => $user_id, 'type' => 2); $curl = new APF_Http_Client_Curl(); $curl->set_url(APF::get_instance()->get_config('sms_url')); $curl->set_attribute(CURLOPT_POST, true); $curl->set_attribute(CURLOPT_POSTFIELDS, $data); $curl->set_attribute(CURLOPT_HTTPHEADER, array("charset=utf-8")); $is_ok = $curl->execute(); if ($is_ok) { $result = json_decode($curl->get_response_text(), true); if ($result['error']) { $is_ok = false; } } return $is_ok; }
/** * 检查手机是否被用户使用 * * @param $mobile 手机号 * @return bool true已被占用 false 没有被占用 */ public function checkUserMobile($mobile) { $userAPIDomain = APF::get_instance()->get_config("user_api_url"); $url = $userAPIDomain . "/memberapi/m"; $postData = array("act" => "check_user_phone", "phone" => $mobile); //curl 获取结果 apf_require_class("APF_Http_Client_Curl"); $curl_client = new APF_Http_Client_Curl('post'); //创建http客户端实例 $curl_client->set_url($url); //设置URL $curl_client->set_attribute(CURLOPT_POSTFIELDS, $postData); $curl_client->execute(); $res = $curl_client->get_response_text(); //从romar的http接口中获取推荐的数据 if (isset($res)) { $res = json_decode($res); } return $res; }
/** * @param $url * @param string $action 取值为update等,与请求URL中名称一致,用于选择错误结果数据模板 * @param $dataXml string 请求体 * @return array|mixed */ private function doRequest($url, $action, $dataXml = null) { // APF_DebuggerInterceptor根据请求参数debug决定是否设置debugger // debug=0清除cookie,关闭调试模式;debug>0设置cookie,开启调试模式 APF::get_instance()->debug(get_class($this) . '->Call: ' . $url); $curlClient = new APF_Http_Client_Curl(); $curlClient->set_url($url); if ($dataXml != null) { $curlClient->set_attribute(CURLOPT_POSTFIELDS, $dataXml); $curlClient->set_attribute(CURLOPT_POST, true); } $userAgent = $this->getUserAgent(); $curlClient->set_attribute(CURLOPT_USERAGENT, $userAgent); $curlClient->set_attribute(CURLOPT_NOSIGNAL, 1); $curlClient->set_attribute(CURLOPT_CONNECTTIMEOUT_MS, $this->connectTimeout); $curlClient->set_attribute(CURLOPT_TIMEOUT_MS, $this->readTimeout); if ($curlClient->execute()) { $responseText = json_decode($curlClient->get_response_text(), true); return $responseText; } else { $errno = $curlClient->get_curl_errno(); if ($errno == 0) { // curl执行没有错误,但是响应不正常 $curlInfo = $curlClient->get_curl_info(); $responseDecoded = json_decode($curlClient->get_response_text(), true); if (is_null($responseDecoded)) { switch ($action) { case "select": $result = $this->getSelectErrorRespTemplate(); break; case "update": $result = $this->getUpdateErrorRespTemplate(); break; } $result['responseHeader']['status'] = $curlInfo['http_code']; $result['error']['code'] = $curlInfo['http_code']; $result['error']['msg'] = $curlClient->get_response_text(); return $result; } else { $responseDecoded['params'] = $this->systemParams; return $responseDecoded; } } else { // curl执行出错 switch ($action) { case "select": $result = $this->getSelectErrorRespTemplate(); break; case "update": $result = $this->getUpdateErrorRespTemplate(); break; } $result['error']['code'] = $errno; $result['error']['msg'] = $curlClient->get_curl_error(); return $result; } } }
private function auth() { $apf = APF::get_instance(); $request = $apf->get_request(); $oauth = $apf->get_config('oauth2'); $cookie_cfg = $apf->get_config('cookie'); $cookie_info = $request->get_cookie($cookie_cfg['name']); if (empty($cookie_info)) { //未登录 $this->_remember_current_url(); $oauth_code = array('client_id' => $oauth['client_id'], 'response_type' => 'code', 'curl' => true); $url = $oauth['oauth_code_url']; $curlObj = new APF_Http_Client_Curl(); $curlObj->set_url($url . '?' . http_build_query($oauth_code)); //不需要验证CURL证书 $curlObj->set_attribute(CURLOPT_SSL_VERIFYPEER, false); $curlObj->set_attribute(CURLOPT_SSL_VERIFYHOST, false); /*var_dump($url);echo "<br>"; var_dump("ouauthcode".$oauth_code); var_dump($curlObj); var_dump($curlObj->execute());*/ if ($curlObj->execute()) { $checkRes = json_decode($curlObj->get_response_text(), true); if (empty($checkRes['code'])) { //验证失败 $this->_check_error(); exit; } $token_data = array('client_id' => $oauth['client_id'], 'client_secret' => $oauth['client_secret'], 'grant_type' => 'authorization_code', 'code' => $checkRes['code']); $token_url = $oauth['oauth_token_url'] . '?' . http_build_query($token_data); $apf->get_instance()->get_response()->redirect($token_url); exit; } else { $this->_check_error(); exit; } } else { $user_info_str = Util_AuthorCrypt::decrypt($cookie_info, $cookie_cfg['key']); $user_info_arr = json_decode($user_info_str, true); if (!empty($user_info_arr['user_id']) && is_numeric($user_info_arr['user_id'])) { //已登录 $request->setUserId($user_info_arr['user_id']); $request->setUserName($user_info_arr['name']); $request->setUserEmail($user_info_arr['email']); $request->setCityName($user_info_arr['city_name']); $request->setUserCode($user_info_arr['code']); $request->setUserJob($user_info_arr['job_name']); $request->setUserInfo($user_info_arr); //上一个返回地址 $return_url = $this->_get_referer_url(); if ($return_url) { $apf->get_response()->redirect('http://' . $return_url); } } else { //无效cookie $this->_remember_current_url(); $apf->get_response()->redirect('/logout'); exit; } } }