123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- namespace Content\Lib;
- use Dever;
- class Base
- {
-
- protected $data;
- public function __construct()
- {
-
- $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']);
- }
-
- 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;
- }
-
- protected function replacePic($pic)
- {
- $pic = Dever::pic($pic);
- if (strstr($pic, 'http://')) {
-
- }
-
- return $pic;
- }
-
- protected function one($data)
- {
- $data = $this->handlePic($data);
- if (isset($data['pic']) && $data['pic']) {
- $data['pic'] = explode(',', $data['pic']);
- }
-
- $data['cdate'] = Dever::mdate($data['cdate'], 2);
- if (isset($data['author_id'])) {
- $data['author'] = $this->handlePic(Dever::load('set/author-one', $data['author_id']));
- }
-
- return $data;
- }
-
- protected function check_user()
- {
- $uid = Dever::input('uid');
- $session = Dever::input('session');
- $state = $this->check_session($uid, $session);
- if (!$state) {
- Dever::alert('请重新登录');
- }
- return $state;
- }
-
- protected function session($uid, $prefix = 'user')
- {
- $secret = md5($prefix . '_' . $uid . '_' . Dever::config('base')->secret);
- return $secret;
- }
-
- protected function check_session($uid, $session, $prefix = 'user')
- {
- $secret = $this->session($uid, $prefix);
- if ($secret != $session) {
- return false;
- }
- return true;
- }
-
- protected function type($type = 1)
- {
- $config = array
- (
- 1 => 'news',
- 2 => 'course',
- );
- return $config[$type];
- }
- }
|