JPushChajian.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. * 最新系统推送1.9.7后
  4. * 软件:信呼OA
  5. * 最后更新:2021-10-09
  6. */
  7. class JPushChajian extends Chajian{
  8. /**
  9. * -------------最新原生app推送app是1.2.3版本 和 最新app+---------------
  10. * title 没有base64的标题
  11. * desc 已经base64了
  12. * cont 原始的内容json
  13. * palias 可推送信息
  14. */
  15. public function push($title, $desc, $cont, $palias)
  16. {
  17. $uids = $palias['uids'];
  18. $alias2019 = $palias['alias2019'];
  19. $pushuids = $palias['pushuids']; //可以推送的用户ID 就是ispush=1
  20. $jparr = $palias['jparr']; //应用内消息
  21. $xmpush = c('xmpush');
  22. $hwpush = c('hwpush');
  23. $getui = c('getui');
  24. //可推送判断
  25. $ketualia = array();
  26. foreach($alias2019 as $ali1){
  27. $ali1aa = explode('|', $ali1);
  28. $_uid = $ali1aa[2];
  29. if(in_array($_uid, $pushuids))$ketualia[] = $ali1;
  30. }
  31. $alias2019 = $ketualia;
  32. //$this->rock->debugs($palias,'pushalias');//判断能不能推送,打印这个
  33. $xharr = array(
  34. 'uids' => $uids,
  35. 'title' => $this->rock->jm->base64encode($title),
  36. 'desc' => $desc,
  37. 'jpreg' => arrvalue($palias, 'jpreg'),
  38. 'systype'=> getconfig('systype')
  39. );
  40. if(!$alias2019)return;
  41. $getuiand = $getuiios = $mybyarr = $xmarr = $hwarr = $iosar = $puarr = array();
  42. foreach($alias2019 as $k=>$ali1){
  43. $ali1aa = explode('|', $ali1);
  44. $regid = $ali1aa[0];
  45. $_web = $ali1aa[1];
  46. if(contain($_web,'custpile')){
  47. $mybyarr[] = $k; //3
  48. }else if(contain($_web,'getui')){
  49. if(contain($_web,'iphone')){
  50. $getuiios[] = $k; //3
  51. }else{
  52. $getuiand[] = $k; //3
  53. }
  54. }else if(contain($_web,'mi')){
  55. $xmarr[] = $k; //0
  56. }else if(contain($_web,'huawei')){
  57. $hwarr[] = $k; //3
  58. }else if(contain($_web,'iphone')){
  59. $iosar[] = $k; //0
  60. }else{
  61. $puarr[] = $ali1;
  62. }
  63. }
  64. $mymsg = '';
  65. $desc = $this->rock->jm->base64decode($desc);
  66. if($xmarr){
  67. if($xmpush->sendbool()){
  68. $vstr = $this->getVal($alias2019, $xmarr, 0);
  69. $msg = $xmpush->androidsend($vstr, $title, $desc);
  70. if($msg)$mymsg.=chr(10).$msg;
  71. }else{
  72. $vsta = $this->getVala($alias2019, $xmarr);
  73. foreach($vsta as $v)$puarr[] = $v;
  74. }
  75. }
  76. if($hwarr){
  77. if($hwpush->sendbool()){
  78. $vstr = $this->getVal($alias2019, $hwarr, 3);
  79. $msg = $hwpush->androidsend($vstr, $title, $desc);
  80. if($msg)$mymsg.=chr(10).$msg;
  81. }else{
  82. $vsta = $this->getVala($alias2019, $hwarr);
  83. foreach($vsta as $v)$puarr[] = $v;
  84. }
  85. }
  86. if($iosar){
  87. if($xmpush->jpushiosbool()){
  88. $vstr = $this->getVal($alias2019, $iosar, 0);
  89. $msg = $xmpush->jpushiossend($vstr, $title, $desc);
  90. if($msg)$mymsg.=chr(10).$msg;
  91. }else{
  92. $vsta = $this->getVala($alias2019, $iosar);
  93. foreach($vsta as $v)$puarr[] = $v;
  94. }
  95. }
  96. if($getuiand){
  97. if($getui->isandroid()){
  98. $vstr = $this->getVal($alias2019, $getuiand, 3);
  99. $msg = $getui->push($vstr, $title, $desc);
  100. if($msg)$mymsg.=chr(10).$msg;
  101. }else{
  102. $vsta = $this->getVala($alias2019, $getuiand);
  103. foreach($vsta as $v)$puarr[] = $v;
  104. }
  105. }
  106. if($getuiios){
  107. if($getui->isios()){
  108. $vstr = $this->getVal($alias2019, $getuiios, 3);
  109. $msg = $getui->push($vstr, $title, $desc);
  110. if($msg)$mymsg.=chr(10).$msg;
  111. }else{
  112. $vsta = $this->getVala($alias2019, $getuiios);
  113. foreach($vsta as $v)$puarr[] = $v;
  114. }
  115. }
  116. if($mybyarr){
  117. if($getui->sendbool()){
  118. $vstr = $this->getVal($alias2019, $mybyarr, 3);
  119. $msg = $getui->push($vstr, $title, $desc);
  120. if($msg)$mymsg.=chr(10).$msg;
  121. }else{
  122. $msg = '自己编译未配置推送';
  123. $mymsg.=chr(10).$msg;
  124. }
  125. }
  126. if($mymsg)$this->rock->debugs($mymsg, 'mypush');
  127. //需要官网隧道
  128. if($puarr){
  129. $xharr['alias2019'] = join(',', $puarr);
  130. $runurl = c('xinhu')->geturlstr('jpushplat', $xharr);
  131. c('curl')->getcurl($runurl);
  132. }
  133. }
  134. private function getVal($alias2019, $new, $oi)
  135. {
  136. $stv = array();
  137. foreach($new as $j){
  138. $stra = explode('|', $alias2019[$j]);
  139. if(isset($stra[$oi]))$stv[]= $stra[$oi];
  140. }
  141. return $stv;
  142. }
  143. private function getVala($alias2019, $new)
  144. {
  145. $stv = array();
  146. foreach($new as $j){
  147. $stv[] = $alias2019[$j];
  148. }
  149. return $stv;
  150. }
  151. /**
  152. * 极光自定义消息发送20250105
  153. */
  154. public function sendJpush($arr)
  155. {
  156. $receid = $arr['receid'];
  157. if(isempt($receid))return;
  158. $toregid= array();
  159. //$this->rock->debugs($arr,'sendJpush');
  160. $rows = m('logintoken')->getall('`uid` in('.$receid.') AND `online`=1 AND `ispush`=1');
  161. foreach($rows as $k=>$rs){
  162. $regid = arrvalue($rs,'regid');
  163. if(!isempt($regid))$toregid[] = $regid;
  164. }
  165. if(!$toregid)return;
  166. $runurl = c('xinhu')->geturlstr('jpushmess', array(
  167. 'msgcont' => $this->rock->jm->base64encode(json_encode($arr)),
  168. 'toregid' => join(',', $toregid)
  169. ));
  170. $str = c('curl')->getcurl($runurl);
  171. return 'ok';
  172. }
  173. }
粤ICP备19079148号