jtoms 4 vuotta sitten
vanhempi
commit
4fb8f1dbd9

+ 357 - 287
src/main/java/com/zhiqiyun/open/router/apis/Oauth2Api.java

@@ -14,6 +14,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
@@ -22,295 +23,364 @@ import java.util.Objects;
 @ServiceMethodBean
 public class Oauth2Api {
 
-	@Autowired
-	private OkHttpClient okHttpClient;
-
-	@Autowired
-	private SystemConfigService systemConfigService;
-
-	@ServiceMethod(method = "oauth2.login", title = "用户密码登录")
-	public OapResponse login(Oauth2LoginRequest request) throws IOException {
-
-		String hostAddress = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "hostAddress");
-		String tenantId = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "tenantId");
-		String clientSecret = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "clientSecret");
-
-		Map<String, String> paramValues = new HashMap<>();
-		paramValues.put("grant_type", "password");
-		paramValues.put("username", request.getUserName());
-		paramValues.put("password", DigestUtils.md5Hex(request.getPassword()));
-		paramValues.put("login_type", "tenant");
-		paramValues.put("scope", "all");
-		paramValues.put("type", "account");
-
-		FormBody.Builder formBuilder = new FormBody.Builder();
-		paramValues.forEach(formBuilder::add);
-
-
-		Request.Builder builder = new Request.Builder();
-		builder.url(String.format("%s/blade-auth/oauth/token", hostAddress));
-		builder.header("Authorization", "Basic " + clientSecret);
-		builder.header("Content-Type", "application/x-www-form-urlencoded");
-		builder.header("Tenant-Id", tenantId);
-		builder.post(formBuilder.build());
-
-		Response resp = this.okHttpClient.newCall(builder.build()).execute();
-		if (resp.isSuccessful()) {
-			String result = Objects.requireNonNull(resp.body()).string();
-			JSONObject jsonObject = JSON.parseObject(result);
-			return OapResponse.success().setBody(jsonObject);
-		} else {
-			try {
-				String result = Objects.requireNonNull(resp.body()).string();
-				log.error(result);
-				JSONObject jsonObject = JSON.parseObject(result);
-				return OapResponse.fail(jsonObject.getString("error"), jsonObject.getString("error_description"));
-			} catch (Exception e) {
-				log.error("", e);
-				return OapResponse.fail("NETWORK_ERROR", "网络异常" + resp.message());
-			}
-		}
-	}
-
-	@ServiceMethod(method = "oauth2.refresh.token", title = "刷新Token")
-	public OapResponse refreshToken(Oauth2RefreshTokenRequest request) throws IOException {
-
-		String hostAddress = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "hostAddress");
-		String tenantId = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "tenantId");
-		String clientSecret = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "clientSecret");
-
-		FormBody.Builder formBuilder = new FormBody.Builder();
-		Map<String, String> paramValues = new HashMap<>();
-		paramValues.put("grant_type", "refresh_token");
-		paramValues.put("scope", "all");
-		paramValues.put("refresh_token", request.getRefreshToken());
-		paramValues.forEach(formBuilder::add);
-
-
-		Request.Builder builder = new Request.Builder();
-		builder.url(String.format("%s/blade-auth/oauth/token", hostAddress));
-		builder.header("Authorization", "Basic " + clientSecret);
-		builder.header("Content-Type", "application/x-www-form-urlencoded");
-		builder.header("Tenant-Id", tenantId);
-		builder.post(formBuilder.build());
-
-		Response resp = this.okHttpClient.newCall(builder.build()).execute();
-		if (resp.isSuccessful()) {
-			String result = Objects.requireNonNull(resp.body()).string();
-			JSONObject jsonObject = JSON.parseObject(result);
-			return OapResponse.success().setBody(jsonObject);
-		} else {
-			try {
-				String result = Objects.requireNonNull(resp.body()).string();
-				JSONObject jsonObject = JSON.parseObject(result);
-				return OapResponse.fail(jsonObject.getString("error"), jsonObject.getString("error_description"));
-			} catch (Exception e) {
-				return OapResponse.fail("NETWORK_ERROR", "网络异常" + resp.message());
-			}
-		}
-	}
-
-	@ServiceMethod(method = "oauth2.account.info", title = "获取用户信息")
-	public OapResponse userInfo(Oauth2UserInfoRequest request) throws IOException {
-
-
-		String hostAddress = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "hostAddress");
+    @Autowired
+    private OkHttpClient okHttpClient;
+
+    @Autowired
+    private SystemConfigService systemConfigService;
+
+    @ServiceMethod(method = "oauth2.login", title = "用户密码登录")
+    public OapResponse login(Oauth2LoginRequest request) throws IOException {
+
+        String hostAddress = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "hostAddress");
+        String tenantId = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "tenantId");
+        String clientSecret = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "clientSecret");
+
+        Map<String, String> paramValues = new HashMap<>();
+        paramValues.put("grant_type", "password");
+        paramValues.put("username", request.getUserName());
+        paramValues.put("password", DigestUtils.md5Hex(request.getPassword()));
+        paramValues.put("login_type", "tenant");
+        paramValues.put("scope", "all");
+        paramValues.put("type", "account");
+
+        FormBody.Builder formBuilder = new FormBody.Builder();
+        paramValues.forEach(formBuilder::add);
+
+
+        Request.Builder builder = new Request.Builder();
+        builder.url(String.format("%s/blade-auth/oauth/token", hostAddress));
+        builder.header("Authorization", "Basic " + clientSecret);
+        builder.header("Content-Type", "application/x-www-form-urlencoded");
+        builder.header("Tenant-Id", tenantId);
+        builder.post(formBuilder.build());
+
+        Response resp = this.okHttpClient.newCall(builder.build()).execute();
+        if (resp.isSuccessful()) {
+            String result = Objects.requireNonNull(resp.body()).string();
+            JSONObject jsonObject = JSON.parseObject(result);
+            return OapResponse.success().setBody(jsonObject);
+        } else {
+            try {
+                String result = Objects.requireNonNull(resp.body()).string();
+                log.error(result);
+                JSONObject jsonObject = JSON.parseObject(result);
+                return OapResponse.fail(jsonObject.getString("error"), jsonObject.getString("error_description"));
+            } catch (Exception e) {
+                log.error("", e);
+                return OapResponse.fail("NETWORK_ERROR", "网络异常" + resp.message());
+            }
+        }
+    }
+
+    @ServiceMethod(method = "oauth2.refresh.token", title = "刷新Token")
+    public OapResponse refreshToken(Oauth2RefreshTokenRequest request) throws IOException {
+
+        String hostAddress = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "hostAddress");
+        String tenantId = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "tenantId");
+        String clientSecret = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "clientSecret");
+
+        FormBody.Builder formBuilder = new FormBody.Builder();
+        Map<String, String> paramValues = new HashMap<>();
+        paramValues.put("grant_type", "refresh_token");
+        paramValues.put("scope", "all");
+        paramValues.put("refresh_token", request.getRefreshToken());
+        paramValues.forEach(formBuilder::add);
+
+
+        Request.Builder builder = new Request.Builder();
+        builder.url(String.format("%s/blade-auth/oauth/token", hostAddress));
+        builder.header("Authorization", "Basic " + clientSecret);
+        builder.header("Content-Type", "application/x-www-form-urlencoded");
+        builder.header("Tenant-Id", tenantId);
+        builder.post(formBuilder.build());
+
+        Response resp = this.okHttpClient.newCall(builder.build()).execute();
+        if (resp.isSuccessful()) {
+            String result = Objects.requireNonNull(resp.body()).string();
+            JSONObject jsonObject = JSON.parseObject(result);
+            return OapResponse.success().setBody(jsonObject);
+        } else {
+            try {
+                String result = Objects.requireNonNull(resp.body()).string();
+                JSONObject jsonObject = JSON.parseObject(result);
+                return OapResponse.fail(jsonObject.getString("error"), jsonObject.getString("error_description"));
+            } catch (Exception e) {
+                return OapResponse.fail("NETWORK_ERROR", "网络异常" + resp.message());
+            }
+        }
+    }
+
+    @ServiceMethod(method = "oauth2.account.info", title = "获取用户信息")
+    public OapResponse userInfo(Oauth2UserInfoRequest request) throws IOException {
+
+
+        String hostAddress = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "hostAddress");
 //		String tenantId = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "tenantId");
