https:///login/token.php?username=test1&password=Test1&service=moodle_mobile_app
的Moodle系统的响应格式是这样的:
{"token":"a2063623aa3244a19101e28644ad3004"}
我试着用PHP处理结果:
if (isset($_POST['username']) && isset($_POST['password'])){
// test1 Test1
// request for a 'token' via moodle url
$json_url = "https:///login/token.php?username=".$_POST['username']."&password=".$_POST['password']."&service=moodle_mobile_app";
$obj = json_decode($json_url);
print $obj->{'token'}; // should print the value of 'token'
} else {
echo "Username or Password was wrong, please try again!";
}
结果,我S:未定义
现在的问题是: 我怎么可以处理JSON响应的Moodle系统格式?任何想法都会很棒。
[UPDATE]: 我已经通过卷曲使用另一种方法和在php.ini中以下行改变:*延长= php_openssl.dll *,* allow_url_include =开*,但现在有一个错误代码:注意:试图获取非对象的属性。以下是更新后的代码:
function curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$moodle = "https:///moodle/login/token.php?username=".$_POST['username']."&password=".$_POST['password']."&service=moodle_mobile_app";
$result = curl($moodle);
echo $result->{"token"}; // print the value of 'token'
谁能告诉我?
2013-01-10
Dozent