示例#1
0
 /**
  * 更新会员的增量信息
  */
 public function doUpNew(ZOL_Request $input, ZOL_Response $output)
 {
     set_time_limit(600);
     error_reporting(E_ALL);
     ini_set("display_errors", 1);
     $db = Db_Andyou::instance();
     $onlyGetFromYun = (int) $input->get("onlyGetFromYun");
     //是否仅更新云端数据
     $allData = (int) $input->get("allData");
     //是否获得所有数据
     //------------------------------------
     //将本地最新添加或者修改的会员同步到远端
     //------------------------------------
     //获取一个同步的时间
     $sql = "select tm from log_yunrsync where name = 'memberinfo_up'";
     $lastUpTm = (int) $db->getOne($sql);
     if ($lastUpTm > 0) {
         $lastUpTm = $lastUpTm - 1;
     }
     if ($allData) {
         $lastUpTm = 0;
     }
     if (!$onlyGetFromYun) {
         //是否仅仅获得远端数据
         //获得最新添加、修改的会员
         $sql = "select id,name,phone,cardno,cateId,byear,bmonth,bday,addTm,remark,introducer,introducerId,allsum,upTm " . " from member where (addTm > {$lastUpTm} or upTm > {$lastUpTm} or rsync = 0) limit 1000";
         $res = $db->getAll($sql);
         $data = array();
         if ($res) {
             foreach ($res as $re) {
                 $re["site"] = $output->sysName;
                 $re["siteObjId"] = $re["id"];
                 $data[] = $re;
             }
         }
         $jsonstr = base64_encode(api_json_encode($data));
         $token = md5("c=Rsync_Member&a=UpNew" . "AAFDFDF&RE3");
         $rtnJson = ZOL_Http::curlPost(array('url' => $output->yunUrl . "?c=Rsync_Member&a=UpNew&token={$token}", 'postdata' => "data={$jsonstr}", 'timeout' => 3));
         #设置同步状态
         $okIdArr = json_decode($rtnJson);
         if ($okIdArr && is_array($okIdArr)) {
             foreach ($okIdArr as $id) {
                 echo "{$id} OK<br/>";
                 $db->query("update member set rsync = 1 where id = {$id} ");
             }
         }
     }
     //获得云端最新的数据
     $urlPart = "c=Rsync_Member&a=GetNew&tm=" . $lastUpTm;
     $token = md5($urlPart . "AAFDFDF&RE3");
     $url = $output->yunUrl . "?{$urlPart}&token={$token}";
     $html = ZOL_Http::curlPage(array('url' => $url, 'timeout' => 30));
     if ($html) {
         $data = api_json_decode($html);
         if ($data) {
             foreach ($data as $d) {
                 $phone = $d["phone"];
                 $sql = "select * from member where phone = '{$phone}' limit 1 ";
                 $info = $db->getRow($sql);
                 if (!$info) {
                     //如果不存在就插入到云端
                     unset($d["id"]);
                     $item = $d;
                     Helper_Dao::insertItem(array('addItem' => $item, 'dbName' => "Db_Andyou", 'tblName' => "member"));
                 } else {
                     #如果云端已经存在了
                     if ($info["upTm"] < $d["upTm"]) {
                         //云端的更新时间比较老
                         $item = array('name' => $d["name"], 'cardno' => $d["cardno"], 'cateId' => $d["cateId"], 'byear' => $d["byear"], 'bmonth' => $d["bmonth"], 'bday' => $d["bday"], 'remark' => $d["remark"], 'score' => $d["score"], 'balance' => $d["balance"], 'allsum' => $d["allsum"], 'introducer' => $d["introducer"], 'introducerId' => $d["introducerId"], 'upTm' => $d["upTm"]);
                         Helper_Dao::updateItem(array('editItem' => $item, 'dbName' => "Db_Andyou", 'tblName' => "member", 'where' => "phone = '{$phone}'"));
                     }
                 }
             }
         }
         if (!$onlyGetFromYun) {
             //是否仅仅获得远端数据
             $db->query("delete from log_yunrsync where name = 'memberinfo_up'");
             $db->query("insert into log_yunrsync(name,tm) values('memberinfo_up'," . SYSTEM_TIME . ")");
         }
     }
     echo "OK";
     exit;
 }
示例#2
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 '';
 }
示例#3
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;
     }
 }