php极光网络一键登录(yii框架)
public function actionAnalysisPhone()
{
$curl = curl_init();
$loginToken = Yii::$app->request->post('loginToken');
// $loginToken = 'xxxxxxxx771oVCFgwgDMLiWTNYgGicek/ie174EkwfomfAODuGwiOe1Rfkl26fVQDLeQWeLLcnXOoGbkGkx6YP8aHQMutjplMXXE4Lkj4MDfy5+j6lTQORo0uRJz8KQFWJ2LsFIeYpUuEEqZ09/KPNMfIFP69uMj9s04WBJDxf7ZwgGYtu1Y916KMgJiwc1BrgYyk/jhIyRydu/IUnPC0IlmCz1frXJ4rTUDnEbla2zx9R5RTs98S1ciq6BxZF/NerDdSZvl7y4RDaBq4xoyJa5ARMg==';
if(!$loginToken){
return ResultHelper::json(301, 'loginToken不能为空!');
}
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.verification.jpush.cn/v1/web/loginTokenVerify',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_SSL_VERIFYPEER=>true,
CURLOPT_POSTFIELDS =>'{"loginToken":"'.$loginToken.'"}',
CURLOPT_HTTPHEADER => array(
'Authorization: Basic OTI3MDIwYTQ1NmRlNmRixxxxxxxwNTUyMDE1OWJmZDUwYmE0Mg==',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
$resultjson = json_decode($response,true);
if ($resultjson['code'] != 8000){
return ResultHelper::json(301, $resultjson['content']);
}
$encrypted = $resultjson['phone'];
// 极光的私钥
$private_key = '-----BEGIN PRIVATE KEY-----
MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAN1NGE2BBR70ROs6
xxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxx
-----END PRIVATE KEY-----';
// // 极光的公钥
$public_key = '-----BEGIN PUBLIC KEY-----
MxxxxxxxxU/GC3I517wUwO2lZuxIuQhFcLI5ek1IJH
5wekDZQyvBLS/lMg5Wi+uqA8PGvX6xxxxx6jJFb7ncjfmHt
N4DPByz8iOLCmpW4lQIDAQAB
-----END PUBLIC KEY-----';
$public_key = wordwrap($public_key, 64, "\n", true);
$pi_key = openssl_pkey_get_private($private_key);
openssl_private_decrypt(base64_decode($encrypted),$decrypted,$pi_key);//私钥解密
$mobile = $decrypted;
//这个mobile就是解密出来的手机号码
return $mobile;
}