1
0
Files
2020-08-06 14:58:51 +08:00

152 lines
4.3 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 app\mobile\controller;
use app\common\service\MemberInfo;
use app\common\service\Score as ScoreService;
use cjango\Wechat\Token;
use think\Cache;
use think\Config;
use tools\Initialize;
use tools\Str;
class _Init extends Initialize
{
public function _initialize()
{
define('UID', self::isLogin());
if (!UID) {
//判断跳转。文章、每日分享、事业介绍详情页,个人资料页面不跳转
self::T();
// $this->redirect('login/wxLogin', 'callback=' . base64_encode(__SELF__));
}
$uid = $this->request->get('uid');
if ($uid) {
$this->shareUser = MemberInfo::show($uid);
}
//分享初始化
self::fenxiang();
}
/**
* 跳转
*/
public function T()
{
$data = [
'Login/index',
'Login/reg',
'Login/autoLogin',
'Login/info',
'Cause/detail',
'Share/detail',
'Article/show',
'Index/info',
'Index/index',
'Help/directdetail',
'Help/detail',
'Invite/index',
'Qrcode/index',
];
$url = CONTROLLER_NAME . '/' . ACTION_NAME;
if (!in_array($url, $data) || (!UID && !$this->request->get('uid'))) {
if (IS_AJAX) {
return $this->error('操作失败', url('login/index'));
} else {
$this->redirect('login/index');
}
}
}
/**
* 分享文章获取积分
*/
public function ShareArticle()
{
if (!empty($this->shareUser->uid) && $this->shareUser->uid != UID) {
ScoreService::share($this->shareUser->uid);
}
}
/**
* 操作成功跳转的快捷方法
* @access protected
* @param mixed $msg 提示信息
* @param string $url 跳转的URL地址
* @param mixed $data 返回的数据
* @param integer $wait 跳转等待时间
* @param array $header 发送的Header信息
* @return void
*/
protected function success($msg = '', $url = null, $data = '', $wait = 3, array $header = [])
{
$msg = $msg ?: '操作成功';
return parent::success($msg, $url, $data, $wait, $header);
}
/**
* 操作错误跳转的快捷方法
* @access protected
* @param mixed $msg 提示信息
* @param string $url 跳转的URL地址
* @param mixed $data 返回的数据
* @param integer $wait 跳转等待时间
* @param array $header 发送的Header信息
* @return void
*/
protected function error($msg = '', $url = null, $data = '', $wait = 3, array $header = [])
{
$msg = $msg ?: '未知错误';
return parent::error($msg, $url, $data, $wait, $header);
}
protected function back($result)
{
if ($result === true) {
return $this->success();
} else {
return $this->error($result);
}
}
/**
* 微信分享
* @return [type] [description]
*/
public function fenxiang()
{
parent::initWechat();
// 微信分享
$ticket = Cache::get('Wechat_ticket');
$config = Config::get('wechat');
if (!$ticket) {
$ticket = Token::ticket();
Cache::set('Wechat_ticket', $ticket, 7000);
}
$wx['appid'] = $config['appid'];
$wx['timestamp'] = time();
$wx['noncestr'] = $noncestr = Str::random(32);
$sign = array(
'noncestr' => $noncestr,
'jsapi_ticket' => $ticket,
'timestamp' => time(),
'url' => __SELF__,
);
ksort($sign);
$signStr = sha1(urldecode(http_build_query($sign)));
$wx['signature'] = $signStr;
$this->assign('wx', $wx);
}
}