Index.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\index\controller;
  3. use think\Controller;
  4. use think\Db;
  5. class Index extends Controller
  6. {
  7. protected $noNeedLogin = '*';
  8. protected $noNeedRight = '*';
  9. protected $layout = '';
  10. public function index()
  11. {
  12. exit;
  13. return $this->view->fetch();
  14. }
  15. public function mini_code()
  16. {
  17. $scene = 'kongjianyuyue';
  18. $page_url = 'pages/active/reserve';
  19. $value = config('wxMiniProgram');
  20. $appid = $value['appid'];
  21. $secret = $value['secret'];
  22. $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $secret;
  23. $res = file_get_contents($url);
  24. $token = json_decode($res, true)['access_token'];
  25. $URL = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' . $token;
  26. $data = [
  27. 'scene' => '1=1', //二维码传入参数
  28. 'page' => $page_url, //扫码后进入页面
  29. 'env_version' => 'trial', //要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。
  30. 'width' => 280, //二维码的宽度,单位 px,最小 280px,最大 1280px
  31. 'auto_color' => false, //自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调,默认 false
  32. 'is_hyaline' => false, //是否需要透明底色,为 true 时,生成透明底色的小程序
  33. 'check_path' => false,
  34. ];
  35. $json = json_encode($data); //数组加密
  36. //$result = $this->api_notice_increment($URL, $json); //用CURL 进行POST请求
  37. $result = curl_post($URL,$json);
  38. $path = ROOT_PATH . 'public/uploads/minicode'; //ROOT_PATH 我使用的是TP5框架
  39. $path2 = '/uploads/minicode';
  40. if (!file_exists($path)) { //判断目录是否存在
  41. mkdir($path, 0777, true);
  42. }
  43. $path = $path . '/' . $scene . '.png'; //最后要写入的目录及文件名
  44. $path2 = $path2 . '/' . $scene . '.png'; //最后要写入的目录及文件名
  45. file_put_contents($path, $result);
  46. $this->assign('mini_path',httpurllocal($path2));
  47. return $this->fetch('index');
  48. // echo '<html><body><img src="'.httpurllocal($path2).'"></body></html>';
  49. }
  50. //基础文章网页
  51. public function basedata(){
  52. $key = input('key','');
  53. if(!$key){
  54. exit;
  55. }
  56. $content = Db::name('basedata')->where('key',$key)->find();
  57. $this->assign('content',$content['content']);
  58. return $this->fetch();
  59. }
  60. }