Esempio n. 1
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));
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 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));
 }