Ejemplo n.º 1
0
 public static function sendImPresence($fromjid, $tojid, $title, $message, $container, $link = "", $linktext = "", $ischeckjid = true, $type = '', $cctomail = '0')
 {
     try {
         if (is_array($tojid)) {
             $tojid = implode(",", $tojid);
         }
         $ec = new \Justsy\OpenAPIBundle\Controller\ApiController();
         $ec->setContainer($container);
         /*
         $url = $controller->generateUrl("JustsyOpenAPIBundle_api_sendpresence",array(
           'From' => $fromjid,
           'To' => $tojid,
           'Title' => $title,
           'Message' => $message,
           'Link' => $link,
           'LinkText' => $linktext
         ),true);
         $s = Utils::getUrlContent($url);
         */
         $s = $ec->sendPresence($fromjid, $tojid, $title, $message, $link, $linktext, $ischeckjid, $type, $cctomail);
         $jo = json_decode($s);
         if ($jo && $jo->{'returncode'} == "0000") {
             return true;
         } else {
             return false;
         }
     } catch (\Exception $e) {
         //var_dump($e->getMessage());
         $container->get('logger')->err($e);
         return false;
     }
 }
Ejemplo n.º 2
0
 public function sendImPresence($parameter)
 {
     $result = array("success" => true, "msg" => "");
     $flag = isset($parameter["flag"]) ? $parameter["flag"] : "online";
     $myjid = isset($parameter["myjid"]) ? $parameter["myjid"] : "";
     $title = isset($parameter["title"]) ? $parameter["title"] : "";
     $container = isset($parameter["container"]) ? $parameter["container"] : null;
     $this->container = $container;
     if (empty($flag)) {
         $result = array("success" => false, "msg" => "请选择发送出席标识(online:在线手机客户端用户;onself:向自己发送;all:向全体人员发送)");
     } else {
         if (empty($title)) {
             $result = array("success" => false, "msg" => "请确认发送的标题Caption");
         } else {
             if ($flag == "onself" && empty($myjid)) {
                 $result = array("success" => false, "msg" => "请确认自己的fafa_jid");
             } else {
                 if (empty($container)) {
                     $result = array("success" => false, "msg" => "请定义container属性");
                 } else {
                     $flag = strtolower($flag);
                     $fromjid = isset($parameter["fromjid"]) ? $parameter["fromjid"] : "";
                     $message = isset($parameter["message"]) ? $parameter["message"] : "";
                     $link = isset($parameter["link"]) ? $parameter["link"] : null;
                     $linktext = isset($parameter["linktext"]) ? $parameter["linktext"] : null;
                     $ischeckjid = isset($parameter["ischeckjid"]) ? (bool) $parameter["ischeckjid"] : false;
                     $type = isset($parameter["type"]) ? $parameter["type"] : Utils::$systemmessage_code;
                     $cctomail = isset($parameter["cctomail"]) ? $parameter["cctomail"] : 0;
                     $eno = isset($parameter["eno"]) ? $parameter["eno"] : null;
                     if (empty($eno) && !empty($container->get('security.context')->getToken())) {
                         $user = $container->get('security.context')->getToken()->getUser();
                         $eno = $user->eno;
                     }
                     if (empty($eno)) {
                         $eno = $container->getParameter('ENO');
                     }
                     $domain = $container->getParameter('edomain');
                     $deploy_mode = $container->getParameter('deploy_mode');
                     //确定发送对象
                     $ds = null;
                     $tojids = array();
                     $ary_micro_account = array();
                     //企业公众号,需要排除的
                     if ($flag == "onself") {
                         array_push($tojids, $myjid);
                     } else {
                         if ($flag == "dept") {
                             //给部门发
                         } else {
                             if ($flag == "roster") {
                                 //给好友发
                             } else {
                                 if ($flag == "to_jids") {
                                     //给指定的一个或者多个jid发
                                 } else {
                                     $this->write_msg($fromjid, $message, '');
                                     //给全企业发
                                     if ($deploy_mode == "E") {
                                         $sql = "select distinct us as fafa_jid from global_session";
                                     } else {
                                         $sql = "select distinct us as fafa_jid from global_session where us like '%{$eno}@{$domain}'";
                                     }
                                     $ds = $this->conn_im->GetData("table", $sql);
                                     try {
                                         $sql = "select jid from we_micro_account where eno=?";
                                         $ds_micro_account = $this->conn->GetData("micro", $sql, array((string) $eno));
                                         for ($i = 0; $i < count($ds_micro_account["micro"]["rows"]); $i++) {
                                             $ary_micro_account[] = $ds_micro_account["micro"]["rows"][$i]["jid"];
                                         }
                                     } catch (\Exception $e) {
                                         $container->get("logger")->err($e);
                                     }
                                 }
                             }
                         }
                     }
                     /*else if ($flag=="all"){
                     	 	 $sql = "select fafa_jid from we_staff where eno='{$eno}' and not exists(select 1 from we_micro_account b where b.eno=we_staff.eno and b.number=we_staff.login_account)";
                     	 	 $ds = $this->conn->GetData("table",$sql);		  	 	
                     	 }*/
                     //发送出席
                     $presence = new \Justsy\OpenAPIBundle\Controller\ApiController();
                     $presence->setContainer($container);
                     if (!empty($ds)) {
                         $rows = $ds["table"]["rows"];
                         $count = count($rows);
                         for ($i = 0; $i < $count; $i++) {
                             $jid = $rows[$i]["fafa_jid"];
                             if (count($ary_micro_account) > 0) {
                                 if (in_array($jid, $ary_micro_account)) {
                                     continue;
                                 }
                             }
                             $tojids[] = $jid;
                             if ($i > 0 && $i % 5000 == 0) {
                                 $to_jid = implode(",", $tojids);
                                 $tojids = array();
                                 $presence->sendPresence($fromjid, $to_jid, $title, $message, $link, $linktext, $ischeckjid, $type, $cctomail);
                             }
                         }
                     }
                     if (count($tojids) > 0) {
                         $to_jid = implode(",", $tojids);
                         $presence->sendPresence($fromjid, $to_jid, $title, $message, $link, $linktext, $ischeckjid, $type, $cctomail);
                     }
                 }
             }
         }
     }
     return $result;
 }
