...
|
...
|
@@ -10,6 +10,47 @@ use think\Db; |
|
|
class ActivityController extends HomeBaseController
|
|
|
{
|
|
|
|
|
|
function _initialize()
|
|
|
{
|
|
|
parent::_initialize(); // TODO: Change the autogenerated stub
|
|
|
if (cmf_is_wechat()) {
|
|
|
if (empty(session('user.id'))) {
|
|
|
require_once EXTEND_PATH . '/WeChatCommon.php';
|
|
|
$wx = new \WeChatCommon();
|
|
|
if (request()->param('code') == NULL) {
|
|
|
$wx->code();
|
|
|
} else {
|
|
|
$code = request()->param('code');
|
|
|
$info = $wx->getOpenid($code);
|
|
|
if(Db::name('user')->where(['openid'=>$info['openid']])->count() == 0) {
|
|
|
//注册新用户
|
|
|
//拉去用户信息
|
|
|
$return = $wx->getUserInfo($info);
|
|
|
$data = [
|
|
|
'user_type' => 2,
|
|
|
'create_time' => time(),
|
|
|
'user_nickname' => $return['nickname'],
|
|
|
'sex' => $return['sex'],
|
|
|
'avatar' => $return['headimgurl'],
|
|
|
'openid' => $info['openid']
|
|
|
];
|
|
|
if(Db::name('user')->insert($data)) {
|
|
|
$userId = Db::name('user')->getLastInsID();
|
|
|
session('user.id', $userId);
|
|
|
session('user.openid', $info['openid']);
|
|
|
}
|
|
|
}else {
|
|
|
$userId = Db::name('user')->where(['openid'=>$info['openid']])->value('id');
|
|
|
session('user.id', $userId);
|
|
|
session('user.openid', $info['openid']);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}else {
|
|
|
//$this->error('请从微信浏览器打开');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @title 活动列表
|
|
|
* @description 默认访问接口
|
...
|
...
|
|