我想让android/iPhone用户匿名提交评论(无需注册博客)到自托管的Wordpress博客。
有没有一种简单、安全的方法可以做到这一点?
到目前为止我研究的内容:
JSON API 插件 -> 运行良好,但没有安全性。
WP-API -> 没有实现提交评论方法 + 没有安全性。
好吧,您可以使用随机数来避免XSS攻击,除此之外,您显然需要您的用户登录。这是一种简单的方法。
https://wordpress.org/support/topic/plugin-json-api-how-to-add-a-comment-or-post
编辑:如果您只需要能够使用他们的姓名和电子邮件地址发布评论。按如下方式使用它,但请确保从 api 设置中启用"响应控制器"
http://yourwebsite.com/api/?json=submit_comment&post_id=170&name=Omer&email=commenter@gmail.com&content=comment
第二次编辑:为了保护注释,您可以使用随机数,如果它不是插件中的内置功能,则必须在submit_comment控制器中添加此功能。但是从您的 android 应用程序生成随机数有点困难。一个简单的解决方案是将现有代码包装在一个条件中。类似于 base64 编码的时间令牌。
if(isset($_GET['token'])){
$token = base64_decode($_GET['token']);
$current_time = time();
$difference = round(abs($current_time - $token) / 60,2);//difference in minutes
if($difference < 5){
// Run the code thats already in submit_comment controller.
}
}
然后在 REST API 中,您可以发送类似
http://yourwebsite.com/api/?json=submit_comment&post_id=170&name=Omer&email=commenter@gmail.com&content=comment&token=BASE64_ENCODED_TIMESTAMP