人人商城

bootstrap.app.inc.php 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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'], 0, '/');
  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. $_W['oauth_account'] = $_W['account']['oauth'] = array(
  101. 'key' => $_W['account']['key'],
  102. 'secret' => $_W['account']['secret'],
  103. 'acid' => $_W['account']['acid'],
  104. 'type' => $_W['account']['type'],
  105. 'level' => $_W['account']['level'],
  106. 'support_oauthinfo' => $_W['account']->supportOauthInfo,
  107. 'support_jssdk' => $_W['account']->supportJssdk,
  108. );
  109. $unisetting = uni_setting_load();
  110. if (empty($unisetting['oauth'])) {
  111. $unisetting['oauth'] = uni_account_global_oauth();
  112. }
  113. if (!empty($unisetting['oauth']['account'])) {
  114. $oauth = account_fetch($unisetting['oauth']['account']);
  115. if (!empty($oauth) && $_W['account']['level'] <= $oauth['level']) {
  116. $_W['oauth_account'] = $_W['account']['oauth'] = array(
  117. 'key' => $oauth['key'],
  118. 'secret' => $oauth['secret'],
  119. 'acid' => $oauth['acid'],
  120. 'type' => $oauth['type'],
  121. 'level' => $oauth['level'],
  122. 'support_oauthinfo' => $oauth->supportOauthInfo,
  123. 'support_jssdk' => $oauth->supportJssdk,
  124. );
  125. unset($oauth);
  126. }
  127. }
  128. if($controller != 'utility') {
  129. $_W['token'] = token();
  130. }
  131. if (!empty($_W['account']['oauth']) && $_W['account']['oauth']['support_oauthinfo'] && empty($_W['isajax'])) {
  132. if (($_W['platform'] == 'account' && !$_GPC['logout'] && empty($_W['openid']) && ($controller != 'auth' || ($controller == 'auth' && !in_array($action, array('forward', 'oauth'))))) ||
  133. ($_W['platform'] == 'account' && !$_GPC['logout'] && empty($_SESSION['oauth_openid']) && ($controller != 'auth'))) {
  134. $state = 'we7sid-'.$_W['session_id'];
  135. if (empty($_SESSION['dest_url'])) {
  136. $_SESSION['dest_url'] = urlencode($_W['siteurl']);
  137. }
  138. $str = '';
  139. if(uni_is_multi_acid()) {
  140. $str = "&j={$_W['acid']}";
  141. }
  142. $oauth_type = 'snsapi_base';
  143. if ($controller == 'entry' && !empty($_GPC['m'])) {
  144. $module_info = module_fetch($_GPC['m']);
  145. if ($module_info['oauth_type'] == OAUTH_TYPE_USERINFO) {
  146. $oauth_type = 'snsapi_userinfo';
  147. }
  148. }
  149. $oauth_url = uni_account_oauth_host();
  150. $url = $oauth_url . "app/index.php?i={$_W['uniacid']}{$str}&c=auth&a=oauth&scope=" . $oauth_type;
  151. $callback = urlencode($url);
  152. $oauth_account = WeAccount::create($_W['account']['oauth']);
  153. if ($oauth_type == 'snsapi_base') {
  154. $forward = $oauth_account->getOauthCodeUrl($callback, $state);
  155. } else {
  156. $forward = $oauth_account->getOauthUserInfoUrl($callback, $state);
  157. }
  158. header('Location: ' . $forward);
  159. exit();
  160. }
  161. }
  162. $_W['account']['groupid'] = $_W['uniaccount']['groupid'];
  163. $_W['account']['qrcode'] = tomedia('qrcode_'.$_W['acid'].'.jpg').'?time='.$_W['timestamp'];
  164. $_W['account']['avatar'] = tomedia('headimg_'.$_W['acid'].'.jpg').'?time='.$_W['timestamp'];
  165. if ($_W['platform'] == 'account' && $_W['account']->supportJssdk && $controller != 'utility') {
  166. if (!empty($unisetting['jsauth_acid'])) {
  167. $jsauth_acid = $unisetting['jsauth_acid'];
  168. } else {
  169. if ($_W['account']['level'] < 3 && !empty($unisetting['oauth']['account'])) {
  170. $jsauth_acid = $unisetting['oauth']['account'];
  171. } else {
  172. $jsauth_acid = $_W['acid'];
  173. }
  174. }
  175. if (!empty($jsauth_acid)) {
  176. $account_api = WeAccount::create($jsauth_acid);
  177. if (!empty($account_api)) {
  178. $_W['account']['jssdkconfig'] = $account_api->getJssdkConfig();
  179. $_W['account']['jsauth_acid'] = $jsauth_acid;
  180. }
  181. }
  182. unset($jsauth_acid, $account_api);
  183. }
  184. $_W['attachurl'] = attachment_set_attach_url();
  185. load()->func('compat.biz');