예제 #1
0
 private function downloadPic()
 {
     interface_log(DEBUG, 0, microtime(true));
     $picData = doCurlGetRequest($this->_url);
     //向文件中写数据
     $fileName = $this->_fromUserName . "_" . time() . ".jpg";
     file_put_contents(ROOT_PATH . "/ff_image/" . $fileName, $picData);
     interface_log(DEBUG, 0, "end download " . microtime(true));
     return $fileName;
 }
예제 #2
0
파일: faceStub.php 프로젝트: bsdcfp/wxmp
 private static function requestToFace($interface, $data)
 {
     $data = array_merge($data, array('api_key' => API_KEY, 'api_secret' => API_SECRET));
     interface_log(DEBUG, 0, "url: " . FACE_URL . $interface . "\ndata:" . var_export($data, true));
     $json = doCurlGetRequest(FACE_URL . $interface, $data, FACE_TIMEOUT);
     interface_log(DEBUG, 0, 'response:' . $json);
     $data = json_decode($json, true);
     if (!$data || $data['error_code']) {
         return false;
     } else {
         return $data;
     }
 }
예제 #3
0
파일: tokenStub.php 프로젝트: bsdcfp/wxmp
 public static function getToken($force = false)
 {
     try {
         $STO = new SingleTableOperation();
         $STO->setTableName("ctoken");
         if ($force == false) {
             $ret = $STO->getObject();
             interface_log(DEBUG, 0, "token data get from ctoken: " . json_encode($ret));
             if (count($ret) == 1) {
                 $token = $ret[0]['token'];
                 $expire = $ret[0]['expire'];
                 $addTimestamp = $ret[0]['addTimestamp'];
                 $current = time();
                 if ($addTimestamp + $expire + 30 < $current) {
                     return $token;
                 }
             }
         }
         $para = array("grant_type" => "client_credential", "appid" => WX_API_APPID, "secret" => WX_API_APPSECRET);
         $url = WX_API_URL . "token";
         interface_log(DEBUG, 0, "url:" . $url . "  req data:" . json_encode($para));
         $ret = doCurlGetRequest($url, $para);
         interface_log(DEBUG, 0, "response data:" . $ret);
         $retData = json_decode($ret, true);
         if (!$retData || $retData['errcode']) {
             interface_log(ERROR, EC_OTHER, "requst wx to get token error");
             return false;
         }
         //从返回数据中获取得到的access_token和它的过期时间,更新ctoken表
         $token = $retData['access_token'];
         $expire = $retData['expires_in'];
         $STO->delObject();
         $STO->addObject(array('token' => $token, "expire" => $expire, "addTimestamp" => time()));
         return $token;
     } catch (DB_Exception $e) {
         interface_log(ERROR, EC_DB_OP_EXCEPTION, "operate ctoken error! msg:" . $e->getMessage());
         return false;
     }
 }