agentModel.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * 应用管理方法
  4. */
  5. class reimplat_agentClassModel extends reimplatModel
  6. {
  7. /**
  8. * 获取所有应用
  9. */
  10. public function listdata()
  11. {
  12. $url = $this->geturl('openagent','listdata');
  13. $result = c('curl')->getcurl($url);
  14. $barr = $this->recordchu($result);
  15. if($barr['success']){
  16. $list = $barr['data']['agentlist'];
  17. $stra = array();
  18. foreach($list as $k=>$rs)$stra[$rs['num']] = $rs['name'];
  19. $this->option->setval('reimplat_agentlist@-7', json_encode($stra, JSON_UNESCAPED_UNICODE));
  20. return returnsuccess($list);
  21. }
  22. return $barr;
  23. }
  24. /**
  25. * 发应用消息
  26. */
  27. public function sendtext($touid,$agentnum, $mess)
  28. {
  29. $touids = $this->gettouid($touid);
  30. if(!$touids)return returnerror(''.$touid.'未关注');
  31. $url = $this->geturl('openagent','sendmsg');
  32. $data['agentnum'] = $agentnum;
  33. $data['touser'] = $touids;
  34. $data['msgtype'] = 'text';
  35. $data['content'] = $mess;
  36. $result = c('curl')->postcurl($url, json_encode($data));
  37. $barr = $this->recordchu($result);
  38. return $barr;
  39. }
  40. /**
  41. * 发卡片消息
  42. */
  43. public function sendtextcard($touid,$agentnum, $wxarr)
  44. {
  45. $touids = $this->gettouid($touid);
  46. if(!$touids)return returnerror(''.$touid.'未关注');
  47. $url = $this->geturl('openagent','sendmsg');
  48. $data['agentnum'] = $agentnum;
  49. $data['touser'] = $touids;
  50. $data['msgtype'] = 'textcard';
  51. $data['content'] = $wxarr;
  52. $result = c('curl')->postcurl($url, json_encode($data));
  53. $barr = $this->recordchu($result);
  54. return $barr;
  55. }
  56. private function gettouid($touid)
  57. {
  58. if($touid=='@all' || $touid=='all')return '@all';
  59. $uarrs = $this->db->getall("select a.`user`,a.`name` from `[Q]admin` a left join `[Q]zreim_user` b on a.`user`=b.`user` where a.`status`=1 and b.id is not null and b.`status`=1 and a.`id` in($touid)");
  60. $uids = '';
  61. foreach($uarrs as $k=>$rs)$uids.=','.$rs['user'].'';
  62. if($uids)$uids = substr($uids, 1);
  63. return $uids;
  64. }
  65. /**
  66. * 发送消息
  67. */
  68. public function sendxiao($touid, $agentname, $wxarr=array(),$iszs=false)
  69. {
  70. $liststr = $this->option->getval('reimplat_agentlist');
  71. if(isempt($liststr))return returnerror('请先获取应用');
  72. if(!$iszs && getconfig('asynsend')=='1'){
  73. $cans['touid'] = $touid;
  74. $cans['agentname'] = $agentname;
  75. $cans['wxarr'] = $wxarr;
  76. $barr = c('rockqueue')->push('cli,reimplatsend', array(
  77. 'body' => $this->rock->jm->base64encode(json_encode($cans))
  78. ));
  79. if($barr['success'])return returnsuccess('anaysend');
  80. }
  81. $yarr = json_decode($liststr, true);
  82. $num = $dnum = '';
  83. foreach($yarr as $k=>$v){
  84. if($dnum=='')$dnum = $k;
  85. if($agentname==$v || $agentname==$k)$num = $k;
  86. }
  87. if($num==''){
  88. $num = $this->reimplat_devnum;
  89. if(isempt($num))$num = $dnum;
  90. }
  91. if(isempt($num))return returnerror('没有找到对应应用('.$agentname.')');
  92. if(is_string($wxarr))$wxarr = array('title'=>$wxarr);
  93. if(arrvalue($wxarr, 'url')){
  94. $barr = $this->sendtextcard($touid, $num, $wxarr);
  95. }else{
  96. $des = arrvalue($wxarr,'description');
  97. $cont = $wxarr['title'];
  98. if($des)$cont.='<br>'.$des.'';
  99. $barr = $this->sendtext($touid, $num, $cont);
  100. }
  101. return $barr;
  102. }
  103. }
粤ICP备19079148号