Review.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Think.Admin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://think.ctolog.com
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/Think.Admin
  12. // +----------------------------------------------------------------------
  13. namespace app\wechat\controller;
  14. use service\FileService;
  15. use service\WechatService;
  16. use think\Controller;
  17. use think\Db;
  18. class Review extends Controller
  19. {
  20. /**
  21. * 显示手机预览
  22. * @return string
  23. */
  24. public function index()
  25. {
  26. $get = $this->request->get();
  27. $content = str_replace("\n", "<br>", $this->request->get('content', '')); // 内容
  28. $type = $this->request->get('type', 'text'); // 类型
  29. $this->assign('type', $type);
  30. // 图文处理
  31. if ($type === 'news' && is_numeric($content) && !empty($content)) {
  32. $news = WechatService::getNewsById($content);
  33. $this->assign('articles', $news['articles']);
  34. }
  35. // 文章预览
  36. if ($type === 'article' && is_numeric($content) && !empty($content)) {
  37. $article = Db::name('WechatNewsArticle')->where('id', $content)->find();
  38. if (!empty($article['content_source_url'])) {
  39. $this->redirect($article['content_source_url']);
  40. }
  41. $this->assign('vo', $article);
  42. }
  43. $this->assign($get);
  44. $this->assign('content', $content);
  45. // 渲染模板并显示
  46. return view();
  47. }
  48. /**
  49. * 微信图片显示
  50. */
  51. public function img()
  52. {
  53. $url = $this->request->get('url', '');
  54. $filename = FileService::getFileName($url, 'jpg', 'tmp/');
  55. if (false === ($img = FileService::getFileUrl($filename))) {
  56. $info = FileService::save($filename, file_get_contents($url));
  57. $img = (is_array($info) && isset($info['url'])) ? $info['url'] : $url;
  58. }
  59. $this->redirect($img);
  60. }
  61. }