Esempio n. 1
0
 public function ThirdpartyRegisterAction()
 {
     $da = $this->get('we_data_access');
     $request = $this->getRequest();
     $login_account = trim($request->get("login_account"));
     //传入的注册账号
     $account_type = $request->get("account_type");
     $appid = $request->get("appid");
     $eno = $request->get("eno");
     $code = $request->get("code");
     $staffinfo = $request->get("staffinfo");
     //数据完整性判断
     if (empty($appid)) {
         return array("returncode" => "9999", "msg" => "应用ID不能为空。");
     }
     if (empty($code)) {
         return array("returncode" => "9999", "msg" => "动态授权码不能为空。");
     }
     if (empty($eno)) {
         return array("returncode" => "9999", "msg" => "企业编号不能为空。");
     }
     if (empty($staffinfo)) {
         return array("returncode" => "9999", "msg" => "注册人员不能为空。");
     }
     if ($account_type != "createfulluser") {
         $sql = "select appkey from we_appcenter_apps where appid=?";
         $ds = $da->GetData("table", $sql, array((string) $appid));
         if ($ds && $ds["table"]["recordcount"] == 0 || empty($ds["table"]["rows"][0]["appkey"])) {
             $result = array("success" => false, "msg" => "应用ID不正确。");
             $response = new Response(json_encode($result));
             $response->headers->set('Content-Type', 'text/json');
             return $response;
         }
         $appkey = $ds["table"]["rows"][0]["appkey"];
         if (strtolower($code) != strtolower(MD5($appid . $appkey))) {
             $result = array("returncode" => "9999", "msg" => "动态授权码不正确。");
             $response = new Response(json_encode($result));
             $response->headers->set('Content-Type', 'text/json');
             return $response;
         }
     }
     $thirdRegister = new \Justsy\OpenAPIBundle\Controller\ApiController();
     $thirdRegister->setContainer($this->container);
     //返回结果
     $result = array("returncode" => "0000", "msg" => "");
     $nick_name = "";
     $stafflist = json_decode($staffinfo, true);
     $openid = null;
     if ($account_type == "email") {
         //邮箱格式
         $parameter = array("email" => $login_account, "reg_name" => $stafflist[0]["nick_name"], "password" => $stafflist[0]["password"], "uid" => $stafflist[0]["uid"]);
         $para = array($parameter);
         $result = $thirdRegister->mail_registerStaff($appid, $code, $eno, json_encode($para));
     } else {
         if ($account_type == "mobile") {
             $parameter = array("mobile" => $login_account, "reg_name" => $stafflist[0]["nick_name"], "password" => $stafflist[0]["password"], "uid" => $stafflist[0]["uid"]);
             $para = array($parameter);
             $result = $thirdRegister->registerStaff($appid, $code, $eno, json_encode($para), 1);
         } else {
             if ($account_type == "createfulluser") {
                 $active = new \Justsy\BaseBundle\Controller\ActiveController();
                 $active->setContainer($this->container);
                 $result = $active->doSave($stafflist);
                 if ($result === true) {
                     $result = array("returncode" => "0000", "msg" => "");
                 } else {
                     $result = array("returncode" => "9999", "msg" => "");
                 }
             } else {
                 if ($account_type == "qq") {
                     if (isset($stafflist[0]["openid"])) {
                         $openid = $stafflist[0]["openid"];
                     }
                     if (!empty($openid)) {
                         $login_account = $this->getAccountByOpenid($openid, "tencent");
                         if (empty($login_account)) {
                             $login_account = $this->delimit_login_account("tencent_");
                             $nick_name = isset($stafflist[0]["nick_name"]) ? $stafflist[0]["nick_name"] : "";
                             if (empty($nick_name)) {
                                 $nick_name = "QQ_" . rand(100000, 999999);
                             }
                             $img_url = isset($stafflist[0]["headimgurl"]) ? $stafflist[0]["headimgurl"] : null;
                             $parameter = array("appid" => $appid, "login_account" => $login_account, "province" => "", "city" => "", "nick_name" => $nick_name, "eno" => $eno, "ldap_uid" => $stafflist[0]["uid"], "openid" => $openid, "sex" => "", "headimgurl" => $img_url, "type" => "tencent");
                             $result = $this->Register($parameter);
                             $this->get("logger")->err($login_account);
                         } else {
                             $result = array("returncode" => "99999", "msg" => "已存在该用户账号!");
                         }
                     } else {
                         $result = array("returncode" => "9999", "msg" => "请传入openid参数值");
                     }
                 } else {
                     if ($account_type == "micro") {
                         if (isset($stafflist[0]["openid"])) {
                             $openid = $stafflist[0]["openid"];
                         }
                         if (!empty($openid)) {
                             $login_account = $this->getAccountByOpenid($openid, "weixin");
                             if (empty($login_account)) {
                                 $login_account = $this->delimit_login_account("weixin_");
                                 $nick_name = isset($stafflist[0]["nick_name"]) ? $stafflist[0]["nick_name"] : null;
                                 if (empty($nick_name)) {
                                     $nick_name = "WX_" . rand(100000, 999999);
                                 }
                                 $img_url = isset($stafflist[0]["headimgurl"]) ? $stafflist[0]["headimgurl"] : null;
                                 $ldap_uid = isset($stafflist[0]["unionid"]) ? $stafflist[0]["unionid"] : null;
                                 $unionid = isset($stafflist[0]["unionid"]) ? $stafflist[0]["unionid"] : null;
                                 $parameter = array("appid" => $appid, "eno" => $eno, "openid" => $openid, "login_account" => $login_account, "nick_name" => $nick_name, "headimgurl" => $img_url, "unionid" => $unionid, "ldap_uid" => $ldap_uid, "sex" => null, "province" => null, "city" => null, "type" => "weixin");
                                 $result = $this->Register($parameter);
                             } else {
                                 $result = array("returncode" => "9999", "msg" => "已存在用户账号!");
                             }
                         } else {
                             $result = array("returncode" => "9999", "msg" => "请传入openid值!");
                         }
                     }
                 }
             }
         }
     }
     $response = new Response(json_encode($result));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }