LoginApi.php
2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* tpshop
* ============================================================================
* * 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* 微信交互类
*/
namespace app\mobile\controller;
use app\home\logic\UsersLogic;
use app\home\logic\CartLogic;
use think\Request;
class LoginApi extends MobileBase{
public $config;
public $oauth;
public $class_obj;
public function __construct(){
parent::__construct();
$this->oauth = I('get.oauth');
//获取配置
$data = M('Plugin')->where("code=:code and type = 'login' ")->bind(['code'=>$this->oauth])->find();
$this->config = unserialize($data['config_value']); // 配置反序列化
if(!$this->oauth)
$this->error('非法操作',U('Home/User/login'));
include_once "plugins/login/{$this->oauth}/{$this->oauth}.class.php";
$class = '\\'.$this->oauth; //
$login = new $class($this->config); //实例化对应的登陆插件
$this->class_obj = $login;
}
public function login(){
if(!$this->oauth)
$this->error('非法操作',U('Home/User/login'));
include_once "plugins/login/{$this->oauth}/{$this->oauth}.class.php";
$this->class_obj->login();
}
public function callback(){
$data = $this->class_obj->respon();
$logic = new UsersLogic();
$data = $logic->thirdLogin($data);
mlog(json_encode($data).microtime(),'loginapi');
if($data['status'] != 1) {
$this->error($data['msg']);
mlog($data['msg'].''.microtime(),'loginapi');
}
session('user',$data['result']);
mlog(json_encode(session('user')).microtime(),'loginapi');
// 登录后将购物车的商品的 user_id 改为当前登录的id
M('cart')->where("session_id", $this->session_id)->save(array('user_id'=>$data['result']['user_id']));
$cartLogic = new CartLogic();
$cartLogic->login_cart_handle($this->session_id,$data['result']['user_id']); //用户登录后 需要对购物车 一些操作
$this->success('登陆成功',U('Mobile/User/index'));
}
}