rockwxqyChajian.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * 信呼企业微信平台
  4. * 2024-11-09
  5. */
  6. class rockwxqyChajian extends Chajian
  7. {
  8. private $platurl = '',$cnum = '';
  9. private $optionobj;
  10. protected function initChajian()
  11. {
  12. $this->platurl = getconfig('rockwxqy_url');
  13. if(!$this->platurl){
  14. $this->platurl = $this->rock->jm->base64decode('aHR0cHM6Ly93eHF5LnJvY2tvYS5jb20v');
  15. }
  16. $this->optionobj = m('option');
  17. $this->cnum = $this->optionobj->getval('wxqyplat_cnum');
  18. }
  19. public function isconfig()
  20. {
  21. if($this->cnum)return true;
  22. return false;
  23. }
  24. public function geturlstr($act, $can=array(),$mact='')
  25. {
  26. $url = $this->platurl;
  27. $mode= 'wxqyopen';
  28. if($mact)$mode = $mact;
  29. $url.= 'index.php?a='.$act.'&m='.$mode.'';
  30. $url.= '&cnum='.$this->cnum.'&xinhukey='.getconfig('xinhukey').'';
  31. if(is_array($can))foreach($can as $k=>$v)$url.='&'.$k.'='.$v.'';
  32. return $url;
  33. }
  34. public function getdata($act, $can=array(), $data=array())
  35. {
  36. if(!$this->cnum)return returnerror('未设置单位编号');
  37. $url = $this->geturlstr($act, $can);
  38. if($data){
  39. $cont = c('curl')->postcurl($url, $data);
  40. }else{
  41. $cont = c('curl')->getcurl($url);
  42. }
  43. $data = array('code'=>201,'success'=>false,'msg'=>'出错了返回:'.htmlspecialchars($cont).'');
  44. if($cont!='' && substr($cont,0,1)=='{'){
  45. $data = json_decode($cont, true);
  46. }
  47. return $data;
  48. }
  49. public function postdata($act, $data=array(), $can=array())
  50. {
  51. return $this->getdata($act, $can, $data);
  52. }
  53. /**
  54. * 发消息
  55. */
  56. public function sendmess($id, $title, $mess, $url='',$picurl='')
  57. {
  58. $where = '`uid` in('.$id.')';
  59. if($id=='all')$where = '1=1';
  60. $rows = m('zwxqy_user')->getall(''.$where.' AND `state`=1','userid,agentid,cnum');
  61. if(!$rows)return returnerror('nouser');
  62. $sdata = array(
  63. 'touser' => $rows,
  64. 'title' => $this->rock->jm->base64encode($title),
  65. 'mess' => $this->rock->jm->base64encode($mess),
  66. 'url' => $this->rock->jm->base64encode($url),
  67. 'picurl' => $this->rock->jm->base64encode($picurl),
  68. );
  69. return $this->postdata('sendmess', json_encode($sdata));
  70. }
  71. /**
  72. * 快捷登录
  73. */
  74. public function authlogin()
  75. {
  76. $backurl = $this->rock->get('backurl');
  77. $rs = m('zwxqy_user')->getone('`state`=1');
  78. if(!$rs){
  79. $url = '?d=we&m=login&errmsg='.$this->rock->jm->base64encode('没有激活的用户').'';
  80. }else{
  81. $url = $this->platurl.'?m=main&yyid='.$rs['agentid'].'';
  82. }
  83. if($backurl)$url.='&backurl='.$backurl.'';
  84. $this->rock->location($url);
  85. }
  86. /**
  87. * 获取打卡记录(需要用异步)
  88. */
  89. public function getcheckindata($uids='', $startdt='', $enddt='', $page=1)
  90. {
  91. $obj = m('weixinqy:daka');
  92. if(!method_exists($obj, 'savecheckindata'))return returnerror('未安装企业微信插件');
  93. $where = '`uid` in('.$uids.') AND ';
  94. if($uids=='')$where = '';
  95. $rows = m('zwxqy_user')->getall(''.$where.'`state`=1','userid,uid');
  96. if(!$rows)return returnerror('没有激活的用户');
  97. $userids = $uids = $uarrs = array();
  98. foreach($rows as $k=>$rs){
  99. $userids[] = $rs['userid'];
  100. $uids[] = $rs['uid'];
  101. $uarrs[$rs['userid']] = $rs['uid'];
  102. }
  103. $sdata = array(
  104. 'userids' => $userids,
  105. 'uids' => $uids,
  106. 'startdt' => $startdt,
  107. 'enddt' => $enddt,
  108. );
  109. $barr = $this->postdata('checkindata', json_encode($sdata));
  110. if(!$barr['success'])return $barr;
  111. $this->rock->debugs($barr['data'],'djcheckdata');
  112. $data = $barr['data'];
  113. if(isset($data['checkindata'])){
  114. $obj->savecheckindata($data, $uarrs);
  115. }
  116. if(isset($data['hardwaredata'])){
  117. $obj->hardwaredata($data['hardwaredata'], $uarrs);
  118. }
  119. return $barr;
  120. }
  121. }
粤ICP备19079148号