Пример #1
0
 protected static function init($mongoServerKey = 0, $isMongoWrite = 0)
 {
     static $reconn = 0;
     static $faildServer = null;
     $mongoKey = self::$_mongoServerKey . $mongoServerKey . $isMongoWrite;
     if (empty(self::$mongo[$mongoKey])) {
         defined('MONGOCACHE_CONF_KEY') || define('MONGOCACHE_CONF_KEY', 'Mongo');
         $memConf = ZOL_Config::get(MONGOCACHE_CONF_KEY);
         if ($memConf) {
             self::$server = $memConf;
         }
         try {
             if ($mongoServerKey) {
                 if (self::$mongoDbArr[$mongoServerKey]) {
                     if ($isMongoWrite) {
                         self::$server = self::$mongoDbArr[$mongoServerKey]['wserver'];
                         self::$eserver = self::$mongoDbArr[$mongoServerKey]['wserver'];
                     } else {
                         self::$server = self::$mongoDbArr[$mongoServerKey]['server'];
                         self::$eserver = self::$mongoDbArr[$mongoServerKey]['eserver'];
                     }
                 }
             } else {
                 self::$server = 'localhost';
                 self::$eserver = 'mongo_server_zoldb';
                 //均衡服务器
             }
             if ($reconn == 0) {
                 $server = self::$server;
             } else {
                 $server = self::$eserver;
             }
             $server = 'mongodb://' . $server;
             self::$mongo[$mongoKey] = new Mongo($server, array('timeout' => self::$timeout, 'persist' => 'Product'));
         } catch (MongoException $e) {
             if (self::$mongo[$mongoKey]) {
                 self::$mongo[$mongoKey]->close();
             }
             self::$mongo[$mongoKey] = null;
             if ($reconn < 2) {
                 ++$reconn;
                 return self::init($mongoServerKey, $isMongoWrite);
             }
             ZOL_Log::write('异常1:' . $e->getMessage(), ZOL_Log::TYPE_ERROR);
             Plugin_Expires::setExpires(0);
             ZOL_Http::sendHeader(404);
             trigger_error($e->getMessage(), E_USER_WARNING);
             exit;
         }
     }
     $reconn = 0;
 }
Пример #2
0
 private function doPost(ZOL_Request $input, ZOL_Response $output)
 {
     $db = Db_Andyou::instance();
     $res = $output->data;
     if ($res) {
         $data = array();
         foreach ($res as $re) {
             $re["site"] = $output->sysName;
             $re["objId"] = $re["id"];
             unset($re["id"]);
             unset($re['rowTm']);
             $data[] = $re;
         }
         $jsonstr = base64_encode(api_json_encode($data));
         echo $jsonstr . "<hr/>";
         $token = md5($output->url . "AAFDFDF&RE3");
         $rtn = ZOL_Http::curlPost(array('url' => $output->yunUrl . "?" . $output->url . "&token={$token}", 'postdata' => "table={$output->table}&data={$jsonstr}", 'timeout' => 3));
         return $rtn;
     }
     return false;
 }
Пример #3
0
 /**
  * 得到标准图片
  */
 public static function getStandImg($imgurl, $size = '220x140')
 {
     $imgApi = "http://image.zol.com.cn/head/pic.php?imgUrl=" . $imgurl;
     //echo $imgApi,'<br>';
     $response = ZOL_Http::curlPage(array('url' => $imgApi));
     if ($response) {
         $response = json_decode($response, true);
         if ($size && isset($response[$size])) {
             return $response[$size];
         }
     }
     return '';
 }
Пример #4
0
 /**
  * 跳转到404
  */
 public static function JumpTo404()
 {
     ZOL_Http::send404Header();
     header("Location:/NoPage/");
     exit;
 }
Пример #5
0
 private function doPost(ZOL_Request $input, ZOL_Response $output)
 {
     $db = Db_Andyou::instance();
     $res = $output->data;
     if ($res) {
         $data = array();
         foreach ($res as $re) {
             $re["site"] = $output->sysName;
             //获得会员的信息
             if (in_array($output->table, array("log_scorechange", "log_cardchange"))) {
                 $minfo = Helper_Member::getMemberInfo(array("id" => $re["memberId"]));
                 $re["phone"] = $minfo["phone"];
             }
             if (in_array($output->table, array("bills"))) {
                 if (empty($re["phone"])) {
                     $minfo = Helper_Member::getMemberInfo(array("id" => $re["memberId"]));
                     $re["phone"] = $minfo["phone"];
                     $db->query("update {$output->table} set phone = '{$minfo["phone"]}' where memberId = {$re["memberId"]}");
                 }
             }
             $data[] = $re;
         }
         $jsonstr = base64_encode(api_json_encode($data));
         echo $jsonstr . "<hr/>";
         $token = md5($output->url . "AAFDFDF&RE3");
         $rtn = ZOL_Http::curlPost(array('url' => $output->yunUrl . "?" . $output->url . "&token={$token}", 'postdata' => "table={$output->table}&data={$jsonstr}", 'timeout' => 3));
         return $rtn;
     }
     return false;
 }
Пример #6
0
 /**
  * 获得 access_token  
  * 
  */
 public static function getAccessToken($paramArr)
 {
     $options = array('appId' => '', 'appSecret' => '', 'exp' => 0);
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     if (empty($appId) || empty($appSecret)) {
         return false;
     }
     $kvKey = "WeixinAccessToken_" . $appId;
     //首先尝试在KV中过得数据
     $token = API_Item_Kv_Db::get(array('key' => $kvKey));
     #var_dump($token);
     if ($token) {
         return $token;
     }
     //请求接口获得
     $jsonStr = ZOL_Http::curlPage(array('url' => "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appId}&secret={$appSecret}"));
     $jsonArr = array();
     if ($jsonStr) {
         $jsonArr = json_decode($jsonStr, true);
     }
     if (!empty($jsonArr['access_token'])) {
         $exp = $exp ? $exp : $jsonArr['expires_in'] - 100;
         $token = $jsonArr['access_token'];
         API_Item_Kv_Db::set(array('key' => $kvKey, 'val' => $token, 'life' => $exp));
         return $token;
     } else {
         return false;
     }
 }