|
|
@@ -26,6 +26,137 @@ class LoginController extends ZskkDefaultController
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public function loginNoPass(LoginService $service)
|
|
|
+ {
|
|
|
+ $params = $this->getParams();
|
|
|
+
|
|
|
+ if (isset($params['appId']) && !empty($params['appId']) && empty($params['username'])){
|
|
|
+ $params['username'] = \think\Db::table('PLATFROM_ACCOUNT')->where('APPID',$params['appId'])->value('RIS_USERNAME');
|
|
|
+ }
|
|
|
+ //获取账号
|
|
|
+ if (isset($params['username']) && !empty($params['username']) ){
|
|
|
+ $data['username'] = $params['username'];
|
|
|
+ }
|
|
|
+ //todo 默认值
|
|
|
+ if (empty($data['username'])){
|
|
|
+ $data['username'] = 'www';
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //测试环境不验证token
|
|
|
+ if (isset($params['appId']) && isset($params['certificate']) && isset($params['token'])){
|
|
|
+
|
|
|
+ $data['appId'] = $params['appId'];
|
|
|
+ $data['tripartiteVoucher'] = $params['certificate'];
|
|
|
+ $data['token'] = $params['token'];
|
|
|
+
|
|
|
+ if (!$data['appId'] || !$data['tripartiteVoucher'] || !$data['token'] || !$data['username']){
|
|
|
+ $this->error(__('参数错误'), '/admin/index/login');
|
|
|
+ }
|
|
|
+
|
|
|
+ //todo: 这里的url需要改成配置项
|
|
|
+ $url = 'http://10.25.14.7:30082/system/sys-sub/token/checkToken';
|
|
|
+ $response = $this->httpGet(
|
|
|
+ $url,
|
|
|
+ $data
|
|
|
+ );
|
|
|
+ if ($response === false) {
|
|
|
+ $this->error(__('验证token失败'), '/admin/index/login');
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ $user = $service->loginNoPass($data['username']);
|
|
|
+ return $this->success($user);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送POST JSON请求
|
|
|
+ *
|
|
|
+ * @param string $url 请求URL
|
|
|
+ * @param array $data 请求数据
|
|
|
+ * @return string|false 返回响应内容,失败返回false
|
|
|
+ */
|
|
|
+ private function httpPostJson($url, $data)
|
|
|
+ {
|
|
|
+ $jsonData = json_encode($data);
|
|
|
+
|
|
|
+ $ch = curl_init();
|
|
|
+
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($ch, CURLOPT_POST, true);
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
+ curl_setopt($ch, CURLOPT_TIMEOUT, 60);
|
|
|
+
|
|
|
+ // 设置请求头
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
|
+ 'Content-Type: application/json',
|
|
|
+ 'Content-Length: ' . strlen($jsonData)
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $response = curl_exec($ch);
|
|
|
+ $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
+ $error = curl_error($ch);
|
|
|
+ curl_close($ch);
|
|
|
+
|
|
|
+ if ($error) {
|
|
|
+ error_log("CURL错误: " . $error);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($httpCode != 0) {
|
|
|
+ error_log("HTTP错误: " . $httpCode);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * HTTP GET 请求
|
|
|
+ * @param string $url 请求 URL
|
|
|
+ * @param array $params 查询参数
|
|
|
+ * @return mixed 响应结果,失败返回 false
|
|
|
+ */
|
|
|
+ private function httpGet($url, $params = [])
|
|
|
+ {
|
|
|
+ // 如果有参数,拼接到 URL 后面
|
|
|
+ if (!empty($params)) {
|
|
|
+ $queryString = http_build_query($params);
|
|
|
+ $url .= (strpos($url, '?') !== false ? '&' : '?') . $queryString;
|
|
|
+ }
|
|
|
+
|
|
|
+ $ch = curl_init();
|
|
|
+
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
+ curl_setopt($ch, CURLOPT_TIMEOUT, 60);
|
|
|
+
|
|
|
+ // 设置请求头
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
|
+ 'Content-Type: application/json'
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $response = curl_exec($ch);
|
|
|
+ $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
+ $error = curl_error($ch);
|
|
|
+ curl_close($ch);
|
|
|
+
|
|
|
+ if ($error) {
|
|
|
+ error_log("CURL 错误:" . $error);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($httpCode != 200 && $httpCode != 201) {
|
|
|
+ error_log("HTTP 错误:" . $httpCode);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
+
|
|
|
public function send_message_again(LoginService $service)
|
|
|
{
|
|
|
$params = $this->getParams();
|