——————————微信公从号授权
$code
= input(
'code'
);
if
(
$code
!=
''
){
$url
=
"https://api.weixin.qq.com/sns/oauth2/access_token?appid="
.config(
'appid'
).
"&secret="
.config(
'appsecret'
).
"&code=$code&grant_type=authorization_code"
;
$result
= https_request(
$url
);
$jsoninfo
= json_decode(
$result
, true);
if
(!
empty
(
$jsoninfo
[
'openid'
])){
$openid
=
$jsoninfo
[
'openid'
];
cookie(
'openid'
,
$openid
,1000);
$res
=
$this
->up_user_info(
$openid
,
$jsoninfo
[
'access_token'
]);
}
}
if
(cookie(
'openid'
) ==
''
) {
$url
=
'http://'
.
$_SERVER
[
'HTTP_HOST'
].
$_SERVER
[
'REQUEST_URI'
];
$url2
= urlencode(
$url
);
header(
"Location:https://open.weixin.qq.com/connect/oauth2/authorize?appid="
.config(
'appid'
).
"&redirect_uri="
.
$url2
.
"&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
);
exit
;
}