Php 使用Web服务API函数挂起Moodle用户

Php 使用Web服务API函数挂起Moodle用户,php,curl,moodle,Php,Curl,Moodle,我正试图通过在PHP中使用Moodle来暂停Moodle中的用户。 我可以更改用户字段,如firstname,但我无法挂起用户 它总是返回“null” 这是我的密码: <?php $serverurl = "http://localhost/web/moodle/webservice/rest/server.php?wstoken=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&wsfunction=core_user_update_users&moodl

我正试图通过在PHP中使用Moodle来暂停Moodle中的用户。 我可以更改用户字段,如firstname,但我无法挂起用户

它总是返回“null”

这是我的密码:

<?php
$serverurl = "http://localhost/web/moodle/webservice/rest/server.php?wstoken=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&wsfunction=core_user_update_users&moodlewsrestformat=json";
$params = "users[0][id]=4&users[0][preferences][0][type]=suspended&users[0][preferences][0][value]=true";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $serverurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);

print_r($response);

curl_close($ch);
?>

将挂起用户添加到Web服务中,使其成为3.2版。如果您使用的是旧版本,不想升级,可以使用
core\u user\u update\u users
功能并将
auth
设置为
nologin


返回
null
的API并不表示有错误-如果出现错误,您将得到一个更详细的错误。

使用moodle 3.7应该可以,但不使用上面示例中的“首选项”,而是 使用以下模板:

wsfunction=core\u user\u update\u users&users[0][id]=1234&users[0][suspended]=1