forward.ctrl.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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['setting']['authmode'] = 1;
  8. unset($_SESSION['uid']);
  9. if($_GPC['__auth']) {
  10. $auth = @json_decode(base64_decode($_GPC['__auth']), true);
  11. if(is_array($auth) && !empty($auth['openid']) && !empty($auth['acid']) && !empty($auth['time']) && !empty($auth['hash'])) {
  12. if(($_W['setting']['authmode'] == 2 && abs($auth['time'] - TIMESTAMP) < 180) || $_W['setting']['authmode'] == 1) {
  13. $fan = mc_fansinfo($auth['openid']);
  14. if(!empty($fan)) {
  15. $hash = md5("{$auth['openid']}{$auth['time']}{$fan['salt']}{$_W['config']['setting']['authkey']}");
  16. if($auth['hash'] == $hash) {
  17. if ($_W['setting']['authmode'] == 2) {
  18. $rec = array();
  19. do{
  20. $rec['salt'] = random(8);
  21. } while ($rec['salt'] == $fan['salt']);
  22. pdo_update ('mc_mapping_fans', $rec, array('uniacid' => $_W['uniacid'], 'acid' => $auth['acid'], 'openid' => $auth['openid']));
  23. }
  24. $_SESSION['uniacid'] = $_W['uniacid'];
  25. $_SESSION['acid'] = $auth['acid'];
  26. $_SESSION['openid'] = $auth['openid'];
  27. if ($_W['account']['level'] == '3' && empty($fan['nickname'])) {
  28. $account_obj = WeAccount::create($_W['account']);
  29. $userinfo = $account_obj->fansQueryInfo($auth['openid']);
  30. if(!is_error($userinfo) && is_array($userinfo) && !empty($userinfo['nickname'])) {
  31. $record = array();
  32. $record['updatetime'] = TIMESTAMP;
  33. $record['nickname'] = stripslashes($userinfo['nickname']);
  34. $record['tag'] = base64_encode(iserializer($userinfo));
  35. $recode['unionid'] = $userinfo['unionid'];
  36. pdo_update('mc_mapping_fans', $record, array('openid' => $fan['openid']));
  37. if(!empty($fan['uid'])) {
  38. $user = mc_fetch($fan['uid'], array('nickname', 'gender', 'residecity', 'resideprovince', 'nationality', 'avatar'));
  39. $record = array();
  40. if(empty($user['nickname']) && !empty($userinfo['nickname'])) {
  41. $record['nickname'] = stripslashes($userinfo['nickname']);
  42. }
  43. if(empty($user['gender']) && !empty($userinfo['sex'])) {
  44. $record['gender'] = $userinfo['sex'];
  45. }
  46. if(empty($user['residecity']) && !empty($userinfo['city'])) {
  47. $record['residecity'] = $userinfo['city'] . '市';
  48. }
  49. if(empty($user['resideprovince']) && !empty($userinfo['province'])) {
  50. $record['resideprovince'] = $userinfo['province'] . '省';
  51. }
  52. if(empty($user['nationality']) && !empty($userinfo['country'])) {
  53. $record['nationality'] = $userinfo['country'];
  54. }
  55. if(empty($user['avatar']) && !empty($userinfo['headimgurl'])) {
  56. $record['avatar'] = $userinfo['headimgurl'];
  57. }
  58. if(!empty($record)) {
  59. mc_update($user['uid'], $record);
  60. }
  61. }
  62. }
  63. }
  64. $member = mc_fetch($fan['uid']);
  65. if (!empty($member)) {
  66. $_SESSION['uid'] = $fan['uid'];
  67. }
  68. }
  69. }
  70. }
  71. }
  72. }
  73. $forward = @base64_decode($_GPC['forward']);
  74. if(empty($forward)) {
  75. $forward = url('mc');
  76. } else {
  77. $forward = (strexists($forward, 'http://') || strexists($forward, 'https://')) ? $forward : $_W['siteroot'] . 'app/' . $forward;
  78. }
  79. if(strexists($forward, '#')) {
  80. $pieces = explode('#', $forward, 2);
  81. $forward = $pieces[0];
  82. }
  83. $forward = str_replace('&wxref=mp.weixin.qq.com', '', $forward);
  84. $forward .= '&wxref=mp.weixin.qq.com#wechat_redirect';
  85. header('location:' . $forward);