wxapp.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. define('IN_MOBILE', true);
  3. require '../framework/bootstrap.inc.php';
  4. load()->app('common');
  5. load()->app('template');
  6. load()->model('mc');
  7. load()->model('app');
  8. $_W['uniacid'] = intval($_GPC['i']);
  9. if (empty($_W['uniacid']))
  10. {
  11. $_W['uniacid'] = intval($_GPC['weid']);
  12. }
  13. $_W['uniaccount'] = $_W['account'] = uni_fetch($_W['uniacid']);
  14. if (empty($_W['uniaccount']))
  15. {
  16. header('HTTP/1.1 404 Not Found');
  17. header('status: 404 Not Found');
  18. exit();
  19. }
  20. $_W['acid'] = $_W['uniaccount']['acid'];
  21. $isdel_account = pdo_get('account', array('isdeleted' => 1, 'acid' => $_W['acid']));
  22. if (!(empty($isdel_account)))
  23. {
  24. exit('指定公众号已被删除');
  25. }
  26. $_W['session_id'] = '';
  27. if (isset($_GPC['state']) && !(empty($_GPC['state'])) && strexists($_GPC['state'], 'we7sid-'))
  28. {
  29. $pieces = explode('-', $_GPC['state']);
  30. $_W['session_id'] = $pieces[1];
  31. unset($pieces);
  32. }
  33. if (empty($_W['session_id']))
  34. {
  35. $_W['session_id'] = $_COOKIE[session_name()];
  36. }
  37. if (empty($_W['session_id']))
  38. {
  39. $_W['session_id'] = $_W['uniacid'] . '-' . random(20);
  40. $_W['session_id'] = md5($_W['session_id']);
  41. setcookie(session_name(), $_W['session_id']);
  42. }
  43. session_id($_W['session_id']);
  44. load()->classs('wesession');
  45. WeSession::start($_W['uniacid'], CLIENT_IP);
  46. if (!(empty($_GPC['j'])))
  47. {
  48. $acid = intval($_GPC['j']);
  49. $_W['account'] = account_fetch($acid);
  50. if (is_error($_W['account']))
  51. {
  52. $_W['account'] = account_fetch($_W['acid']);
  53. }
  54. else
  55. {
  56. $_W['acid'] = $acid;
  57. }
  58. $_SESSION['__acid'] = $_W['acid'];
  59. $_SESSION['__uniacid'] = $_W['uniacid'];
  60. }
  61. if (!(empty($_SESSION['__acid'])) && ($_SESSION['__uniacid'] == $_W['uniacid']))
  62. {
  63. $_W['acid'] = intval($_SESSION['__acid']);
  64. $_W['account'] = account_fetch($_W['acid']);
  65. }
  66. if ((!(empty($_SESSION['acid'])) && ($_W['acid'] != $_SESSION['acid'])) || (!(empty($_SESSION['uniacid'])) && ($_W['uniacid'] != $_SESSION['uniacid'])))
  67. {
  68. $keys = array_keys($_SESSION);
  69. foreach ($keys as $key )
  70. {
  71. unset($_SESSION[$key]);
  72. }
  73. unset($keys, $key);
  74. }
  75. $_SESSION['acid'] = $_W['acid'];
  76. $_SESSION['uniacid'] = $_W['uniacid'];
  77. if (!(empty($_SESSION['openid'])))
  78. {
  79. $_W['openid'] = $_SESSION['openid'];
  80. $_W['unionid'] = $_SESSION['unionid'];
  81. $_W['fans'] = mc_fansinfo($_W['openid']);
  82. $_W['fans']['from_user'] = $_W['fans']['openid'] = $_W['openid'];
  83. }
  84. if (!(empty($_SESSION['uid'])) || (!(empty($_W['fans'])) && !(empty($_W['fans']['uid']))))
  85. {
  86. $uid = intval($_SESSION['uid']);
  87. if (empty($uid))
  88. {
  89. $uid = $_W['fans']['uid'];
  90. }
  91. _mc_login(array('uid' => $uid));
  92. unset($uid);
  93. }
  94. if (empty($_W['openid']) && !(empty($_SESSION['oauth_openid'])))
  95. {
  96. $_W['openid'] = $_SESSION['oauth_openid'];
  97. $_W['fans'] = array('openid' => $_SESSION['oauth_openid'], 'from_user' => $_SESSION['oauth_openid'], 'follow' => 0);
  98. }
  99. $unisetting = uni_setting_load();
  100. if (!(empty($unisetting['oauth']['account'])))
  101. {
  102. $oauth = account_fetch($unisetting['oauth']['account']);
  103. if (!(empty($oauth)) && ($_W['account']['level'] <= $oauth['level']))
  104. {
  105. $_W['oauth_account'] = $_W['account']['oauth'] = array('key' => $oauth['key'], 'secret' => $oauth['secret'], 'acid' => $oauth['acid'], 'type' => $oauth['type'], 'level' => $oauth['level']);
  106. unset($oauth);
  107. }
  108. else
  109. {
  110. $_W['oauth_account'] = $_W['account']['oauth'] = array('key' => $_W['account']['key'], 'secret' => $_W['account']['secret'], 'acid' => $_W['account']['acid'], 'type' => $_W['account']['type'], 'level' => $_W['account']['level']);
  111. }
  112. }
  113. else
  114. {
  115. $_W['oauth_account'] = $_W['account']['oauth'] = array('key' => $_W['account']['key'], 'secret' => $_W['account']['secret'], 'acid' => $_W['account']['acid'], 'type' => $_W['account']['type'], 'level' => $_W['account']['level']);
  116. }
  117. $_W['account']['groupid'] = $_W['uniaccount']['groupid'];
  118. $_W['account']['qrcode'] = tomedia('qrcode_' . $_W['acid'] . '.jpg') . '?time=' . $_W['timestamp'];
  119. $_W['account']['avatar'] = tomedia('headimg_' . $_W['acid'] . '.jpg') . '?time=' . $_W['timestamp'];
  120. $_W['attachurl'] = $_W['attachurl_local'] = $_W['siteroot'] . $_W['config']['upload']['attachdir'] . '/';
  121. if (!(empty($_W['setting']['remote'][$_W['uniacid']]['type'])))
  122. {
  123. $_W['setting']['remote'] = $_W['setting']['remote'][$_W['uniacid']];
  124. }
  125. if (!(empty($_W['setting']['remote']['type'])))
  126. {
  127. if ($_W['setting']['remote']['type'] == ATTACH_FTP)
  128. {
  129. $_W['attachurl'] = $_W['attachurl_remote'] = $_W['setting']['remote']['ftp']['url'] . '/';
  130. }
  131. else if ($_W['setting']['remote']['type'] == ATTACH_OSS)
  132. {
  133. $_W['attachurl'] = $_W['attachurl_remote'] = $_W['setting']['remote']['alioss']['url'] . '/';
  134. }
  135. else if ($_W['setting']['remote']['type'] == ATTACH_QINIU)
  136. {
  137. $_W['attachurl'] = $_W['attachurl_remote'] = $_W['setting']['remote']['qiniu']['url'] . '/';
  138. }
  139. else if ($_W['setting']['remote']['type'] == ATTACH_COS)
  140. {
  141. $_W['attachurl'] = $_W['attachurl_remote'] = $_W['setting']['remote']['cos']['url'] . '/';
  142. }
  143. }
  144. $acl = array( 'home' => array('default' => 'home'), 'mc' => array('default' => 'home') );
  145. $controllers = array();
  146. $handle = opendir(IA_ROOT . '/app/source/');
  147. if (!(empty($handle)))
  148. {
  149. while ($dir = readdir($handle))
  150. {
  151. if (($dir != '.') && ($dir != '..'))
  152. {
  153. $controllers[] = $dir;
  154. }
  155. }
  156. }
  157. if (!(in_array($controller, $controllers)))
  158. {
  159. $controller = 'home';
  160. }
  161. $init = IA_ROOT . '/app/source/' . $controller . '/__init.php';
  162. if (is_file($init))
  163. {
  164. require $init;
  165. }
  166. $actions = array();
  167. $handle = opendir(IA_ROOT . '/app/source/' . $controller);
  168. if (!(empty($handle)))
  169. {
  170. while ($dir = readdir($handle))
  171. {
  172. if (($dir != '.') && ($dir != '..') && strexists($dir, '.ctrl.php'))
  173. {
  174. $dir = str_replace('.ctrl.php', '', $dir);
  175. $actions[] = $dir;
  176. }
  177. }
  178. }
  179. if (empty($actions))
  180. {
  181. $str = '';
  182. if (uni_is_multi_acid())
  183. {
  184. $str = '&j=' . $_W['acid'];
  185. }
  186. header('location: index.php?i=' . $_W['uniacid'] . $str . '&c=home?refresh');
  187. }
  188. if (!(in_array($action, $actions)))
  189. {
  190. $action = $acl[$controller]['default'];
  191. }
  192. if (!(in_array($action, $actions)))
  193. {
  194. $action = $actions[0];
  195. }
  196. require _forward($controller, $action);
  197. function _forward($c, $a)
  198. {
  199. $file = IA_ROOT . '/app/source/' . $c . '/' . $a . '.ctrl.php';
  200. return $file;
  201. }
  202. ?>