bootstrap.app.inc.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. load()->model('mc');
  8. load()->model('app');
  9. load()->model('account');
  10. load()->model('attachment');
  11. load()->model('module');
  12. $_W['uniacid'] = intval($_GPC['i']);
  13. if(empty($_W['uniacid'])) {
  14. $_W['uniacid'] = intval($_GPC['weid']);
  15. }
  16. $_W['uniaccount'] = $_W['account'] = uni_fetch($_W['uniacid']);
  17. if(empty($_W['uniaccount'])) {
  18. header('HTTP/1.1 404 Not Found');
  19. header("status: 404 Not Found");
  20. exit;
  21. }
  22. if (!empty($_W['uniaccount']['endtime']) && TIMESTAMP > $_W['uniaccount']['endtime']) {
  23. exit('抱歉,您的公众号服务已过期,请及时联系管理员');
  24. }
  25. if (app_pass_visit_limit()) {
  26. exit('访问受限,请及时联系管理员!');
  27. }
  28. $_W['acid'] = $_W['uniaccount']['acid'];
  29. $isdel_account = pdo_get('account', array('isdeleted' => 1, 'acid' => $_W['acid']));
  30. if (!empty($isdel_account)) {
  31. exit('指定公众号已被删除');
  32. }
  33. if (!empty($_W['account']['setting']['bind_domain']) && !empty($_W['account']['setting']['bind_domain']['domain']) && strpos($_W['siteroot'], $_W['account']['setting']['bind_domain']['domain']) === false) {
  34. header('Location:' . $_W['account']['setting']['bind_domain']['domain']. $_SERVER['REQUEST_URI']);
  35. exit;
  36. }
  37. $_W['session_id'] = '';
  38. if (isset($_GPC['state']) && !empty($_GPC['state']) && strexists($_GPC['state'], 'we7sid-')) {
  39. $pieces = explode('-', $_GPC['state']);
  40. $_W['session_id'] = $pieces[1];
  41. unset($pieces);
  42. }
  43. if (empty($_W['session_id'])) {
  44. $_W['session_id'] = $_COOKIE[session_name()];
  45. }
  46. if (empty($_W['session_id'])) {
  47. $_W['session_id'] = "{$_W['uniacid']}-" . random(20) ;
  48. $_W['session_id'] = md5($_W['session_id']);
  49. setcookie(session_name(), $_W['session_id']);
  50. }
  51. session_id($_W['session_id']);
  52. load()->classs('wesession');
  53. WeSession::start($_W['uniacid'], CLIENT_IP);
  54. if (!empty($_GPC['j'])) {
  55. $acid = intval($_GPC['j']);
  56. $_W['account'] = account_fetch($acid);
  57. if (is_error($_W['account'])) {
  58. $_W['account'] = account_fetch($_W['acid']);
  59. } else {
  60. $_W['acid'] = $acid;
  61. }
  62. $_SESSION['__acid'] = $_W['acid'];
  63. $_SESSION['__uniacid'] = $_W['uniacid'];
  64. }
  65. if (!empty($_SESSION['__acid']) && $_SESSION['__uniacid'] == $_W['uniacid']) {
  66. $_W['acid'] = intval($_SESSION['__acid']);
  67. $_W['account'] = account_fetch($_W['acid']);
  68. }
  69. if ((!empty($_SESSION['acid']) && $_W['acid'] != $_SESSION['acid']) ||
  70. (!empty($_SESSION['uniacid']) && $_W['uniacid'] != $_SESSION['uniacid'])) {
  71. $keys = array_keys($_SESSION);
  72. foreach ($keys as $key) {
  73. unset($_SESSION[$key]);
  74. }
  75. unset($keys, $key);
  76. }
  77. $_SESSION['acid'] = $_W['acid'];
  78. $_SESSION['uniacid'] = $_W['uniacid'];
  79. if (!empty($_SESSION['openid'])) {
  80. $_W['openid'] = $_SESSION['openid'];
  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. $uid = intval($_SESSION['uid']);
  86. if (empty($uid)) {
  87. $uid = $_W['fans']['uid'];
  88. }
  89. _mc_login(array('uid' => $uid));
  90. unset($uid);
  91. }
  92. if (empty($_W['openid']) && !empty($_SESSION['oauth_openid'])) {
  93. $_W['openid'] = $_SESSION['oauth_openid'];
  94. $_W['fans'] = array(
  95. 'openid' => $_SESSION['oauth_openid'],
  96. 'from_user' => $_SESSION['oauth_openid'],
  97. 'follow' => 0
  98. );
  99. }
  100. $unisetting = uni_setting_load();
  101. if (!empty($unisetting['oauth']['account'])) {
  102. $oauth = account_fetch($unisetting['oauth']['account']);
  103. if (!empty($oauth) && $_W['account']['level'] <= $oauth['level']) {
  104. $_W['oauth_account'] = $_W['account']['oauth'] = array(
  105. 'key' => $oauth['key'],
  106. 'secret' => $oauth['secret'],
  107. 'acid' => $oauth['acid'],
  108. 'type' => $oauth['type'],
  109. 'level' => $oauth['level'],
  110. );
  111. unset($oauth);
  112. } else {
  113. $_W['oauth_account'] = $_W['account']['oauth'] = array(
  114. 'key' => $_W['account']['key'],
  115. 'secret' => $_W['account']['secret'],
  116. 'acid' => $_W['account']['acid'],
  117. 'type' => $_W['account']['type'],
  118. 'level' => $_W['account']['level'],
  119. );
  120. }
  121. } else {
  122. $_W['oauth_account'] = $_W['account']['oauth'] = array(
  123. 'key' => $_W['account']['key'],
  124. 'secret' => $_W['account']['secret'],
  125. 'acid' => $_W['account']['acid'],
  126. 'type' => $_W['account']['type'],
  127. 'level' => $_W['account']['level'],
  128. );
  129. }
  130. if($controller != 'utility') {
  131. $_W['token'] = token();
  132. }
  133. if (!empty($_W['account']['oauth']) && $_W['account']['oauth']['level'] == '4' && empty($_W['isajax'])) {
  134. if (($_W['container'] == 'wechat' && !$_GPC['logout'] && empty($_W['openid']) && ($controller != 'auth' || ($controller == 'auth' && !in_array($action, array('forward', 'oauth'))))) ||
  135. ($_W['container'] == 'wechat' && !$_GPC['logout'] && empty($_SESSION['oauth_openid']) && ($controller != 'auth'))) {
  136. $state = 'we7sid-'.$_W['session_id'];
  137. if (empty($_SESSION['dest_url'])) {
  138. $_SESSION['dest_url'] = urlencode($_W['siteurl']);
  139. }
  140. $str = '';
  141. if(uni_is_multi_acid()) {
  142. $str = "&j={$_W['acid']}";
  143. }
  144. $oauth_type = 'snsapi_base';
  145. if ($controller == 'entry' && !empty($_GPC['m'])) {
  146. $module_info = module_fetch($_GPC['m']);
  147. if ($module_info['oauth_type'] == OAUTH_TYPE_USERINFO) {
  148. $oauth_type = 'snsapi_userinfo';
  149. }
  150. }
  151. $url = (!empty($unisetting['oauth']['host']) ? ($unisetting['oauth']['host'] . $sitepath . '/') : $_W['siteroot'] . 'app/') . "index.php?i={$_W['uniacid']}{$str}&c=auth&a=oauth&scope=" . $oauth_type;
  152. $callback = urlencode($url);
  153. $oauth_account = WeAccount::create($_W['account']['oauth']);
  154. if ($oauth_type == 'snsapi_base') {
  155. $forward = $oauth_account->getOauthCodeUrl($callback, $state);
  156. } else {
  157. $forward = $oauth_account->getOauthUserInfoUrl($callback, $state);
  158. }
  159. header('Location: ' . $forward);
  160. exit();
  161. }
  162. }
  163. $_W['account']['groupid'] = $_W['uniaccount']['groupid'];
  164. $_W['account']['qrcode'] = tomedia('qrcode_'.$_W['acid'].'.jpg').'?time='.$_W['timestamp'];
  165. $_W['account']['avatar'] = tomedia('headimg_'.$_W['acid'].'.jpg').'?time='.$_W['timestamp'];
  166. if ($_W['container'] == 'wechat') {
  167. if (!empty($unisetting['jsauth_acid'])) {
  168. $jsauth_acid = $unisetting['jsauth_acid'];
  169. } else {
  170. if ($_W['account']['level'] < 3 && !empty($unisetting['oauth']['account'])) {
  171. $jsauth_acid = $unisetting['oauth']['account'];
  172. } else {
  173. $jsauth_acid = $_W['acid'];
  174. }
  175. }
  176. if (!empty($jsauth_acid)) {
  177. $account_api = WeAccount::create($jsauth_acid);
  178. if (!empty($account_api)) {
  179. $_W['account']['jssdkconfig'] = $account_api->getJssdkConfig();
  180. $_W['account']['jsauth_acid'] = $jsauth_acid;
  181. }
  182. }
  183. unset($jsauth_acid, $account_api);
  184. }
  185. $_W['attachurl'] = attachment_set_attach_url();
  186. load()->func('compat.biz');