Php 服务器正在返回AWS cognito凭据

Php 服务器正在返回AWS cognito凭据,php,android,amazon-web-services,amazon-cognito,Php,Android,Amazon Web Services,Amazon Cognito,我正在从事一个android项目,在该项目中,服务器将ping AWS cogntio以获取标识ID和令牌。用PHP编写的服务器代码。使用AWSAbstractCognitoDeveloperIdentityProvider类中的refresh方法,我希望ping我的服务器以获取该标识和令牌。每当刷新方法ping myserver时,服务器必须连接到AWS cognito并获取该标识和令牌。将该标识ID和令牌返回给客户端。但事实并非如此。 这是我的密码: 服务器端: requir

我正在从事一个android项目,在该项目中,服务器将ping AWS cogntio以获取标识ID和令牌。用PHP编写的服务器代码。使用AWSAbstractCognitoDeveloperIdentityProvider类中的refresh方法,我希望ping我的服务器以获取该标识和令牌。每当刷新方法ping myserver时,服务器必须连接到AWS cognito并获取该标识和令牌。将该标识ID和令牌返回给客户端。但事实并非如此。 这是我的密码:

服务器端:

        require 'vendor/autoload.php';

        use Aws\CognitoIdentity\CognitoIdentityClient;
        use Aws\Sts\StsClient;
        use Aws\Credentials\Credentials;
        use Aws\S3\S3Client;

   $Client = CognitoIdentityClient::factory(array(
 'version' => 'latest',
 'profile'=> 'project1',
  'region'  => 'ap-northeast-1'
   ));

      $result = $Client->getOpenIdTokenForDeveloperIdentity(array(
  'IdentityPoolId' => 'ap-northeast-1:b871fa5f-23a2-480d-baa6-b4ed31437244',
  'Logins' => array(
      'login.blupinch.app' => "7386372871",
  ),
  'TokenDuration' => 36000
  ));

  echo $result['IdentityId']."==".$result['Token'];

 }
客户端代码:

  public class Auth extends AWSAbstractCognitoDeveloperIdentityProvider {


public Auth(String accountId, String identityPoolId, Regions region) {
    super(accountId, identityPoolId, region);


}


@Override
public String getProviderName() {
    return "login.blupinch.app";
}

public String refresh() {

    setToken(null);

    if (getProviderName() != null &&
            !this.loginsMap.isEmpty() &&
            this.loginsMap.containsKey(getProviderName())) {

            Idtoken();

        update(identityId, token);

        return token;



    } else {

        this.getIdentityId();
        return null;
    }
}

public String getIdentityId() {


    identityId = null;
    if (identityId == null) {


        if (getProviderName() != null && !this.loginsMap.isEmpty()
                && this.loginsMap.containsKey(getProviderName())) {

               Idtoken();
            update(identityId, token);
            return identityId;

        } else {
            return super.getIdentityId();
        }

    } else {
        return identityId;
    }

}

public void Idtoken(){

    String line = "";
    String response="";


    String serverurl = "http://10.0.3.2/credentials.php";
    try {
        URL url = new URL(serverurl);
        HttpURLConnection http = (HttpURLConnection) url.openConnection();
        http.setRequestMethod("POST");
        http.setDoInput(true);



        InputStream IS = http.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(IS,"iso-8859-1"));
        while ((line = bufferedReader.readLine())!=null)
        {
            response = response + line;

        }
        bufferedReader.close();
        IS.close();
        http.disconnect();
        String[] splitter = response.split("==");
        identityId = splitter[0];
        token = splitter[1];
        Log.d("IDENTITYID",identityId);
        Log.d("TOKEN",token);

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (UnknownHostException e)
    {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

}
警告:

           02-29 12:55:45.563 452-799/? W/AudioFlinger: write blocked for  10041 msecs, 6 delayed writes, thread 0xf58ba000
           02-29 12:55:45.779 16968-17029/? W/System.err:                                java.io.FileNotFoundException: http://10.0.3.2/credentials.php
           02-29 12:55:45.779 16968-17029/? W/System.err:     at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:206)
           02-29 12:55:45.779 16968-17029/? W/System.err:     at com.example.sandesh.filer.UpDown.Auth.Idtoken(Auth.java:107)
           02-29 12:55:45.779 16968-17029/? W/System.err:     at com.example.sandesh.filer.UpDown.Auth.refresh(Auth.java:46)
           02-29 12:55:45.779 16968-17029/? W/System.err:     at com.amazonaws.auth.CognitoCredentialsProvider.startSession(CognitoCredentialsProvider.java:537)
           02-29 12:55:45.779 16968-17029/? W/System.err:     at com.amazonaws.auth.CognitoCredentialsProvider.refresh(CognitoCredentialsProvider.java:503)
           02-29 12:55:45.779 16968-17029/? W/System.err:     at com.amazonaws.auth.CognitoCachingCredentialsProvider.refresh(CognitoCachingCredentialsProvider.java:462)
           02-29 12:55:45.779 16968-17029/? W/System.err:     at com.example.sandesh.filer.UpDown.upload.doInBackground(upload.java:93) 
           02-29 12:55:45.779 16968-17029/? W/System.err:     at com.example.sandesh.filer.UpDown.upload.doInBackground(upload.java:28)    
           02-29 12:55:45.779 16968-17029/? W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:292)
           02-29 12:55:45.779 16968-17029/? W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
           02-29 12:55:45.779 16968-17029/? W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
           02-29 12:55:45.779 16968-17029/? W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
           02-29 12:55:45.779 16968-17029/? W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
           02-29 12:55:45.779 16968-17029/? W/System.err:     at              java.lang.Thread.run(Thread.java:818)

如果您在模拟器中运行,并且试图访问在本地主机上运行的服务器,则IP地址为10.0.2.2


谢谢您的回复。但我正在使用Genymotion。它是10.0.3.2。附加信息:我观察到服务器ping aws cognito以获取标识Id和令牌时有延迟。我所做的是删除了整个代码,除了一个echo“helloworld”。然后运行刷新方法。我发现收到了字符串helloworld,因为不需要延迟获取echo“helloworld”。这个延迟会导致问题吗?当我在浏览器中打开服务器代码(credentials.php)时,我也发现了这一点。标识ID和令牌未在浏览器中打印(此处echo根本不起作用)。但是当我从命令行运行它时,就像这个php credentilas.php。它很好用。它呼应身份Id和令牌。