public function getDataAccessAction()
 {
     $request = $this->getRequest();
     //判断是否是访问api控制器,是则直接跳转过去
     $module = trim($request->get("module"));
     if (!empty($module) && strpos($module, "Api") !== false) {
         $action = trim($request->get("action"));
         $apiclass = "\\Justsy\\OpenAPIBundle\\Controller\\" . $module . "Controller";
         $apiclass = new $apiclass();
         $apiclass->setContainer($this->container);
         return call_user_func_array(array($apiclass, $action . "Action"), array());
     }
     //访问权限校验
     $api = new \Justsy\OpenAPIBundle\Controller\ApiController();
     $api->setContainer($this->container);
     $isWeFaFaDomain = $api->checkWWWDomain();
     $da = $this->get('we_data_access');
     if (!$isWeFaFaDomain) {
         $token = $api->checkAccessToken($request, $da);
         if (!$token) {
             $re = array("returncode" => "9999");
             $re["code"] = "err0105";
             $re["msg"] = "参数Appid或Openid或Access_token未指定或无效.";
             return $this->responseJson($request, $re);
         }
     }
     $dbAccessInf = new \Justsy\InterfaceBundle\Controller\DataInterfaceController();
     $dbAccessInf->setContainer($this->container);
     $response = $dbAccessInf->getDataAccessAction();
     return $response;
 }
 public static function tokenAction($container, $con, $appid, $openid, $encrypt)
 {
     $da = $con;
     //$result = Utils::do_post_request("http://www.wefafa.com", array());
     $sql = "select appkey from we_appcenter_apps where appid=?";
     $ds = $da->GetData("t", $sql, array((string) $appid));
     $result = "";
     if (count($ds["t"]["rows"]) == 0) {
         $json = array("error" => "invalid appid");
     } else {
         $appkey = $ds["t"]["rows"][0]["appkey"];
         $sql = "select 1 from we_staff_account_bind a,we_staff b where a.bind_account=b.openid and a.bind_account=? and a.appid=?";
         $ds = $da->GetData("tb", $sql, array((string) $openid, (string) $appid));
         if (count($ds["tb"]["rows"]) > 0) {
             $api = new \Justsy\OpenAPIBundle\Controller\ApiController();
             $api->setContainer($container->container);
             $code = md5($appid . $appkey);
             $json = $api->getProxySession($appid, $code, "394usjf0sd");
         } else {
             $json = array("error" => "not bind");
         }
     }
     return $json;
 }
 public function sendsharemsgAction()
 {
     $da = $this->get("we_data_access");
     $da_im = $this->get("we_data_access_im");
     $re = array("returncode" => ReturnCode::$SUCCESS, 'msg' => '');
     $res = $this->getRequest();
     $user = $this->get('security.context')->getToken()->getUser();
     try {
         //获取接收者
         $openids = $res->get("openids");
         $groupid = $res->get("groupid");
         $circleid = $res->get("circleid");
         //分享到指定的圈子中,需要单独 处理。不走实时消息通道
         if (empty($openids) && empty($groupid) && empty($circleid)) {
             $toType = $res->get("totype");
             //分享目标类型,当openids\groupid\circleid存在时无效
             //分享到其他网站或者平台上,暂时支持微信朋友圈\QQ空间
             $re = "";
             $response = new Response($res->get('jsoncallback') ? $res->get('jsoncallback') . "(" . json_encode($re) . ");" : json_encode($re));
             $response->headers->set('Content-Type', 'text/json');
             return $response;
         }
         //获取推送的分享图片地址
         $imgurl = $res->get("imgurl");
         //获取推送的分享内容
         $content = $res->get("content");
         $shareitem = array();
         $shareitem["content"] = $content;
         if (!empty($imgurl)) {
             $shareitem["image"] = array("value" => $imgurl, "type" => "URL");
         }
         $shareitem["iosclass"] = $res->get("iosclass");
         $shareitem["androidclass"] = $res->get("androidclass");
         $shareitem["bizdata"] = $res->get("bizdata");
         if (!empty($circleid)) {
             $ref_url = json_encode(array("iosclass" => $shareitem["iosclass"], "androidclass" => $shareitem["androidclass"], "bizdata" => $shareitem["bizdata"]));
             //分享到圈子
             $conv_id = \Justsy\BaseBundle\DataAccess\SysSeq::GetSeqNextValue($da, "we_convers_list", "conv_id");
             $conv = new \Justsy\BaseBundle\Business\Conv();
             $conv->newShareTrend($da, $user->getUserName(), $conv_id, $content, $imgurl, $circleid, "ALL", $ref_url, array(), "00", null);
             $response = new Response($res->get('jsoncallback') ? $res->get('jsoncallback') . "(" . json_encode($re) . ");" : json_encode($re));
             $response->headers->set('Content-Type', 'text/json');
             return $response;
         }
         $msgBody = array();
         $msgBody["snssharemsg"] = array("shareitem" => $shareitem);
         $tolist = array();
         if (!empty($groupid)) {
             $groupmgr = new \Justsy\BaseBundle\Management\GroupMgr($da, $da_im);
             //$groupdata = $groupmgr->GetByIM($groupid);
             $tolist = $groupmgr->getGroupMembersJidByIM($groupid);
             $msgBody["snssharemsg"]["shareitem"]["groupid"] = $groupid;
         }
         if (!empty($openids)) {
             $tolist = array_merge($tolist, explode(",", $openids));
         }
         $cnt = count($tolist);
         if ($cnt > 0) {
             $api = new \Justsy\OpenAPIBundle\Controller\ApiController();
             $api->setContainer($this->container);
             $re = $api->sendMsg2($user->fafa_jid, implode(",", $tolist), json_encode($msgBody), "sharemsg", true);
         }
     } catch (\Exception $e) {
         $re["returncode"] = ReturnCode::$SYSERROR;
         $re["msg"] = "系统错误";
         $this->get('logger')->err($e);
     }
     $response = new Response($res->get('jsoncallback') ? $res->get('jsoncallback') . "(" . json_encode($re) . ");" : json_encode($re));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
Beispiel #4
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));
 }
 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;
 }
