'xkIVfO', 'test' => 'IQB5Nr', 'test1' => 'ATviy6' ]; if (!isset($zhuan[$notify])) abort(404, '页面不存在'); $notify = $zhuan[$notify]; // 判断是否合法 $had = Miniprogram::where(['notify' => $notify])->count(); if ($had == 0) abort(404, '企业不存在'); $aes = new Aes(config('app.jwt_key')); $appid = config('app.kfweb_appid'); $state = $aes->encrypt(rand(1000, 9999) . $notify); $redirect_uri = urlencode(request()->domain() . "/crm/login.html"); $wechatUrl = "https://open.weixin.qq.com/connect/qrconnect?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_login&state=$state#wechat_redirect"; return redirect($wechatUrl); } /** * 授权登录 * * @param string $code * @return array */ public function login($code, $state) { $aes = new Aes(config('app.jwt_key')); $state = $aes->decrypt($state); if (!$state) abort(404, '网址不存在'); $notify = substr($state, 4); // 判断是否合法 $root_id = Miniprogram::where(['notify' => $notify])->value('root_id'); if (empty($root_id)) abort(404, '企业不存在'); $oplatdata = (new Oplatform())->getAccessToken(config('app.kfweb_appid'), config('app.kfweb_secret'), $code); if (!$oplatdata) { trace($oplatdata, 'error'); abort(404, '请求失败,请重新输入网址!'); } if (isset($oplatdata['errcode'])) { // code已经被使用 if (in_array($oplatdata['errcode'], [40029, 40163, 41008, 42003])) { abort(404, '请求失败,请重新输入网址!'); } else { trace($oplatdata, 'error'); abort(404, $oplatdata['errmsg']); } } $userIds = User::where([['unionid', '=', $oplatdata['unionid']], ['root_id', '=', $root_id]])->column('id'); // 查询用户数量 $condition = [ ['root_id', '=', $root_id], ['uid', 'in', $userIds], ['state', '=', '在职'] ]; $emp = Employee::with('user')->where($condition)->find(); if (empty($emp)) { echo '