PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/PigCms/Lib/Action/Chat/IndexAction.class.php

https://gitlab.com/colin.luo/shbs
PHP | 312 lines | 288 code | 19 blank | 5 comment | 48 complexity | 508853ab751227fb36042e194a52b4c4 MD5 | raw file
  1. <?php
  2. class IndexAction extends UserAction{
  3. public $thisWxUser;
  4. public function _initialize(){
  5. parent :: _initialize();
  6. $this -> assign('token', session('token'));
  7. }
  8. public function index(){
  9. $Page = new Page($count, 50);
  10. $show = $Page -> show();//'token' => $_SESSION['token'],
  11. //获取好友列表
  12. foreach($list as $key => $limen){
  13. $dataUp['joinUpDate'] = time();
  14. $dataUp['uid'] = session('userId');
  15. $dataUp['id'] = $limen['id'];
  16. }
  17. $this -> assign('page', $show);
  18. $this -> display();
  19. }
  20. function getTime(){
  21. if (!$sTime) return '';
  22. $cTime = time();
  23. $dTime = $cTime - $sTime;
  24. $dDay = intval(date("z", $cTime)) - intval(date("z", $sTime));
  25. $dYear = intval(date("Y", $cTime)) - intval(date("Y", $sTime));
  26. if($type == 'normal'){
  27. if($dTime < 60){
  28. if($dTime < 10){
  29. return '刚刚';
  30. }else{
  31. return intval(floor($dTime / 10) * 10) . "秒前";
  32. }
  33. }elseif($dTime < 3600){
  34. return intval($dTime / 60) . "分钟前";
  35. }elseif($dYear == 0 && $dDay == 0){
  36. return '今天' . date('H:i', $sTime);
  37. }elseif($dYear == 0){
  38. return date("m月d日 H:i", $sTime);
  39. }else{
  40. return date("Y-m-d H:i", $sTime);
  41. }
  42. }elseif($type == 'mohu'){
  43. if($dTime < 60){
  44. return $dTime . "秒前";
  45. }elseif($dTime < 3600){
  46. return intval($dTime / 60) . "分钟前";
  47. }elseif($dTime >= 3600 && $dDay == 0){
  48. return intval($dTime / 3600) . "小时前";
  49. }elseif($dDay > 0 && $dDay <= 7){
  50. return intval($dDay) . "天前";
  51. }elseif($dDay > 7 && $dDay <= 30){
  52. return intval($dDay / 7) . '周前';
  53. }elseif($dDay > 30){
  54. return intval($dDay / 30) . '个月前';
  55. }
  56. }elseif($type == 'full'){
  57. return date("Y-m-d , H:i:s", $sTime);
  58. }elseif($type == 'ymd'){
  59. return date("Y-m-d", $sTime);
  60. }else{
  61. if($dTime < 60){
  62. return $dTime . "秒前";
  63. }elseif($dTime < 3600){
  64. return intval($dTime / 60) . "分钟前";
  65. }elseif($dTime >= 3600 && $dDay == 0){
  66. return intval($dTime / 3600) . "小时前";
  67. }elseif($dYear == 0){
  68. return date("Y-m-d H:i:s", $sTime);
  69. }else{
  70. return date("Y-m-d H:i:s", $sTime);
  71. }
  72. }
  73. }
  74. //获取好友列表
  75. public function ajaxList(){
  76. if(IS_AJAX){
  77. if($data != false){
  78. foreach($data as $key => $limen){
  79. $dataUp['joinUpDate'] = time();
  80. $dataUp['uid'] = session('userId');
  81. $dataUp['id'] = $limen['id'];
  82. $list1[$key]['endtime'] = $this -> getTime($limen['enddate'], 'mohu');
  83. }
  84. echo json_encode($list1);
  85. }
  86. }else{
  87. exit('erorr:3306');
  88. }
  89. }
  90. //获取聊天信息
  91. public function ajaxMain(){
  92. if(IS_AJAX){
  93. if(!$time = $this -> _post('time', 'htmlspecialchars')){
  94. exit(1);
  95. }
  96. if($list != false){
  97. $list = array_reverse($list);
  98. echo json_encode($list);
  99. }else{
  100. echo 1;
  101. }
  102. }else{
  103. exit('{eror:2031}');
  104. }
  105. }
  106. public function main(){
  107. foreach($msgList as $key => $List){
  108. $msgList[$key]['type'] = 1;
  109. }
  110. foreach($logs as $key => $List){
  111. $logs[$key]['type'] = 2;
  112. }
  113. $newarray = array_merge($msgList, $logs);
  114. $enddata = $logs?$this -> array2sort($newarray, 'enddate'):$msgList;
  115. $this -> assign('msgList', $enddata);
  116. $endtime = $msgList[0];
  117. $userInfo['openid'] = $where['openid'];
  118. $this -> assign('endtime', $endtime['enddate']);
  119. $this -> assign('userInfo', $userInfo);
  120. $this -> display();
  121. }
  122. private function array2sort($a, $sort, $d = ''){
  123. $num = count($a);
  124. if(!$d){
  125. for($i = 0;$i < $num;$i++){
  126. for($j = 0;$j < $num-1;$j++){
  127. if($a[$j][$sort] > $a[$j + 1][$sort]){
  128. foreach ($a[$j] as $key => $temp){
  129. $t = $a[$j + 1][$key];
  130. $a[$j + 1][$key] = $a[$j][$key];
  131. $a[$j][$key] = $t;
  132. }
  133. }
  134. }
  135. }
  136. }else{
  137. for($i = 0;$i < $num;$i++){
  138. for($j = 0;$j < $num-1;$j++){
  139. if($a[$j][$sort] < $a[$j + 1][$sort]){
  140. foreach ($a[$j] as $key => $temp){
  141. $t = $a[$j + 1][$key];
  142. $a[$j + 1][$key] = $a[$j][$key];
  143. $a[$j][$key] = $t;
  144. }
  145. }
  146. }
  147. }
  148. }
  149. return $a;
  150. }
  151. function showExternalPic(){
  152. $wecha_id = $this -> _get('wecha_id');
  153. $token = $this -> _get('token');
  154. $imgData = S($token . '_' . $wecha_id);
  155. $types = array('gif' => 'image/gif', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'png' => 'image/png',);
  156. if (!$imgData){
  157. $url = htmlspecialchars($_GET['url']);
  158. $dir = pathinfo($url);
  159. $host = $dir['dirname'];
  160. $refer = 'http://www.qq.com/';
  161. $ch = curl_init($url);
  162. curl_setopt ($ch, CURLOPT_REFERER, $refer);
  163. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  164. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  165. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  166. $data = curl_exec($ch);
  167. curl_close($ch);
  168. $ext = strtolower(substr(strrchr($url, '.'), 1, 10));
  169. $ext = 'jpg';
  170. $type = $types[$ext] ? $types[$ext] : 'image/jpeg';
  171. header("Content-type: " . $type);
  172. echo $data;
  173. }else{
  174. $ext = 'jpg';
  175. $type = $types[$ext] ? $types[$ext] : 'image/jpeg';
  176. header("Content-type: " . $type);
  177. echo $imgData;
  178. }
  179. }
  180. public function send(){
  181. $this -> send_info($this -> _post('keyword'), $this -> _get('openid', 'htmlspecialchars'), session('userId'));
  182. }
  183. public function send_info($content, $openid, $pid = 1, $type = 1){
  184. $data['pid'] = (int)$openid;
  185. $data['keyword'] = $content;
  186. $data['public_number_id'] = (int)1;
  187. $data['openid'] = (string)$pid;
  188. $field['fields'] = json_encode($data);
  189. $return=$this->getRpcData("serviceLogs/insert",$field);
  190. echo 1;
  191. exit;
  192. if($api['appid'] == false || $api['appsecret'] == false){
  193. $this -> error('必须先填写【AppId】【 AppSecret】');
  194. exit;
  195. }
  196. $url_get = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $api['appid'] . '&secret=' . $api['appsecret'];
  197. $json = json_decode($this -> curlGet($url_get));
  198. $qrcode_url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $json -> access_token;
  199. $data = '{
  200. "touser":"' . $openid . '",
  201. "msgtype":"text",
  202. "text":
  203. {
  204. "content":"' . $content . '"
  205. }
  206. }';
  207. $post = $this -> api_notice_increment($qrcode_url, $data);
  208. $json_decode = json_decode($post);
  209. if ($checkRt){
  210. }else{
  211. }
  212. if($json_decode -> errmsg == 'ok'){
  213. echo 1;
  214. }else{
  215. echo 2;
  216. }
  217. }
  218. function api_notice_increment($url, $data){
  219. $ch = curl_init();
  220. $header = "Accept-Charset: utf-8";
  221. curl_setopt($ch, CURLOPT_URL, $url);
  222. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  223. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  224. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  225. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  226. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  227. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  228. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  229. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  230. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  231. $tmpInfo = curl_exec($ch);
  232. if ($errorno){
  233. return array('rt' => false, 'errorno' => $errorno);
  234. }else{
  235. return $tmpInfo;
  236. $js = json_decode($tmpInfo, 1);
  237. return $js['ticket'];
  238. }
  239. }
  240. function curlGet($url){
  241. $ch = curl_init();
  242. $header = "Accept-Charset: utf-8";
  243. curl_setopt($ch, CURLOPT_URL, $url);
  244. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
  245. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  246. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  247. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  248. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  249. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  250. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  251. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  252. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  253. $temp = curl_exec($ch);
  254. return $temp;
  255. }
  256. //查看自己的信息记录
  257. public function Informationrecord(){
  258. if(IS_AJAX){
  259. $conf['loginName'] = $this -> _get('username', 'htmlspecialchars');
  260. $page = $_GET['page'];
  261. $rows = $_GET['rows'];
  262. $conf['startTime'] = $_GET['startTime'];
  263. $conf['endTime'] = $_GET['endTime'];
  264. if (!empty($conf['loginName'])){
  265. $conf['loginName'] = $conf['loginName'];
  266. }
  267. //分页
  268. $conf['pageNo'] = !empty($page)?$page:1;
  269. $conf['pageSize'] = !empty($rows)?$rows:10;
  270. $conf['needTotalSize'] = "true";
  271. $conf['publicNumberId']=(int)1;
  272. $questlist = $this->getRpcData('serviceLogs/queryServiceLogsByLoginName', $conf);
  273. foreach($questlist['data']['records'] as $key=>$value){
  274. $records[$key]['id'] = $value['id'];
  275. $records[$key]['keyword'] = $value['keyword'];
  276. $records[$key]['itemName'] = $value['itemName'];
  277. $records[$key]['title'] = $value['title'];
  278. $records[$key]['useNumber'] = $value['useNumber'];
  279. $records[$key]['time'] = date('Y-m-d H:i:s',$value['startTime']/1000)."~".date('Y-m-d H:i:s',$value['endTime']/1000);
  280. if ($value['status'] == "show"){
  281. $records[$key]['status'] = "开启";
  282. }
  283. else{
  284. $records[$key]['status'] = "关闭";
  285. }
  286. }
  287. $data['total'] = $questlist['data']['totalSize'];
  288. $data['rows'] = $records;
  289. echo json_encode($data);
  290. }
  291. }
  292. }
  293. ?>