User.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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\Request;
  14. use think\facade\Session;
  15. class User extends BaseController {
  16. public function login() {
  17. $channelId = input('channelId');
  18. if (empty($channelId)){
  19. throw new ApiException('渠道id不为空');
  20. }
  21. file_put_contents('log', date('Y-m-d H:i:s').Request::url(true).'-'.json_encode(input()).PHP_EOL, FILE_APPEND);
  22. // if (empty(input('unionid'))){
  23. // throw new ApiException('unionid不为空');
  24. // }
  25. $params = [
  26. 'id' => $channelId,
  27. 'userid' => input('unionid'),
  28. 'name' => input('nickName'),
  29. 'avatar' => input('avatar'),
  30. 'key' => md5(input('unionid').CommonService::getSetData($channelId)['channel_auth_code'])
  31. ];
  32. Session::set('wxId',input('unionid'));
  33. (new UserModel())->insertGetId([
  34. 'channel_id' => $channelId,
  35. 'unionid' => input('unionid'),
  36. 'name' => input('nickName'),
  37. 'avatar' => input('avatar'),
  38. 'key' => $params['key'],
  39. ]);
  40. header('Location:http://webcasting.bizconfstreaming.com/activity.php?a=userAssign&'.http_build_query($params));
  41. }
  42. public function clearSession() {
  43. // var_dump($_SERVER);
  44. Session::clear();
  45. // var_dump($_SERVER);
  46. }
  47. }