| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 | <?phpnamespace Content\Lib;use Dever;class Base{    # 定义返回数据    protected $data;    public function __construct($state = 1)    {        if ($state == 2) {            return;        }        # 获取小程序id        $id = Dever::input('appid');        if (!$id || $id < 0) {            Dever::alert('错误的小程序id');        }        # 获取小程序基本信息        $this->data['info'] = Dever::load('set/info-one', $id);        if (!$this->data['info']) {            Dever::alert('小程序信息不存在');        }        $this->data['info'] = $this->handlePic($this->data['info']);    }    /**     * 替换所有图片地址为https     *     * @return mixed     */    protected function handlePic($data)    {        $config = array        (            'pic', 'content', 'logo', 'top'        );        foreach ($config as $k => $v) {            if (isset($data[$v]) && $data[$v]) {                $data[$v] = $this->replacePic($data[$v]);            }        }        return $data;    }    /**     * 替换所有图片地址为https     *     * @return mixed     */    protected function replacePic($pic)    {        $pic = Dever::pic($pic);        if (strstr($pic, 'http://')) {            $pic = str_replace('http://', 'https://', $pic);        }                return $pic;    }    /**     * 将数据中的图片地址进行替换     *     * @return mixed     */    protected function one($data, $state = 1)    {        $data = $this->handlePic($data);        if ($state == 2 && isset($data['pic']) && $data['pic']) {            //$data['pic'] = explode(',', $data['pic']);        }        if (isset($data['video']) && $data['video']) {            $data['video'] = Dever::load('content/v1/video.mp4', $data['video']);        }        if (isset($data['sdate']) && $data['sdate']) {            $data['sdate'] = date('m/d', $data['sdate']);        }        if (isset($data['edate']) && $data['edate']) {            $data['edate'] = date('m/d', $data['edate']);        }        $data['cdate'] = date('Y-m-d', $data['cdate']);        //$data['cdate'] = Dever::mdate($data['cdate'], 2);        if (isset($data['author_id'])) {            $data['author'] = $this->handlePic(Dever::load('set/author-one', $data['author_id']));            //$data['author']['cdate'] = date('Y.m.d', $data['author']['cdate']);            $data['author']['cdate'] = $data['cdate'];        }                return $data;    }    /**     * 验证用户     *     * @return mixed     */    protected function check_user()    {        $uid = Dever::input('uid');        $session = Dever::input('session');        $state = $this->check_session($uid, $session);        if (!$state) {            Dever::alert('请重新登录');        }        return $state;    }    /**     * 生成登录session串 先做个简单的吧     *     * @return mixed     */    protected function session($uid, $prefix = 'user')    {        $secret = md5($prefix . '_' . $uid . '_' . Dever::config('base')->secret);        return $secret;    }    /**     * 验证登录session串     *     * @return mixed     */    protected function check_session($uid, $session, $prefix = 'user')    {        $secret = $this->session($uid, $prefix);        if ($secret != $session) {            return false;        }        return true;    }    /**     * 获取对应的类型     *     * @return mixed     */    public function type($type = 1)    {        $config = array        (            1 => 'content/news',            2 => 'content/course',            3 => 'content/meeting',            4 => 'comment/review',        );        return $config[$type];    }}
 |