ThirdPartyLogin.php
1.3 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
<?php
/**
* Created by PhpStorm.
* User: billy
* Date: 10/02/2017
* Time: 6:23 PM
*/
namespace App\Common;
use App\Common\Enums\LoginType;
/**
* Class ThirdPartyLogin
* @package App\Common
*/
class ThirdPartyLogin
{
public static function verify($openId, $accessToken, $type)
{
if ($type == LoginType::QQ)
{
return self::qq_verify($openId, $accessToken);
}
else if($type == LoginType::WECHAT)
{
return self::wechat_verify($openId, $accessToken);
}
}
private static function qq_verify($openId, $accessToken)
{
$target = "https://graph.qq.com/oauth2.0/me?access_token=".$accessToken;
$result = Http::Get($target);
if($result != null)
{
if (preg_match('/openid":"'.$openId.'"/', $result))
{
return true;
}
}
return false;
}
private static function wechat_verify($openId, $accessToken)
{
$target = "https://api.weixin.qq.com/sns/auth?access_token=".$accessToken."&openid=".$openId;
$result = Http::Get($target);
if($result != null)
{
if (preg_match('/"errcode":0,/', $result))
{
return true;
}
}
return false;
}
}