User.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Author: luzheng.liu
  4. * Time: 2020/12/5 17:15
  5. */
  6. namespace app\index\controller;
  7. use app\common\service\CommonService;
  8. use app\index\BaseController;
  9. use app\index\exception\ApiException;
  10. use app\index\model\UserModel;
  11. use app\index\model\VisitorModel;
  12. use think\facade\Cache;
  13. use think\facade\Session;
  14. class User extends BaseController {
  15. public function login() {
  16. $channelId = input('channelId');
  17. if (empty($channelId)){
  18. throw new ApiException('渠道id不为空');
  19. }
  20. // if (empty(input('unionid'))){
  21. // throw new ApiException('unionid不为空');
  22. // }
  23. $params = [
  24. 'id' => $channelId,
  25. 'userid' => input('unionid'),
  26. 'name' => input('nickName'),
  27. 'avatar' => input('avatar'),
  28. 'key' => md5(input('unionid').CommonService::getSetData($channelId)['channel_auth_code'])
  29. ];
  30. Session::set('wxId',input('unionid'));
  31. (new UserModel())->insertGetId([
  32. 'channel_id' => $channelId,
  33. 'unionid' => input('unionid'),
  34. 'name' => input('nickName'),
  35. 'avatar' => input('avatar'),
  36. 'key' => $params['key'],
  37. ]);
  38. header('Location:http://webcasting.bizconfstreaming.com/activity.php?a=userAssign&'.http_build_query($params));
  39. }
  40. public function clearSession() {
  41. // var_dump($_SERVER);
  42. Session::clear();
  43. // var_dump($_SERVER);
  44. }
  45. }