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 #2
0
 public function revokeMsgAction()
 {
     //判断请求域。是wefafa或子域则不验证授权令牌
     $isWeFaFaDomain = $this->checkWWWDomain();
     $request = $this->get("request");
     $da = $this->get("we_data_access");
     if (!$isWeFaFaDomain) {
         $token = $this->checkAccessToken($request, $da);
         if (!$token) {
             return $this->responseJson($request, Utils::WrapResultError('参数Appid或Openid或Access_token未指定或无效.'));
         }
     }
     $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();
     if (empty($staffdata)) {
         $result = Utils::WrapResultError("无效操作帐号");
         return $this->responseJson($request, $result);
     }
     $to_jid = array();
     $chatjid = $request->get('jid');
     $to_jid[] = $chatjid;
     $groupid = $request->get('groupid');
     $msgid = $request->get('msgid');
     if (empty($chatjid) && empty($groupid)) {
         return $this->responseJson($request, Utils::WrapResultError('无效的撤回类型.'));
     }
     if (empty($msgid)) {
         return $this->responseJson($request, Utils::WrapResultError('无效的消息ID.'));
     }
     if (!empty($groupid)) {
         $groupMgr = new \Justsy\BaseBundle\Management\GroupMgr($da, $this->get("we_data_access_im"), $this->container);
         $to_jid = $groupMgr->getGroupMembersJidByIM($groupid);
         //群消息默认采用的发送时的iq ID。生成规则:Msgid =case QMsgid of []-> From#jid.luser++"-"++IQId; _-> QMsgid end,
         //生成消息ID
         $jid_user = explode('@', $staffdata['jid'])[0];
         $msgid = $jid_user . '-' . $msgid;
     }
     $msgtype = !empty($chatjid) ? 'chat' : 'group';
     $notice = array();
     $message = json_encode(Utils::WrapMessage('message_revoke', array('type' => $msgtype, 'msgid' => $msgid, 'sender' => array('nick_name' => $staffdata['nick_name'], 'photo' => $staffdata['photo_path'], 'jid' => $staffdata['jid'], 'sendtime' => date("Y-m-d H:i:s", time()))), $notice));
     $success = Utils::sendImMessage($staffdata['jid'], $to_jid, "message_revoke", $message, $this->container, "", "", false, Utils::$systemmessage_code);
     return $this->responseJson($request, Utils::WrapResultOK(''));
 }