csmreq("username2", true); $ff = strpos($username2, "@"); $service = new AdminService(); if ($ff === false) { // 手机号码 if (strlen($username2) == 11) { $row = $service->getRowByMobile($username2); $username2 = $row ? $row->username : $username2; } } else { // 邮箱地址 $row = $service->getRowByEmail($username2); $username2 = $row ? $row->username : $username2; } // 如果帐号不存在,且待审核中,则报错 if (true) { $service = new AdminService(); $row = $service->getRowByUsername($username2); if (!$row) { $dao2 = new \app\admin\model\csmadmin\Adminapply(); $row2 = $dao2->where('mobile|email', '=', $username2) ->order("id", "desc") ->find(); if ($row2 && $row2->auditstatus == '0') { CsmUtils::error("您的帐号正在审核中,暂无法登陆,请耐心等待审核。"); } } } $this->success('', '', array( "username" => $username2 )); } /* * 修改钉钉Dialog * http://127.0.0.1/fastadmin_plugin_csmmeet/public/q3HJDu2RgE.php/csmadmin/csmadminapp/modifydddialog */ public function modifydddialog() { $config = get_addon_config(CsmContants::$ADDONS); $ddappid = $config['ddappid']; $this->assign("ddappid", $ddappid); $this->assign("hosturl", $_SERVER["REQUEST_SCHEME"] . "://" . $_SERVER["SERVER_NAME"]); return $this->view->fetch(); } /** * 钉钉扫码,根据$loginTmpCode获取钉钉信息 * * @see https://ding-doc.dingtalk.com/doc#/serverapi2/kymkv6 row返回内容:{ * "errcode": 0, * "errmsg": "ok", * "user_info": { * "nick": "张三", * "openid": "liSii8KCxxxxx", * "unionid": "7Huu46kk" * } * } */ public function sendddlogintmpcode() { $loginTmpCode = $this->csmreq("code", true); $row = DDUtils::getUserInfoByLoginTmpCode($loginTmpCode); $this->assign("row", $row); return $this->view->fetch(); } /* * 修改微信Dialog * http://127.0.0.1/fastadmin_plugin_csmmeet/public/q3HJDu2RgE.php/csmadmin/csmadminapp/modifywxdialog */ public function modifywxdialog() { $sceneId = time(); $wxqdurl = WxUtils::qrcodeCreate($sceneId); $this->assign("wxqdurl", $wxqdurl); $this->assign("scene_id", $sceneId); return $this->view->fetch(); } // //http://127.0.0.1/fastadmin_plugin_csmmeet/public/q3HJDu2RgE.php/csmadmin/csmadminapp/parseWxCode // public function parseWxCode(){ // $postStr = " // // // 1586088016 // // // // // // "; // $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); // $openid = $postObj->FromUserName; //openid // $event = strtolower($postObj->Event); // $eventKey = (int)($postObj->EventKey); // var_dump($eventKey); // } public function getWxByOpenID() { $sceneId = $this->csmreq("scene_id", true); $dao = new \app\admin\model\csmadmin\Wxscan(); $row = $dao->where("scene_id", "=", $sceneId)->find(); if ($row != null) { $this->success('', null, array( 'row' => $row )); } else { $this->error(''); } } /* * 修改手机号码Dialog * http://127.0.0.1/fastadmin_plugin_csmmeet/public/q3HJDu2RgE.php/csmadmin/csmadminapp/modifymobiledialog */ public function modifymobiledialog() { if ($this->request->isAjax()) { $mobile = $this->csmreq("csmadminmobile", true); $event = $this->csmreq("csmadminevent", true); $ccode = $this->csmreq("csmadminccode", true); $sendccode = Session::get(CsmadminUtils::getSessionKey($mobile, $event)); if ($sendccode == $ccode) { $this->success(); } else { $this->error('验证码错误!'); } } return $this->view->fetch(); } // 发送消息 public function sendMobileCodeAjax() { $mobile = $this->csmreq("mobile", true); $event = $this->csmreq("event", true); $captcha = $this->csmreq("captcha", true); $captchaResult = \think\Validate::is($captcha, 'captcha'); if (!$captchaResult) { $this->error('验证码不正确'); } if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) { $this->error(__('手机号不正确')); } $last = Smslib::get($mobile, $event); if ($last && time() - $last['createtime'] < 60) { $this->error(__('发送频繁')); } $ipSendTotal = \app\common\model\Sms::where([ 'ip' => $this->request->ip() ])->whereTime('createtime', '-1 hours')->count(); if ($ipSendTotal >= 5) { $this->error(__('发送频繁')); } if (!Hook::get('sms_send')) { $this->error(__('请在后台插件管理安装短信验证插件')); } $ccode = Random::numeric(4); Session::set(CsmadminUtils::getSessionKey($mobile, $event), $ccode); $ret = CsmNotify::sendccodesms($mobile, $ccode, $event); if ($ret) { $this->success(__('发送成功')); } else { $this->error(__('发送失败,请检查短信配置是否正确')); } } /* * 修改邮箱Dialog * http://127.0.0.1/fastadmin_plugin_csmmeet/public/q3HJDu2RgE.php/csmadmin/csmadminapp/modifyemaildialog */ public function modifyemaildialog() { if ($this->request->isAjax()) { $email = $this->csmreq("csmadminemail", true); $event = $this->csmreq("csmadminevent", true); $ccode = $this->csmreq("csmadminccode", true); $sendccode = Session::get(CsmadminUtils::getSessionKey($email, $event)); if ($sendccode == $ccode) { $this->success(); } else { $this->error('验证码错误!'); } } return $this->view->fetch(); } // 发送消息 public function sendEmailCodeAjax() { $email = $this->csmreq("email", true); $event = $this->csmreq("event", true); $captcha = $this->csmreq("captcha", true); $captchaResult = \think\Validate::is($captcha, 'captcha'); if (!$captchaResult) { $this->error('验证码不正确'); } $last = Emslib::get($email, $event); if ($last && time() - $last['createtime'] < 60) { $this->error(__('发送频繁')); } $ccode = mt_rand(1000, 9999); $obj = \app\common\library\Email::instance(); $result = $obj->to($email) ->subject('验证码') ->message("你的验证码是:" . $ccode) ->send(); if ($result) { Session::set(CsmadminUtils::getSessionKey($email, $event), $ccode); $this->success(__('发送成功')); } else { $this->error(__('发送失败,请检查邮件配置是否正确')); } } /** * 获取是否微信登录,并返回微信appid(用于在微信容器中,自动登录) * * v1.5.0 增加后台管理功能微信中自动登录 * @return void */ public function getWeixinh5mobileurl() { $config = get_addon_config(CsmContants::$ADDONS); $haswxfield = $config["haswxfield"]; $wxappid = $config["wxappid"]; //var_dump(['haswxfield' => $haswxfield, 'wxappid' => $wxappid]); $this->success('', null, ['haswxfield' => $haswxfield, 'wxappid' => $wxappid]); } /** * 微信H5,通过code登录 * * v1.5.0 增加后台管理功能微信中自动登录 * * @see https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html#0 */ public function h5loginbycode() { $code = $this->csmreq('code', true); $config = get_addon_config(CsmContants::$ADDONS); $appid = $config['wxappid']; // $config['cloginwxappid']; $appsecret = $config['wxappsecret']; // $config['cloginwxappsecret']; $weixinurl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$appid}&secret={$appsecret}&code={$code}&grant_type=authorization_code"; $weixin = Http::get($weixinurl); $weixinsr = json_decode($weixin,true); if($weixinsr!=null && isset($weixinsr['openid'])){ $dao = new \app\admin\model\csmadmin\Admin(); $row = $dao->where('wxuserid','=',$weixinsr['openid'])->where('status','=','normal')->find(); if($row){ $service = new AdminService(); $row = $service->getRowById($row->faadmin_id); if ($row) { $service->directLogin($row); $this->success(); } else { $this->error('帐号不存在,请重新登录!'); } $this->success('', null, ['row' => $row]); } } $this->error('帐号不存在,请重新登录!'); } }