Slack文档说我们需要替换字符&,<和>与&等等。
我有一个非常简单的方法,我做了以下卷曲请求:
$data = "payload=" . json_encode(array(
"channel" => "#{$room}",
"text" => $message,
"icon_emoji" => $icon,
"username" => 'My Bot'
));
$ch = curl_init($webhookUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
现在我将以下$数据发送给Slack,文本中包含&
:
payload={"channel":"#test","text":"This is a test & looking not good","icon_emoji":":monkey_face:","username":"My Bot"}
Result "invalid_payload"
我收到回复“invalid_payload”。
当我删除&从文中,一切都很好:
payload={"channel":"#test","text":"This is a test looking good","icon_emoji":":monkey_face:","username":"My Bot"}
Result "ok"
有人知道我需要改变什么,带有&的文字也会有效吗?
谢谢!