Beispiel #6
0
 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));
 }
Beispiel #7
0
 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 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));
 }
Beispiel #9
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;
     }
 }
Beispiel #10
0
 public function UploadFileAction()
 {
     $da = $this->get('we_data_access');
     $da_im = $this->get('we_data_access_im');
     $request = $this->getRequest();
     $content = $request->get("update_content");
     $version1 = $request->get("version_1");
     $version2 = $request->get("version_2");
     $version3 = $request->get("version_3");
     $version4 = $request->get("version_4");
     $version = $version1 . "." . $version2 . "." . $version3 . "." . $version4;
     $plist_url = $request->get("plist_url");
     $plist_url = empty($plist_url) ? null : $plist_url;
     $openid = $request->get('openid');
     $staffinfo = new \Justsy\BaseBundle\Management\Staff($da, $this->get("we_data_access_im"), $openid, $this->get("logger"), $this->container);
     $staffdata = $staffinfo->getInfo();
     $login_account = $staffdata["login_account"];
     $fileElementName = 'filedata';
     $success = true;
     $msg = "";
     try {
         $filename = $_FILES[$fileElementName]['name'];
         $filesize = $_FILES[$fileElementName]['size'];
         $filetemp = $_FILES[$fileElementName]['tmp_name'];
         //判断文件类型
         $file_name = basename($filename);
         $fixedType = explode(".", strtolower($file_name));
         $fixedType = $fixedType[count($fixedType) - 1];
         $type = 0;
         if ($fixedType == "apk") {
             $type = 1;
         } else {
             if ($fixedType == "ipa") {
                 $type = 2;
             }
         }
         //比较版本号
         $sql = "select max(replace(version,'.','')) version from we_version where type=?;";
         try {
             $ds = $da->GetData("table", $sql, array((string) $type));
             if ($ds && $ds["table"]["recordcount"] > 0) {
                 $old_ver = (int) $ds["table"]["rows"][0]["version"];
                 $new_ver = $version1 . $version2 . $version3 . $version4;
                 $new_ver = (int) $new_ver;
                 if ($new_ver <= $old_ver) {
                     return Utils::WrapResultError("你输入的版本号比数据库里的小,请重新输入");
                 }
             }
         } catch (\Exception $e) {
             return Utils::WrapResultError($e->getMessage());
         }
         $fileid = $this->saveCertificate($filetemp, $filename);
         if (!empty($fileid)) {
             //上传文件成功后返回文件id
             $url = $this->container->getParameter('FILE_WEBSERVER_URL');
             $path = $_SERVER['DOCUMENT_ROOT'] . "/download/app";
             $dir = explode('src', __DIR__);
             if (!is_dir($dir[0] . '/download/app')) {
                 mkdir($dir[0] . '/download/app', 0777, true);
             }
             $path = $path . "/";
             $dowurl = $url . $fileid;
             $id = SysSeq::GetSeqNextValue($da, "we_version", "id");
             $sql = "insert into we_version(id,version,type,update_content,filename,date,staffid,fileid,plist_url)values(?,?,?,?,?,now(),?,?,?)";
             $para = array((string) $id, (string) $version, (string) $type, (string) $content, (string) $file_name, (string) $login_account, (string) $fileid, $plist_url);
             try {
                 $da->ExecSQL($sql, $para);
                 //发送出席
                 $presence = new \Justsy\OpenAPIBundle\Controller\ApiController();
                 $presence->setContainer($this->container);
                 $my_jid = $staffdata['jid'];
                 $sql = "select distinct us from global_session;";
                 $ds = $da_im->GetData("us", $sql);
                 $tojids = array();
                 $title = "";
                 if ($type == 1) {
                     $title = "andorid";
                 } else {
                     if ($type == 2) {
                         $title = "ios";
                     } else {
                         $title = "pc";
                     }
                 }
                 $sendMessage = new \Justsy\BaseBundle\Common\SendMessage($da, $da_im);
                 $body = "有新版本(" . $version . "),请及时更新!";
                 $notice = Utils::WrapMessageNoticeinfo($body, '系统通知', null, null);
                 $msg = json_encode(Utils::WrapMessage('newversion', array('type' => $title), $notice));
                 $parameter = array("eno" => $staffdata['eno'], "flag" => "all", "title" => "newversion", "message" => $msg, "container" => $this->container);
                 $sendMessage->sendImMessage($parameter);
             } catch (\Exception $e) {
                 $success = false;
                 $this->get("logger")->err($e->getMessage());
                 $msg = "添加数据记录失败!";
                 return Utils::WrapResultError($e->getMessage());
             }
         } else {
             $success = false;
             $msg = "上传安装包文件失败";
             return Utils::WrapResultError($msg);
         }
     } catch (\Exception $e) {
         $success = false;
         $msg = "上传安装包失败。";
         $this->get("logger")->err($e->getMessage());
         return Utils::WrapResultError($e->getMessage());
     }
     //删除上传的文件
     @unlink($_FILES[$fileElementName]);
     return Utils::WrapResultOK("");
 }
 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");
     }
 }
 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);
 }
Beispiel #13
0
 public function startBellAction()
 {
     $ec = new \Justsy\OpenAPIBundle\Controller\ApiController();
     $type = $this->getRequest()->get('type');
     $ec->setContainer($this->container);
     $re = $ec->timerRemindTaskAction()->getContent();
     if (json_decode($re)->s == '1') {
         $res = new Response(json_encode(array('s' => 1, 'message' => '', '_type' => $type)));
         $res->headers->set('Content-Type', 'text/json');
         return $res;
     } else {
         $res = new Response(json_encode(array('s' => 0, 'message' => "提醒未设置成功。<a href=''>重试</a>")));
         $res->headers->set('Content-Type', 'text/json');
         return $res;
     }
 }