subscribeinfoModel.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. //订阅的
  3. class flow_subscribeinfoClassModel extends flowModel
  4. {
  5. public function flowrsreplace($rs, $lx=0)
  6. {
  7. $filepath = $rs['filepath'];
  8. if(!file_exists(iconv('utf-8','gb2312',$filepath))){
  9. $filepath = '文件不存在了';
  10. $rs['ishui']= 1;
  11. }else{
  12. $filepath = '<a href="'.URL.''.$filepath.'"';
  13. if(!$this->rock->ismobile())$filepath.=' target="_blank"';
  14. $filepath .= '>打开</a>';
  15. }
  16. $rs['filepath'] = $filepath;
  17. return $rs;
  18. }
  19. /**
  20. * 订阅运行发送
  21. */
  22. public function subscribe($id, $nowid=0, $receid='', $recename='')
  23. {
  24. $rs = $this->db->getone('[Q]subscribe','`id`='.$id.'');
  25. if(!$rs)return returnerror('不存在');
  26. if($rs['status']=='0')return returnerror('未启用不能运行');
  27. $title = $rs['title']; //订阅标题
  28. $cont = $rs['cont']; //提醒内容
  29. $suburl = $this->rock->jm->base64decode($rs['suburl']);
  30. $suburlpost = $this->rock->jm->base64decode($rs['suburlpost']);
  31. if(isempt($suburl) || isempt($suburlpost))return;
  32. $base = m('base');
  33. $suburlpost = $base->strreplace($suburlpost,0,1);
  34. $title = $base->strreplace($title,0,1);
  35. $cont = $base->strreplace($cont,0,1);
  36. $url = getconfig('localurl', URL).$suburl;
  37. //请求参数处理
  38. $params = array();
  39. $canarr = explode('&', $suburlpost);
  40. foreach($canarr as $csnstr){
  41. $nets = explode('=', $csnstr);
  42. $params[$nets[0]] = $nets[1];
  43. }
  44. if($nowid==0)$nowid = $rs['optid'];
  45. $params['exceltitle'] = $title;
  46. $params['exceltype'] = 'html';
  47. $params['tablename_abc'] = $this->rock->jm->encrypt($params['tablename_abc']);
  48. $params['exceltitle'] = $this->rock->jm->encrypt($params['exceltitle']);
  49. $params['excelfields'] = $this->rock->jm->encrypt($params['excelfields']);
  50. $params['excelheader'] = $this->rock->jm->encrypt($params['excelheader']);
  51. //传个让不需要登录验证
  52. $subscribe_post = 'subscribe_'.time().'';
  53. $subscribe_key = md5($url.time().$subscribe_post);
  54. $params['subscribe_key'] = $subscribe_key;
  55. $params['subscribe_post'] = $subscribe_post;
  56. $params['subscribe_adminid']= $nowid;
  57. $this->option->setval('subscribe_key', $subscribe_key);
  58. $bstr = c('curl')->postcurl($url, $params);
  59. $this->db->update('[Q]subscribe',"`lastdt`='{$this->rock->now}'", '`id`='.$id.'');
  60. if(!isempt($bstr) && substr($bstr, 0, 1)=='{'){
  61. $publicurl = $this->rock->getouturl();//公网URL
  62. $barr = json_decode($bstr, true);
  63. $htmlpath = $barr['url'];
  64. if($barr['downCount']==0)return returnerror('记录数为0,没有可订阅数据');
  65. $url = $publicurl.$htmlpath;
  66. //发送提醒
  67. if(isempt($receid)){
  68. $receid = $rs['optid'];
  69. $recename = $rs['optname'];
  70. }
  71. $newid = $this->insert(array(
  72. 'mid' => $id,
  73. 'receid' => $receid,
  74. 'recename' => $this->rock->xssrepstr($recename),
  75. 'title' => $title,
  76. 'cont' => $cont,
  77. 'optdt' => $this->rock->now,
  78. 'filepath' => $htmlpath,
  79. ));
  80. //推送提醒
  81. $receid = $this->pushs($receid, $cont,$title,array(
  82. 'id' => $newid
  83. ));
  84. $this->update(array('receid' => $receid), $newid);
  85. return returnsuccess();
  86. }else{
  87. m('log')->addlogs('订阅运行', 'ID('.$id.')运行失败:'.$bstr.'', 2);
  88. return returnerror('error:'.$bstr.'');
  89. }
  90. }
  91. }
粤ICP备19079148号