Index.php 4.7 KB

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