Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sunac-quanmin
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
HTML5-李恒逸
sunac-quanmin
Commits
7c3fe360
Commit
7c3fe360
authored
Jul 03, 2017
by
HTML5-侯张振
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
微信登陆验证
parent
4c1ed4f3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
124 additions
and
0 deletions
+124
-0
weixin.php
html/application/controllers/distributor/weixin.php
+124
-0
No files found.
html/application/controllers/distributor/weixin.php
0 → 100644
View file @
7c3fe360
<?php
/**
* 微信快速登陆
* Class Controller_Index
*/
class
Controller_Index
extends
Stourweb_Controller
{
private
$_api
;
private
$_conf
=
null
;
//初始化设置
public
function
before
()
{
parent
::
before
();
$this
->
_conf
();
$this
->
_api
=
VENDORPATH
.
'api/'
;
require
$this
->
_api
.
'weixin.class.php'
;
}
//首页
public
function
action_index
()
{
if
(
isset
(
$_GET
[
'refer'
]))
{
Cookie
::
set
(
'_refer'
,
$_GET
[
'refer'
]);
}
else
{
die
();
}
$author
=
new
weixinPHP
(
$this
->
_conf
[
'appid'
],
$this
->
_conf
[
'appkey'
],
$this
->
_conf
[
'callback'
],
time
());
$url
=
$author
->
login_url
();
header
(
"Location:
{
$url
}
"
);
exit
;
}
//第三方回调
public
function
action_back
()
{
$user
=
array
();
$code
=
$_GET
[
'code'
];
$author
=
new
weixinPHP
(
$this
->
_conf
[
'appid'
],
$this
->
_conf
[
'appkey'
],
$this
->
_conf
[
'callback'
],
time
());
$tokenarr
=
$author
->
access_token
(
$code
);
$token
=
$tokenarr
[
'access_token'
];
$openid
=
$tokenarr
[
'openid'
];
$author
=
$author
->
get_user_info
(
$openid
,
$token
);
if
(
isset
(
$author
[
'openid'
]))
{
$author
[
'unionid'
]
=
$author
[
'unionid'
]
?
$author
[
'unionid'
]
:
$author
[
'openid'
];
$user
[
'openid'
]
=
$author
[
'unionid'
];
$user
[
'unionid'
]
=
$author
[
'unionid'
];
$user
[
'nickname'
]
=
$author
[
'nickname'
];
$user
[
'litpic'
]
=
$author
[
'headimgurl'
];
$user
[
'from'
]
=
'weixin'
;
//登陆状态
$member
=
Common
::
islogin
();
if
(
!
empty
(
$member
))
{
$user
[
'mid'
]
=
$member
[
'mid'
];
Common
::
third_login_bind
(
$user
);
}
$rs
=
Db
::
query
(
Database
::
SELECT
,
'(select * from `sline_member_third` where openid="'
.
$author
[
'openid'
]
.
'") union (select * from `sline_member_third` where openid="'
.
$author
[
'unionid'
]
.
'")'
)
->
execute
()
->
current
();
if
(
!
empty
(
$rs
))
{
if
(
$rs
[
'openid'
]
!=
$author
[
'unionid'
])
{
//更改openId
DB
::
update
(
'member_third'
)
->
set
(
array
(
'openid'
=>
$author
[
'unionid'
]))
->
where
(
'id'
,
'='
,
$rs
[
'id'
])
->
execute
();
//整理多余用户
$richUser
=
DB
::
select
()
->
from
(
'member_third'
)
->
where
(
'openid'
,
'='
,
$author
[
'unionid'
])
->
and_where
(
'id'
,
'<>'
,
$rs
[
'id'
])
->
execute
()
->
current
();
if
(
$richUser
)
{
DB
::
delete
(
'member_third'
)
->
where
(
'id'
,
'='
,
$richUser
[
'id'
])
->
execute
();
DB
::
delete
(
'member'
)
->
where
(
'mid'
,
'='
,
$richUser
[
'mid'
])
->
execute
();
DB
::
update
(
'member_order'
)
->
set
(
array
(
'memberid'
=>
$rs
[
'mid'
]))
->
where
(
'memberid'
,
'='
,
$richUser
[
'mid'
])
->
execute
();
}
}
if
(
!
empty
(
$rs
[
'nickname'
]))
{
unset
(
$user
[
'nickname'
]);
}
Common
::
write_login_info
(
$rs
);
$this
->
request
->
redirect
(
Cookie
::
get
(
'_refer'
));
}
$view
=
View
::
factory
(
'default/'
.
Common
::
st_platform
());
$view
->
user
=
$user
;
$content
=
Common
::
head_bottom
();
$view
=
str_replace
(
array
(
'<stourweb_title/>'
,
'<stourweb_content/>'
,
'<stourweb_header/>'
),
array
(
'绑定账号'
,
$view
->
render
(),
''
),
$content
);
$this
->
response
->
body
(
$view
);
}
else
{
//跳转至登陆也
$this
->
request
->
redirect
(
Common
::
get_main_host
()
.
'/member/login'
);
}
}
//绑定账号
public
function
action_bind
()
{
echo
Common
::
third_bind
(
$_POST
);
}
/**
* 配置第三方登陆信息
*/
private
function
_conf
()
{
$arr
=
DB
::
select
()
->
from
(
'sysconfig'
)
->
where
(
"varname in('cfg_wx_client_appkey','cfg_wx_client_appsecret')"
)
->
execute
()
->
as_array
();
$info
=
array
(
"callback"
=>
Common
::
get_main_host
()
.
"/plugins/login_wx_client/index/back/"
);
foreach
(
$arr
as
$v
)
{
if
(
$v
[
'varname'
]
==
'cfg_wx_client_appkey'
)
{
$info
[
'appid'
]
=
$v
[
'value'
];
}
if
(
$v
[
'varname'
]
==
'cfg_wx_client_appsecret'
)
{
$info
[
'appkey'
]
=
$v
[
'value'
];
}
}
$this
->
_conf
=
$info
;
}
}
?>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment