Commit c291e6f2 by renyizhao

创建newapi账号时 带手机号

parent c0d5047f
...@@ -52,6 +52,7 @@ public class AppAiTokenController { ...@@ -52,6 +52,7 @@ public class AppAiTokenController {
AiTokenService.AiTokenResult result = aiTokenService.getOrCreateToken( AiTokenService.AiTokenResult result = aiTokenService.getOrCreateToken(
user.getId(), user.getId(),
user.getMobile(),
user.getNewapiUsername(), user.getNewapiUsername(),
user.getNewapiPassword(), user.getNewapiPassword(),
user.getNewapiUserId(), user.getNewapiUserId(),
......
...@@ -46,8 +46,9 @@ public class AiTokenService { ...@@ -46,8 +46,9 @@ public class AiTokenService {
*/ */
private static final Pattern GIFT_PATTERN = Pattern.compile("^Increased user quota by (\\d+)$"); private static final Pattern GIFT_PATTERN = Pattern.compile("^Increased user quota by (\\d+)$");
public AiTokenResult getOrCreateToken(Long userId, String newApiUsername, String newApiPassword, public AiTokenResult getOrCreateToken(Long userId, String displayName, String newApiUsername,
Long newApiUserId, String newApiAccessToken, String newApiKey) { String newApiPassword, Long newApiUserId,
String newApiAccessToken, String newApiKey) {
log.info("[AiTokenService] userId={}, hasApiKey={}", userId, newApiKey != null && !newApiKey.isEmpty()); log.info("[AiTokenService] userId={}, hasApiKey={}", userId, newApiKey != null && !newApiKey.isEmpty());
if (newApiKey != null && !newApiKey.isEmpty()) { if (newApiKey != null && !newApiKey.isEmpty()) {
...@@ -70,17 +71,17 @@ public class AiTokenService { ...@@ -70,17 +71,17 @@ public class AiTokenService {
} }
log.info("[AiTokenService] 无账号密码,从第1步开始"); log.info("[AiTokenService] 无账号密码,从第1步开始");
return createTokenFull(userId); return createTokenFull(userId, displayName);
} }
private AiTokenResult createTokenFull(Long userId) { private AiTokenResult createTokenFull(Long userId, String displayName) {
String username = "puhui_" + userId; String username = "puhui_" + userId;
String password = RandomUtil.randomString(12); String password = RandomUtil.randomString(12);
log.info("[AiTokenService.createTokenFull] 准备注册: username={}", username); log.info("[AiTokenService.createTokenFull] 准备注册: username={}, displayName={}", username, displayName);
try { try {
// 使用管理员接口注册(关闭游客注册后使用) // 使用管理员接口注册(关闭游客注册后使用)
NewApiResponse<Void> registerResp = newApiClient.adminRegister(username, password); NewApiResponse<Void> registerResp = newApiClient.adminRegister(username, password, displayName);
log.info("[AiTokenService.createTokenFull] 注册结果: success={}, message={}", registerResp.getSuccess(), registerResp.getMessage()); log.info("[AiTokenService.createTokenFull] 注册结果: success={}, message={}", registerResp.getSuccess(), registerResp.getMessage());
if (!Boolean.TRUE.equals(registerResp.getSuccess())) { if (!Boolean.TRUE.equals(registerResp.getSuccess())) {
......
...@@ -64,15 +64,20 @@ public class NewApiClient { ...@@ -64,15 +64,20 @@ public class NewApiClient {
/** /**
* 管理员注册用户(关闭游客注册后使用此接口) * 管理员注册用户(关闭游客注册后使用此接口)
* POST /api/user/ * POST /api/user/
*
* @param displayName 显示名称(对应 NewAPI 的 display_name 字段),为空时 NewAPI 会默认取 username
*/ */
public NewApiResponse<Void> adminRegister(String username, String password) { public NewApiResponse<Void> adminRegister(String username, String password, String displayName) {
String url = newApiProperties.getBaseUrl() + "/api/user/"; String url = newApiProperties.getBaseUrl() + "/api/user/";
log.info("[NewApiClient.adminRegister] 请求URL: {}", url); log.info("[NewApiClient.adminRegister] 请求URL: {}", url);
log.info("[NewApiClient.adminRegister] 请求参数: username={}, password={}", username, "***"); log.info("[NewApiClient.adminRegister] 请求参数: username={}, password={}, displayName={}", username, "***", displayName);
Map<String, Object> body = new HashMap<>(); Map<String, Object> body = new HashMap<>();
body.put("username", username); body.put("username", username);
body.put("password", password); body.put("password", password);
if (StrUtil.isNotBlank(displayName)) {
body.put("display_name", displayName);
}
try { try {
HttpResponse response = HttpRequest.post(url) HttpResponse response = HttpRequest.post(url)
......
...@@ -166,8 +166,8 @@ wx: # 参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-sta ...@@ -166,8 +166,8 @@ wx: # 参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-sta
# 芋道配置项,设置当前项目所有自定义的配置 # 芋道配置项,设置当前项目所有自定义的配置
computility: computility:
new-api: new-api:
base-url: http://10.0.0.207:3000 base-url: http://10.0.0.207:3002
admin-token: V33oMN4fI5H0wKSs0gXipXZ4WvU6DQ== admin-token: HWfIG6YoehIwTC6MKSQYy5vn68FApwA7
admin-user-id: 1 admin-user-id: 1
captcha: captcha:
enable: false # 本地环境,暂时关闭图片验证码,方便登录等接口的测试; enable: false # 本地环境,暂时关闭图片验证码,方便登录等接口的测试;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment