示例#1
0
 /**
  * Converter objetos em array.
  * 
  * @param type $var
  * @return type
  */
 public static function objectToArray($var)
 {
     $result = array();
     $references = array();
     // loop over elements/properties
     foreach ($var as $key => $value) {
         // recursively convert objects
         if (is_object($value) || is_array($value)) {
             // but prevent cycles
             if (!in_array($value, $references)) {
                 // Verificar se o valor é nulo. Não adiciona tuplas
                 // vazias ao json
                 if (!is_null($value) && !empty($value)) {
                     $result[$key] = JsonUtil::objectToArray($value);
                     $references[] = $value;
                 }
             }
         } else {
             // Verificar se o valor é nulo. Não adiciona tuplas
             // vazias ao json
             if (!is_null($value) && !empty($value)) {
                 // simple values are untouched
                 $result[$key] = utf8_encode($value);
             }
         }
     }
     return $result;
 }
 public function addValue($name, $value)
 {
     if (is_string($value)) {
         $value = JsonUtil::jsonString($value);
     }
     $this->data[$name] = new JsonValue($value);
 }
示例#3
0
 /**
  * 通过客服接口发送多条图文消息到多个人
  * $openid  
  * $articles  参考sendImageTextMsg
  */
 function sendMultiImageTextMsgToMultiUser($openidarr, $articles)
 {
     $news = array("articles" => $articles);
     foreach ($openidarr as $openid) {
         $data = JsonUtil::getJsonStrFromArray(array("touser" => $openid, "msgtype" => "news", "news" => $news));
         parent::sendMsgByService($data);
     }
 }
 /**
  * @param $kikaku_content
  * jsonの出力 / 配列に入ったものを結合 / やり方がおかしい
  * @return string
  * @throws Exception
  */
 protected function jsonOutput($kikaku_content)
 {
     $i = 0;
     $json_output = '[' . "\n";
     foreach ($kikaku_content as $key => $value) {
         /*仕上げ処理*/
         unset($this->kikaku_all[$key]->comment);
         //共通
         $this->kikaku_all[$key]->img_address = getImgUrl($this->kikaku_all[$key]->project_type, $this->kikaku_all[$key]->project_number);
         $i++;
         //カンマ挿入用にループ数をカウント
         $json_output .= json_encode($this->kikaku_all[$key]);
         if (!(count($kikaku_content) == $i)) {
             $json_output .= ",\n";
         }
         //最後の行にカンマを挿入しない
     }
     $json_output .= "\n" . ']';
     //必要か!?
     $json_util = new JsonUtil();
     return $json_util->jsonReFormat($json_output);
 }
示例#5
0
function reply()
{
    // msgid 是回复的目标消息id 对应表 的 replyid
    $msgid = $_POST["msgid"];
    if (empty($msgid)) {
        return;
    }
    $content = $_POST["content"];
    if (empty($content)) {
        return;
    }
    $openid = $_POST["createby"];
    if (empty($openid)) {
        return;
    }
    // 回复消息要做2件事
    // 1 调微信接口
    $paramContent = array();
    $contentTemp = array("content" => "管理员回复:\r\n" . $content);
    $paramContent = array("msgtype" => "text", "text" => $contentTemp);
    $data = JsonUtil::getJsonStrFromArray(array_merge($paramContent, array("touser" => $openid)));
    //LogUtil::logs("queryGroupUserAndReplyMsg data ====>".$data, getLogFile("/business.log"));
    $tp = new TypeParent();
    $response = $tp->sendMsgByService($data);
    if ($response["errcode"] == 0) {
        // 回复成功
        // 2 保存回复的消息
        $msgtype = "1";
        // 消息类型: 0表示用户发送  1表示管理员回复 2表示管理员群发消息 3 自动回复  4聊天室信息
        $status = "0";
        // 消息状态 :0: 消息发送成功  1: 发送中 2 发送失败, 保存成功 3 发送成功, 保存失败 4 表示这条信息是用户送的,并且已经得到回复
        $createtime = DateUtil::getCurrentTime();
        $createby = $_SESSION['cn_sysadmin']['user_id'];
        // 消息类型: 0表示用户发送  1表示管理员回复 2表示管理员群发消息 3 自动回复  4聊天室信息
        DBUtil::saveMsg($createby, $content, $createtime, $msgid, $msgtype, $status);
        // 原来设计是将状态改为4用来标识已回复,现在能查到回复内容,就取消这个方案了
        //		$sql = "update wx_user_msg set status = '4' where id ='$msgid'";
        //		DBUtil::updateMsg($sql);
    }
    showlist();
}
示例#6
0
 /**
 * 根据图片素材的id,拼装多图文素材
 * 	$mediaid  
 * 	$title  图文消息的标题  不可空
 		$sourceurl 阅读原文的链接 可空
 		$content 图文  的 文, 不可空
 		$digest 图片消息的描述, 可空
 		$showcoverpic 是否显示封面,1为显示,0为不显示 
 * 
 */
 public static function uploadmultipicmsg($articles)
 {
     $url = wxUploadPicMsg() . WxUtil::getWxTokenFromDB();
     //$articles[] = $article;
     $dataarr = array("articles" => $articles);
     $data = JsonUtil::getJsonStrFromArray($dataarr);
     //echo $data;
     $response = RequestUtil::httpPost($url, $data, 'post');
     return $response;
 }
示例#7
0
 public function newRef($node, $parent, $nodeindex, $nodename)
 {
     if (array_key_exists('$ref', $node)) {
         if (strspn($node['$ref'], '#') != 1) {
             $error = JsonUtil::uiMessage('jsonschema-badidref', $node['$ref']);
             throw new JsonSchemaException($error);
         }
         $idref = $node['$ref'];
         try {
             $node = $this->idtable[$idref];
         } catch (Exception $e) {
             $error = JsonUtil::uiMessage('jsonschema-badidref', $node['$ref']);
             throw new JsonSchemaException($error);
         }
     }
     return new TreeRef($node, $parent, $nodeindex, $nodename);
 }
示例#8
0
function initUser()
{
    $remoteTemp = WxUtil::getUserList();
    //echo print_r($remoteTemp);
    if (!empty($remoteTemp)) {
        $remoteUsers = $remoteTemp["data"];
        if (!empty($remoteUsers)) {
            global $db;
            $res = $db->query("SELECT openid FROM wx_user_info ");
            $rowList = $db->fetch_all($res);
            $user_info_list = array();
            // 每次最多查询100个用户
            $itemp = 0;
            $remoteOpenidArray = $remoteUsers["openid"];
            $openidArray = array();
            // 先过滤一遍
            foreach ($remoteOpenidArray as $openid) {
                if (!in_array(array("openid" => $openid), $rowList)) {
                    // 只取openid不在数据库中的
                    $openidArray[] = $openid;
                }
            }
            LogUtil::logs("微信总用户数: ====> " . count($openidArray), getLogFile("/business.log"));
            $saveTimes = 1;
            foreach ($openidArray as $openid) {
                if (!in_array(array("openid" => $openid), $rowList)) {
                    //echo $openid." is not in<br />";
                    // 组装一个信息
                    if ($itemp % 100 == 0) {
                        $user_to_query = array();
                    }
                    $toqueryuser = array("openid" => $openid, "lang" => "zh-CN");
                    $user_to_query[] = $toqueryuser;
                    //LogUtil::logs("itemp====> ".$itemp, getLogFile("/business.log"));
                    if (count($user_to_query) == 100 || $itemp == count($openidArray) - 1) {
                        // 每满100条,查询一次
                        LogUtil::logs("====> 第" . $saveTimes . "次发起微信查询", getLogFile("/business.log"));
                        $pdata = JsonUtil::getJsonStrFromArray(array("user_list" => $user_to_query));
                        $batchUserInfo = WxUtil::getBatchUserInfo($pdata);
                        if (empty($batchUserInfo)) {
                            // 先检查是否存在特殊字符
                        }
                        if (!empty($batchUserInfo)) {
                            $user_info_list = $batchUserInfo["user_info_list"];
                            transactionSave($user_info_list);
                            $countres = $db->query("SELECT count(1) as totalcount from wx_user_info a");
                            $countObj = $db->fetch($countres);
                            $nums = $countObj["totalcount"];
                            LogUtil::logs("已保存用户数 ====> " . $nums, getLogFile("/business.log"));
                        } else {
                            LogUtil::logs("====> 第" . $saveTimes . "次发起微信查询出错", getLogFile("/business.log"));
                            LogUtil::logs("查询的用户openid请求参数====> " . $pdata, getLogFile("/business.log"));
                            LogUtil::logs("查询的用户openid结果====>" . JsonUtil::getJsonStrFromArray($batchUserInfo), getLogFile("/business.log"));
                        }
                        $saveTimes++;
                    }
                    $itemp++;
                }
            }
            return "同步完成";
        }
    }
}
示例#9
0
<?php

