public static function ssoAction($controller, $conn, $appid, $openid, $token, $encrypt) { //重新授权 $app = new \Justsy\BaseBundle\Management\App($controller->container); $appdata = $app->getappinfo(array("appid" => $appid)); if (empty($appdata)) { $resp = new Response("无效的APPID"); $resp->headers->set('Content-Type', 'text/html'); return $resp; } $auth_url = $appdata["authorization_url"]; if (empty($auth_url)) { $resp = new Response("无效的配置:授权地址无效"); $resp->headers->set('Content-Type', 'text/html'); return $resp; } //判断是否绑定 $bindinfo = $app->getappbind(array("appid" => $appid, "openid" => $openid)); if (empty($bindinfo)) { $controller->get("logger")->err("================not bind"); //重定向到绑定页面 return $controller->render("JustsyBaseBundle:AppCenter:h5bundle.html.twig", array('appid' => $appid, 'openid' => $openid, 'ssomodule' => self::$bind_type . "Controller")); } else { /* $syspara = new \Justsy\BaseBundle\DataAccess\SysParam($controller->container); $sysappid = $syspara->GetSysParam("sso_".strtolower(self::$bind_type)."_appid"); if(empty($sysappid)) { $resp = new Response("未配置集成登录业务系统或参数".strtolower(self::$bind_type)."_appid"); $resp->headers->set('Content-Type', 'text/html'); return $resp; }*/ $sysinfo = $appdata; //$app->getbussysteminfo(array("appid"=>$sysappid)); $wwwUrl = $sysinfo["inf_url"]; $loginUrl = $sysinfo["authorization_url"]; if (empty($wwwUrl)) { $resp = new Response("未正确配置业务系统,请检查服务地址"); $resp->headers->set('Content-Type', 'text/html'); return $resp; } //获取seesionid $cookie_key = self::$bind_type . "_" . $openid; $getsessionUrl = $wwwUrl . "index.php?m=api&f=getSessionID&t=json"; $controller->get("logger")->err("getsessionUrl:" . $getsessionUrl); $sessionre = Utils::do_get_request_cookie($getsessionUrl, null, null, $cookie_key); $controller->get("logger")->err("session data:" . $sessionre); $sessionre = json_decode($sessionre, true); if ($sessionre["status"] != "success") { $resp = new Response("获取seesion失败"); $resp->headers->set('Content-Type', 'text/html'); return $resp; } $sessionre = json_decode($sessionre["data"], true); $sid = $sessionre["sessionID"]; //用户身份认证 $controller->get("logger")->err("================loginUrl:" . $loginUrl . "&sid=" . $sid . "&account=" . $bindinfo["bind_uid"] . "&password="******"authkey"]); $authResult = Utils::do_post_request_cookie($loginUrl . "&sid=" . $sid . "&account=" . $bindinfo["bind_uid"] . "&password="******"authkey"], null, null, $cookie_key); $retuenAry = array("session" => array("access_token" => $sid), "appid" => $appid, "openid" => $openid); $controller->get("logger")->err("pms login result:" . $authResult); //认证失败时要求重新绑定 $authResult = json_decode($authResult, true); if (!isset($authResult["status"]) || $authResult["status"] != "success") { return $controller->render("JustsyBaseBundle:AppCenter:h5bundle.html.twig", array('appid' => $appid, 'openid' => $openid, 'ssomodule' => "PmsController")); } $app->setappsession($retuenAry); //$re = Utils::do_post_request_cookie($wwwUrl."?m=my&f=index&t=json",null,null,$cookie_key); //$controller->get("logger")->err("my-todo result:".$re); } $result = array("returncode" => "0000", "data" => $authResult); return self::responseJson(json_encode($result)); }
public static function bindAction($controller, $con, $appid, $openid, $params) { $re = array("returncode" => "0000"); try { $bindinfo = $params->get("auth"); $bindinfo = explode(",", $bindinfo); $bind_uid = $bindinfo[0]; $authkey = count($bindinfo) == 1 ? "" : DES::encrypt($bindinfo[1]); $app = new \Justsy\BaseBundle\Management\App($controller->container); $appdata = $app->getappinfo(array("appid" => $appid)); //获取应用信息 //自动身份认证 $cookie_key = self::$bind_type . "_" . $openid; $loginUrl = $appdata["authorization_url"]; if (!empty($loginUrl)) { $authResult = Utils::do_get_request_cookie($loginUrl . "&" . http_build_query(array("uid" => $bind_uid, "upwd" => md5(DES::decrypt($authkey)))), null, null, $cookie_key); $authResult = json_decode($authResult, true); if (!isset($authResult["islogin"]) || $authResult["islogin"] != "1") { return $controller->render("JustsyBaseBundle:AppCenter:h5bundle.html.twig", array('appid' => $appid, 'openid' => $openid, 'errormsg' => '绑定的帐号或密码不正确', 'ssomodule' => self::$bind_type . "Controller")); } } $app->setappbind(array("appid" => $appid, "openid" => $openid, "bind_type" => self::$bind_type, "bind_uid" => $bind_uid, "authkey" => $authkey)); } catch (\Exception $e) { $response = new Response($e->getMessage()); $response->headers->set('Content-Type', 'text/html'); return $response; } return self::responseJson(json_encode($re)); }
public static function rest($controller, $user, $re, $parameters, $need_params) { $cookie_key = $authtype . "_" . $user->openid; $loginUrl = $appdata["authorization_url"]; if (empty($loginUrl)) { throw new \Exception("认证接口未配置!"); } $bindinfo = $app->getappbind(array("appid" => $parameters["appid"], "openid" => $user->openid)); if (empty($bindinfo)) { throw new \Exception("帐号未绑定K3!"); } //$container->get("logger")->err("k3 login url:".$loginUrl); //获取绑定的k3帐号和密码进行k3登录认证 $authResult = Utils::do_get_request_cookie($loginUrl, "provider=credentials&UserName="******"bind_uid"] . "&Password="******"authkey"] . "&PasswordIsEncrypted=false&RememberMe=false", null, $cookie_key); //$container->get("logger")->err("k3 login result:".$authResult); $authResult = json_decode($authResult, true); if (!isset($authResult["Result"])) { throw new \Exception("用户认证失败!"); } if (!$authResult["Result"]["ResponseStatus"]["IsSuccess"]) { throw new \Exception($authResult["Result"]["ResponseStatus"]["Message"]); } //$container->get("logger")->err("k3 api url:".$url); $http_data = Utils::do_post_request_cookie($url, $str_para, null, $cookie_key, $method); //$container->get("logger")->err("k3 api result:".$http_data); return $http_data; }