public function media_get($media_id) { $access_token = $this->getAccessToken(); Logger::debug($access_token); $url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token={$access_token}&media_id=" . $media_id; $res = $this->httpGet($url); $file_path = "media/wechat/" . date("Ymdhis") . rand(10, 99) . rand(100, 999) . rand(1000, 9999) . ".jpg"; Model_Tools_Qiniu::upload_content($res, $file_path); $url = "http://" . PtConfig::$qiniu['domain'] . "/" . $file_path; Logger::debug($url); return $url; }
static function get_avatar($url) { try { $content = file_get_contents($url); if (!empty($content)) { $res = Model_Tools_Qiniu::upload_content($content, "wechat/avatar/" . md5($url)); $url = Model_Tools_Qiniu::get_res_url($res); } } catch (Exception $e) { self::_error(array(__METHOD__, "get_avatar error", $e->getMessage())); } return $url; }