public function WeiXinLoginAction()
 {
     $deploy_mode = $this->container->getParameter('deploy_mode');
     $da = $this->get("we_data_access");
     $request = $this->getRequest();
     $openid = $request->get("openid");
     $unionid = $request->get("unionid");
     $logintype = $request->get("logintype");
     $logintype = empty($logintype) ? "02" : $logintype;
     $ldap_uid = null;
     $login_account = $unionid . "@fafatime.com";
     $staffMgr = new \Justsy\BaseBundle\Management\Staff($da, $this->get('we_data_access_im'), $login_account, $this->get("logger"), $this->container);
     $staffdata = $staffMgr->getInfo();
     $re = array("returncode" => ReturnCode::$SYSERROR, "msg" => "");
     $password = "";
     //账号为空表示不存在
     if (empty($staffdata)) {
         $eno = $deploy_mode == "C" ? Utils::$PUBLIC_ENO : "";
         if (empty($eno)) {
             $cacheobj = new \Justsy\BaseBundle\Management\Enterprise($da, $this->get("logger"), $this->container);
             //获取用户认证模块
             $authConfig = $cacheobj->getUserAuth();
             if (!empty($authConfig)) {
                 $eno = $authConfig["ENO"];
             }
             if (empty($eno)) {
                 $re["returncode"] = ReturnCode::$SYSERROR;
                 $re["msg"] = "企业号不能为空。";
                 return $re;
             }
         }
         $ldap_uid = $unionid;
         $password = rand(1000000, 999999);
         $parameter = array("appid" => $request->get("appid"), "eno" => $eno, "openid" => $openid, "nick_name" => $request->get("nickname"), "sex" => $request->get("sex"), "province" => $request->get("province"), "city" => $request->get("city"), "headimgurl" => $request->get("headimgurl"), "unionid" => $unionid, "account" => "", "password" => $password, "ldap_uid" => $ldap_uid, "type" => "weixin");
         $staffdata = $staffMgr->createstaff($parameter);
         //注册用户账号
         if ($staffdata["returncode"] == ReturnCode::$SUCCESS) {
             $re = $this->autologin($login_account, $password, $logintype);
         } else {
             $re = $staffdata;
         }
     } else {
         $password = DES::decrypt($staffdata["t_code"]);
         $re = $this->autologin($login_account, $password, $logintype);
     }
     //$staffdata["des"] = DES::decrypt($staffdata["t_code"]);
     $response = new Response(json_encode($re));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
Exemple #2
0
 public function createstaff($parameter)
 {
     $deploy_mode = $this->container->getParameter('deploy_mode');
     $mobile_num = $parameter['account'];
     $mobile_pwd = $parameter['password'];
     $org_pwd = $mobile_pwd;
     //原始密码
     $deptid = isset($parameter['deptid']) ? $parameter['deptid'] : "";
     $eno = isset($parameter['eno']) ? $parameter['eno'] : $this->container->getParameter('ENO');
     $nick_name = $parameter['nick_name'];
     $ldap_uid = isset($parameter["ldap_uid"]) ? $parameter["ldap_uid"] : "";
     //优先采用第三方标识做为帐号,其次使用手机号做为帐号
     $login_account = empty($ldap_uid) ? $mobile_num : $ldap_uid;
     if (empty($login_account)) {
         return Utils::WrapResultError("请输入帐号!");
     }
     if (empty($mobile_pwd)) {
         return Utils::WrapResultError("请输入密码!");
     }
     if (empty($nick_name)) {
         return Utils::WrapResultError("请输入昵称!");
     }
     if (!strpos($login_account, "@")) {
         $domain = $this->container->getParameter('edomain');
         $login_account .= "@" . $domain;
     }
     $this->account = $login_account;
     $isHd = $this->getInfo();
     if (!empty($isHd)) {
         //已经注册,直接返回
         return Utils::WrapResultOK($isHd);
     }
     if (!empty($mobile_num) && Utils::validateMobile($mobile_num)) {
         if ($this->checkUser($mobile_num)) {
             return Utils::WrapResultError("该手机号已被绑定,请解绑后重试");
         }
     }
     $da = $this->conn;
     $da_im = $this->conn_im;
     try {
         //同步人员到业务系统
         $syncurl = null;
         try {
             //判断是否需要同步到其他系统
             $syspara = new \Justsy\BaseBundle\DataAccess\SysParam($this->container);
             $syncurl = $syspara->GetSysParam('staff_sync_url', '');
         } catch (\Exception $e) {
         }
         $cacheobj = new \Justsy\BaseBundle\Management\Enterprise($da, $this->logger, $this->container);
         //获取用户认证模块
         $authConfig = $cacheobj->getUserAuth();
         if (!empty($syncurl) && !empty($authConfig)) {
             try {
                 $classname = $authConfig["ssoauthmodule"];
                 if (!empty($classname)) {
                     $parameters = array("nick_name" => $nick_name, "mobile" => $login_account, "password" => $mobile_pwd);
                     $classname = "\\Justsy\\InterfaceBundle\\SsoAuth\\Sso" . $classname;
                     $re = call_user_func(array($classname, 'createUser'), $this->container, $parameters);
                     $ldap_uid = $re["ldap_uid"];
                     //该 属性必须由对应用户认证模块的方法createUser返回
                 }
             } catch (\Exception $e) {
                 $this->get("logger")->err($e);
                 return Utils::WrapResultError($e->getMessage());
             }
         }
         if (!empty($authConfig) && empty($eno)) {
             $eno = $authConfig["ENO"];
         }
         //验证企业号
         if (!empty($eno)) {
             $enterinfo = $cacheobj->getInfo($eno);
             if ($enterinfo == null) {
                 return Utils::WrapResultError("未找到您注册的企业!");
             }
             $edomain = $enterinfo['edomain'];
         }
         if (empty($deptid)) {
             $deptinfo = new \Justsy\BaseBundle\Management\Dept($da, $da_im);
             $deptid = $deptinfo->getDefaultDept($eno);
             $fafa_deptid = $deptid["deptid"];
             $deptid = $deptid["deptid"];
         } else {
             $deptinfo = new \Justsy\BaseBundle\Management\Dept($da, $da_im);
             $deptid = $deptinfo->getinfo($deptid);
             $fafa_deptid = $deptid["deptid"];
             $deptid = $deptid["deptid"];
         }
         $auth_level = "S";
         $eno_vip = $enterinfo['vip_level'];
         $eno_level = $enterinfo['eno_level'];
         $edomain = $enterinfo['edomain'];
         $circleId = $enterinfo['circle_id'];
         //注册jid
         $jid = SysSeq::GetSeqNextValue($da, "we_staff", "fafa_jid");
         $jid .= "-" . $eno . "@" . $edomain;
         //生成密码
         $user = new UserSession($login_account, $mobile_pwd, $login_account, array("ROLE_USER"));
         $factory = $this->container->get("security.encoder_factory");
         $encoder = $factory->getEncoder($user);
         $pwd = $encoder->encodePassword($mobile_pwd, $user->getSalt());
         $mobile_pwd = DES::encrypt($mobile_pwd);
         $istester = "";
         //是否是通过万能验证码激活的测试人员
         //插入人员、圈子信息
         $sqls[] = "insert into we_staff (dept_id,login_account,eno,password,nick_name,photo_path,state_id,fafa_jid,photo_path_small,photo_path_big,openid,register_date,active_date,t_code,auth_level,mobile,mobile_bind,ldap_uid,login_source) values (?,?,?,?,?,?,?,?,?,?,?,(select register_date from we_register where login_account=?),now(),?,?,?,?,?,?)";
         $sqls[] = "insert into we_circle_staff (circle_id,login_account,nick_name) values (?,?,?)";
         $sqls[] = "update we_register set state_id='3' where login_account=?";
         $paras[] = array((string) $deptid, (string) $login_account, (string) $eno, (string) $pwd, (string) $nick_name, (string) '', (string) "1", (string) $jid, (string) '', (string) '', (string) md5($eno . $login_account), (string) $login_account, (string) $mobile_pwd, (string) $auth_level, empty($mobile_num) ? null : (string) $mobile_num, empty($mobile_num) ? null : (string) $mobile_num, (string) $ldap_uid, $istester);
         $paras[] = array((string) $circleId, (string) $login_account, (string) $nick_name);
         $paras[] = array((string) $login_account);
         $da->ExecSQLs($sqls, $paras);
         //向RBAC跟新用户身份
         //$staffRole=new \Justsy\BaseBundle\Rbac\StaffRole($da,$da_im,$this->logger);
         //$staffRole->InsertStaffRoleByCode($login_account,$auth_level.$eno_vip,$eno);
     } catch (\Exception $e) {
         $this->logger->err($e);
         return Utils::WrapResultError($e->getMessage());
     }
     //写we_im库
     $sqls = array();
     $paras = array();
     try {
         //写入人员 如果$jid_old为空执行原有逻辑,否则更新旧jid数据
         if (empty($jid_old)) {
             $sqls = array();
             $paras = array();
             $pinyin = Utils::Pinyin($nick_name);
             $employeeid = SysSeq::GetSeqNextValue($da_im, "im_employee", "employeeid");
             $sqls[] = "insert into im_employee (employeeid, deptid, loginname, password, employeename,spell) values (?, ?, ?, ?, ?,?)";
             $paras[] = array((string) $employeeid, (string) $fafa_deptid, (string) $jid, (string) $mobile_pwd, (string) $nick_name, (string) $pinyin);
             $sqls[] = "insert into users (username, password, created_at) values (?, ?, now())";
             $paras[] = array((string) $jid, (string) $mobile_pwd);
             $sqls[] = "insert into im_b_msg_read (employeeid, lastid, readdatetime) values (?, (select max(id) from im_b_msg), now())";
             $paras[] = array((string) $jid);
             $da_im->ExecSQLs($sqls, $paras);
             try {
                 $da_im->ExecSQL("call dept_emp_stat(?)", array((string) $jid));
             } catch (\Exception $e) {
             }
             $this->syncAttrsToIM();
             $jid_old = $jid;
         }
     } catch (\Exception $e) {
         $this->logger->err($e);
         return Utils::WrapResultError($e->getMessage());
     }
     //关注自己所属企业的开放的内部公众号
     $mac = new \Justsy\BaseBundle\Management\MicroAccountMgr($da, $da_im, $login_account, $this->logger, $this->container);
     $mac->attenCompanyOpenAccount();
     //自动关注当前企业的开放公众号
     $re = $this->getInfo();
     return Utils::WrapResultOK($re);
 }