public static function rest($controller, $user, $re, $parameters, $need_params) { $appid = $parameters["appid"]; $openid = $user->openid; $cookie_key = self::$bind_type . "_" . $openid; $restUrl = $re["inf_url"]; $str_para = array(); $app = new \Justsy\BaseBundle\Management\App($controller); $bindinfo = $app->getappbind(array("appid" => $appid, "openid" => $openid)); if (!empty($parameters)) { //将参数数组转化为字符串 if (is_array($parameters) && !empty($need_params)) { $parameters["uid"] = $bindinfo["bind_uid"]; for ($i = 0; $i < count($need_params); $i++) { $pname = $need_params[$i]["paramname"]; $val = isset($parameters[$pname]) ? $parameters[$pname] : $need_params[$i]["paramvalue"]; $str_para[$pname] = $val; } } } if (strpos($restUrl, "?") === false) { $restUrl = $restUrl . "?" . http_build_query($str_para); } else { $restUrl = $restUrl . "&" . http_build_query($str_para); } $controller->get("logger")->err("===============restUrl:" . $restUrl); $re = Utils::do_post_request_cookie($restUrl, null, null, $cookie_key); //session过期时自动登录 /*$sessionActive = true; if(!$sessionActive) { $appinfo = $app->getappinfo(array("appid"=>$appid)); $loginUrl = $appdata["authorization_url"]; //登录 $authResult = Utils::do_get_request_cookie($loginUrl."&".http_build_query(array("uid"=>$bindinfo["bind_uid"],"upwd"=>md5(DES::decrypt($bindinfo["authkey"])))), null, null, $cookie_key); //重新提交 $re = Utils::do_post_request_cookie($restUrl."&".http_build_query($str_para),null,null,$cookie_key); }*/ return $re; }
public static function rest($controller, $user, $re, $parameters, $need_params) { $appid = $parameters["appid"]; $openid = $user->openid; $cookie_key = self::$bind_type . "_" . $openid; //获取绑定的sid $app = new \Justsy\BaseBundle\Management\App($controller); $sessioninfo = $app->getappsession(array("appid" => $appid, "openid" => $openid)); if (empty($sessioninfo)) { return array("status" => "fail", "msg" => "session已过期"); } $data = $sessioninfo["access_token"]; $appinfo = $app->getappinfo(array("appid" => $appid)); $restUrl = $re["inf_url"]; $str_para = array(); if (!empty($parameters)) { //将参数数组转化为字符串 if (is_array($parameters) && !empty($need_params)) { for ($i = 0; $i < count($need_params); $i++) { $pname = $need_params[$i]["paramname"]; $val = isset($parameters[$pname]) ? $parameters[$pname] : $need_params[$i]["paramvalue"]; $str_para[$pname] = $val; } } } $re = Utils::do_post_request_cookie($restUrl . "&" . http_build_query($str_para), null, null, $cookie_key); //对data进行2次转换 $tmpObj = json_decode($re, true); if (isset($tmpObj["data"])) { $txt = $tmpObj["data"]; $fChar = substr($txt, 0, 1); if ($fChar == "{" || $fChar == "[") { $tmpObj["data"] = json_decode($txt, true); $re = json_encode($tmpObj); } } return $re; }
public function push_receiverlistAction() { $da = $this->get("we_data_access"); $da_im = $this->get('we_data_access_im'); $request = $this->getRequest(); //访问权限校验 $api = new \Justsy\OpenAPIBundle\Controller\ApiController(); $api->setContainer($this->container); $isWeFaFaDomain = $api->checkWWWDomain(); if (!$isWeFaFaDomain) { $token = $api->checkAccessToken($request, $da); if (!$token) { $re = array("returncode" => "9999"); $re["code"] = "err0105"; $re["msg"] = "参数Appid或Openid或Access_token未指定或无效."; return $this->responseJson($request, $re); } } $openid = $request->get("openid"); $staffinfo = new \Justsy\BaseBundle\Management\Staff($da, $da_im, $openid, $this->get("logger"), $this->container); $staffdata = $staffinfo->getInfo(); if (empty($staffdata)) { $result = Utils::WrapResultError("无效操作帐号"); return $this->responseJson($request, $result); } $appid = $request->get('appid'); $appmgr = new \Justsy\BaseBundle\Management\App($this->container); $appdata = $appmgr->getappinfo(array('appid' => $appid)); if (empty($appdata)) { $result = Utils::WrapResultError("无效应用标识"); return $this->responseJson($request, $result); } $data = $request->get("data"); //部门名称 if (empty($data)) { $result = Utils::WrapResultError("无效的数据"); return $this->responseJson($request, $result); } $data = json_decode($data, true); $noticeMgr = new \Justsy\BaseBundle\Management\PromptlyNotice($this->container, $staffdata, $appdata); $result = $noticeMgr->getReceiverList($data); return $this->responseJson($request, $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 ? "" : $bindinfo[1]; $sql = "select appkey from we_appcenter_apps where appid=?"; $ds = $con->GetData("t", $sql, array((string) $appid)); if (count($ds["t"]["rows"]) == 0) { $re = array("returncode" => "9999", "msg" => "appid is not found"); } else { //$appkey = $ds["t"]["rows"][0]["appkey"]; $sql = "delete from we_staff_account_bind where bind_account=? and bind_type=? and appid=?"; $con->ExecSQL($sql, array((string) $openid, self::$bind_type, $appid)); //$authkey=$authcode;//DES::encrypt2($authcode,$appkey); //$bind_uid=$authkey; $sql = "insert into we_staff_account_bind(bind_account,appid,bind_uid,authkey,bind_type,bind_created)values(?,?,?,?,?,now())"; $con->ExecSQL($sql, array((string) $openid, (string) $appid, (string) $bind_uid, (string) $authkey, (string) self::$bind_type)); $app = new \Justsy\BaseBundle\Management\App($controller->container); $app->refreshappbind(array("appid" => $appid, "openid" => $openid)); } } catch (\Exception $e) { return array("returncode" => "9999", "msg" => $e->getMessage()); } return self::responseJson(json_encode($re)); }
public function appPublish($appid) { $result = array("s" => true); try { $user = $this->get('security.context')->getToken()->getUser(); $eno = $user->eno; $staff = $user->getUserName(); $da = $this->get("we_data_access"); $caption = ""; if ($appid == "PORTAL") { $caption = "portal_publish"; } else { $caption = "app_publish"; } if ($appid == "PORTAL") { $appid = $eno; $sql = "select * from we_apps_portalconfig where appid=?"; } else { $sql = "select * from we_appcenter_apps where appid=?"; } $dataset = $da->GetData("t", $sql, array((string) $appid)); //判断配置文件是否有编辑或者更改,没有变化时不用发布 $sql = "select publishversion from we_apps_publish where appid=? order by id+0 desc limit 0,1"; $versiondt = $da->GetData("t_v", $sql, array((string) $appid)); $version = count($dataset["t"]["rows"]) == 0 ? 0 : $dataset["t"]["rows"][0]["version"]; $publishversion_max = $versiondt["t_v"]["recordcount"] > 0 ? $versiondt["t_v"]["rows"][0]["publishversion"] : ""; if ($version == $publishversion_max) { $result = array("s" => false, "msg" => "当前版本无更新"); } else { //获取原配置文件生成用于发布的xml文件 //对门户android文件的处理 $doc = $this->get('doctrine.odm.mongodb.document_manager')->getRepository('JustsyMongoDocBundle:WeDocument')->find($dataset["t"]["rows"][0]["configfileid"]); if ($doc == null) { return array("s" => false, "msg" => "配置文件不存在"); } $xmldata = $doc->getFile()->getBytes(); $path = "/tmp/" . $appid . "_publish.xml"; $cont = fopen($path, 'w'); fwrite($cont, $xmldata); fclose($cont); $fileid = $this->saveFile($path); //对门户ios文件的处理 $ios_fileid = null; if ($appid == $eno) { $ios_fileid = $dataset["t"]["rows"][0]["ios_configfileid"]; if (!empty($ios_fileid)) { $doc = $this->get('doctrine.odm.mongodb.document_manager')->getRepository('JustsyMongoDocBundle:WeDocument')->find($ios_fileid); if (empty($doc)) { $ios_fileid = $fileid; } else { $xmldata = $doc->getFile(); if (empty($xmldata)) { $ios_fileid = $fileid; } else { $xmldata = $xmldata->getBytes(); $path = "/tmp/" . $appid . "ios_publish.xml"; $cont = fopen($path, 'w'); fwrite($cont, $xmldata); fclose($cont); $ios_fileid = $this->saveFile($path); } } } } $id = SysSeq::GetSeqNextValue($da, "we_apps_publish", "id"); $sqls = array(); $paras = array(); //更改发布状态 $sql = "update we_apps_publish set publishstate=0 where appid=?"; $parameter = array((string) $appid); array_push($sqls, $sql); array_push($paras, $parameter); //添加发布信息 $sql = "insert into we_apps_publish(id,appid,configfileid,ios_configfileid,publishdate,publishstaff,publishstate,publishversion)value(?,?,?,?,now(),?,1,?)"; $parameter = array((string) $id, (string) $appid, (string) $fileid, $ios_fileid, (string) $staff, (string) $version); array_push($sqls, $sql); array_push($paras, $parameter); //更改应用表最新发布日期及发布人员 $sql = "update we_appcenter_apps set publishdate=now(),publishstaff=? where appid=?"; $parameter = array((string) $user->nick_name, (string) $appid); array_push($sqls, $sql); array_push($paras, $parameter); $da->ExecSQLs($sqls, $paras); $cacheupdate = new \Justsy\BaseBundle\Management\App($this->container); $cacheupdate->refreshPortal(array("eno" => $eno)); //成功后返回的内容 $sql = "select date_format(date_add(publishdate,interval 8 hour),'%Y-%m-%d %H:%i') publishdate from we_apps_publish where appid=? order by id+0 desc limit 1"; $ds = $da->GetData("date", $sql, array((string) $appid)); $date = $ds["date"]["rows"][0]["publishdate"]; //发送出席 $sql = "select fafa_jid from we_staff where state_id!=3 and eno=?"; $ds = $da->GetData("jid", $sql, array((string) $eno)); $tojid = array(); $message = $version; if ($ds && $ds["jid"]["recordcount"] > 0) { for ($i = 0; $i < $ds["jid"]["recordcount"]; $i++) { array_push($tojid, $ds["jid"]["rows"][$i]["fafa_jid"]); if (count($tojid) > 200) { Utils::sendImPresence($this->container->getParameter('im_sender'), implode(",", $tojid), $caption, $message, $this->container, "", "", false, Utils::$systemmessage_code); $tojid = array(); } } } if (count($tojid) > 0) { Utils::sendImPresence($this->container->getParameter('im_sender'), implode(",", $tojid), $caption, $message, $this->container, "", "", false, Utils::$systemmessage_code); } //近回结果//近回结果 $result = array("s" => true, "date" => $date, "staff" => $user->nick_name, "version" => $version, "fileid" => $fileid); } } catch (\Exception $e) { $this->get('logger')->err($e); $result = array("s" => false, "msg" => $e->getMessage()); } return $result; }
public function register($paraObj) { $ename = $paraObj["ename"]; //企业名称不能为空 if (empty($ename)) { return Utils::WrapResultError("请输入企业名称"); } $currUser = $paraObj["user"]; if (empty($currUser)) { return Utils::WrapResultError("请登录后重试", ReturnCode::$NOTLOGIN); } if ($currUser->eno != Utils::$PUBLIC_ENO) { return Utils::WrapResultError("你已成功加入企业,不能创建企业"); } $da = $this->da; $en_row = $this->getInfoByName($ename); if (!empty($en_row)) { return Utils::WrapResultError('企业已存在'); } $da_im = $this->container->get('we_data_access_im'); $authtype = $paraObj["authtype"]; $website = $paraObj["website"]; $phone = $paraObj["phone"]; $address = $paraObj["address"]; $eno = SysSeq::GetSeqNextValue($da, "we_enterprise", "eno"); $auth_level = "S"; $eno_vip = '1'; $edomain = $eno; $login_account = $currUser->getUsername(); $sqls[] = "insert into we_enterprise (eno,edomain,ename,sys_manager,create_staff,state_id,eshortname,create_date,vip_level,eno_level,industry,addr,ewww,telephone,mstyle) values(?, ?, ?, ?, ?, ?, ?, now(), ?, ?, ?, ?, ?, ?,'outpriv')"; $paras[] = array((string) $eno, (string) $edomain, (string) $ename, (string) $login_account, (string) $login_account, (string) "1", (string) $ename, (string) $eno_vip, (string) $auth_level, "", (string) $address, (string) $website, (string) $phone); $sqls[] = "insert into we_enterprise_stored (id,enoname,eshortname,eno,auth) values(?, ?, ?, ?, ?)"; $paras[] = array((string) $eno, (string) $ename, (string) $ename, (string) $eno, (string) $authtype); $eshortname = $ename; $circleName = $eshortname; $circleId = SysSeq::GetSeqNextValue($da, "we_circle", "circle_id"); $sqls[] = "insert into we_circle (circle_id,circle_name,create_staff,manager,join_method,enterprise_no,network_domain,create_date,fafa_groupid) values (?,?,?,?,?,?,?,now(),?)"; $paras[] = array((string) $circleId, (string) $circleName, (string) $login_account, (string) $login_account, (string) 1, (string) $eno, (string) $edomain, ""); if (true) { //写入企业 $im_dept_sqls = array(); $im_dept_paras = array(); $subdomain = "fafacn.com"; //$da_im->ExecSQL($sql, $para); //写入IM库部门表 $depts = array(); $pdeptid = "v" . $eno; $sql = "insert into im_base_dept (deptid, deptname, pid, path, noorder) values (?, ?, ?, ?, ?)"; $pid = "-10000"; $pubDeptPath = "/-10000/" . $pdeptid . "/"; $para = array((string) $pdeptid, (string) $ename, (string) $pid, (string) $pubDeptPath, (string) $eno); $im_dept_sqls[] = $sql; $im_dept_paras[] = $para; $depts[] = "{$pdeptid},{$ename}"; //创建默认部门:公共帐号 $pid = $pdeptid; $pubDeptID = $pdeptid . "999"; //公共部门编号 $pubDeptPath = $pubDeptPath . $pubDeptID . "/"; //公共部门路径 $para = array((string) $pubDeptID, (string) "公共帐号", (string) $pid, (string) $pubDeptPath, (double) 1); $im_dept_sqls[] = $sql; $im_dept_paras[] = $para; $depts[] = $pubDeptID . ",公共帐号"; //创建默认部门:公众号。公共部门子部门 $pid = $pubDeptID; $pubDeptID = $pubDeptID . "888"; //公共部门子部门“公众号”部门编号 $pubDeptPath = $pubDeptPath . $pubDeptID . "/"; $para = array((string) $pubDeptID, (string) "公众号", (string) $pid, (string) $pubDeptPath, (double) 1); $im_dept_sqls[] = $sql; $im_dept_paras[] = $para; $depts[] = $pubDeptID . ",公众号"; //创建默认部门 $dnames = explode(",", "体验部门,行政部,销售部,财务部,客服服务部,总经办,技术部"); $sn = 2; foreach ($dnames as $key => $value) { if (empty($value)) { continue; } $deptid = SysSeq::GetSeqNextValue($da_im, "im_base_dept", "deptid"); $para = array((string) $deptid, (string) $value, (string) $pdeptid, (string) "/-10000/" . $pdeptid . "/" . $deptid . "/", $value == "体验部门" ? (int) $pdeptid : (int) $sn); $im_dept_sqls[] = $sql; $im_dept_paras[] = $para; //$da_im->ExecSQL($sql, $para); $depts[] = "{$deptid},{$value}"; $sn++; } //写入虚拟人员 $users = array("service,客服", "admin,管理员", "guest,匿名访客", "front,前台", "sale,销售"); foreach ($users as $key => $value) { if (empty($value)) { continue; } $ary = explode(",", $value); $pwd = strcmp($ary[0], "guest") == 0 ? "ljy20080511" : ""; $im_dept_sqls[] = "insert into im_employee (employeeid, deptid, loginname, password, employeename) values (?, ?, ?, ?, ?)"; $im_dept_paras[] = array((string) $pdeptid . "-" . $ary[0], (string) $pdeptid . "999", (string) $ary[0] . "-" . $eno . "@" . $subdomain, (string) $pwd, (string) $ary[1]); $im_dept_sqls[] = "insert into users (username, password, created_at) values (?, ?, now())"; $im_dept_paras[] = array((string) $ary[0] . "-" . $eno . "@" . $subdomain, (string) $pwd); } $im_dept_sqls[] = "insert into im_dept_stat(deptid,empcount)values(?,6)"; $im_dept_paras[] = array((string) $pdeptid); $da_im->ExecSQLs($im_dept_sqls, $im_dept_paras); //we_sns写入部门表 foreach ($depts as $key => $value) { if (empty($value)) { continue; } $ary = explode(",", $value); $deptid = SysSeq::GetSeqNextValue($da, "we_department", "dept_id"); $sqls[] = "insert into we_department (eno,dept_id,dept_name,parent_dept_id,fafa_deptid,create_staff) values (?,?,?,?,?,?)"; $paras[] = array((string) $eno, (string) $deptid, (string) $ary[1], (string) $deptid, (string) $ary[0], (string) $login_account); } try { $StaticTrendMgr = new \Justsy\BaseBundle\Management\StaticTrendMgr($da, $da_im); $StaticTrendMgr->RegisterPublish($ename, $circleId, $circleName, $login_account, $currUser->nick_name); } catch (\Exception $e) { $this->get("logger")->err($e); } } $da->ExecSQLs($sqls, $paras); //向RBAC跟新用户身份 //$staffRole=new StaffRole($da,$da_im,$this->logger); //$staffRole->InsertStaffRoleByCode($login_account,$auth_level.$eno_vip,$eno); //为新企业创建默认的外部公众号 try { //解密 $pwd = $currUser->t_code; $micro_name = $ename; $public_number = "_wexin_" . $eno . "@fafatime.com"; $micro_type = '1'; $micro_use = '0'; // $concern = '0'; $create_account = $login_account; //企业默认公众号 $micro = new MicroAccountMgr($da, $da_im, $currUser, $this->logger, $this->container); $micro->insertMicroAccount($micro_name, $public_number, $pwd, $micro_type, $micro_use, $concern, '', '', '', '', '', $this->container->get('security.encoder_factory')); //创建默认微应用 $appid = Utils::getAppid($eno, $login_account); $appkey = Utils::getAppkey(); $micro_number = "_push_" . $eno . "@fafatime.com"; $micro->register(null, $micro_number, "企业推送服务", $micro_type, "1", "", $concern, "", "", $pwd, "", "", "", $this->container->get('security.encoder_factory'), $this->container->get('doctrine.odm.mongodb.document_manager'), $appid); $updateSQL[] = "update we_staff set dept_id=(SELECT dept_id FROM we_department where eno=? and fafa_deptid=?),eno=? where login_account in(?,?)"; $updatePara[] = array((string) $eno, "v" . $eno . "999", (string) $eno, (string) $micro_number, (string) $public_number); $updateSQL[] = "update we_micro_account set eno=? where number in(?,?)"; $updatePara[] = array((string) $eno, (string) $micro_number, (string) $public_number); $updateSQL[] = "insert into we_appcenter_apps(appid,appkey,appname,state,appdeveloper,appdesc,apptype) values(?,?,?,?,?,?,?);"; $updatePara[] = array($appid, $appkey, "企业推送服务", 0, $eno, "企业推送服务", '00'); $da->ExecSQLs($updateSQL, $updatePara); } catch (\Exception $e) { $this->logger->err("创建默认公众号发生异常:" . $e); } //自动选择企业门户 $App = new \Justsy\BaseBundle\Management\App($this->container); $App->portal_template(array("eno" => $eno, "login_account" => $login_account)); //通知创建者其他设备 Utils::sendImMessage("", $currUser->fafa_jid, "enterprise_create", $ename, $this->container, "", "", false, '', '0'); $jid = SysSeq::GetSeqNextValue($da, "we_staff", "fafa_jid"); $jid .= "-" . $eno . "@fafacn.com"; $staffObj = new \Justsy\BaseBundle\Management\Staff($da, $da_im, $login_account, $this->logger, $this->container); $tr = $staffObj->swtichEno($eno, $circleId); //更换企业号 if ($tr) { $staffObj->updateJid($currUser->fafa_jid, $jid); } //更新im库中的jid $data = $staffObj->getInfo(true); //更新人员缓存信息 $data = $this->getInfo($eno); //缓存企业信息 return Utils::WrapResultOK($data); }
public function getByDsid($user, $re, $parameters, $container) { if (isset($re["inf_url"]) && !empty($re["inf_url"])) { $url = $re["inf_url"]; $is_auth = $re["is_auth"]; //接口是否需要认证,1:需要认证 0:不认证 $str_para = ""; if (empty($parameters) || $parameters == "{}") { $parameters = $re["inf_parameter"]; } $need_para = $re["inf_parameter"]; if (!empty($need_para) && is_string($need_para)) { $need_para = json_decode($need_para, true); } $app = new \Justsy\BaseBundle\Management\App($container); //parameters为json数据格式 if (empty($parameters)) { throw new \Exception("参数appid不能为空!"); } $parameters = is_array($parameters) ? $parameters : json_decode($parameters, true); $appdata = $app->getappinfo(array("appid" => $parameters["appid"])); $authtype = isset($appdata["authtype"]) ? $appdata["authtype"] : ""; if (!empty($authtype) && $is_auth == "1") { $classname = dirname(dirname(dirname(dirname(__FILE__)))) . "/OpenAPIBundle/Controller/Sso" . ucfirst($authtype) . "Controller.php"; //$container->get("logger")->err("===========file_exists ".$classname); if (file_exists($classname)) { $classname = "\\Justsy\\OpenAPIBundle\\Controller\\Sso" . ucfirst($authtype) . "Controller"; //$container->get("logger")->err("===========load ".$classname); $re = call_user_func(array($classname, 'rest'), $container, $user, $re, $parameters, $need_para); //$container->get("logger")->err("===========load ".$classname." result:".json_encode($re)); return $re; } } if (!empty($parameters)) { //将参数数组转化为字符串 if (is_array($parameters) && !empty($need_para)) { for ($i = 0; $i < count($need_para); $i++) { $pname = $need_para[$i]["paramname"]; $val = isset($parameters[$pname]) ? $parameters[$pname] : $need_para[$i]["paramvalue"]; $str_para .= $pname . "=" . $val . "&"; } $str_para = rtrim($str_para, "&"); } } $method = $re["req_action"]; $method = $method != "GET" ? "POST" : "GET"; $container->get("logger")->err("authtype:" . $authtype); $optional_headers = null; if ($authtype == "header") { $userpara = $appdata["userdefined_para"]; if (!empty($userpara)) { $optional_headers = json_decode($userpara, true); } } else { if ($authtype == "basic") { $userpara = $appdata["userdefined_para"]; if (!empty($userpara)) { $userpara = json_decode($userpara, true); $user = $userpara["user"]; $pass = $userpara["pass"]; $optional_headers = array("Authorization" => "Basic " . base64_encode("{$user}:{$pass}")); } } } if ($method == "GET") { if (strpos($url, "?") === false) { $url = $url . "?" . $str_para; } else { $url = $url . "&" . $str_para; } $container->get("logger")->err($url); return Rest::getByURL($url); } else { $method = "POST"; if (strpos($url, "?") === false) { $url = $url . "?" . $str_para; } else { $url = $url . "&" . $str_para; } $str_para = ""; } $container->get("logger")->err($url); //,CURLOPT_COOKIE $http_data = Utils::do_post_request_cookie($url, null, $optional_headers, $_COOKIE, $method); /* $params = array('http' => array('timeout'=>3,'method' => $method,'content' => $str_para)); $ctx = stream_context_create($params); $fp = @fopen($url, 'r', false, $ctx); if (!$fp) { throw new \Exception("接口地址出错,请检查您的接口地址(".$url.")"); } //获取数据 $http_data = @stream_get_contents($fp); if ($http_data === false) { throw new \Exception("访问的接口地址(".$url.")服务器出错!"); }*/ return $http_data; } else { throw new \Exception("接口地址为空,请检查!"); } }
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 function bindAction($openid, $appid) { $da = $this->get("we_data_access"); $request = $this->get("request"); //$authcode = $request->get("auth"); /* $bind_type= $request->get("bind_type"); $modules=SsoModules::$modules; $isbindtype=false; $classname=''; for($i=0;$i<count($modules);$i++){ if($modules[$i]['bind_type']==$bind_type){ $isbindtype=true; $classname=$modules[$i]['module_code']; } } if(!$isbindtype){ return $this->responseJson(array("returncode"=>"9999","msg"=>'bind_type无效'),$request->get('jsoncallback')); }*/ $app = new \Justsy\BaseBundle\Management\App($this->container); $appinfo = $app->getappinfo(array("appid" => $appid)); if (empty($appinfo)) { $resp = new Response("invalid appid"); $resp->headers->set('Content-Type', 'text/html'); return $resp; } $classname = ucfirst($appinfo["authtype"]) . "Controller"; $encrypt = $request->get("encrypt"); if (empty($classname) || $classname == "null") { //$classname = "SsoWefafaController"; //$resp = new Response($request->get('jsoncallback') ? $request->get('jsoncallback')."(".json_encode($row).");" : json_encode($row)); $resp = new Response("invalid ssomodule"); $resp->headers->set('Content-Type', 'text/html'); return $resp; } $classname = "\\Justsy\\OpenAPIBundle\\Controller\\Sso" . $classname; try { return call_user_func(array($classname, 'bindAction'), $this, $this->get("we_data_access"), $appid, $openid, $request); //$resp = new Response($request->get('jsoncallback') ? $request->get('jsoncallback')."(".json_encode($re).");" : json_encode($re)); //$resp->headers->set('Content-Type', 'text/json'); //return $resp; } catch (\Exception $e) { $resp = new Response("invalid ssomodule"); $resp->headers->set('Content-Type', 'text/html'); return $resp; } //$bx_data=$request->get("data") }
public function tencentexmailloginAction() { $request = $this->getRequest(); $param = $request->get("params"); if (empty($param)) { $param = array(); } else { if (is_string($param)) { $param = json_decode($param, true); } } if (!isset($param["appid"])) { $param["appid"] = $request->get("appid"); } $openid = $request->get("openid"); $staffObj = new \Justsy\BaseBundle\Management\Staff($this->get('we_data_access'), $this->get('we_data_access_im'), $openid, $this->get("logger")); $user = $staffObj->getSessionUser(); $appid = $param["appid"]; //$openid = $user->openid; //$ldap_uid = $user->ldap_uid; //判断是否绑定 $app = new \Justsy\BaseBundle\Management\App($this->container); $appdata = $app->getappinfo(array("appid" => $appid)); if (empty($appdata)) { $resp = new Response("无效的APPID"); $resp->headers->set('Content-Type', 'text/html'); return $resp; } $agent = $appdata["clientid"]; //判断是否绑定 $bindinfo = $app->getappbind(array("appid" => $appid, "openid" => $openid)); if (empty($bindinfo)) { //$controller->get("logger")->err("================not bind"); //重定向到绑定页面 return $this->render("JustsyBaseBundle:AppCenter:h5bundle.html.twig", array('appid' => $appid, 'openid' => $openid, 'ssomodule' => "OAuth2")); } $ldap_uid = $bindinfo["bind_uid"]; $cacheKey = md5($appid . $openid); $data = Cache_Enterprise::get(Cache_Enterprise::$EN_OAUTH2, $cacheKey, $this->container); if (empty($data)) { $this->get("logger")->err("{$appid}.{$openid}"); $resp = new Response("太长时间未操作,请重新进入应用"); $resp->headers->set('Content-Type', 'text/html'); return $resp; } $data = json_decode($data, true); $acctoken = $data["access_token"]; //$this->get("logger")->err($acctoken); //获取authkey $url = "http://openapi.exmail.qq.com:12211/openapi/mail/authkey"; $authkey = Utils::do_post_request($url, "alias=" . $ldap_uid . "&access_token=" . $acctoken); //$this->get("logger")->err($url."?"."alias=".$ldap_uid."&access_token=".$acctoken); //$this->get("logger")->err($authkey); if (empty($authkey)) { $resp = new Response("腾讯企业邮箱登录失败"); $resp->headers->set('Content-Type', 'text/html'); return $resp; } $authkey = json_decode($authkey, true); if (!isset($authkey["auth_key"])) { if ($authkey["error"] == "invalid_token") { Cache_Enterprise::delete(Cache_Enterprise::$EN_OAUTH2, $cacheKey, $this->container); $resp = new Response("腾讯企业邮箱登录失败:<br>token无效或已经过期,请稍后重试!"); } else { $resp = new Response("腾讯企业邮箱登录失败:<br>" . json_encode($authkey)); } $resp->headers->set('Content-Type', 'text/html'); return $resp; } $authkey = $authkey["auth_key"]; $login_url = "https://exmail.qq.com/cgi-bin/login?fun=bizopenssologin&method=bizauth&agent=" . $agent . "&user="******"&ticket=" . $authkey; //$this->get("logger")->err($login_url); return Utils::http_redirect($login_url); }