-		String clientSecret = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "clientSecret");
+        String clientSecret = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "clientSecret");
 
-		Request.Builder builder = new Request.Builder();
-		builder.url(String.format("%s/blade-user/account/info", hostAddress));
-		builder.header("Authorization", "Basic " + clientSecret);
-		builder.header("Blade-Auth", "bearer " + request.getAccessToken());
-		builder.header("Content-Type", "application/x-www-form-urlencoded");
+        Request.Builder builder = new Request.Builder();
+        builder.url(String.format("%s/blade-user/account/info", hostAddress));
+        builder.header("Authorization", "Basic " + clientSecret);
+        builder.header("Blade-Auth", "bearer " + request.getAccessToken());
+        builder.header("Content-Type", "application/x-www-form-urlencoded");
 //		builder.header("Tenant-Id", tenantId);
 
-		Response resp = this.okHttpClient.newCall(builder.build()).execute();
-		if (resp.isSuccessful()) {
-			String result = Objects.requireNonNull(resp.body()).string();
-			JSONObject jsonObject = JSON.parseObject(result);
-			String code = jsonObject.getString("code");
-			String msg = jsonObject.getString("msg");
-			JSONObject data = jsonObject.getJSONObject("data");
-
-			if (StringUtils.equals("200", code)) {
-				return OapResponse.success().setBody(data);
-			}
-			return OapResponse.fail("REMOTE_ERROR_" + code, msg);
-		} else {
-			return OapResponse.fail("NETWORK_ERROR", "网络异常" + resp.message());
-		}
-	}
-
-	@ServiceMethod(method = "oauth2.validate.token", title = "验证登录状态")
-	public OapResponse validateToken(Oauth2UserInfoRequest request) throws IOException {
-
-
-		String hostAddress = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "hostAddress");
-		String clientSecret = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "clientSecret");
-
-		Request.Builder builder = new Request.Builder();
-		builder.url(String.format("%s/blade-user/account/info", hostAddress));
-		builder.header("Authorization", "Basic " + clientSecret);
-		builder.header("Blade-Auth", "bearer " + request.getAccessToken());
-		builder.header("Content-Type", "application/x-www-form-urlencoded");
-
-		Response resp = this.okHttpClient.newCall(builder.build()).execute();
-		if (resp.isSuccessful()) {
-			String result = Objects.requireNonNull(resp.body()).string();
-			JSONObject jsonObject = JSON.parseObject(result);
-			String code = jsonObject.getString("code");
-			String msg = jsonObject.getString("msg");
-			JSONObject data = jsonObject.getJSONObject("data");
-
-			if (StringUtils.equals("200", code)) {
-				return OapResponse.success().setBody(data);
-			}
-			return OapResponse.fail("REMOTE_ERROR_" + code, msg);
-		} else {
-			return OapResponse.fail("NETWORK_ERROR", "网络异常" + resp.message());
-		}
-	}
-
-	@ServiceMethod(method = "oauth2.wechat.mp.login", title = "微信公众号授权登录")
-	public OapResponse oauthWechatLogin(Oauth2WechatMpLoginRequest request) throws IOException {
-
-		String hostAddress = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "hostAddress");
-		String clientSecret = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "clientSecret");
-
-		Map<String, String> paramValues = new HashMap<>();
-		paramValues.put("code", request.getCode());
-		FormBody.Builder formBuilder = new FormBody.Builder();
-		paramValues.forEach(formBuilder::add);
-
-
-		Request.Builder builder = new Request.Builder();
-		builder.url(String.format("%s/blade-auth/oauth/callback/%s", hostAddress, request.getSource()));
-		builder.header("Authorization", "Basic " + clientSecret);
-		builder.header("Content-Type", "application/x-www-form-urlencoded");
-		builder.post(formBuilder.build());
-
-		Response resp = this.okHttpClient.newCall(builder.build()).execute();
-		if (resp.isSuccessful()) {
-			String result = Objects.requireNonNull(resp.body()).string();
-			JSONObject jsonObject = JSON.parseObject(result);
-			String code = jsonObject.getString("code");
-			String msg = jsonObject.getString("msg");
-			JSONObject data = jsonObject.getJSONObject("data");
-
-			if (StringUtils.equals("200", code)) {
-				return OapResponse.success().setBody(data);
-			}
-			return OapResponse.fail("REMOTE_ERROR_" + code, msg);
-		} else {
-			return OapResponse.fail("NETWORK_ERROR", "网络异常" + resp.message());
-		}
-	}
-
-	@ServiceMethod(method = "oauth2.wechat.mp.bind", title = "微信公众号账号绑定")
-	public OapResponse oauthWechatBind(Oauth2WechatMpBindRequest request) throws IOException {
-
-		String hostAddress = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "hostAddress");
-		String clientSecret = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "clientSecret");
-
-		Map<String, String> paramValues = new HashMap<>();
-		paramValues.put("uuid", request.getUuid());
-		paramValues.put("username", request.getUsername());
-		paramValues.put("password", request.getPassword());
-
-		RequestBody body = RequestBody.create(JSON.toJSONString(paramValues), MediaType.parse("application/json; charset=utf-8"));
-
-		Request.Builder builder = new Request.Builder();
-		builder.url(String.format("%s/blade-auth/oauth/bind/%s", hostAddress, request.getSource()));
-		builder.header("Authorization", "Basic " + clientSecret);
-		builder.header("Content-Type", "application/json");
-		builder.post(body);
-
-		Response resp = this.okHttpClient.newCall(builder.build()).execute();
-		if (resp.isSuccessful()) {
-			String result = Objects.requireNonNull(resp.body()).string();
-			JSONObject jsonObject = JSON.parseObject(result);
-			String code = jsonObject.getString("code");
-			String msg = jsonObject.getString("msg");
-			JSONObject data = jsonObject.getJSONObject("data");
-
-			if (StringUtils.equals("200", code)) {
-				return OapResponse.success().setBody(data);
-			}
-			return OapResponse.fail("REMOTE_ERROR_" + code, msg);
-		} else {
-			return OapResponse.fail("NETWORK_ERROR", "网络异常" + resp.message());
-		}
-	}
-
-	@ServiceMethod(method = "oauth2.wechat.mp.register.bind", title = "微信公众号注册绑定")
-	public OapResponse oauthWechatRegisterBind(Oauth2WechatMpRegisterBindRequest request) throws IOException {
-
-		String hostAddress = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "hostAddress");
-		String clientSecret = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "clientSecret");
-
-		Map<String, String> paramValues = new HashMap<>();
-		paramValues.put("uuid", request.getUuid());
-		paramValues.put("username", request.getUsername());
-		paramValues.put("password", request.getPassword());
-
-		RequestBody body = RequestBody.create(JSON.toJSONString(paramValues), MediaType.parse("application/json; charset=utf-8"));
-
-		Request.Builder builder = new Request.Builder();
-		builder.url(String.format("%s/blade-auth/oauth/bind/%s", hostAddress, request.getSource()));
-		builder.header("Authorization", "Basic " + clientSecret);
-		builder.header("Content-Type", "application/json");
-		builder.post(body);
-
-		Response resp = this.okHttpClient.newCall(builder.build()).execute();
-		if (resp.isSuccessful()) {
-			String result = Objects.requireNonNull(resp.body()).string();
-			JSONObject jsonObject = JSON.parseObject(result);
-			String code = jsonObject.getString("code");
-			String msg = jsonObject.getString("msg");
-			JSONObject data = jsonObject.getJSONObject("data");
-
-			if (StringUtils.equals("200", code)) {
-				return OapResponse.success().setBody(data);
-			}
-			return OapResponse.fail("REMOTE_ERROR_" + code, msg);
-		} else {
-			return OapResponse.fail("NETWORK_ERROR", "网络异常" + resp.message());
-		}
-	}
-
-	@ServiceMethod(method = "oauth2.wechat.register", title = "注册用户")
-	public OapResponse oauthRegister(Oauth2RegisterRequest request) throws IOException {
-
-		String hostAddress = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "hostAddress");
-		String clientSecret = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "clientSecret");
-
-		Map<String, String> paramValues = new HashMap<>();
-		paramValues.put("account", request.getAccount());
-		paramValues.put("password", request.getPassword());
-
-		RequestBody body = RequestBody.create(JSON.toJSONString(paramValues), MediaType.parse("application/json; charset=utf-8"));
-
-		Request.Builder builder = new Request.Builder();
-		builder.url(String.format("%s/blade-user/account/submit", hostAddress));
-		builder.header("Authorization", "Basic " + clientSecret);
-		builder.header("Content-Type", "application/json");
-		builder.post(body);
-
-		Response resp = this.okHttpClient.newCall(builder.build()).execute();
-		if (resp.isSuccessful()) {
-			String result = Objects.requireNonNull(resp.body()).string();
-			JSONObject jsonObject = JSON.parseObject(result);
-			String code = jsonObject.getString("code");
-			String msg = jsonObject.getString("msg");
-			JSONObject data = jsonObject.getJSONObject("data");
-
-			if (StringUtils.equals("200", code)) {
-				return OapResponse.success().setBody(data);
-			}
-			return OapResponse.fail("REMOTE_ERROR_" + code, msg);
-		} else {
-			return OapResponse.fail("NETWORK_ERROR", "网络异常" + resp.message());
-		}
-	}
+        Response resp = this.okHttpClient.newCall(builder.build()).execute();
+        if (resp.isSuccessful()) {
+            String result = Objects.requireNonNull(resp.body()).string();
+            JSONObject jsonObject = JSON.parseObject(result);
+            String code = jsonObject.getString("code");
+            String msg = jsonObject.getString("msg");
+            JSONObject data = jsonObject.getJSONObject("data");
+
+            if (StringUtils.equals("200", code)) {
+                return OapResponse.success().setBody(data);
+            }
+            return OapResponse.fail("REMOTE_ERROR_" + code, msg);
+        } else {
+            return OapResponse.fail("NETWORK_ERROR", "网络异常" + resp.message());
+        }
+    }
+
+    @ServiceMethod(method = "oauth2.validate.token", title = "验证登录状态")
+    public OapResponse validateToken(Oauth2UserInfoRequest request) throws IOException {
+
+
+        String hostAddress = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "hostAddress");
+        String clientSecret = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "clientSecret");
+
+        Request.Builder builder = new Request.Builder();
+        builder.url(String.format("%s/blade-user/account/info", hostAddress));
+        builder.header("Authorization", "Basic " + clientSecret);
+        builder.header("Blade-Auth", "bearer " + request.getAccessToken());
+        builder.header("Content-Type", "application/x-www-form-urlencoded");
+
+        Response resp = this.okHttpClient.newCall(builder.build()).execute();
+        if (resp.isSuccessful()) {
+            String result = Objects.requireNonNull(resp.body()).string();
+            JSONObject jsonObject = JSON.parseObject(result);
+            String code = jsonObject.getString("code");
+            String msg = jsonObject.getString("msg");
+            JSONObject data = jsonObject.getJSONObject("data");
+
+            if (StringUtils.equals("200", code)) {
+                return OapResponse.success().setBody(data);
+            }
+            return OapResponse.fail("REMOTE_ERROR_" + code, msg);
+        } else {
+            return OapResponse.fail("NETWORK_ERROR", "网络异常" + resp.message());
+        }
+    }
+
+    @ServiceMethod(method = "oauth2.wechat.mp.login", title = "微信公众号授权登录")
+    public OapResponse oauthWechatLogin(Oauth2WechatMpLoginRequest request) throws IOException {
+
+        String hostAddress = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "hostAddress");
+        String clientSecret = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "clientSecret");
+
+        Map<String, String> paramValues = new HashMap<>();
+        paramValues.put("code", request.getCode());
+        FormBody.Builder formBuilder = new FormBody.Builder();
+        paramValues.forEach(formBuilder::add);
+
+
+        Request.Builder builder = new Request.Builder();
+        builder.url(String.format("%s/blade-auth/oauth/callback/%s", hostAddress, request.getSource()));
+        builder.header("Authorization", "Basic " + clientSecret);
+        builder.header("Content-Type", "application/x-www-form-urlencoded");
+        builder.post(formBuilder.build());
+
+        Response resp = this.okHttpClient.newCall(builder.build()).execute();
+        if (resp.isSuccessful()) {
+            String result = Objects.requireNonNull(resp.body()).string();
+            JSONObject jsonObject = JSON.parseObject(result);
+            String code = jsonObject.getString("code");
+            String msg = jsonObject.getString("msg");
+            JSONObject data = jsonObject.getJSONObject("data");
+
+            if (StringUtils.equals("200", code)) {
+                return OapResponse.success().setBody(data);
+            }
+            return OapResponse.fail("REMOTE_ERROR_" + code, msg);
+        } else {
+            return OapResponse.fail("NETWORK_ERROR_" + resp.code(), "网络异常" + resp.message());
+        }
+    }
+
+    @ServiceMethod(method = "oauth2.wechat.mp.bind", title = "微信公众号账号绑定")
+    public OapResponse oauthWechatBind(Oauth2WechatMpBindRequest request) throws IOException {
+
+        String hostAddress = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "hostAddress");
+        String clientSecret = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "clientSecret");
+
+        Map<String, String> paramValues = new HashMap<>();
+        paramValues.put("uuid", request.getUuid());
+        paramValues.put("username", request.getUsername());
+        paramValues.put("password", request.getPassword());
+
+        RequestBody body = RequestBody.create(JSON.toJSONString(paramValues), MediaType.parse("application/json; charset=utf-8"));
+
+        Request.Builder builder = new Request.Builder();
+        builder.url(String.format("%s/blade-auth/oauth/bind/%s", hostAddress, request.getSource()));
+        builder.header("Authorization", "Basic " + clientSecret);
+        builder.header("Content-Type", "application/json");
+        builder.post(body);
+
+        Response resp = this.okHttpClient.newCall(builder.build()).execute();
+        if (resp.isSuccessful()) {
+            String result = Objects.requireNonNull(resp.body()).string();
+            JSONObject jsonObject = JSON.parseObject(result);
+            String code = jsonObject.getString("code");
+            String msg = jsonObject.getString("msg");
+            JSONObject data = jsonObject.getJSONObject("data");
+
+            if (StringUtils.equals("200", code)) {
+                return OapResponse.success().setBody(data);
+            }
+            return OapResponse.fail("REMOTE_ERROR_" + code, msg);
+        } else {
+            return OapResponse.fail("NETWORK_ERROR", "网络异常" + resp.message());
+        }
+    }
+
+    @ServiceMethod(method = "oauth2.wechat.mp.register.bind", title = "微信公众号注册绑定")
+    public OapResponse oauthWechatRegisterBind(Oauth2WechatMpRegisterBindRequest request) throws IOException {
+
+        String hostAddress = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "hostAddress");
+        String clientSecret = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "clientSecret");
+
+        Map<String, String> paramValues = new HashMap<>();
+        paramValues.put("uuid", request.getUuid());
+        paramValues.put("username", request.getUsername());
+        paramValues.put("password", request.getPassword());
+
+        RequestBody body = RequestBody.create(JSON.toJSONString(paramValues), MediaType.parse("application/json; charset=utf-8"));
+
+        Request.Builder builder = new Request.Builder();
+        builder.url(String.format("%s/blade-auth/oauth/bind/%s", hostAddress, request.getSource()));
+        builder.header("Authorization", "Basic " + clientSecret);
+        builder.header("Content-Type", "application/json");
+        builder.post(body);
+
+        Response resp = this.okHttpClient.newCall(builder.build()).execute();
+        if (resp.isSuccessful()) {
+            String result = Objects.requireNonNull(resp.body()).string();
+            JSONObject jsonObject = JSON.parseObject(result);
+            String code = jsonObject.getString("code");
+            String msg = jsonObject.getString("msg");
+            JSONObject data = jsonObject.getJSONObject("data");
+
+            if (StringUtils.equals("200", code)) {
+                return OapResponse.success().setBody(data);
+            }
+            return OapResponse.fail("REMOTE_ERROR_" + code, msg);
+        } else {
+            return OapResponse.fail("NETWORK_ERROR", "网络异常" + resp.message());
+        }
+    }
+
+    /**
+     * 已经对接成功
+     *
+     * @param request
+     * @return
+     * @throws IOException
+     */
+    @ServiceMethod(method = "oauth2.register", title = "注册用户")
+    public OapResponse oauthRegister(Oauth2RegisterRequest request) throws IOException {
+
+        String hostAddress = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "hostAddress");
+        String clientSecret = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "clientSecret");
+
+        Map<String, String> paramValues = new HashMap<>();
+        paramValues.put("account", request.getAccount());
+        paramValues.put("password", request.getPassword());
+
+        RequestBody requestBody = RequestBody.create(JSON.toJSONString(paramValues), MediaType.parse("application/json; charset=utf-8"));
+
+        Request.Builder builder = new Request.Builder();
+        builder.url(String.format("%s/blade-user/account/submit", hostAddress));
+        builder.header("Authorization", "Basic " + clientSecret);
+        builder.header("Content-Type", "application/json");
+        builder.post(requestBody);
+
+        Response resp = this.okHttpClient.newCall(builder.build()).execute();
+        if (resp.isSuccessful()) {
+            String result = Objects.requireNonNull(resp.body()).string();
+            log.info(result);
+            JSONObject jsonObject = JSON.parseObject(result);
+            String code = jsonObject.getString("code");
+            String msg = jsonObject.getString("msg");
+            JSONObject data = jsonObject.getJSONObject("data");
+
+            if (StringUtils.equals("200", code)) {
+                return OapResponse.success().setBody(data);
+            }
+            return OapResponse.fail("REMOTE_ERROR_" + code, msg);
+        } else {
+            String body = Objects.requireNonNull(resp.body()).string();
+            log.info(body);
+            if (Arrays.asList(401, 400).contains(resp.code())) {
+                JSONObject object = JSON.parseObject(body);
+                return OapResponse.fail("ERROR", object.getString("msg"));
+            } else {
+                return OapResponse.fail("NETWORK_ERROR", "网络异常" + resp.message());
+            }
+        }
+    }
+
+    /**
+     * 已经对接成功
+     *
+     * @param request
+     * @return
+     * @throws IOException
+     */
+    @ServiceMethod(method = "oauth2.update.info", title = "更新用户信息")
+    public OapResponse oauthUpdateInfo(Oauth2UpdateInfoRequest request) throws IOException {
+
+        String hostAddress = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "hostAddress");
+        String clientSecret = this.systemConfigService.getStringValue("OAUTH2_API_CONFIG", "clientSecret");
+
+        Map<String, String> paramValues = new HashMap<>();
+        paramValues.put("name", request.getName());
+        paramValues.put("realName", request.getRealName());
+        paramValues.put("sex", request.getSex().toString());
+        paramValues.put("email", request.getEmail());
+        paramValues.put("phone", request.getPhone());
+
+        RequestBody requestBody = RequestBody.create(JSON.toJSONString(paramValues), MediaType.parse("application/json; charset=utf-8"));
+
+        Request.Builder builder = new Request.Builder();
+        builder.url(String.format("%s/blade-user/account/update-info", hostAddress));
+        builder.header("Authorization", "Basic " + clientSecret);
+        builder.header("Blade-Auth", "bearer " + request.getAccessToken());
+        builder.header("Content-Type", "application/json");
+        builder.post(requestBody);
+
+        Response resp = this.okHttpClient.newCall(builder.build()).execute();
+        if (resp.isSuccessful()) {
+            String result = Objects.requireNonNull(resp.body()).string();
+            log.info(result);
+            JSONObject jsonObject = JSON.parseObject(result);
+            String code = jsonObject.getString("code");
+            String msg = jsonObject.getString("msg");
+            JSONObject data = jsonObject.getJSONObject("data");
+
+            if (StringUtils.equals("200", code)) {
+                return OapResponse.success().setBody(data);
+            }
+            return OapResponse.fail("REMOTE_ERROR_" + code, msg);
+        } else {
+            String body = Objects.requireNonNull(resp.body()).string();
+            log.info(body);
+            if (Arrays.asList(401, 400).contains(resp.code())) {
+                JSONObject object = JSON.parseObject(body);
+                return OapResponse.fail("ERROR", object.getString("msg"));
+            } else {
+                return OapResponse.fail("NETWORK_ERROR", "网络异常" + resp.message());
+            }
+        }
+    }
 }

