ty0716 Posted July 29, 2015 Report Posted July 29, 2015 $response = $api->get or $response = $api->post all try. Internal error: Failed to retrieve the default valuestdClass Object ( [error] => stdClass Object ( [message] => An unexpected error occured. [response] => Internal error: Failed to retrieve the default value ) ) <?php session_start(); require_once "api/blesta_api.php"; $user = "wechat"; $key = "79aae**************cff42c66"; $url = "http://a.zy62.com/api/"; $api = new BlestaApi($url, $user, $key); $data = array( 'Session' =>session_id(), 'vars' => array( 'username' => "test", 'password' => "test", 'remember_me' => "true", 'ip_address' => "120.202.21.195" ) ); $response = $api->get("Users", "login", $data); //$response = $api->get("users", "get", array('user_id' => 1)); print_r($response->response()); print_r($response->errors()); //print_r($api->lastRequest()); ?> Quote
0 Michael Posted July 29, 2015 Report Posted July 29, 2015 I've edited your hash in your post to ensure if that is the correct information people can't use it. Quote
0 Adam Posted July 29, 2015 Report Posted July 29, 2015 What are you trying to do? I believe the issue is that you are not passing a valid Session object. If you read the docs the login function takes two arguments, a Session Object and an array of user attributes. The session object is defined here: http://source-docs.blesta.com/class-Session.html which is not the same as PHP's session class you are currently using (does not appear Blesta Session module implments PHP's SessionHandlerInterface). You might want to use the auth function if you want to verify if a user exists. -Adam Quote
0 ty0716 Posted July 29, 2015 Author Report Posted July 29, 2015 What are you trying to do? I believe the issue is that you are not passing a valid Session object. If you read the docs the login function takes two arguments, a Session Object and an array of user attributes. The session object is defined here: http://source-docs.blesta.com/class-Session.html which is not the same as PHP's session class you are currently using (does not appear Blesta Session module implments PHP's SessionHandlerInterface). You might want to use the auth function if you want to verify if a user exists. -Adam Then can i use API to get session? Quote
0 Adam Posted July 29, 2015 Report Posted July 29, 2015 Then can i use API to get session? What are you trying to do? ... For what purpose are you calling the login module for Blesta? -Adam Quote
0 ty0716 Posted July 30, 2015 Author Report Posted July 30, 2015 What are you trying to do? ... For what purpose are you calling the login module for Blesta? -Adam Yes, i have anther site, and i want to user login this site,then i can know this user's input whether correct.If true return client_id. Quote
0 Adam Posted July 30, 2015 Report Posted July 30, 2015 Yes, i have anther site, and i want to user login this site,then i can know this user's input whether correct.If true return client_id. You have two solutions (not in any particular order): One solution is you can make two separate calls. First make a call to the function auth from the user model. If the function returns true, then you make another call to get the client id via the function getByUsername. getByUsername will return an object for that user, which would include the client id (among other properties that you might need). Second solution is to pass in the correct Session Object to the login function you have above. You might want to include miniPHP's session object and pass that in. You could also create a class that has the same public methods as miniPHP's session class, but do nothing / return null (that might work). A complete list of the functions and parameters for users can be found here: http://source-docs.blesta.com/class-Users.html More information on miniPHP's session class can be found here: http://source-docs.blesta.com/class-Session.html -Adam Quote
0 ty0716 Posted July 30, 2015 Author Report Posted July 30, 2015 You have two solutions (not in any particular order): One solution is you can make two separate calls. First make a call to the function auth from the user model. If the function returns true, then you make another call to get the client id via the function getByUsername. getByUsername will return an object for that user, which would include the client id (among other properties that you might need). Second solution is to pass in the correct Session Object to the login function you have above. You might want to include miniPHP's session object and pass that in. You could also create a class that has the same public methods as miniPHP's session class, but do nothing / return null (that might work). A complete list of the functions and parameters for users can be found here: http://source-docs.blesta.com/class-Users.html More information on miniPHP's session class can be found here: http://source-docs.blesta.com/class-Session.html -Adam Now i use first,ths! Quote
Question
ty0716
$response = $api->get or $response = $api->post all try.
7 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.