Wx.class.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. *
  4. */
  5. class Wx
  6. {
  7. public static function getWeixinInfo()
  8. {
  9. $wx_info = es_session::get('wx_info');
  10. if ($wx_info['openid']) {
  11. return $wx_info;
  12. }
  13. if (!isWeixin()) {
  14. return false;
  15. }
  16. $m_config = load_auto_cache("m_config");
  17. if (!($m_config['wx_gz_appid'] && $m_config['wx_gz_secrit'])) {
  18. return false;
  19. }
  20. $current_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
  21. fanwe_require(APP_ROOT_PATH . "system/utils/weixin.php");
  22. $weixin = new weixin($m_config['wx_gz_appid'], $m_config['wx_gz_secrit'], $current_url);
  23. if (!($_REQUEST['code'] && $_REQUEST['state'] == 1)) {
  24. $wx_url = $weixin->scope_get_code();
  25. app_redirect($wx_url);
  26. }
  27. $wx_info = $weixin->scope_get_userinfo($_REQUEST['code']);
  28. fanwe_require(APP_ROOT_PATH . "system/libs/user.php");
  29. es_session::set("wx_info", $wx_info);
  30. wxMakeUser($wx_info);
  31. return $wx_info;
  32. }
  33. }