//设置访问权限为所有域
header("Access-Control-Allow-Origin:*");
//设置默认时区
date_default_timezone_set("PRC");
include 'main.php';
//模块名称
$mod = $_REQUEST['mod'];
//动作名称
$action = $_REQUEST['action'];
//参数
$params = $_REQUEST['params'];
$jsonObj = json_decode($params);
$res = Main::call($mod, $action, $jsonObj);
echo JsonUtil::json_encode_cn($res);
示例#10
0
function echoRespnse($status_code, $response)
{
    $slim = \Slim\Slim::getInstance();
    // Http response code
    $slim->status($status_code);
    // setting response content type to json
    $slim->response()->header('Content-Type', 'application/json;charset=utf-8');
    // Chamada ao método estático para conversão de caracter UTF-8.
    // Tranforma o array ou objeto em JSON.
    echo json_encode(JsonUtil::objectToArray($response));
    //echo json_encode($response, JSON_HEX_QUOT | JSON_HEX_TAG);
    //echo json_encode($response, JSON_FORCE_OBJECT, true);
    //echo Zend_Json::encode($response);
    $slim->stop();
}
示例#11
0
 /**
  * 查到用户组里面的所有组员,再向其发送消息 
  */
 function queryGroupUserAndReplyMsg($userGroup, $postData)
 {
     global $db;
     // 发消息的人自己
     $userSelfOpenid = $postData["FromUserName"];
     $content = $postData["Content"];
     $createtime = DateUtil::getCurrentTime();
     // 用户发送的信息,要保存到数据库
     // 消息类型: 0表示用户发送  1表示管理员回复 2表示管理员群发消息 3 自动回复  4聊天室信息
     DBUtil::saveMsg($userSelfOpenid, $content, $createtime, "", "4", "0");
     // 查询所有的组员
     $arr = array();
     $userGroupId = $userGroup['groupid'];
     $nickname = $userGroup['nickname'];
     // TODO 这个$res可以缓存到文件中
     $res = $db->query("SELECT a.*, b.nickname, b.headimgurl FROM wx_group_user a left join wx_user_info b \r\n\t\t on a.openid = b.openid \r\n\t\t where a.groupid = '{$userGroupId}' and a.userisin = '0' ");
     $row = $db->fetch_all($res);
     //LogUtil::logs("用户组: ====>".print_r($row,true), getLogFile("/business.log"));
     foreach ($row as $val) {
         //LogUtil::logs("ppppppp ====>".print_r($val,true), getLogFile("/business.log"));
         // 循环每个人推送一条消息
         $openid = $val['openid'];
         if ($userSelfOpenid != $openid) {
             // 从组中除去发信息者自己
             $headimgurl = $val['headimgurl'];
             $contentTemp = array("content" => $nickname . "说:\r\n" . $content);
             $paramContent = array("touser" => $openid, "msgtype" => "text", "text" => $contentTemp);
             $data = JsonUtil::getJsonStrFromArray($paramContent);
             LogUtil::logs("queryGroupUserAndReplyMsg data ====>" . $data, getLogFile("/business.log"));
             parent::sendMsgByService($data);
         }
     }
     return getSuccessStr();
 }
