人人商城

notice.ctrl.php 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. $_W['page']['title'] = '发送客服消息 - 粉丝管理 - 粉丝管理';
  8. $dos = array('keyword', 'fans', 'transmit', 'post', 'tpl', 'log', 'end');
  9. $do = in_array($do, $dos) ? $do : 'fans';
  10. define('ACTIVE_FRAME_URL', url('mc/fans/tpl'));
  11. if($do == 'keyword') {
  12. if($_W['isajax']) {
  13. $condition = '';
  14. $key_word = trim($_GPC['key_word']);
  15. if(!empty($key_word)) {
  16. $condition = " AND content LIKE '%{$key_word}%' AND (module = 'news' OR module = 'cover')";
  17. } else {
  18. $condition = " AND (module = 'news' OR module = 'cover')";
  19. }
  20. $data = pdo_fetchall('SELECT content, module, rid FROM ' . tablename('rule_keyword') . " WHERE uniacid = :uniacid AND status != 0 " . $condition . ' ORDER BY uniacid DESC,displayorder DESC LIMIT 100', array(':uniacid' => $_W['uniacid']));
  21. $exit_da = array();
  22. if(!empty($data)) {
  23. foreach($data as $da) {
  24. $exit_da[] = array('content' => $da['content'], 'rid' => $da['rid']);
  25. }
  26. }
  27. exit(json_encode($exit_da));
  28. }
  29. exit('error');
  30. }
  31. if($do == 'fans') {
  32. $fanid = intval($_GPC['fanid']);
  33. $fans = pdo_fetch('SELECT acid,openid FROM ' . tablename('mc_mapping_fans') . ' WHERE uniacid = :uniacid AND fanid = :fanid', array(':uniacid' => $_W['uniacid'], ':fanid' => $fanid));
  34. template('mc/notice');
  35. exit();
  36. }
  37. if($do == 'post') {
  38. $msgtype = trim($_GPC['msgtype']);
  39. $acid = $_W['acid'];
  40. $send['touser'] = trim($_GPC['openid']);
  41. $send['msgtype'] = $msgtype;
  42. $fans = pdo_fetch('SELECT salt,acid,openid FROM ' . tablename('mc_mapping_fans') . ' WHERE acid = :acid AND openid = :openid', array(':acid' => $acid, ':openid' => $send['touser']));
  43. if($msgtype == 'text') {
  44. $send['text'] = array('content' => urlencode($_GPC['content']));
  45. } elseif($msgtype == 'image') {
  46. $send['image'] = array('media_id' => $_GPC['media_id']);
  47. } elseif($msgtype == 'voice') {
  48. $send['voice'] = array('media_id' => $_GPC['media_id']);
  49. } elseif($msgtype == 'video') {
  50. $send['video'] = array(
  51. 'media_id' => $_GPC['media_id'],
  52. 'thumb_media_id' => $_GPC['thumb_media_id'],
  53. 'title' => urlencode($_GPC['title']),
  54. 'description' => urlencode($_GPC['description'])
  55. );
  56. } elseif($msgtype == 'music') {
  57. $send['music'] = array(
  58. 'musicurl' => tomedia($_GPC['musicurl']),
  59. 'hqmusicurl' => tomedia($_GPC['hqmusicurl']),
  60. 'title' => urlencode($_GPC['title']),
  61. 'description' => urlencode($_GPC['description']),
  62. 'thumb_media_id' => $_GPC['thumb_media_id'],
  63. );
  64. } elseif($msgtype == 'news') {
  65. $rid = intval($_GPC['ruleid']);
  66. $rule = pdo_fetch('SELECT module,name FROM ' . tablename('rule') . ' WHERE id = :rid', array(':rid' => $rid));
  67. if(empty($rule)) {
  68. exit(json_encode(array('status' => 'error', 'message' => '没有找到指定关键字的回复内容,请检查关键字的对应规则')));
  69. }
  70. $idata = array('rid' => $rid, 'name' => $rule['name'], 'module' => $rule['module']);
  71. $module = $rule['module'];
  72. $reply = pdo_fetchall('SELECT * FROM ' . tablename($module . '_reply') . ' WHERE rid = :rid', array(':rid' => $rid));
  73. if($module == 'cover') {
  74. $idata['do'] = $reply[0]['do'];
  75. $idata['cmodule'] = $reply[0]['module'];
  76. }
  77. if(!empty($reply)) {
  78. foreach($reply as $c) {
  79. $row = array();
  80. $row['title'] = urlencode($c['title']);
  81. $row['description'] = urlencode($c['description']);
  82. !empty($c['thumb']) && ($row['picurl'] = tomedia($c['thumb']));
  83. if(strexists($c['url'], 'http://') || strexists($c['url'], 'https://')) {
  84. $row['url'] = $c['url'];
  85. } else {
  86. $pass['time'] = TIMESTAMP;
  87. $pass['acid'] = $fans['acid'];
  88. $pass['openid'] = $fans['openid'];
  89. $pass['hash'] = md5("{$fans['openid']}{$pass['time']}{$fans['salt']}{$_W['config']['setting']['authkey']}");
  90. $auth = base64_encode(json_encode($pass));
  91. $vars = array();
  92. $vars['__auth'] = $auth;
  93. $vars['forward'] = base64_encode($c['url']);
  94. $row['url'] = $_W['siteroot'] . 'app/' . murl('auth/forward', $vars);
  95. }
  96. $news[] = $row;
  97. }
  98. $send['news']['articles'] = $news;
  99. } else {
  100. $idata = array();
  101. $send['news'] = '';
  102. }
  103. }
  104. if($acid) {
  105. $acc = WeAccount::create($acid);
  106. $data = $acc->sendCustomNotice($send);
  107. if(is_error($data)) {
  108. exit(json_encode(array('status' => 'error', 'message' => $data['message'])));
  109. } else {
  110. $account = account_fetch($acid);
  111. $message['from'] = $_W['openid'] = $send['touser'];
  112. $message['to'] = $account['original'];
  113. if(!empty($message['to'])) {
  114. $sessionid = md5($message['from'] . $message['to'] . $_W['uniacid']);
  115. load()->classs('wesession');
  116. load()->classs('account');
  117. session_id($sessionid);
  118. WeSession::start($_W['uniacid'], $_W['openid'], 300);
  119. $processor = WeUtility::createModuleProcessor('chats');
  120. $processor->begin(300);
  121. }
  122. if($send['msgtype'] == 'news') {
  123. $send['news'] = $idata;
  124. }
  125. pdo_insert('mc_chats_record',array(
  126. 'uniacid' => $_W['uniacid'],
  127. 'acid' => $acid,
  128. 'flag' => 1,
  129. 'openid' => $send['touser'],
  130. 'msgtype' => $send['msgtype'],
  131. 'content' => iserializer($send[$send['msgtype']]),
  132. 'createtime' => TIMESTAMP,
  133. ));
  134. exit(json_encode(array('status' => 'success', 'message' => '消息发送成功')));
  135. }
  136. exit();
  137. }
  138. }
  139. if($do == 'tpl') {
  140. $fanid = intval($_GPC['id']);
  141. $fans = pdo_fetch('SELECT fanid,acid,uid,tag,openid FROM ' . tablename('mc_mapping_fans') . ' WHERE uniacid = :uniacid AND fanid = :id', array(':uniacid' => $_W['uniacid'], ':id' => $fanid));
  142. $account = account_fetch($fans['acid']);
  143. if(empty($account['original'])) {
  144. message('发送客服消息前,您必须完善公众号原始ID', url('account/post', array('acid' => $fans['acid'], 'uniacid' => $_W['uniacid'])));
  145. }
  146. $maxid = pdo_fetchcolumn('SELECT id FROM ' . tablename('mc_chats_record') . ' WHERE acid=:acid AND openid = :openid ORDER BY id DESC LIMIT 1', array(':acid' => $fans['acid'], ':openid' => $fans['openid']));
  147. $maxid = ($maxid - 5) > 0 ? ($maxid - 5) : 0;
  148. if(!empty($fans)) {
  149. if (is_base64($fans['tag'])){
  150. $fans['tag'] = base64_decode($fans['tag']);
  151. }
  152. if (is_serialized($fans['tag'])) {
  153. $fans['tag'] = iunserializer($fans['tag']);
  154. }
  155. }
  156. if(!empty($fans['tag']['nickname'])) {
  157. $nickname = $fans['tag']['nickname'];
  158. } else {
  159. $nickname = $fans['openid'];
  160. }
  161. template('mc/notice');
  162. }
  163. if($do == 'log') {
  164. $fanid = intval($_GPC['fanid']);
  165. $id = intval($_GPC['id']);
  166. $type = trim($_GPC['type']) ? trim($_GPC['type']) : 'asc';
  167. $fans = pdo_fetch('SELECT fanid,acid,openid,tag FROM ' . tablename('mc_mapping_fans') . ' WHERE uniacid = :uniacid AND fanid = :id', array(':uniacid' => $_W['uniacid'], ':id' => $fanid));
  168. if(!empty($fans)) {
  169. if (is_base64($fans['tag'])){
  170. $fans['tag'] = base64_decode($fans['tag']);
  171. }
  172. if (is_serialized($fans['tag'])) {
  173. $fans['tag'] = iunserializer($fans['tag']);
  174. }
  175. if(!empty($fans['tag']['headimgurl'])) {
  176. $avatar = rtrim($fans['tag']['headimgurl'], '0');
  177. } else {
  178. $avatar = 'resource/images/noavatar_middle.gif';
  179. }
  180. }
  181. if($type == 'asc') {
  182. $data = pdo_fetchall('SELECT * FROM ' . tablename('mc_chats_record') . ' WHERE acid=:acid AND openid = :openid AND id > :id ORDER BY id ASC LIMIT 5', array(':acid' => $fans['acid'], ':openid' => $fans['openid'], ':id' => $id), 'id');
  183. } else {
  184. $data = pdo_fetchall('SELECT * FROM ' . tablename('mc_chats_record') . ' WHERE acid=:acid AND openid = :openid AND id < :id ORDER BY id DESC LIMIT 5', array(':acid' => $fans['acid'], ':openid' => $fans['openid'], ':id' => $id), 'id');
  185. }
  186. ksort($data);
  187. if(!empty($data)) {
  188. $str = '';
  189. foreach($data as &$da) {
  190. $da['content'] = is_serialized($da['content']) ? iurldecode(iunserializer($da['content'])) : iurldecode($da['content']);
  191. if($da['flag'] == 2) {
  192. if($da['msgtype'] == 'text') {
  193. $str .= tpl_chats_log(emotion($da['content']), $da['createtime']);
  194. } elseif($da['msgtype'] == 'image') {
  195. $imageurl = tomedia($da['content'], true);
  196. $content = '<a href="'.$imageurl.'" target="_blank"><img src="'.$imageurl.'" width="200"></a>';
  197. $str .= tpl_chats_log($content, $da['createtime']);
  198. } elseif($da['msgtype'] == 'link') {
  199. $content = '<a href="'.$da['content'].'" target="_blank">'.$da['content'].'</a>';
  200. $str .= tpl_chats_log($content, $da['createtime']);
  201. } elseif($da['msgtype'] == 'location') {
  202. $content = '<a target="_blank" href="https://st.map.soso.com/api?size=800*600&center='.$da['content']['location_y'].','.$da['content']['location_x'].'&zoom='.$da['content']['scale'].'&markers='.$da['content']['location_y'].','.$da['content']['location_x'].'"><img src="data:image/jpg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAcEBAQFBAcFBQcKBwUHCgwJB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9uyPgysjzAfSVAAAAAAA6vgc+0yyf3/9BYsuRHyZvDx9orv7JG/gYqWOHAgAAAAAAClCAChACtABShACoApQgANKdwArQgJAAphIAVoBAoBIAACAAAAAAAOr4HPtMsn9/wD0Fiy5EfJ6Nws8GMu8rrdr2SpPhFlGTeaWeEnEFpTQ+QyFSx5efBrfUlGWY7P85nvgCni2vp0H4rPfADxbX06D8VnvgB4tr6dB+Kz3wA8W19Og/FZ74AeLa+nQfis98AFcG19cJ/MfjM98GCJPBtfrU+Y+vyzHfHy01Pe4mkrEvi2vrT6j8Znvj6jMqfBvfTV+Y8mnyrPfAFPFtfWv1H4rHfAFU8G99MZVg6P9VjvgCE+DW/VfqPxmO+LqxVlPFrfroPxme+J4EDxa366D8ZjviHYkkf4Nr7ZTUg6KeeY74iJLI/FrfroPxme+LcCo8Wt+ug/GZ74cAPFrfroPxme+HADxa366D8ZnvhwA8Wt+ug/GZ74cAPFrfroPxme+HAFfFrfroPxme+HAHo3BBwVWpYlpfKC3MKZCUGiJHSol0xlRS1GWjZooKtkpH//Z"></a>';
  203. $str .= tpl_chats_log($content, $da['createtime']);
  204. }
  205. } else {
  206. if($da['msgtype'] == 'text') {
  207. $str .= tpl_chats_log(emotion($da['content']['content']), $da['createtime'], 1);
  208. } elseif($da['msgtype'] == 'image') {
  209. $image = media2local($da['content']['media_id']);
  210. $content = '<a href="'.$image.'" target="_blank"><img src="'.$image.'" width="200"></a>';
  211. $str .= tpl_chats_log($content, $da['createtime'], 1);
  212. } elseif($da['msgtype'] == 'voice') {
  213. $image = media2local($da['content']['media_id']);
  214. $content = '<a href="'.$image.'" target="_blank"><i class="fa fa-bullhorn"></i> 语音消息</a>';
  215. $str .= tpl_chats_log($content, $da['createtime'], 1);
  216. } elseif($da['msgtype'] == 'music') {
  217. $music = tomedia($da['content']['hqmusicurl']);
  218. if(empty($music)) {
  219. $music = tomedia($da['content']['musicurl']);
  220. }
  221. $content = '<a href="'.$music.'" target="_blank"><i class="fa fa-music"></i> 音乐消息</a>';
  222. $str .= tpl_chats_log($content, $da['createtime'], 1);
  223. } elseif($da['msgtype'] == 'video') {
  224. $video = media2local($da['content']['media_id']);
  225. $content = '<a href="'.$video.'" target="_blank"><i class="fa fa-video-camera"></i> 视频消息</a>';
  226. $str .= tpl_chats_log($content, $da['createtime'], 1);
  227. } elseif($da['msgtype'] == 'news') {
  228. if($da['content']['module'] == 'news') {
  229. $url = url('platform/reply/post', array('m' => 'news', 'rid' => $da['content']['rid']));
  230. } elseif($da['content']['module'] == 'cover') {
  231. if(in_array($da['content']['cmodule'], array('mc', 'site', 'card'))) {
  232. $url = url('platform/cover/' . $da['content']['cmodule']);
  233. } else {
  234. $eid = pdo_fetchcolumn('SELECT eid FROM ' . tablename('modules_bindings') . ' WHERE module = :m AND do = :do AND entry = :entry', array(':m' => $da['content']['cmodule'], ':do' => $da['content']['do'], ':entry' => 'cover'));
  235. $li['url'] = url('platform/cover/', array('eid' => $eid));
  236. }
  237. }
  238. $content = '<a href="'. $url .'" target="_blank"><i class="fa fa-file-image-o"></i> 图文消息:' . $da['content']['name'] . '</a>';
  239. $str .= tpl_chats_log($content, $da['createtime'], 1);
  240. }
  241. }
  242. }
  243. if($type == 'asc') {
  244. $exit = json_encode(array('code' => 1, 'str' => $str, 'id' => max(array_keys($data))));
  245. } else {
  246. $exit = json_encode(array('code' => 1, 'str' => $str, 'id' => min(array_keys($data))));
  247. }
  248. } else {
  249. $exit = json_encode(array('code' => 2, 'str' => '', 'id' => $id));
  250. }
  251. echo $exit;
  252. exit();
  253. }
  254. if($do == 'end') {
  255. $fanid = intval($_GPC['fanid']);
  256. $fans = pdo_fetch('SELECT fanid,acid,openid FROM ' . tablename('mc_mapping_fans') . ' WHERE uniacid = :uniacid AND fanid = :id', array(':uniacid' => $_W['uniacid'], ':id' => $fanid));
  257. $account = account_fetch($fans['acid']);
  258. $message['from'] = $_W['openid'] = $fans['openid'];
  259. $message['to'] = $account['original'];
  260. if(!empty($message['to'])) {
  261. $sessionid = md5($message['from'] . $message['to'] . $_W['uniacid']);
  262. load()->classs('wesession');
  263. load()->classs('account');
  264. session_id($sessionid);
  265. WeSession::start($_W['uniacid'], $_W['openid'], 300);
  266. $processor = WeUtility::createModuleProcessor('chats');
  267. $processor->end();
  268. }
  269. if(!empty($_GPC['from'])) {
  270. $url = base64_decode($_GPC['from']);
  271. } else {
  272. $url = url('mc/fans/', array('acid' => $fans['acid']));
  273. }
  274. header('Location:' . $url);
  275. exit();
  276. }
  277. function iurldecode($str) {
  278. if(!is_array($str)) {
  279. return urldecode($str);
  280. }
  281. foreach($str as $key => $val) {
  282. $str[$key] = iurldecode($val);
  283. }
  284. return $str;
  285. }
  286. function tpl_chats_log($content, $time, $flag = 2) {
  287. global $avatar;
  288. if($flag == 2) {
  289. $str = '<div class="pull-left col-lg-12 col-md-12 col-sm-12 col-xs-12">' .
  290. '<div class="pull-left">' .
  291. '<img src="' . $avatar . '" width="35"><br>' .
  292. '</div>' .
  293. '<div class="alert alert-info pull-left infol">' .
  294. $content . '<br>' . date('m-d H:i:s', $time) .
  295. '</div>' .
  296. '<div style="clear:both"></div>' .
  297. '</div>'.
  298. '<div style="clear:both"></div>';
  299. } else {
  300. $str = '<div class="pull-left col-lg-12 col-md-12 col-sm-12 col-xs-12">' .
  301. '<div class="pull-right">' .
  302. '<img src="resource/images/gw-wx.gif" width="35" style="border:2px solid #418BCA;border-radius:5px"><br>' .
  303. '</div>' .
  304. '<div class="alert alert-info pull-right infor">' .
  305. $content . '<br>' . date('m-d H:i:s', $time) .
  306. '</div>' .
  307. '<div style="clear:both"></div>' .
  308. '</div>'.
  309. '<div style="clear:both"></div>';
  310. }
  311. return $str;
  312. }