adminSso(); $array = [ "partnerId"=>$request->get("partnerId"), "expires"=>$request->get("expires"), "nonce"=>$request->get("nonce"), "data"=>urlencode($request->get("data")), ]; ksort($array); $str =""; foreach ($array as $key=>$value){ $str = $str . $key . '=' . $value . '&'; } $str = substr($str, 0,strlen($str)-1); $signature = hash_hmac('SHA256',$str, env("B_API_SECRET_KEY")); Log::info(json_encode($array)); Log::info("signature:".$signature); try{ if($signature==$request->get("signature")){ $data = json_decode(base64_decode($request->get("data")),true); $adminUserId = $data["admin_user_id"]; $aghCorpId = $data["corp_id"]; $name = $data["admin_name"]; $adminUser = Admin::where("admin_user_id",$adminUserId)->first(); if(empty($adminUser)){ $corp = Corps::where("source_id",$aghCorpId)->where("source_type","agh")->first(); if($corp){ $res = Admin::insert([ "username" => "agh_".$adminUserId, "name" => $name, "corp_id" => $corp->corp_id, "is_admin" => 0, "admin_user_id" => $adminUserId, "status" => 1, "create_time" => time(), "update_time" => time(), ]); if($res){ $adminUser = Admin::where("admin_user_id",$adminUserId)->first(); } }else{ $ret = AghApiService::getInstance()->getCorpInfo($aghCorpId); if($ret["errno"]==0){ $corpSource = $ret["body"]; $query = []; $query['source_id'] = $corpSource['enterpriseId']; $query['source_type'] = 'agh'; $query['corp_name'] = $corpSource['fullName']; $query['corp_short_name'] = $corpSource['abbName']; $query['contact_name'] = $corpSource['contact']; $query['contact_phone'] = $corpSource['cellPhone']; $query['contact_email'] = $corpSource['email']; $query['contact_address'] = $corpSource['address']; $query['status'] = $corpSource['state'] == true ? 1 : 0; $query['update_time'] = time(); $query["create_time"] = time(); Corps::insert($query); $corp = Corps::where("source_id",$aghCorpId)->where("source_type","agh")->first(); if($corp){ $res = Admin::insert([ "username" => "agh_".$adminUserId, "name" => $name, "corp_id" => $corp->corp_id, "is_admin" => 0, "admin_user_id" => $adminUserId, "status" => 1, "create_time" => time(), "update_time" => time(), ]); if($res){ $adminUser = Admin::where("admin_user_id",$adminUserId)->first(); } } } } } if($adminUser){ $corp = Corps::where("corp_id", $adminUser["corp_id"])->first(); DB::table("agh_admin_log")->insert([ "admin_id" =>$adminUser["id"], "name" =>$adminUser["name"], "corp_id" =>$corp["corp_id"], "agh_corp_id" =>$corp["source_id"], "corp_name" =>$corp["corp_name"], "first_time" =>$adminUser["create_time"], "create_time" => time() ]); $request->session()->put('userInfo', $adminUser); $redirect = $request->get("redirect"); if(empty($redirect)){ return redirect("/manage"); }else{ header("location:".$redirect); } } return "认证成功,但找不到该企业信息"; } }catch (\Exception $exception){ Log::info($exception->getTraceAsString()); } return "认证不通过"; } }