Thinkphp3.2 畅言评论回推接口制作

 5562

最近在做项目的时候用到了畅言评论,因为是第三方评论,所以没办法直接入库,但是畅言提供了评论回推接口,尝试着制作了一下,废话不多说,上代码:

第一步:获取畅言数据并转为数组

  1. $cy_data = htmlspecialchars_decode(I('data'));//获取畅言返回数据,并转码
  2. $data = json_decode($cy_data,true);//将JSON转为数组

第二步,根据自身业务需求完成后续操作

畅言返回的数组格式为:

  1. Array
  2. (
  3.     [comments] => Array
  4.         (
  5.             [0] => Array
  6.                 (
  7.                     [apptype] => 
  8.                     [attachment] => Array()
  9.                     [channelid] => 
  10.                     [channeltype] =>  //1为评论框直接发表的评论,2为第三方回流的评论
  11.                     [cmtid] =>  //评论唯一ID
  12.                     [content] =>  //评论内容
  13.                     [ctime] =>  //评论时间
  14.                     [from] =>  //评论来源
  15.                     [ip] =>  //发布ip
  16.                     [opcount] =>  //评论被踩次数
  17.                     [referid] => 
  18.                     [replyid] =>  //回复的评论ID,没有为0
  19.                     [score] => 
  20.                     [spcount] =>  //评论被顶次数
  21.                     [status] => 
  22.                     [user] => Array
  23.                         (
  24.                             [nickname] =>  //发布者昵称
  25.                             [sohuPlusId] => 
  26.                             [usericon] =>  //发布者头像(留空使用默认头像)
  27.                             [userid] =>  //发布者ID
  28.                             [userurl] =>  //发布者主页地址(可留空)
  29.                         )
  30.                     [useragent] =>  //浏览器信息
  31.                 )
  32.         )
  33.     [metadata] => {"local_ip":"127.0.0.1"}
  34.     [sourceid] =>  //文章Id
  35.     [title] =>  //文章标题
  36.     [ttime] =>  //文章创建时间
  37.     [url] =>  //文章url
  38. )

完整的Json数据为:

  1. {
  2.     "title":"123",                      //文章标题
  3.     "url":"http://localhost/?p=9",      //文章url
  4.     "ttime":1401327899094,      //文章创建时间
  5.     "sourceid":"9",                     //文章Id
  6.     "parentid":"0",                     //文章所属专辑的ID,多个的话以,号分隔
  7.     "categoryid":"",                    //文章所属频道ID(可留空)
  8.     "ownerid":"",                       //文章发布者ID(可留空)
  9.     "metadata":"",                      //文章其他信息(可留空)
  10.     "comments":[
  11.         {
  12.             "cmtid":"358",                                  //评论唯一ID
  13.             "ctime":1401327899094,                          //评论时间
  14.             "content":"2013年8月1日18:36:29 O(∩_∩)O~",      //评论内容        
  15.             "replyid":"0",                                  //回复的评论ID,没有为0
  16.             "user":{
  17.                 "userid":"1",                               //发布者ID
  18.                 "nickname":"admin",                         //发布者昵称
  19.                 "usericon":"",                              //发布者头像(留空使用默认头像)
  20.                 "userurl":"",                                //发布者主页地址(可留空)
  21.                 "usermetadata":{                            //其它用户相关信息,例如性别,头衔等数据
  22.                     "area": "北京市",
  23.                     "gender": "1",
  24.                     "kk": "",
  25.                     "level": 1
  26.                 }
  27.             },
  28.             "ip":"127.0.0.1",                                                                       //发布ip
  29.             "useragent":"Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0",        //浏览器信息
  30.             "channeltype":"1",                                      //1为评论框直接发表的评论,2为第三方回流的评论
  31.             "from":"",                                                                              //评论来源
  32.             "spcount":"",                                                                           //评论被顶次数
  33.             "opcount":"",                                                                           //评论被踩次数
  34.             "attachment":[                                          //附件列表
  35.                 {
  36.                     "type":1                                        //1为图片、2为语音、3为视频
  37.                     "desc":""                                      //描述,
  38.                     "url":"http://img.sohu.itc/xxxx"               //附件地址
  39.                 }
  40.             ]
  41.         }
  42.     ]
  43. }


你可以参照以上字段进行下一步业务的处理!



本文网址:https://www.zztuku.com/index.php/detail-7687.html
站长图库 - Thinkphp3.2 畅言评论回推接口制作
申明:如有侵犯,请 联系我们 删除。

评论(0)条

您还没有登录,请 登录 后发表评论!

提示:请勿发布广告垃圾评论,否则封号处理!!

    编辑推荐

    PS制作超酷黑白像素文字效果