public function reply($data) { $noticeid = $data["noticeid"]; if (empty($noticeid)) { return Utils::WrapResultError("noticeid不能为空"); } $files = isset($data["files"]) ? $data["files"] : ''; if (!empty($files) && is_array($files)) { $files = implode(',', $files); } $sql = 'update im_pushnotice_memebr set receive_time=now() where noticeid=? and employeeid=? and receive_time is not null'; $sql1 = 'insert into im_pushnotice_msg(id,replyid,msg,created,us,msgid)values(?,?,?,now(),?,?)'; $replyid = SysSeq::GetSeqNextValue($this->conn_im, "im_pushnotice_msg", "id"); $sql = 'select count(1)+1 cnt from im_pushnotice_msg where replyid=?'; $ds = $this->conn_im->Getdata('t', $sql, array((int) $noticeid)); $cnt = $ds['t']['rows'][0]['cnt']; $senddata = array(); $senddata = array('noticeid' => $noticeid, 'reply_count' => $cnt, 'reply' => array('id' => $replyid, 'nickname' => $this->user["nick_name"], 'photo' => $this->user["photo_path"], 'jid' => $this->user["jid"], 'text' => $data["reply-text"], 'files' => $files, 'sendtime' => date("Y-m-d H:i:s", time()))); $notice = array(); // Utils::WrapMessageNoticeinfo($data["reply-text"],$this->module["appname"],null,$this->module["logo"]); $msg = Utils::WrapMessage('push-notice-reply', $senddata, $notice); $msgxml = Utils::WrapMessageXml($this->module["jid"], $msg, 'push-notice-reply-' . $replyid); $this->conn_im->ExecSQLs(array($sql, $sql1), array(array((int) $noticeid, (string) $this->user["jid"]), array((int) $replyid, (int) $noticeid, (string) json_encode($senddata['reply']), $this->user['jid'], 'push-notice-reply-' . $replyid))); $noticeinfo = $this->getinfo($noticeid); $receiver = $this->getmember($noticeid); $receiver[] = $noticeinfo["us"]; Utils::findonlinejid($this->conn_im, $receiver); if (!empty($receiver)) { //发送消息 $presence = new \Justsy\OpenAPIBundle\Controller\ApiController(); $presence->setContainer($this->container); $presence->sendMsg($this->module["jid"], $receiver, '通知回复', json_encode($msg)); } return Utils::WrapResultOK(array('noticeid' => $noticeid)); }
public static function sendImMessage($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); if (!empty($linktext) && is_array($linktext)) { $linktext = Utils::makeBusButton($linktext); } $s = $ec->sendMsg($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) { $container->get('logger')->err($e); return false; } }
public function sendImMessage($parameter) { $result = array("success" => true, "msg" => ""); $flag = isset($parameter["flag"]) ? $parameter["flag"] : "all"; $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 == "online") { 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); } else { if ($flag == "onself") { array_push($tojids, $myjid); } else { if ($flag == "all") { $this->write_msg($fromjid, $message, ''); if ($deploy_mode == "E") { $sql = "SELECT a.username fafa_jid,b.priority FROM users a inner join global_session b on a.username=b.us order by b.priority desc"; } else { $sql = "SELECT a.username fafa_jid,b.priority FROM users a inner join global_session b on a.username=b.us where a.username like '%{$eno}@{$domain}' order by b.priority desc"; } //$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_im->GetData("table", $sql); $sql = "select jid from we_micro_account where eno=?"; try { $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); } } } } //发送出席 $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->sendMsg($fromjid, $to_jid, $title, $message, $link, $linktext, $ischeckjid, $type, $cctomail); } } } if (count($tojids) > 0) { $to_jid = implode(",", $tojids); $presence->sendMsg($fromjid, $to_jid, $title, $message, $link, $linktext, $ischeckjid, $type, $cctomail); } } } } } return $result; }
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"); } }