dpi74187 2016-08-31 09:14
浏览 53
已采纳

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

I am trying to suspend a user in Moodle by using Moodle's Web service API functions in PHP. I can change user fields like firstname, but I am not capable to suspend the user.

It always returns "null".

Here is my code:

<?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);
?>
  • 写回答

1条回答 默认 最新

  • doutangguali32556 2017-09-13 04:44
    关注

    Suspending a user was added to the Web Services in MDL-31465 which made it into version 3.2. If you're on an older version and don't want to upgrade, you can use the core_user_update_users function and set auth to nologin.

    The API returning null does not indicate an error - if something goes wrong, you'll get a more verbose error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型
  • ¥15 Todesk 远程写代码 anaconda jupyter python3
  • ¥15 我的R语言提示去除连锁不平衡时clump_data报错,图片以下所示,卡了好几天了,苦恼不知道如何解决,有人帮我看看怎么解决吗?
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 VUE项目怎么运行,系统打不开