ReceiveQueryController.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace App\Http\Controllers\Web\Sharedata;
  3. use App\Http\Controllers\Web\WebBaseController;
  4. use App\Models\Company;
  5. use App\Models\Member;
  6. use App\Models\MemberInfo;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Facades\Cache;
  9. use Illuminate\Support\Facades\DB;
  10. use App\Services\Receive\ReceiveService;
  11. use App\Services\Auth\AuthService;
  12. use App\Models\Achievement\ExamName;
  13. use App\Repositories\Achievement\ExamnamesRepository;
  14. class ReceiveQueryController extends WebBaseController
  15. {
  16. private $currenttime;
  17. protected $visitor;
  18. protected $receiveService;
  19. private $authService;
  20. private $encrypt = "rsKVyec52fqEKpk4RRD2TU8fKvPxt6ombKg0qSq1velPQtBHVi";
  21. protected $examnamesRepository;
  22. public function __construct( AuthService $authService)
  23. {
  24. $this->authService = $authService;
  25. $this->currenttime = time();
  26. }
  27. public function checkuser(Request $request){
  28. $arr = $request->all();
  29. $data['sign']=$arr['sign'];
  30. $data['username']=$arr['username'];
  31. $data['userType']=$arr['userType'];
  32. $data['timestr']=$arr['timestr'];
  33. /* $user=$this->authService->checkUser($arr['username'],$arr['password'],$arr['utype']);*/
  34. if ($this->check_auth($data)) {
  35. if($data['userType']=='1'){
  36. $result = Company::where(array('username'=>$arr['username']))->select('id')->first();
  37. }else{
  38. $result = Member::where(array('username'=>$arr['username']))->select('id')->first();
  39. }
  40. if($result){
  41. $user=$this->authService->checkUser($arr['username'],$arr['password'],$arr['userType']);
  42. if($user){
  43. return $this->EResponse(['msg' => $user->id, 'state' => 1]);
  44. }else{
  45. return $this->EResponse(['msg' => '密码不正确', 'state' => 2]);
  46. }
  47. }else{
  48. return $this->EResponse(['msg' => '账号不存在', 'state' => 2]);
  49. }
  50. }else{
  51. return $this->EResponse(['msg' => '认证失败', 'state' => 0]);
  52. }
  53. }
  54. protected function check_auth($arr)
  55. {
  56. $auth = false;
  57. $fromsign = $arr['sign']; //获取来自人才E家的签名sign
  58. unset($arr['sign']);
  59. $sign = $this->ss_encrypt($arr);
  60. // $sign = "B4B3E78A0BF0535A041EF781183EF7CD";
  61. if ($fromsign === $sign && ($this->currenttime - $arr['timestr'] <= 360)) {
  62. $auth = true;
  63. }
  64. return $auth;
  65. }
  66. /*
  67. * 加密或解密
  68. *
  69. * */
  70. protected function ss_encrypt($data = array())
  71. {
  72. $sign = '';
  73. ksort($data);
  74. foreach ($data as $key => $val) {
  75. if ($val != null && $val != '') {
  76. $sign .= trim($key) . '=' . trim($val) . "&";
  77. }
  78. }
  79. /* dd($sign . 'key=' . $this->encrypt);
  80. dd(trim(strtoupper(md5($sign . 'key=' . $this->encrypt))));*/
  81. return trim(strtoupper(md5($sign . 'key=' . $this->encrypt)));
  82. }
  83. }