IndexController.php 3.8 KB
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\portal\controller;

use app\admin\model\BabyModel;
use app\admin\model\SlideItemModel;
use cmf\controller\HomeBaseController;
use EasyWeChat\Foundation\Application;
use think\Cache;
use think\Db;

class IndexController extends HomeBaseController
{
    protected $abc;
    public function index()
    {
        // 生成页面二维码(用户推广)
        $url = url('index','','',true);
        $qrcode = $this->createQRcode($url,'Q',9);
        $name = '首页';
        $this->qrcodePage($url,$name,$qrcode);
        // 轮播图
        $slide_model = new SlideItemModel();
        $slide_where = [
            'slide_id' => 1,
            'status' => 1
        ];
        $slideList = $slide_model->where($slide_where)->order(['list_order'=>'ASC'])->select();
        $this->assign('slideList', $slideList);

        $this->nav_bottom(1,0,0);
//        $url = url('user/Register/index',['type'=>1,'']);
        return $this->fetch(':index');
    }

    // 视频详情页面
    public function detail() {
        if (cmf_is_user_login()) {
            if(!session('baby_age')) {
                $this->success("用户已登录",url('user/Login/chooseAge'),['user'=>cmf_get_current_user()]);
            } else {
                $id = $this->request->param('id',0,'intval');
                if(!$id) {
                    $this->error('参数错误');
                }
                $baby_model = new BabyModel();
                $where = [
                    'id' => $id
                ];
                $babyInfo = $baby_model->where($where)->find();
                $babyInfo['video_url'] = $this->change($babyInfo['video_url']);
                $this->assign('babyInfo',$babyInfo);
                return $this->fetch(':detail');
            }
        } else {
            $this->error("此用户未登录!",url('user/Login/index'));
        }
    }

    /**
     * 腾讯外链视频转换成video可识别视频
     * @param video 视频路径
     * @return 视频转换后路径
     */
    private function change($video) {
        $videoArray = explode('/',$video);
        $videoId = explode('.',$videoArray[count($videoArray)-1])[0];
        $url = "http://vv.video.qq.com/getinfo?vids=$videoId&platform=101001&charge=0&otype=json&defn=shd";
        $data = $this->curl($url);
        $data = substr($data,13,strlen($data)-14);
        $array = json_decode($data,true);
        if(!empty($array['msg'])) {
            $this->error('视频地址错误');
            return $array['msg'];
        }
        return $array['vl']['vi'][0]['ul']['ui'][0]['url']
            .$array['vl']['vi'][0]['fn']
            ."?vkey="
            .$array['vl']['vi'][0]['fvkey'];
    }

    public function test() {
        return $this->fetch(':test');
    }

    // 微信h5支付(测试)
    public function wxpayh5() {
        require_once VENDOR_PATH.'WxpayAPI/WxpayH5.php';
        $h5 = new \WxpayH5('wx8f31a4eb6d72f174','1512102931','kgAFbJx2MpAxQI2iJBTffrzFwxrnqE4h','2018092053101549',
            '测试支付','1','{"h5_info": {"type":"Wap","wap_url": "http://m.wanlin-edu.com","wap_name": "测试支付"}}' );
        $result = $h5->pay();
        var_dump($result);
        $mweb_url = '';
        if(!empty($result['mweb_url'])) {
            $mweb_url = $result['mweb_url'];
        }
        $this->assign('mwen_url',$mweb_url);
        return $this->fetch(':h5');
    }
}