+ 36 - 0
src/main/java/com/zhiqiyun/open/router/request/oauth2/Oauth2UpdateInfoRequest.java

@@ -0,0 +1,36 @@
+package com.zhiqiyun.open.router.request.oauth2;
+
+import com.dliyun.oap.framework.annotation.ServiceParamField;
+import com.dliyun.oap.framework.request.AbstractOapRequest;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.validation.constraints.NotBlank;
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class Oauth2UpdateInfoRequest extends AbstractOapRequest {
+    @ServiceParamField(describe = "用户认证的Token")
+    @NotBlank
+    private String accessToken;
+
+    @ServiceParamField(describe = "姓名")
+    @NotBlank
+    private String name;
+
+    @ServiceParamField(describe = "真实姓名")
+    @NotBlank
+    private String realName;
+
+    @ServiceParamField(describe = "性别(1,2)")
+    @NotBlank
+    private Integer sex;
+
+    @ServiceParamField(describe = "邮箱")
+    @NotBlank
+    private String email;
+
+    @ServiceParamField(describe = "手机号码")
+    @NotBlank
+    private String phone;
+}

+ 3 - 5
src/test/java/com/zhiqiyun/TestSdk.java

@@ -5,8 +5,6 @@ import com.dliyun.AlgorithmType;
 import com.dliyun.DefaultClient;
 import com.dliyun.Response;
 
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -19,9 +17,9 @@ public class TestSdk {
 				AlgorithmType.RSA
 		);
 		Map<String, Object> form1 = new HashMap<>();
-		form1.put("source", "1");
-		form1.put("code", "2");
-		Response<Map<String, Object>> response = client.execute("oauth2.wechat.mp", "1.0.0", form1);
+		form1.put("userName", "stjdydayou");
+		form1.put("password", "123456");
+		Response<Map<String, Object>> response = client.execute("oauth2.login", "1.0.0", form1);
 		System.out.println(JSON.toJSONString(response));
 	}
 }