request->get(); // 内容 $content = $this->request->get('content', ''); $this->assign('content', $content); // 类型 $type = $this->request->get('type', 'text'); $this->assign('type', $type); // 图文处理 if ($type === 'news' && is_numeric($content) && !empty($content)) { $news = News::get($content, ['appid' => $this->real_appid]); $this->assign('articles', $news['articles']); } // 文章预览 if ($type === 'article' && is_numeric($content) && !empty($content)) { $article = Db::name('WechatNewsArticle')->where('id', $content)->find(); $this->assign('vo', $article); } $this->assign($get); // 渲染模板并显示 return view(); } /** * 微信图片显示 */ public function wechatImage() { $url = input('get.url', ''); $filename = 'upload/tmp/' . join('/', str_split(md5($url), 16)); $realfile = ROOT_PATH . 'public/' . $filename; file_exists(dirname($realfile)) || mkdir(dirname($realfile), 0755, true); if (!file_exists($realfile)) { file_put_contents($realfile, file_get_contents($url)); } $this->redirect(pathinfo($this->requestbaseFile(true), PATHINFO_DIRNAME) . '/' . $filename); } }