人人商城

forward.ctrl.php 3.4KB

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. pdo_update('mc_mapping_fans', $record, array('openid' => $fan['openid']));
  36. if(!empty($fan['uid'])) {
  37. $user = mc_fetch($fan['uid'], array('nickname', 'gender', 'residecity', 'resideprovince', 'nationality', 'avatar'));
  38. $record = array();
  39. if(empty($user['nickname']) && !empty($userinfo['nickname'])) {
  40. $record['nickname'] = stripslashes($userinfo['nickname']);
  41. }
  42. if(empty($user['gender']) && !empty($userinfo['sex'])) {
  43. $record['gender'] = $userinfo['sex'];
  44. }
  45. if(empty($user['residecity']) && !empty($userinfo['city'])) {
  46. $record['residecity'] = $userinfo['city'] . '市';
  47. }
  48. if(empty($user['resideprovince']) && !empty($userinfo['province'])) {
  49. $record['resideprovince'] = $userinfo['province'] . '省';
  50. }
  51. if(empty($user['nationality']) && !empty($userinfo['country'])) {
  52. $record['nationality'] = $userinfo['country'];
  53. }
  54. if(empty($user['avatar']) && !empty($userinfo['headimgurl'])) {
  55. $record['avatar'] = $userinfo['headimgurl'];
  56. }
  57. if(!empty($record)) {
  58. mc_update($user['uid'], $record);
  59. }
  60. }
  61. }
  62. }
  63. $member = mc_fetch($fan['uid']);
  64. if (!empty($member)) {
  65. $_SESSION['uid'] = $fan['uid'];
  66. }
  67. }
  68. }
  69. }
  70. }
  71. }
  72. $forward = @base64_decode($_GPC['forward']);
  73. if(empty($forward)) {
  74. $forward = url('mc');
  75. } else {
  76. $forward = (strexists($forward, 'http://') || strexists($forward, 'https://')) ? $forward : $_W['siteroot'] . 'app/' . $forward;
  77. }
  78. if(strexists($forward, '#')) {
  79. $pieces = explode('#', $forward, 2);
  80. $forward = $pieces[0];
  81. }
  82. $forward = str_replace('&wxref=mp.weixin.qq.com', '', $forward);
  83. $forward .= '&wxref=mp.weixin.qq.com#wechat_redirect';
  84. header('location:' . $forward);