public function appbizproxyurlAction(Request $request) { $appid = $request->get("appid"); $action = $request->get("action"); $da = $this->get('we_data_access'); if ($action == "download") { $sql = "select a.*,b.number from we_appcenter_apps a,we_micro_account b where a.appid=b.micro_source and a.appid=?"; $ds = $da->GetData("t", $sql, array((string) $appid)); $ds["t"]["rows"][0]["appkey"] = DES::encrypt($ds["t"]["rows"][0]["appkey"]); $appInfo = array('s' => 1, "data" => $ds["t"]["rows"][0]); $resp = new Response(json_encode($appInfo)); $resp->headers->set('Content-Type', 'text/json'); return $resp; } else { $result = array("s" => 1); try { $sql = "select count(1) cnt from we_appcenter_apps a "; $ds = $da->GetData("t", $sql, array()); $curuser = $this->get('security.context')->getToken()->getUser(); $maxNo = $curuser->eno . ((int) $ds["t"]["rows"][0]["cnt"] + 1); $sql = "select a.* from we_appcenter_apps a where a.appid=?"; $ds = $da->GetData("t", $sql, array((string) $appid)); if ($ds && count($ds["t"]["rows"]) > 0) { $appInfo = $ds["t"]["rows"][0]; $factory = $this->get('security.encoder_factory'); $dm = $this->get('doctrine.odm.mongodb.document_manager'); $account = strtolower("mapp" . $maxNo . "@" . $curuser->edomain); if (strpos($account, ".") === false) { $account = $account . ".com"; } $MicroAccountMgr = new \Justsy\BaseBundle\Management\MicroAccountMgr($da, $this->get('we_data_access_im'), $curuser, $this->get("logger"), $this->container); $re = $MicroAccountMgr->register("", $account, $appInfo["appname"], "1", "1", "", "1", "", "1", $appInfo["appkey"], $appInfo["logo"], $appInfo["logo"], $appInfo["logo"], $factory, $dm, $appid); } } catch (\Exception $e) { $result = array("s" => 0, 'msg' => $e->getMessage()); } $resp = new Response(json_encode($result)); $resp->headers->set('Content-Type', 'text/json'); return $resp; } }
public function TextPictureMsgAction() { //if($_SERVER['REQUEST_METHOD']!="POST") // return $this->responseJson(json_encode(array("error"=>"10009","msg"=>"HTTP请求仅支持POST提交方式"))); $conn = $this->get("we_data_access"); $conn_im = $this->get("we_data_access_im"); $request = $this->getRequest(); $micro_account = $request->get('micro_account'); $micro_groupid = $request->get('micro_groupid'); $appid = $request->get('appid'); $openid = 'wefafaproxy'; $recopenid = $request->get('openid'); $access_token = $request->get('access_token'); $msg = $request->get('msg'); if (empty($appid) && empty($micro_account)) { return $this->responseJson(json_encode(array('returncode' => '9999', 'msg' => 'appid不能为空。'))); } if (empty($access_token)) { return $this->responseJson(json_encode(array('returncode' => '9999', 'msg' => '访问令牌不能为空。'))); } if (empty($msg)) { return $this->responseJson(json_encode(array('returncode' => '9999', 'msg' => '消息不能为空。'))); } $msgObj = json_decode($msg); if (empty($msgObj)) { return $this->responseJson(json_encode(array('returncode' => '9999', 'msg' => '消息格式不正确。'))); } if (empty($openid)) { $openid = "wefafaproxy"; } $token_appid = $this->checkAccessToken($conn, $appid, $openid, $access_token); if ($token_appid === false) { return $this->responseJson(json_encode(array('returncode' => '0001', 'msg' => '访问令牌已过期。'))); } if ($token_appid != $appid) { return $this->responseJson(json_encode(array('returncode' => '0001', 'msg' => 'appid无效。'))); } //token通过认证 if (empty($micro_account)) { $sql_micro_account = "select number from we_micro_account where micro_source=? "; $data_micro_account = $conn->GetData("dt", $sql_micro_account, array((string) $appid)); if ($data_micro_account != null && count($data_micro_account["dt"]["rows"]) > 0 && !empty($data_micro_account["dt"]["rows"][0]["number"])) { $micro_account = $data_micro_account["dt"]["rows"][0]["number"]; } else { return $this->responseJson(json_encode(array('returncode' => '9999', 'msg' => '应用未开启业务代理,不能推送消息。'))); } } $login_account = $micro_account; if ($openid != "wefafaproxy") { $staff = $this->checkOpenid($conn, $openid); if (empty($staff)) { return $this->responseJson(json_encode(array('returncode' => '9999', 'msg' => 'openid不存在。'))); } } $sql = "SELECT b.fafa_jid openid FROM we_micro_account a LEFT JOIN we_staff b ON b.login_account=a.number AND b.eno=a.eno WHERE a.number=?;"; $para = array($micro_account); $data = $conn->GetData('dt', $sql, $para); if ($data == null || count($data['dt']['rows']) == 0 || empty($data['dt']['rows'][0]['openid'])) { return $this->responseJson(json_encode(array('returncode' => '9999', 'msg' => '微应用帐号不存在。'))); } $microOpenid = $data['dt']['rows'][0]['openid']; $re = array('returncode' => '9999', 'msg' => '消息发送失败。'); try { $msgType = 'TEXTPICTURE'; $send_state = '2'; $sqls = array(); $paras = array(); $headitem = array(); $items = array(); $file_url = $this->container->getParameter('FILE_WEBSERVER_URL'); $id = SysSeq::GetSeqNextValue($conn, 'we_micro_send_message', 'id'); $sqls[] = "INSERT INTO `we_micro_send_message` (`id`, `send_account`, `send_groupid`, `send_datetime`, `send_state`, `send_isbutton`, `send_source`,`send_type`) VALUES (?, ?, ?, now(), ?, ?, ?,?);"; $paras[] = array($id, $micro_account, $micro_groupid, $send_state, false, 'interface', $msgType); foreach ($msgObj as $tpmkey => $tpmvalue) { if ($tpmkey == 'headitem') { $headitem = $tpmvalue; if (empty($headitem)) { return $this->responseJson(json_encode($error)); } $head_title = ''; $head_img = ''; $head_contentHtml = ''; $head_link = ''; foreach ($headitem as $hkey => $hvalue) { if ($hkey == 'title') { $head_title = $hvalue; } else { if ($hkey == 'image') { $head_img = $hvalue; } else { if ($hkey == 'content') { $head_contentHtml = htmlspecialchars_decode($hvalue); } } } } if (empty($head_title)) { return $this->responseJson(json_encode(array('returncode' => '9999', 'msg' => '消息头部标题不能为空。'))); } if (empty($head_img)) { return $this->responseJson(json_encode(array('returncode' => '9999', 'msg' => '消息头部图片不能为空。'))); } if (empty($head_contentHtml)) { return $this->responseJson(json_encode(array('returncode' => '9999', 'msg' => '消息头部内容不能为空。'))); } $uniqid = str_replace('.', '', uniqid('', true)); $head_link = $this->getLink($uniqid); if (strpos($head_img, $file_url) === false) { $head_img = $file_url . $head_img; } $headitem = array('title' => $head_title, 'image' => array('type' => 'URL', 'value' => $head_img), 'link' => $head_link); $msgid = SysSeq::GetSeqNextValue($conn, 'we_micro_message', 'id'); $sqls[] = "INSERT INTO `we_micro_message` (`id`, `send_id`, `msg_title`, `msg_type`, `msg_text`, `msg_content`, `msg_summary`, `msg_img_type`, `msg_img_url`, `msg_web_url`, `ishead`, `isread`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; $paras[] = array($msgid, $id, $head_title, $msgType, null, $head_contentHtml, null, 'URL', $head_img, $uniqid, true, false); } else { if ($tpmkey == 'items') { $item = $tpmvalue; if (empty($item)) { return $this->responseJson(json_encode($error)); } $item_array = array(); for ($i = 0; $i < count($item); $i++) { $item_title = ''; $item_img = ''; $item_contentHtml = ''; $item_link = ''; foreach ($item[$i] as $itemkey => $itemvalue) { if ($itemkey == 'title') { $item_title = $itemvalue; } else { if ($itemkey == 'image') { $item_img = $itemvalue; } else { if ($itemkey == 'content') { $item_contentHtml = htmlspecialchars_decode($itemvalue); } } } } if (empty($item_title)) { return $this->responseJson(json_encode(array('returncode' => '9999', 'msg' => '消息子项标题不能为空。'))); } if (empty($item_img)) { return $this->responseJson(json_encode(array('returncode' => '9999', 'msg' => '消息子项图片不能为空。'))); } if (empty($item_contentHtml)) { return $this->responseJson(json_encode(array('returncode' => '9999', 'msg' => '消息子项内容不能为空。'))); } $uniqid = str_replace('.', '', uniqid('', true)); $item_link = $this->getLink($uniqid); if (strpos($item_img, $file_url) === false) { $item_img = $file_url . $item_img; } $item_array = array('title' => $item_title, 'image' => array('type' => 'URL', 'value' => $item_img), 'link' => $item_link); array_push($items, $item_array); $msgid = SysSeq::GetSeqNextValue($conn, 'we_micro_message', 'id'); $sqls[] = "INSERT INTO `we_micro_message` (`id`, `send_id`, `msg_title`, `msg_type`, `msg_text`, `msg_content`, `msg_summary`, `msg_img_type`, `msg_img_url`, `msg_web_url`, `ishead`, `isread`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; $paras[] = array($msgid, $id, $item_title, $msgType, null, $item_contentHtml, null, 'URL', $item_img, $uniqid, false, false); } } } } $msgContent = array('textpicturemsg' => array('headitem' => $headitem, 'item' => $items)); $msgContent = json_encode($msgContent); $fafa_jids = array(); $sqls_staff = array(); $paras_staff = array(); $apicontroller = new \Justsy\OpenAPIBundle\Controller\ApiController(); $apicontroller->setContainer($this->container); $MicroAccountMgr = new \Justsy\BaseBundle\Management\MicroAccountMgr($conn, $conn_im, $login_account, $this->get("logger"), $this->container); if ($this->checkint($micro_groupid)) { $count = $MicroAccountMgr->check_micro_fans_groupid($micro_account, $micro_groupid); $microdata = array(); if ($count > 0) { //分组主键在数据库不存在 $microdata = $MicroAccountMgr->get_micro_fans_group($micro_account, $micro_groupid); for ($i = 0; $i < count($microdata); $i++) { if (!in_array($microdata[$i]["fafa_jid"], $fafa_jids) && !empty($microdata[$i]["fafa_jid"])) { if (!in_array($microdata[$i]["fafa_jid"], $fafa_jids)) { array_push($fafa_jids, $microdata[$i]["fafa_jid"]); $staffid = SysSeq::GetSeqNextValue($conn, 'we_micro_message_recipient', 'id'); $sqls_staff[] = "INSERT INTO `we_micro_message_recipient` (`id`, `send_id`, `eno`, `login_account`, `openid`, `fafa_jid`, `rec_datetime`) VALUES (?, ?, ?, ?, ?, ?, now());"; $paras_staff[] = array($staffid, $id, $microdata[$i]["eno"], $microdata[$i]["login_account"], $microdata[$i]["openid"], $microdata[$i]["fafa_jid"]); } } } } if (!empty($recopenid)) { $openids = explode(',', $recopenid); for ($i = 0; $i < count($openids); $i++) { $sql_staff = "select fafa_jid,login_account,openid,eno from we_staff where openid=?"; $data_staff = $conn->GetData("dt", $sql_staff, array((string) $openids[$i])); if ($data_staff != null && count($data_staff["dt"]["rows"]) > 0) { if (!in_array($data_staff["dt"]["rows"][0]["fafa_jid"], $fafa_jids)) { array_push($fafa_jids, $data_staff["dt"]["rows"][0]["fafa_jid"]); $staffid = SysSeq::GetSeqNextValue($conn, 'we_micro_message_recipient', 'id'); $sqls_staff[] = "INSERT INTO `we_micro_message_recipient` (`id`, `send_id`, `eno`, `login_account`, `openid`, `fafa_jid`, `rec_datetime`) VALUES (?, ?, ?, ?, ?, ?, now());"; $paras_staff[] = array($staffid, $id, $data_staff["dt"]["rows"][0]["eno"], $data_staff["dt"]["rows"][0]["login_account"], $data_staff["dt"]["rows"][0]["openid"], $data_staff["dt"]["rows"][0]["fafa_jid"]); } } } } } else { if (!empty($recopenid)) { $openids = explode(',', $recopenid); for ($i = 0; $i < count($openids); $i++) { $sql_staff = "select fafa_jid,login_account,openid,eno from we_staff where openid=?"; $data_staff = $conn->GetData("dt", $sql_staff, array((string) $openids[$i])); if ($data_staff != null && count($data_staff["dt"]["rows"]) > 0) { if (!in_array($data_staff["dt"]["rows"][0]["fafa_jid"], $fafa_jids)) { array_push($fafa_jids, $data_staff["dt"]["rows"][0]["fafa_jid"]); $staffid = SysSeq::GetSeqNextValue($conn, 'we_micro_message_recipient', 'id'); $sqls_staff[] = "INSERT INTO `we_micro_message_recipient` (`id`, `send_id`, `eno`, `login_account`, `openid`, `fafa_jid`, `rec_datetime`) VALUES (?, ?, ?, ?, ?, ?, now());"; $paras_staff[] = array($staffid, $id, $data_staff["dt"]["rows"][0]["eno"], $data_staff["dt"]["rows"][0]["login_account"], $data_staff["dt"]["rows"][0]["openid"], $data_staff["dt"]["rows"][0]["fafa_jid"]); } } } } else { $microdata = $MicroAccountMgr->get_micro_all_fans($micro_account); for ($i = 0; $i < count($microdata); $i++) { if (!in_array($microdata[$i]["fafa_jid"], $fafa_jids) && !empty($microdata[$i]["fafa_jid"])) { array_push($fafa_jids, $microdata[$i]["fafa_jid"]); $staffid = SysSeq::GetSeqNextValue($conn, 'we_micro_message_recipient', 'id'); $sqls_staff[] = "INSERT INTO `we_micro_message_recipient` (`id`, `send_id`, `eno`, `login_account`, `openid`, `fafa_jid`, `rec_datetime`) VALUES (?, ?, ?, ?, ?, ?, now());"; $paras_staff[] = array($staffid, $id, $microdata[$i]["eno"], $microdata[$i]["login_account"], $microdata[$i]["openid"], $microdata[$i]["fafa_jid"]); } } } } if (!empty($fafa_jids)) { $jids = array(); for ($i = 0; $i < count($fafa_jids); $i++) { array_push($jids, (string) $fafa_jids[$i]); if (count($jids) == 500) { $re = $apicontroller->sendMsg2($microOpenid, implode(",", $jids), $msgContent, $msgType, false, "0", $id); $jids = array(); } } if (!empty($jids)) { $re = $apicontroller->sendMsg2($microOpenid, implode(",", $jids), $msgContent, $msgType, false, "0", $id); } } if (!empty($re['returncode']) && $re['returncode'] == '0000') { //添加发送消息数据 if (!empty($sqls)) { $conn->ExecSQLs($sqls, $paras); } //添加接收人员 if (!empty($sqls_staff)) { $conn->ExecSQLs($sqls_staff, $paras_staff); } } } catch (\Exception $e) { $this->get('logger')->err($e->getMessage()); } return $this->responseJson(json_encode($re)); }
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); }