我在尝试使用外部论坛运行器 api 向论坛上的用户发送消息时遇到了麻烦。
我已经能够使用此代码成功登录:
function login($username, $password){
$postdata = "cmd=login&username=".$username."&password=".$password;
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://forums.<<<website>>>.org/forumrunner/request.php', false, $context);
$resultantArray = json_decode($result, true);
if($resultantArray['success'] == true){
$this->loginresult=$resultantArray;
return true;
} else {
$this->loginresult=false;
return false;
}
}
结果:
array(5) { ["success"]=> bool(true) ["data"]=> array(6) { ["username"]=> string(8) "<<<Username>>>" ["authenticated"]=> bool(true) ["v"]=> string(5) "1.1.1" ["p"]=> string(5) "xen10" ["requires_authentication"]=> bool(false) ["reg"]=> bool(true) } ["ads"]=> int(0) ["pm_notices"]=> int(0) ["sub_notices"]=> int(0) } string(4395) "
这样就可以了,并发送回登录成功消息,但是启动新对话的代码不起作用(验证失败):
function sendPM($recipients, $title, $message) {
$postdata = "cmd=start_conversation&recipients=".$recipients."&title=".$title."&message=".$message."&d=1";
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://forums.<<<website>>>.org/forumrunner/request.php', false, $context);
$resultantArray = json_decode($result, true);
if($resultantArray['success'] == true){
$this->pmresult=$resultantArray;
return true;
} else {
$this->pmresult=$result;
return false;
}
}
和错误(重要部分):
{"success":false,"message":"You do not have permission to view this page or perform this action."}
我相信我需要传递某种安全令牌,但我不知道从哪里得到它。