示例#12
0
 /**
  * 查到用户组里面的所有组员,再向其发送消息 
  */
 function queryGroupUserAndReplyMsg($userGroupId, $postData)
 {
     global $db;
     // 发消息的人自己
     $userSelfOpenid = $postData["FromUserName"];
     $content = $postData["Content"];
     $createtime = DateUtil::getCurrentTime();
     $mediaid = $postData["MediaId"];
     // 用户发送的信息,要保存到数据库
     // 消息类型: 0表示用户发送  1表示管理员回复 2表示管理员群发消息 3 自动回复  4聊天室信息
     DBUtil::saveMsg($userSelfOpenid, "图片消息", $createtime, "", "4", "0");
     // 查询所有的组员
     $arr = array();
     // TODO 这个$res可以缓存到文件中
     $res = $db->query("SELECT * FROM wx_group_user where groupid = '{$userGroupId}' and userisin = '0' ");
     $row = $db->fetch_all($res);
     foreach ($row as $val) {
         // 循环每个人推送一条消息
         $openid = $val['openid'];
         // 从组中除去发信息者自己
         if ($userSelfOpenid != $openid) {
             // 拼接
             /*{
             		    "touser":"******",
             		    "msgtype":"image",
             		    "image":
             		    {
             		      "media_id":"MEDIA_ID"
             		    }
             		}*/
             $paramContent = array("touser" => $openid, "msgtype" => "image", "image" => array("media_id" => $mediaid));
             $data = JsonUtil::getJsonStrFromArray($paramContent);
             LogUtil::logs("queryGroupUserAndReplyMsg data ====>" . $data, getLogFile("/business.log"));
             parent::sendMsgByService($data);
         }
     }
     return getSuccessStr();
 }
示例#13
0
<?php

/*********** Includes ***********/
include_once "../dao/acceso.php";
include_once "../utils/json.php";
include_once "../models/acceso.php";
include_once "../utils/session.php";
if (isset($_REQUEST["password"]) and isset($_REQUEST["user"])) {
    $pass = $_REQUEST["password"];
    $user = $_REQUEST["user"];
    $oAccess = new AccesoDAO();
    $access = $oAccess->sendCredentials($pass, $user);
    $oJson = new JsonUtil();
    if ($access != false) {
        /*Json parse*/
        $json_access = $oJson->getJsonData($access, false);
        $jsonDecode = (array) json_decode($json_access);
        $accesoDecode = (array) $jsonDecode['data'][0];
        /*Store model acceso*/
        $oAccModel = new accesoModel();
        $oAccModel->setUser($user);
        $oAccModel->setName($accesoDecode["acc_name"]);
        /*Store my session acceso*/
        $oSession = new sessionUtil("acceso");
        $oSession->storeMySession(serialize($oAccModel));
    } else {
        $json_access = $oJson->getJson($oAccess->getMessage());
    }
    echo $json_access;
} else {
    //        echo "ok";
示例#14
0
 /**
  * 图文消息推送预览接口
  */
 public function batchSendPicMsgYulan($openidarr, $mediaid)
 {
     $yulanurl = "https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token=";
     $data = array("touser" => $openidarr, "mpnews" => array("media_id" => $mediaid), "msgtype" => "mpnews");
     $datastr = JsonUtil::getJsonStrFromArray($data);
     //echo print_r($datastr);
     $url = $yulanurl . WxUtil::getWxTokenFromDB();
     $response = RequestUtil::httpPost($url, $datastr, 'post');
     if ($response['errcode'] == 0) {
         return "图文消息群发成功";
     }
     return $respArr["errcode"] . ":" . $respArr["errmsg"];
 }