Utils.php
4.64 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
* Created by PhpStorm.
* User: liuziyang
* Date: 14-3-2
* Time: 16:31
*/
class YHMAuth_User_Utils
{
static $smsAuthPrivateKey = '05a9371223f4eab96818b7c4cabce1e7';
static $defaultPassword = 'yohobuy9646abcdeedcba';
/**
* 检测第三方登录信息
* @param $source
* @param $uid
* @param $nickName
* @param null $email
* @return array
*/
static function check($source, $uid, $nickName, $email = null, array $package = array())
{
$trueEmail = $email;
if (empty($email)) {
$trueEmail = $email = $source . '__' . $uid . '@yohoinc.com';
}
$oldFormatEmail = $source . '__' . $uid . '@yohoe.cn';
$_profile = QINPassport_Models_Profile_Client::getProfileByEmail($email);
if (empty($_profile)) {
$_profile = QINPassport_Models_Profile_Client::getProfileByEmail($oldFormatEmail);
if (!empty($_profile)) {
$trueEmail = $oldFormatEmail;
}
}
$result = array(
'email' => $trueEmail,
'source' => $source,
'nickname' => $nickName
);
return array_merge($result, $package);
}
/**
* reg | repassword
* @param $mobile
* @param $package
* @param int $sleep
* @param string $project
* @return array
*/
static function sendSms($mobile, $package, $sleep = 86400, $project = 'reg')
{
// $ip = Q_Utils_Request::getClientIp();
// $mc = QINLib_Utils::Mc('home', 'mobile');
// $exists = $mc->get($ip);
// if (empty($exists)) {
// $mc->set($ip, 0, 86400);
// }
// $result = $mc->increment($ip, 1);
// if ($result > 4) {
// return array();
// }
if (empty($package['code']) || empty($package['token_key'])) {
return array();
}
if (Q_Version::VERSION == 'QF.1.0') {
$mc = Q_Cache::factory()->setPrefix('passport_space.timeout_put');
} else {
$mc = Q_Cache::factory(array(
'domain' => 'passport_space',
'class' => 'timeout_put'
));
}
$key = 'register_timeout_put_' . $mobile . '_' . $sleep . '_' . $project;
$putSmsData = $mc->get($key);
if (!empty($putSmsData)) {
return $putSmsData;
}
$mc->set($key, $package, $sleep);
$package['private_key'] = self::$smsAuthPrivateKey;
$tokenKey = $package['token_key'];
unset($package['token_key']);
$verify = Q_Utils_AuthCode::verifySign(Q_Utils_AuthCode::getSign($package), $tokenKey);
if (empty($mobile) && $verify == false) {
return array();
}
$message = array('code' => $package['code']);
QINSms_Utils_Message::Sms($project, $mobile, $message);
return $package;
}
/**
* 获得注册用户的来源
* Enter description here ...
*/
static function getChannel()
{
$yh_union_key = !isset($_COOKIE['_QYH_UNION']) || empty($_COOKIE['_QYH_UNION']) ? NULL : $_COOKIE['_QYH_UNION'];
if (empty($yh_union_key)) {
return 0;
}
$yh_union_info = Q_Utils_AuthCode::decode($yh_union_key, 'q_union_yohobuy');
if (empty($yh_union_info)) {
return 0;
}
$yh_union_info = json_decode($yh_union_info, true);
if (empty($yh_union_info['client_id'])) {
return 0;
}
return $yh_union_info['client_id'];
}
/**
* 显示 iframe 登录
* @param $uid
* @param $channel
* @param string $mode
* @return string
*/
static function getSyncStatusLink($uid, $channel, $mode = 'local')
{
$auth = YHMAuth_Factory::profile($channel, $mode);
$session = $auth->getSession();
$state = 2;
if (!empty($session)) {
$state = 1;
}
$ssoUid = 0;
$_ssoProfile = QINPassport_Models_Sso_Client::getSsoRelationByUid($uid);
if (!empty($_ssoProfile)) {
$ssoUid = $_ssoProfile['sso_uid'];
}
$link = $auth->getSyncStatusLink($ssoUid, $state);
#return '<iframe name="newssoproxy" src="' . $link . '" width="0" height="0" style="display:none"></iframe>';
return '<script type="text/javascript" src="' . $link . '" async="async"></script>';
}
/**
* @param $channel
* @param string $mode
* @return string
*/
static function getCurrentLoginUidLink($channel, $mode = 'local')
{
$auth = YHMAuth_Factory::profile($channel, $mode);
return $auth->getCurrentLoginUidLink();
}
}