|
@@ -7,12 +7,21 @@
|
|
|
|
|
|
package cn.com.qmth.examcloud.app.service;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.app.model.Constants;
|
|
|
+import cn.com.qmth.examcloud.app.model.ResBody;
|
|
|
import cn.com.qmth.examcloud.app.model.Result;
|
|
|
+import cn.com.qmth.examcloud.app.utils.HttpBuilder;
|
|
|
+import cn.com.qmth.examcloud.app.utils.HttpUtils;
|
|
|
+import cn.com.qmth.examcloud.app.utils.JsonMapper;
|
|
|
+import okhttp3.*;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
/**
|
|
|
* 认证中心业务服务接口
|
|
|
*/
|
|
@@ -22,9 +31,64 @@ public class UserAuthService {
|
|
|
@Autowired
|
|
|
private PropertyService propertyService;
|
|
|
|
|
|
- public Result init() throws Exception {
|
|
|
- log.debug("init...");
|
|
|
- return new Result().success();
|
|
|
+ public Result login(String account, String password, String rootOrgId) throws Exception {
|
|
|
+ final String requestUrl = propertyService.getUserAuthUrl() + "/api/ecs_core/auth/login";
|
|
|
+ //封装请求参数
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
+ params.put("accountValue", account);
|
|
|
+ params.put("password", password);
|
|
|
+ params.put("accountType", "COMMON_LOGIN_NAME");
|
|
|
+ params.put("rootOrgId", rootOrgId);
|
|
|
+ params.put("domain", "");
|
|
|
+ String json = new JsonMapper().toJson(params);
|
|
|
+ RequestBody formBody = FormBody.create(MediaType.parse(Constants.CHARSET_JSON_UTF8), json);
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(requestUrl)
|
|
|
+ .post(formBody)
|
|
|
+ .build();
|
|
|
+ //执行请求
|
|
|
+ Response response = HttpBuilder.client.getInstance().newCall(request).execute();
|
|
|
+ String bodyStr = response.body().string();
|
|
|
+ if (response.isSuccessful()) {
|
|
|
+ return new Result().success(bodyStr);
|
|
|
+ } else {
|
|
|
+ log.debug(bodyStr);
|
|
|
+ ResBody body = new JsonMapper().fromJson(bodyStr, ResBody.class);
|
|
|
+ if (body != null && body.getCode() != null) {
|
|
|
+ return new Result().error(body.getDesc());
|
|
|
+ }
|
|
|
+ return new Result().error(bodyStr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Result updatePassword(String key, String token, String userId, String password) throws Exception {
|
|
|
+ final String requestUrl = propertyService.getUserAuthUrl() + "/api/ecs_core/user/password";
|
|
|
+ //封装请求参数
|
|
|
+ RequestBody formBody = new FormBody.Builder()
|
|
|
+ .add("userId", userId)
|
|
|
+ .add("password", password)
|
|
|
+ .build();
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(requestUrl)
|
|
|
+ .put(formBody)
|
|
|
+ .addHeader("key", key)
|
|
|
+ .addHeader("token", token)
|
|
|
+ .build();
|
|
|
+ //执行请求
|
|
|
+ return HttpUtils.call(request);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Result demo(String key, String token, String userId, String password) throws Exception {
|
|
|
+ final String requestUrl = String.format(propertyService.getUserAuthUrl() + "/api/ecs_core/user/password?userId=%s&password=%s", userId, password);
|
|
|
+ //封装请求参数
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(requestUrl)
|
|
|
+ .get()
|
|
|
+ .addHeader("key", key)
|
|
|
+ .addHeader("token", token)
|
|
|
+ .build();
|
|
|
+ //执行请求
|
|
|
+ return HttpUtils.call(request);
|
|
|
}
|
|
|
|
|
|
}
|