Ejemplo n.º 3
0
 public function sendPresence($conv_id, $da, $circle_id, $post_to_group, $type)
 {
     $groupid = "";
     $group_type = "group";
     $fafa_jid = array();
     $jid = "";
     if ($circle_id == "10000") {
         return;
     }
     $user = $this->get('security.context')->getToken()->getUser();
     if ($post_to_group != "ALL" && $post_to_group != "PRIVATE") {
         $groupObj = new \Justsy\BaseBundle\Management\GroupMgr($da, $this->get('we_data_access_im'), $this->container);
         $getGroupInfo = $groupObj->Get($post_to_group);
         $jid = $getGroupInfo["fafa_groupid"];
         $fafa_jid = $groupObj->getGroupMembersJid($post_to_group, "1");
         //获取允许接收群组动态通知的成员列表
         $groupid = $post_to_group;
     } else {
         $group_type = "circle";
         $groupid = $circle_id;
         $circlemgr = new \Justsy\BaseBundle\Management\CircleMgr($da, $this->get('we_data_access_im'));
         $getGroupInfo = $circlemgr->Get($circle_id);
         $jid = $getGroupInfo["fafa_groupid"];
         //判断是否是私密,私密时不向圈子成员发出席
         if ($post_to_group == "PRIVATE") {
             $group_type = "private";
         } else {
             if ($circle_id == "9999") {
                 $staffMgr = new \Justsy\BaseBundle\Management\Staff($da, $this->get('we_data_access_im'), $user, $this->get("logger"), $this->container);
                 $fafa_jid = $staffMgr->getFriendJidList($conv_id);
             } else {
                 $fafa_jid = $circlemgr->getCircleMembersJid($circle_id, "1");
             }
         }
     }
     $cc_jid = array();
     //获取抄送的人员jid
     $sql = "select b.fafa_jid from we_convers_notify a ,we_staff b where a.cc_login_account=b.login_account and conv_id=?";
     $ds = $da->getData("ds", $sql, array((string) $conv_id));
     if ($ds && count($ds["ds"]["rows"]) > 0) {
         for ($i = 0; $i < count($ds["ds"]["rows"]); $i++) {
             $cc_jid[] = $ds["ds"]["rows"][$i]["fafa_jid"];
         }
     }
     //发送即时消息
     $ec = new \Justsy\OpenAPIBundle\Controller\ApiController();
     $ec->setContainer($this->container);
     $message = array($group_type . "id" => $groupid, "t" => $type, "jid" => $jid);
     $link = $this->generateUrl("JustsyBaseBundle_view_oneconv", array("conv_root_id" => $conv_id), true);
     $linkButtons = Utils::makeBusButton(array(array("code" => "action", "text" => "详细", "blank" => "1", "value" => "")));
     //分次发送通知。每次200个号
     $c = 0;
     $sendAry = array();
     for ($i = 0; $i < count($fafa_jid); $i++) {
         $sendAry[] = $fafa_jid[$i];
         $c++;
         if ($c >= 200) {
             $r = $ec->sendPresence($user->fafa_jid, implode(",", $sendAry), "", json_encode($message), $link, $linkButtons, false, $group_type . "_newtrend");
             $c = 0;
             $sendAry = array();
         }
     }
     if ($c > 0) {
         $r = $ec->sendPresence($user->fafa_jid, implode(",", $sendAry), "", json_encode($message), $link, $linkButtons, false, $group_type . "_newtrend", "0");
     }
     if (count($cc_jid) > 0) {
         //给抄送人员推消息
         $r = $ec->sendMsg($user->fafa_jid, implode(",", $cc_jid), "", json_encode($message), $link, $linkButtons, false, "private_newtrend");
     }
 }