コード例 #1
0
ファイル: UserProvider.php プロジェクト: 3116246/haolinju
 public function loadUserByUsername($username, $comeform = "")
 {
     if (Utils::validateMobile($username)) {
         //手机登录
         return $this->loadUserByUsernameWithMobile($username);
     }
     $DataAccess = $this->container->get('we_data_access');
     $staff = new \Justsy\BaseBundle\Management\Staff($DataAccess, $this->container->get('we_data_access_im'), $username, $this->container->get("logger"), $this->container);
     $us = $staff->getInfo();
     if (!empty($us)) {
         $us = $staff->getSessionUser($us);
         return $us;
     } else {
         throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
     }
 }
コード例 #2
0
 public function SendMsgAction()
 {
     $conn = $this->get("we_data_access");
     $conn_im = $this->get("we_data_access_im");
     $request = $this->getRequest();
     $currUser = $this->get('security.context')->getToken();
     if ($currUser == null) {
         $openid = $request->get('openid');
         $staffinfo = new \Justsy\BaseBundle\Management\Staff($conn, $conn_im, $openid, $this->get("logger"), $this->container);
         $staffdata = $staffinfo->getInfo();
         if (empty($staffdata)) {
             $re = array('returncode' => '9999', 'msg' => '无效的操作人');
             return $this->responseJson(json_encode($re));
         }
         $user = $staffinfo->getSessionUser($staffdata);
     } else {
         $user = $this->get('security.context')->getToken()->getUser();
     }
     //公众号相关参数
     $microObj = $request->get('microObj');
     $microName = $microObj["microName"];
     //接收对象(公众号名称)
     $microNumber = $microObj["microNumber"];
     //接收对象(公众号帐号)
     $microOpenid = $microObj["microOpenid"];
     //接收对象(公众号Openid)
     $microType = $microObj["microType"];
     //接收对象(公众号类型,内部或外部)
     $microUse = $microObj["microUse"];
     //接收对象(是公众号还是微应用)
     $microGroupId = "";
     //$microObj["microGroupId"]; //接收对象(公众号分组主键)
     //消息参数
     $msgType = "";
     //消息类型
     $msgContent = "";
     //消息内容(XML拼接Json字符串,包括标题,图片,摘要等)
     $msgContentHtml = "";
     //消息内容(HTML内容)
     $msgTitle = "";
     //消息标题
     $imgUrl = "";
     //图片地址
     $formid = "";
     //表单编号。推送表单时设置
     $webpage_url = "";
     //网页地址。推送网页地址时设置
     $msgObj_list = $request->get('msgObj');
     //消息对象
     if (!empty($msgObj_list)) {
         foreach ($msgObj_list as $key => $val) {
             if ($key == "type") {
                 $msgType = $val;
             } else {
                 if ($key == "msgContent") {
                     $msgContent = $val;
                 } else {
                     if ($key == "contentHtml") {
                         $msgContentHtml = $val;
                     } else {
                         if ($key == "title") {
                             $msgTitle = $val;
                         } else {
                             if ($key == "imgUrl") {
                                 $imgUrl = $val;
                             } else {
                                 if ($key == "formid") {
                                     $formid = $val;
                                 } else {
                                     if ($key == "webpage_url") {
                                         $webpage_url = $val;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $staffinfo = new \Justsy\BaseBundle\Management\Staff($conn, $conn_im, empty($microNumber) ? $microOpenid : $microNumber, $this->get("logger"), $this->container);
     $staffdata = $staffinfo->getInfo();
     if (empty($staffdata)) {
         $re = array('returncode' => '9999', 'msg' => '请选择接收对象');
         return $this->responseJson(json_encode($re));
     } else {
         $microOpenid = $staffdata["openid"];
         $microNumber = $staffdata["login_account"];
     }
     $re = array('returncode' => '0000');
     $sqls = array();
     $paras = array();
     $send_state = '2';
     $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, $microNumber, $microGroupId, $send_state, false, 'wefafa', $msgType);
     $error = array('returncode' => '9999', 'msg' => '消息内容有误,请检查');
     //处理消息
     switch ($msgType) {
         case 'PICTURE':
             $title = '';
             //标题
             $image_type = '';
             //图片类型  URL或CODE
             $image_value = '';
             //图片地址
             $content = '';
             //摘要
             $link = '';
             //手机端点击之后连接地址
             try {
                 foreach ($msgContent as $key => $value) {
                     if ($key == 'picturemsg') {
                         $picturemsg = $value;
                         //判断参数是否为空。并返回错误提示
                         if (empty($picturemsg)) {
                             return $this->responseJson(json_encode($error));
                         }
                         foreach ($picturemsg as $pkey => $pvalue) {
                             if ($pkey == 'headitem') {
                                 $headitem = $pvalue;
                                 //判断参数是否为空。并返回错误提示
                                 if (empty($headitem)) {
                                     return $this->responseJson(json_encode($error));
                                 }
                                 foreach ($headitem as $hkey => $hvalue) {
                                     if ($hkey == 'title') {
                                         $title = $hvalue;
                                     } else {
                                         if ($hkey == 'image') {
                                             $image = $hvalue;
                                             //判断参数是否为空。并返回错误提示
                                             if (empty($image)) {
                                                 return $this->responseJson(json_encode($error));
                                             }
                                             foreach ($image as $ikey => $ivalue) {
                                                 if ($ikey == 'type') {
                                                     $image_type = $ivalue;
                                                 } else {
                                                     if ($ikey == 'value') {
                                                         $image_value = $ivalue;
                                                     }
                                                 }
                                             }
                                         } else {
                                             if ($hkey == 'content') {
                                                 $content = $hvalue;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             } catch (Exception $e) {
                 $this->get('logger')->err($e->getMessage());
                 return $this->responseJson(json_encode($error));
             }
             if (!empty($webpage_url)) {
                 $link = $webpage_url;
                 $uniqid = $webpage_url;
             } else {
                 $uniqid = str_replace('.', '', uniqid('', true));
                 $link = !empty($formid) ? $this->getWebFormLink($formid) : $this->getLink($uniqid);
                 if (!empty($formid)) {
                     $uniqid = $link;
                 }
             }
             $noticeinfo = Utils::WrapMessageNoticeinfo($title, $microName);
             $msgContent = Utils::WrapMessage("mm-picturemsg", array('headitem' => array('title' => $title, 'image' => array('type' => $image_type, 'value' => $image_value), 'content' => $content, 'link' => $link)), $noticeinfo);
             //$msgContent= array('picturemsg'=>array('headitem'=>array('title'=>$title,'image'=>array('type'=>$image_type,'value'=>$image_value),'content'=>$content,'link'=>$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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
             $msgContentHtml = $this->SetElementStyle($msgContentHtml);
             $paras[] = array($msgid, $id, $title, $msgType, null, $msgContentHtml, $content, $image_type, $image_value, $uniqid, true, false);
             break;
         case 'TEXTPICTURE':
             try {
                 $headitem = array();
                 $items = array();
                 foreach ($msgContent as $key => $value) {
                     if ($key == 'textpicturemsg') {
                         $textpicturemsg = $value;
                         if (empty($textpicturemsg)) {
                             return $this->responseJson(json_encode($error));
                         }
                         foreach ($textpicturemsg as $tpmkey => $tpmvalue) {
                             if ($tpmkey == 'headitem') {
                                 $headitem = $tpmvalue;
                                 if (empty($headitem)) {
                                     return $this->responseJson(json_encode($error));
                                 }
                                 $head_title = '';
                                 $head_img_type = '';
                                 $head_img_url = '';
                                 $head_contentHtml = '';
                                 $head_link = '';
                                 $formid = "";
                                 foreach ($headitem as $hkey => $hvalue) {
                                     if ($hkey == 'title') {
                                         $head_title = $hvalue;
                                     } else {
                                         if ($hkey == 'image') {
                                             $image = $hvalue;
                                             if (empty($image)) {
                                                 return $this->responseJson(json_encode($error));
                                             }
                                             foreach ($image as $imgkey => $imgvalue) {
                                                 if ($imgkey == 'type') {
                                                     $head_img_type = $imgvalue;
                                                 } else {
                                                     if ($imgkey == 'value') {
                                                         $head_img_url = $imgvalue;
                                                     }
                                                 }
                                             }
                                         } else {
                                             if ($hkey == 'content') {
                                                 $head_contentHtml = $hvalue;
                                             } else {
                                                 if ($hkey == 'formid') {
                                                     $formid = $hvalue;
                                                 }
                                             }
                                         }
                                     }
                                 }
                                 $uniqid = str_replace('.', '', uniqid('', true));
                                 $head_link = !empty($formid) ? $this->getWebFormLink($formid) : $this->getLink($uniqid);
                                 $headitem = array('title' => $head_title, 'image' => array('type' => $head_img_type, 'value' => $head_img_url), '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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
                                 $head_contentHtml = $this->SetElementStyle($head_contentHtml);
                                 $paras[] = array($msgid, $id, $head_title, $msgType, null, $head_contentHtml, null, $head_img_type, $head_img_url, $uniqid, true, false);
                             } else {
                                 if ($tpmkey == 'item') {
                                     $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_type = '';
                                         $item_img_url = '';
                                         $item_contentHtml = '';
                                         $item_link = '';
                                         $formid = "";
                                         foreach ($item[$i] as $itemkey => $itemvalue) {
                                             if ($itemkey == 'title') {
                                                 $item_title = $itemvalue;
                                             } else {
                                                 if ($itemkey == 'image') {
                                                     $image = $itemvalue;
                                                     if (empty($image)) {
                                                         return $this->responseJson(json_encode($error));
                                                     }
                                                     foreach ($image as $imgkey => $imgvalue) {
                                                         if ($imgkey == 'type') {
                                                             $item_img_type = $imgvalue;
                                                         } else {
                                                             if ($imgkey == 'value') {
                                                                 $item_img_url = $imgvalue;
                                                             }
                                                         }
                                                     }
                                                 } else {
                                                     if ($itemkey == 'content') {
                                                         $item_contentHtml = $itemvalue;
                                                     } else {
                                                         if ($itemkey == 'formid') {
                                                             $formid = $itemvalue;
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                         $uniqid = str_replace('.', '', uniqid('', true));
                                         $item_link = !empty($formid) ? $this->getWebFormLink($formid) : $this->getLink($uniqid);
                                         $item_array = array('title' => $item_title, 'image' => array('type' => $item_img_type, 'value' => $item_img_url), '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, $item_img_type, $item_img_url, $uniqid, false, false);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $noticeinfo = Utils::WrapMessageNoticeinfo($headitem["title"], $microName);
                 $msgContent = Utils::WrapMessage("mm-textpicturemsg", array('headitem' => $headitem, 'item' => $items), $noticeinfo);
                 //$msgContent= array('textpicturemsg'=>array('headitem'=>$headitem,'item'=>$items));
             } catch (\Exception $e) {
                 $this->get('logger')->err($e->getMessage());
                 return $this->responseJson(json_encode($error));
             }
             break;
         case 'TEXT':
             foreach ($msgContent as $key => $value) {
                 if ($key == 'textmsg') {
                     $textmsg = $value;
                     //判断参数是否为空。并返回错误提示
                     if (empty($textmsg)) {
                         return $this->responseJson(json_encode($error));
                     }
                     foreach ($textmsg as $tkey => $tvalue) {
                         if ($tkey == 'item') {
                             $items = $tvalue;
                             //判断参数是否为空。并返回错误提示
                             if (empty($items)) {
                                 return $this->responseJson(json_encode($error));
                             }
                             $new_items = array();
                             for ($i = 0; $i < count($items); $i++) {
                                 $title = '';
                                 $content = '';
                                 foreach ($items[$i] as $itemkey => $itemvalue) {
                                     if ($itemkey == 'title') {
                                         $title = $itemvalue;
                                     } else {
                                         if ($itemkey == 'content') {
                                             $content = $itemvalue;
                                         }
                                     }
                                 }
                                 if (empty($title)) {
                                     return $this->responseJson(json_encode($error));
                                 }
                                 if (empty($content)) {
                                     return $this->responseJson(json_encode($error));
                                 }
                                 array_push($new_items, array('title' => $title, 'content' => $content));
                                 $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, $title, $msgType, $content, null, null, null, null, null, false, false);
                             }
                             $noticeinfo = Utils::WrapMessageNoticeinfo($title, $microName);
                             $msgContent = Utils::WrapMessage("mm-textmsg", array('item' => $new_items), $noticeinfo);
                             // array('code'=>'textmsg','data'=>array('item'=>$new_items),'noticeinfo'=>'');
                         }
                     }
                 }
             }
             break;
         default:
             //消息类型有误
             return $this->responseJson(json_encode($error));
             break;
     }
     $msgContent = json_encode($msgContent);
     try {
         $staffMgr = new \Justsy\BaseBundle\Management\Staff($conn, $conn_im, $microNumber, $this->get("logger"), $this->container);
         $microData = $staffMgr->getInfo();
         $mic_jid = $microData["fafa_jid"];
         $msgxml = Utils::WrapMicroMessageXml($mic_jid, $msgContent, $id);
         $im_msg_sql = "insert into im_microaccount_msg(microaccount,msg,created,us,msgid)values(?,?,now(),?,?)";
         $conn_im->ExecSQL($im_msg_sql, array((string) $mic_jid, (string) $msgxml, "", (string) $id));
         $fafa_jids = array();
         $sqls_staff = array();
         $paras_staff = array();
         $apicontroller = new \Justsy\OpenAPIBundle\Controller\ApiController();
         $apicontroller->setContainer($this->container);
         $serviceMgr = new \Justsy\BaseBundle\Management\Service($this->container);
         //$this->get('logger')->err("================1:".time());
         $fafa_jids = $serviceMgr->service_sendjid($mic_jid, true);
         //$this->get('logger')->err("================:".json_encode($fafa_jids));
         if (!empty($fafa_jids)) {
             $jids = array();
             $count = count($fafa_jids);
             for ($i = 0; $i < $count; $i++) {
                 array_push($jids, (string) $fafa_jids[$i]);
                 if ($i > 0 && $i % 5000 == 0) {
                     $re = $apicontroller->sendMsg2($microOpenid, implode(",", $jids), $msgContent, $msgType, false, "0", $id);
                     $jids = array();
                 }
             }
             if (!empty($jids) && count($jids) > 0) {
                 $re = $apicontroller->sendMsg2($microOpenid, implode(",", $jids), $msgContent, $msgType, false, "0", $id);
             }
         }
         //$this->get('logger')->err("================3:".time());
         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());
         $re = array('returncode' => '9999', 'msg' => '消息发送失败');
     }
     return $this->responseJson(json_encode($re));
 }
コード例 #3
0
 public function getDataAccessAction()
 {
     $request = $this->get("request");
     $module = $request->get("module");
     $action = $request->get("action");
     $params = $request->get("params");
     $class = null;
     $re["action"] = $action;
     if (empty($params)) {
         $params = array();
     } else {
         if (is_string($params)) {
             $params = json_decode($params, true);
         }
     }
     $currUser = $this->get('security.context')->getToken();
     if (empty($currUser)) {
         $openid = $request->get("openid");
         if (empty($openid)) {
             $re = array();
             $re["returncode"] = ReturnCode::$SYSERROR;
             $re["msg"] = "openid不能为空";
             return $this->responseJson($request, $re);
         }
         $staffObj = new \Justsy\BaseBundle\Management\Staff($this->get('we_data_access'), $this->get('we_data_access_im'), $openid, $this->get("logger"), $this->container);
         $currUser = $staffObj->getSessionUser();
     } else {
         $currUser = $currUser->getUser();
     }
     $params["user"] = $currUser;
     $module = strtolower($module);
     //转化为小写
     if ($module == "app") {
         $class = new \Justsy\BaseBundle\Management\App($this->container);
     } else {
         if ($module == "staff") {
             $class = new \Justsy\BaseBundle\Management\Staff($this->get('we_data_access'), $this->get('we_data_access_im'), $currUser->getUserName(), $this->get("logger"), $this->container);
         } else {
             if ($module == "enterprise") {
                 $class = new \Justsy\BaseBundle\Management\Enterprise($this->get('we_data_access'), $this->get("logger"), $this->container);
             } else {
                 if ($module == "dept") {
                     $class = new \Justsy\BaseBundle\Management\Dept($this->get('we_data_access'), $this->get('we_data_access_im'), $this->container);
                 } else {
                     if ($module == "group") {
                         $class = new \Justsy\BaseBundle\Management\GroupMgr($this->get('we_data_access'), $this->get('we_data_access_im'), $this->container);
                     } else {
                         if ($module == "microaccount") {
                             $class = new \Justsy\BaseBundle\Management\MicroAccountMgr($this->get('we_data_access'), $this->get('we_data_access_im'), $currUser->getUserName(), $this->get("logger"), $this->container);
                         } else {
                             if ($module == "service") {
                                 $class = new \Justsy\BaseBundle\Management\Service($this->container);
                             } else {
                                 if ($module == "announcer") {
                                     $class = new \Justsy\BaseBundle\Management\Announcer($this->container);
                                 } else {
                                     if ($module == "rolefunc") {
                                         $class = new \Justsy\BaseBundle\Management\RoleFunc($this->container);
                                     } else {
                                         if ($module == "role") {
                                             $class = new \Justsy\BaseBundle\Management\Role($this->container);
                                         } else {
                                             if ($module == "portal") {
                                                 $class = new \Justsy\BaseBundle\Management\Portal($this->container);
                                             } else {
                                                 if ($module == "sysparam") {
                                                     $class = new \Justsy\BaseBundle\Management\EnoParamManager($this->get('we_data_access'), $this->get('we_data_access_im'), $this->container);
                                                 } else {
                                                     if ($module == "servermonitor") {
                                                         $class = new \Justsy\BaseBundle\Management\ServerMonitor($this->container);
                                                     } else {
                                                         if ($module == "hrattendance") {
                                                             $class = new \Justsy\BaseBundle\Management\HrAttendance($this->container);
                                                         } else {
                                                             $result = array("returncode" => "9999", "msg" => "请转入正确的模块名称!");
                                                             return $this->responseJson($request, $result);
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $result = call_user_func_array(array($class, $action), array($params));
     return $this->responseJson($request, $result);
 }
コード例 #4
0
 public function getHisMessageAction()
 {
     $request = $this->getRequest();
     $conn = $this->get("we_data_access");
     $conn_im = $this->get("we_data_access_im");
     $logger = $this->get("logger");
     $container = $this->container;
     $api = new \Justsy\OpenAPIBundle\Controller\ApiController();
     $api->setContainer($this->container);
     $isWeFaFaDomain = $api->checkWWWDomain();
     if (!$isWeFaFaDomain) {
         $token = $api->checkAccessToken($request, $conn);
         if (!$token) {
             $re = array("returncode" => "9999");
             $re["code"] = "err0105";
             $re["msg"] = "参数Appid或Openid或Access_token未指定或无效.";
             return $this->responseJson($re);
         }
     }
     $microaccount = $request->get("microaccount");
     //微应用帐号
     $microgroupid = $request->get("microgroupid");
     //微应用分组ID
     $pageindex = $request->get("pageindex");
     //分页索引数
     $factory = $this->get('security.encoder_factory');
     if (empty($microaccount)) {
         return $this->responseJson(array("returncode" => ReturnCode::$SYSERROR, "msg" => "帐号不能为空."));
     }
     if (empty($pageindex)) {
         $pageindex = 1;
     }
     $baseinfoCtl = new \Justsy\BaseBundle\Management\Staff($conn, $conn_im, $request->get("openid"), $this->get("logger"), $this->container);
     $currUser = $baseinfoCtl->getSessionUser();
     if (empty($currUser)) {
         return $this->responseJson(array("returncode" => ReturnCode::$SYSERROR, "msg" => "无效的操作帐号"));
     }
     $sql_micro = "select number,type from we_micro_account where jid=?";
     $para_micro = array($microaccount);
     $data_micro = $conn->GetData("dt", $sql_micro, $para_micro);
     if ($data_micro == null || count($data_micro["dt"]["rows"]) == 0 || empty($data_micro["dt"]["rows"][0]["number"])) {
         return $this->responseJson(array("returncode" => ReturnCode::$SYSERROR, "msg" => "微应用帐号不存在."));
     }
     $microaccount = $data_micro["dt"]["rows"][0]['number'];
     $login_account = $currUser->getUserName();
     $micr_type = $data_micro["dt"]["rows"][0]["type"];
     //var_dump($login_account);
     $sql_total = "select count(1) as count from we_micro_send_message where send_account=? ";
     $para_total = array($microaccount);
     if (!empty($microgroupid)) {
         $sql_total = "select count(1) as count from we_micro_send_message where send_account=? and send_groupid=? ";
         $para_total = array($microaccount, $microgroupid);
     }
     $data_total = $conn->GetData("dt", $sql_total, $para_total);
     $total = 0;
     if ($data_total != null && count($data_total['dt']['rows']) > 0) {
         $total = $data_total['dt']['rows'][0]['count'];
     }
     $totalpage = 1;
     if ($total > 1) {
         $totalpage = ceil($total / 10);
     }
     $startrow = ($pageindex - 1) * 10;
     $sql = "select * from we_micro_send_message where send_account=? order by send_datetime desc LIMIT " . $startrow . ",10";
     $para = array($microaccount);
     if (!empty($microgroupid)) {
         $sql = "select * from we_micro_send_message where send_account=? and send_groupid=? order by send_datetime desc LIMIT " . $startrow . ",10";
         $para = array($microaccount, $microgroupid);
     }
     $re = array('returncode' => '9999', "msg" => '消息获取失败');
     $data_row = $conn->GetData("dt", $sql, $para);
     //var_dump($sql);
     if ($data_row != null && count($data_row['dt']['rows']) > 0) {
         $objlist = array();
         $pushMgr = new \Justsy\AdminAppBundle\Controller\MsgPushController();
         $pushMgr->setContainer($this->container);
         for ($i = 0; $i < count($data_row['dt']['rows']); $i++) {
             $send_id = $data_row['dt']['rows'][$i]["id"];
             $send_type = $data_row['dt']['rows'][$i]["send_type"];
             $send_datetime = $data_row['dt']['rows'][$i]["send_datetime"];
             $sql = "select * from we_micro_message where send_id=?";
             $para = array($send_id);
             $dataitem = $conn->GetData("dt", $sql, $para);
             if ($dataitem != null && count($dataitem['dt']['rows']) > 0) {
                 $list = array("type" => $send_type, "date" => $send_datetime);
                 //var_dump($send_type);
                 switch ($send_type) {
                     case 'TEXT':
                         $text_items = array();
                         for ($l = 0; $l < count($dataitem['dt']['rows']); $l++) {
                             $item = array('title' => $dataitem['dt']['rows'][$l]["msg_title"], 'content' => $dataitem['dt']['rows'][$l]["msg_text"]);
                             array_push($text_items, $item);
                         }
                         $list['data'] = array('item' => $text_items);
                         //var_dump($list);
                         break;
                     case 'PICTURE':
                         for ($j = 0; $j < count($dataitem['dt']['rows']); $j++) {
                             $headitem = array("title" => $dataitem['dt']['rows'][$j]["msg_title"], 'content' => $dataitem['dt']['rows'][$j]["msg_summary"], 'image' => array('type' => $dataitem['dt']['rows'][$j]["msg_img_type"], 'value' => $dataitem['dt']['rows'][$j]["msg_img_url"]), 'link' => $pushMgr->getLink($dataitem['dt']['rows'][$j]["msg_web_url"]));
                             $list['data'] = array("headitem" => $headitem);
                         }
                         break;
                     case 'TEXTPICTURE':
                         $items = array();
                         for ($k = 0; $k < count($dataitem['dt']['rows']); $k++) {
                             $ishead = $dataitem['dt']['rows'][$k]["ishead"];
                             //var_dump($ishead);
                             if ($ishead == "1") {
                                 $headitem = array("title" => $dataitem['dt']['rows'][$k]["msg_title"], 'content' => $dataitem['dt']['rows'][$k]["msg_text"], 'image' => array('type' => $dataitem['dt']['rows'][$k]["msg_img_type"], 'value' => $dataitem['dt']['rows'][$k]["msg_img_url"]), 'link' => $pushMgr->getLink($dataitem['dt']['rows'][$k]["msg_web_url"]));
                                 $data['headitem'] = $headitem;
                             } else {
                                 $item = array("title" => $dataitem['dt']['rows'][$k]["msg_title"], 'content' => $dataitem['dt']['rows'][$k]["msg_text"], 'image' => array('type' => $dataitem['dt']['rows'][$k]["msg_img_type"], 'value' => $dataitem['dt']['rows'][$k]["msg_img_url"]), 'link' => $pushMgr->getLink($dataitem['dt']['rows'][$k]["msg_web_url"]));
                                 array_push($items, $item);
                             }
                         }
                         if (!empty($items)) {
                             $data['item'] = $items;
                         }
                         $list['data'] = $data;
                         break;
                 }
                 array_push($objlist, $list);
             }
         }
         if (!empty($objlist)) {
             $re = array('returncode' => '0000', "total" => $total, 'totalpage' => $totalpage, 'list' => $objlist);
         }
     } else {
         $re = array('returncode' => '0000', "total" => 0, 'totalpage' => 1, 'list' => array());
     }
     return $this->responseJson($re);
 }
コード例 #5
0
 public function getMicroMessageAction()
 {
     $request = $this->getRequest();
     $conn = $this->get("we_data_access");
     $conn_im = $this->get("we_data_access_im");
     $logger = $this->get("logger");
     $container = $this->container;
     $microaccount = $request->get("microaccount");
     //微应用帐号
     $microgroupid = $request->get("microgroupid");
     //微应用分组ID
     $pageindex = $request->get("pageindex");
     //分页索引数
     $factory = $this->get('security.encoder_factory');
     if (empty($microaccount)) {
         return $this->responseJson(array("returncode" => ReturnCode::$SYSERROR, "msg" => "微应用帐号不能为空."));
     }
     if (empty($pageindex)) {
         $pageindex = 1;
     }
     $currUser = $this->get('security.context')->getToken();
     if (!empty($currUser)) {
         $currUser = $currUser->getUser();
     } else {
         $baseinfoCtl = new \Justsy\BaseBundle\Management\Staff($da, null, $request->get("openid"), $this->get("logger"));
         $currUser = $baseinfoCtl->getSessionUser();
     }
     if (empty($currUser)) {
         return $this->responseJson(array("returncode" => ReturnCode::$SYSERROR, "msg" => "您还没有登录呢."));
     }
     $sql_micro = "select number,type from we_micro_account where number=?";
     $para_micro = array($microaccount);
     $data_micro = $conn->GetData("dt", $sql_micro, $para_micro);
     if ($data_micro == null || count($data_micro["dt"]["rows"]) == 0 || empty($data_micro["dt"]["rows"][0]["number"])) {
         return $this->responseJson(array("returncode" => ReturnCode::$SYSERROR, "msg" => "微应用帐号不存在."));
     }
     $login_account = $currUser->getUserName();
     $micr_type = $data_micro["dt"]["rows"][0]["type"];
     //var_dump($login_account);
     $sql_atten = "select count(1) as count from we_staff_atten where atten_type='01' and login_account=? and atten_id=?";
     $para_atten = array($login_account, $microaccount);
     $data_atten = $conn->GetData("dt", $sql_atten, $para_atten);
     $isatten = false;
     if ($data_atten == null || count($data_atten["dt"]["rows"]) == 0 || empty($data_atten["dt"]["rows"][0]["count"])) {
         $isatten = true;
         //没有被关注
     }
     //$microgroupid="";
     if ($isatten) {
         //没有关注
         if ($micr_type == "0") {
             //内部微应用帐号需要判断是否关注该公众号
             return $this->responseJson(array("returncode" => ReturnCode::$SYSERROR, "msg" => "未关注微应用帐号."));
         }
     } else {
         //已经关注
         //$sql_micro_group="select GROUP_CONCAT(id) as id from we_micro_account_group where micro_account=? ORDER BY id";
         //$para_micro_group=array($microaccount);
         //$data_micro_group=$conn->GetData("dt",$sql_micro_group,$para_micro_group);
         //if($data_micro_group!=null && count($data_micro_group["dt"]["rows"])>0 && !empty($data_micro_group["dt"]["rows"][0]["id"])){
         //  $microgroupid=$data_micro_group["dt"]["rows"][0]["id"];
         //}
     }
     $sql_total = "select count(1) as count from we_micro_send_message where send_account=? ";
     $para_total = array($microaccount);
     if (!empty($microgroupid)) {
         $sql_total = "select count(1) as count from we_micro_send_message where send_account=? and send_groupid=? ";
         $para_total = array($microaccount, $microgroupid);
     }
     $data_total = $conn->GetData("dt", $sql_total, $para_total);
     $total = 0;
     if ($data_total != null && count($data_total['dt']['rows']) > 0) {
         $total = $data_total['dt']['rows'][0]['count'];
     }
     $totalpage = 1;
     if ($total > 1) {
         $totalpage = ceil($total / 10);
     }
     $startrow = ($pageindex - 1) * 10;
     $sql = "select * from we_micro_send_message where send_account=? order by send_datetime desc LIMIT " . $startrow . ",10";
     $para = array($microaccount);
     if (!empty($microgroupid)) {
         $sql = "select * from we_micro_send_message where send_account=? and send_groupid=? order by send_datetime desc LIMIT " . $startrow . ",10";
         $para = array($microaccount, $microgroupid);
     }
     $re = array('returncode' => '9999', "msg" => '消息获取失败');
     $data_row = $conn->GetData("dt", $sql, $para);
     //var_dump($sql);
     if ($data_row != null && count($data_row['dt']['rows']) > 0) {
         $objlist = array();
         for ($i = 0; $i < count($data_row['dt']['rows']); $i++) {
             $send_id = $data_row['dt']['rows'][$i]["id"];
             $send_type = $data_row['dt']['rows'][$i]["send_type"];
             $send_datetime = $data_row['dt']['rows'][$i]["send_datetime"];
             $sql = "select * from we_micro_message where send_id=?";
             $para = array($send_id);
             $dataitem = $conn->GetData("dt", $sql, $para);
             if ($dataitem != null && count($dataitem['dt']['rows']) > 0) {
                 $list = array("type" => $send_type, "date" => $send_datetime);
                 //var_dump($send_type);
                 switch ($send_type) {
                     case 'TEXT':
                         $text_items = array();
                         for ($l = 0; $l < count($dataitem['dt']['rows']); $l++) {
                             $item = array('title' => $dataitem['dt']['rows'][$l]["msg_title"], 'content' => $dataitem['dt']['rows'][$l]["msg_text"]);
                             array_push($text_items, $item);
                         }
                         $list['data'] = array('item' => $text_items);
                         //var_dump($list);
                         break;
                     case 'PICTURE':
                         for ($j = 0; $j < count($dataitem['dt']['rows']); $j++) {
                             $headitem = array("title" => $dataitem['dt']['rows'][$j]["msg_title"], 'content' => $dataitem['dt']['rows'][$j]["msg_summary"], 'image' => array('type' => $dataitem['dt']['rows'][$j]["msg_img_type"], 'value' => $dataitem['dt']['rows'][$j]["msg_img_url"]), 'link' => $dataitem['dt']['rows'][$j]["msg_web_url"]);
                             $list['data'] = array("headitem" => $headitem);
                         }
                         break;
                     case 'TEXTPICTURE':
                         $items = array();
                         for ($k = 0; $k < count($dataitem['dt']['rows']); $k++) {
                             $ishead = $dataitem['dt']['rows'][$k]["ishead"];
                             //var_dump($ishead);
                             if ($ishead == "1") {
                                 $headitem = array("title" => $dataitem['dt']['rows'][$k]["msg_title"], 'content' => $dataitem['dt']['rows'][$k]["msg_text"], 'image' => array('type' => $dataitem['dt']['rows'][$k]["msg_img_type"], 'value' => $dataitem['dt']['rows'][$k]["msg_img_url"]), 'link' => $dataitem['dt']['rows'][$k]["msg_web_url"]);
                                 $data['headitem'] = $headitem;
                             } else {
                                 $item = array("title" => $dataitem['dt']['rows'][$k]["msg_title"], 'content' => $dataitem['dt']['rows'][$k]["msg_text"], 'image' => array('type' => $dataitem['dt']['rows'][$k]["msg_img_type"], 'value' => $dataitem['dt']['rows'][$k]["msg_img_url"]), 'link' => $dataitem['dt']['rows'][$k]["msg_web_url"]);
                                 array_push($items, $item);
                             }
                         }
                         if (!empty($items)) {
                             $data['item'] = $items;
                         }
                         $list['data'] = $data;
                         break;
                 }
                 array_push($objlist, $list);
             }
         }
         if (!empty($objlist)) {
             $re = array('returncode' => '0000', "total" => $total, 'totalpage' => $totalpage, 'list' => $objlist);
         }
     } else {
         $re = array('returncode' => '0000', "total" => 0, 'totalpage' => 1, 'list' => array());
     }
     //$data=array('microaccount'=>$microaccount,'microgroupid'=>$microgroupid,'pageindex'=>$pageindex);
     //$data='microaccount='.$microaccount.'&microgroupid='.$microgroupid.'&pageindex='.$pageindex;
     //var_dump($data);
     //$re=$this->do_post_request('http://mp.wefafa.com/interface/getmessagelist',$data);
     return $this->responseJson($re);
 }