memberconnectfun.php
3.96 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
//驗證登錄方式
function MemberConnect_CheckApptype($apptype){
global $empire,$dbtbpre;
$appr=$empire->fetch1("select * from {$dbtbpre}enewsmember_connect_app where apptype='$apptype' and isclose=0 limit 1");
if(!$appr['id'])
{
printerror2('請選擇登錄方式','../../../');
}
return $appr;
}
//驗證openid
function MemberConnect_CheckOpenid($apptype,$openid){
global $empire,$dbtbpre;
$mcr['id']=0;
$mcr['userid']=0;
if(!$apptype||!trim($openid))
{
return $mcr;
}
$mcr=$empire->fetch1("select id,userid from {$dbtbpre}enewsmember_connect where apptype='$apptype' and bindkey='$openid' limit 1");
return $mcr;
}
//處理登錄
function MemberConnect_DoLogin($apptype,$openid){
global $empire,$dbtbpre;
$apptype=RepPostVar($apptype);
$openid=RepPostVar($openid);
$mcr=MemberConnect_CheckOpenid($apptype,$openid);
if($mcr['id'])
{
$lifetime=0;
$r=$empire->fetch1("select ".eReturnSelectMemberF('*')." from ".eReturnMemberTable()." where ".egetmf('userid')."='".$mcr['userid']."' limit 1");
DoEcmsMemberLogin($r,$lifetime);
MemberConnect_UpdateBindLogin($mcr['id']);
MemberConnect_ResetVar();
printerrortourl('../../../');
}
else
{
printerrortourl('../tobind.php');
}
}
//更新登錄綁定
function MemberConnect_UpdateBindLogin($id){
global $empire,$dbtbpre;
$id=(int)$id;
$lasttime=time();
$empire->query("update {$dbtbpre}enewsmember_connect set loginnum=loginnum+1,lasttime='$lasttime' where id='$id' limit 1");
}
//寫入登陸綁定
function MemberConnect_InsertBind($apptype,$openid,$userid){
global $empire,$dbtbpre;
$apptype=RepPostVar($apptype);
$openid=RepPostVar($openid);
$userid=(int)$userid;
$time=time();
//驗證是否重複
MemberConnect_CheckReBind($apptype,$userid);
$empire->query("insert into {$dbtbpre}enewsmember_connect(userid,apptype,bindkey,bindtime,loginnum,lasttime) values('$userid','$apptype','$openid','$time',1,'$time');");
}
//驗證是否綁定過
function MemberConnect_CheckReBind($apptype,$userid){
global $empire,$dbtbpre;
$num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsmember_connect where userid='$userid' and apptype='$apptype' limit 1");
if($num)
{
printerror2("此帳號已綁定過,不能重複綁定","history.go(-1)");
}
}
//刪除登陸綁定
function MemberConnect_DelBind($id){
global $empire,$dbtbpre,$public_r;
$user_r=islogin();//是否登陸
$id=(int)$id;
$sql=$empire->query("delete from {$dbtbpre}enewsmember_connect where id='$id' and userid='$user_r[userid]';");
if($sql)
{
printerror2("已解除綁定","../memberconnect/ListBind.php");
}
else
{
printerror("DbError","history.go(-1)",1);
}
}
//原帳號綁定登錄
function MemberConnect_BindUser($userid){
global $empire,$dbtbpre,$public_r;
$apptype=RepPostVar($_SESSION['apptype']);
$openid=RepPostVar($_SESSION['openid']);
if(!trim($apptype)||!trim($openid))
{
printerror2('來自的鏈接不存在','../../../');
}
$appr=MemberConnect_CheckApptype($apptype);//驗證登錄方式
MemberConnect_CheckBindKey($apptype,$openid);
MemberConnect_InsertBind($apptype,$openid,$userid);
MemberConnect_ResetVar();
}
//綁定驗證符
function MemberConnect_GetBindKey($apptype,$openid){
global $ecms_config;
$checkpass=md5(md5('check-'.$apptype.'-empirecms-'.$openid).'-#empire.cms!-'.$openid.'-|-empirecms-|-'.$ecms_config['cks']['ckrndtwo']);
return $checkpass;
}
//驗證綁定驗證符
function MemberConnect_CheckBindKey($apptype,$openid){
global $ecms_config;
$pass=md5(md5('check-'.$apptype.'-empirecms-'.$openid).'-#empire.cms!-'.$openid.'-|-empirecms-|-'.$ecms_config['cks']['ckrndtwo']);
$checkpass=$_SESSION['openidkey'];
if($pass!=$checkpass)
{
printerror2('來自的鏈接不存在','../../../');
}
}
//重置變量
function MemberConnect_ResetVar(){
$_SESSION['state']='';
$_SESSION['openid']='';
$_SESSION['apptype']='';
$_SESSION['openidkey']='';
}
?>