PP手机号一键登录

APP手机号一键登录(极光)
1.极光注册账号创建应用,设置认证
2.认证时RSA 加密公钥是   -----BEGIN RSA PRIVATE KEY-----  、-----END RSA PRIVATE KEY-----包含的字符串
配置完成后移动端调用极光接口获取token值,用token值请求服务器端
php服务
public function getMobile()
    {
        $param = $this->param;
        $data['loginToken'] = $param['loginToken'];
        $data['exID'] = $param['exID'];
        $data = json_encode($data);
        $url = 'https://api.verification.jpush.cn/v1/web/loginTokenVerify';
        $res = $this->postCurl($url,$data);
        if($res['code'] != 8000){
            return resultArray(['code'=>400, 'error' =>'认证失败']);
        }
        //认证成功对手机号解密
        $prefix = '-----BEGIN RSA PRIVATE KEY-----';
        $suffix = '-----END RSA PRIVATE KEY-----';
        $result = '';
        $encrypted = $res['phone'];
        $prikey = '自己的私钥';
        $key = $prefix . "\n" . $prikey . "\n" . $suffix;
        $r = openssl_private_decrypt(base64_decode($encrypted), $result, openssl_pkey_get_private($key));
        return $result;
    }
    public function postCurl($url,$data)
    {
        $appKey = '自己的appkey';
        $masterSecret = '自己masterSecret';
        $base = base64_encode("{$appKey}:{$masterSecret}");
        $add = "Authorization: Basic " . $base;
        $headerArray =array("Content-type:application/json",$add);
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        $result = json_decode($output,true);
        return $result;
    }

你可能感兴趣的:(极光,php)