Files
tuiguangzhushou/extend/tools/Initialize.php
2020-08-06 15:26:41 +08:00

107 lines
2.9 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace tools;
use app\common\service\Wechat as WechatService;
use think\Controller;
use think\Session;
/**
* 所有模块的公共方法
*/
class Initialize extends Controller
{
/**
* 判断是否登录返回当前UID
* @return integer
*/
final protected static function isLogin()
{
$user = Session::get('user_auth');
if (empty($user)) {
return 0;
} else {
return Session::get('user_auth_sign') == Crypt::dataAuthSign($user) ? $user['uid'] : 0;
}
}
/**
* 初始化微信
* @return void
*/
final protected function initWechat()
{
WechatService::instance();
// $token = Cache::get('wechat_access_token');
// $config = Config::get('wechat');
// if (!$token) {
// Wechat::instance($config);
// $token = Token::get();
// Cache::set('wechat_access_token', $token, 7200);
// $config['access_token'] = $token;
// Wechat::instance($config, true);
// } else {
// $config['access_token'] = $token;
// Wechat::instance($config);
// }
}
/**
* 微信分享
*/
protected function jsWechat()
{
$wx = WechatService::jsWechat();
// $ticket = Cache::get('Wechat_ticket');
// $config = Config::get('wechat_config');
// self::initWechat();
// if (!$ticket) {
// $ticket = Token::ticket();
// Cache::set('Wechat_ticket', $ticket, 7000);
// }
// $now_time = time();
// $wx['appid'] = $config['appid'];
// $wx['timestamp'] = $now_time;
// $wx['noncestr'] = $noncestr = \tools\Str::random(32);
// $sign = array(
// 'noncestr' => $noncestr,
// 'jsapi_ticket' => $ticket,
// 'timestamp' => $now_time,
// 'url' => __SELF__,
// );
// ksort($sign);
// $signStr = sha1(urldecode(http_build_query($sign)));
// $wx['signature'] = $signStr;
return $wx;
}
/**
* 模板变量赋值
* @param string $name 变量名
* @param mixed $value 变量值
*/
final public function __set($name, $value)
{
$this->view->$name = $value;
}
/**
* 取得模板显示变量的值
* @param string $name 模板变量
* @return mixed|null
*/
final public function __get($name)
{
return $this->view->$name ?? null;
}
}