Index.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 首页接口
  7. */
  8. class Index extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. public function index()
  13. {
  14. $this->success();
  15. }
  16. private function mini_code($scene, $page_url, $introcode)
  17. {
  18. $value = config('wxMiniProgram');
  19. $appid = $value['appid'];
  20. $secret = $value['secret'];
  21. $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $secret;
  22. $res = file_get_contents($url);
  23. $token = json_decode($res, true)['access_token'];
  24. $URL = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' . $token;
  25. $data = [
  26. 'scene' => 'introcode='.$introcode, //二维码传入参数
  27. 'page' => $page_url, //扫码后进入页面
  28. 'env_version' => 'release', //要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。
  29. 'width' => 280, //二维码的宽度,单位 px,最小 280px,最大 1280px
  30. 'auto_color' => false, //自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调,默认 false
  31. 'is_hyaline' => false, //是否需要透明底色,为 true 时,生成透明底色的小程序
  32. 'check_path' => false,
  33. ];
  34. $json = json_encode($data); //数组加密
  35. //$result = $this->api_notice_increment($URL, $json); //用CURL 进行POST请求
  36. $result = curl_post($URL,$json);
  37. $path = ROOT_PATH . 'public/uploads/minicode'; //ROOT_PATH 我使用的是TP5框架
  38. $path2 = '/uploads/minicode';
  39. if (!file_exists($path)) { //判断目录是否存在
  40. mkdir($path, 0777, true);
  41. }
  42. $path = $path . '/' . $scene . '.png'; //最后要写入的目录及文件名
  43. $path2 = $path2 . '/' . $scene . '.png'; //最后要写入的目录及文件名
  44. file_put_contents($path, $result);
  45. return $path2;
  46. }
  47. //生成视频分享海报
  48. public function shareposter() {
  49. // if($this->auth->group_id != 2){$this->error('你是不是来错地方了?');}
  50. $inviteimage = $this->mini_code($this->auth->id,'pages/index/index',$this->auth->username);
  51. echo httpurllocal($inviteimage);//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  52. }
  53. /**
  54. * 首页
  55. */
  56. public function home(){
  57. //
  58. $home = Db::name('home')->order('id asc')->select();
  59. $home = list_domain_image($home,['image','remark_image']);
  60. $home_top = [];
  61. $home_button = [];
  62. foreach ($home as $k => $v){
  63. if($v['category'] == 1){
  64. $home_top[] = $v;
  65. }else{
  66. $home_button[] = $v;
  67. }
  68. }
  69. $zhengwu = Db::name('zhengwufuwu')->where('status',1)->order('weigh','desc')->select();
  70. $gonggao = Db::name('message_sys')->field('id,title,info,updatetime')->order('weigh','desc')->find();
  71. $zhengce = Db::name('zhengcejiedu')->field('id,title,image,audio_file,video_file,updatetime')->order('weigh','desc')->find();
  72. $zhengce = info_domain_image($zhengce,['image','audio_file','video_file']);
  73. //
  74. $result = [
  75. 'index_logo' => localpath_to_netpath(config('site.index_logo')),
  76. 'index_title' => config('site.index_title'),
  77. 'index_title_info' => config('site.index_title_info'),
  78. 'ysszd_logo' => localpath_to_netpath(config('site.ysszd_logo')),
  79. 'ysszd_title' => config('site.ysszd_title'),
  80. 'ysszd_title_info' => config('site.ysszd_title_info'),
  81. 'ysszd_icon' => localpath_to_netpath(config('site.ysszd_icon')),
  82. 'ysszd_url' => config('site.ysszd_url'),
  83. 'home_top' => $home_top,
  84. 'home_button' => $home_button,
  85. 'zhengwu' => $zhengwu,
  86. 'gonggao' => $gonggao,
  87. 'zhengce' => $zhengce,
  88. ];
  89. $this->success(1,$result);
  90. }
  91. //便民页
  92. public function bianmin(){
  93. $cate = Db::name('bianmin_category')->order('id', 'asc')->select();
  94. $bianmin = Db::name('bianmin')->order('id', 'asc')->select();
  95. $bianmin = list_domain_image($bianmin, ['image','remark_image']);
  96. foreach ($cate as $key => $item) {
  97. foreach ($bianmin as $value) {
  98. if($item['id'] == $value['category_id']){
  99. $cate[$key]['child'][] = $value;
  100. }
  101. }
  102. }
  103. $rs = [
  104. 'index_logo' => localpath_to_netpath(config('site.index_logo')),
  105. 'index_title' => config('site.index_title'),
  106. 'index_title_info' => config('site.index_title_info'),
  107. 'bianmin' => $cate,
  108. ];
  109. $this->success(1,$rs);
  110. }
  111. }