Appearance
用户注册
更新用户信息允许已授权的用户通过此接口更新自己的信息。
接口信息
- 接口:
/users - 请求方式:
POST - 需要鉴权: 是
注意事项
新增参数 tenant_id ,如果不填,会加入到系统默认的云节点
请求参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| name | string | 是 | 客户账号 |
| string | 是 | 邮箱 | |
| phone | string | 是 | 手机号 |
| password | string | 是 | 密码 |
| password_confirmation | string | 是 | 确认密码 |
| tenant_id | string | 否 | 云节点id |
请求示例
cURL
curl -X POST "https://ai.api.longlonglong.cn/users" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"name": "测试租户_会员5",
"email": "ema1il@xx.com",
"phone": "186151681144",
"password": "123456",
"password_confirmation": "123456",
"tenant_id": "f2d216a3-9ea5-4f1d-a170-ce9ebed49eaf"
}'Go
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
url := "https://ai.api.longlonglong.cn/users"
data := map[string]string{
"name": "测试租户_会员5",
"email": "ema1il@xx.com",
"phone": "186151681144",
"password": "123456",
"password_confirmation": "123456",
"tenant_id": "f2d216a3-9ea5-4f1d-a170-ce9ebed49eaf",
}
jsonData, _ := json.Marshal(data)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer YOUR_TOKEN")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}JavaScript
const url = "https://ai.api.longlonglong.cn/users";
const data = {
name: "测试租户_会员5",
email: "ema1il@xx.com",
phone: "186151681144",
password: "123456",
password_confirmation: "123456",
tenant_id: "f2d216a3-9ea5-4f1d-a170-ce9ebed49eaf"
};
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_TOKEN"
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error("Error:", error));Java
import java.net.URI;
import java.net.http.*;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
HttpClient client = HttpClient.newHttpClient();
String body = "{\"name\":\"测试租户_会员5\",\"email\":\"ema1il@xx.com\",\"phone\":\"186151681144\",\"password\":\"123456\",\"password_confirmation\":\"123456\",\"tenant_id\":\"f2d216a3-9ea5-4f1d-a170-ce9ebed49eaf\"}";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://ai.api.longlonglong.cn/users"))
.header("Content-Type", "application/json")
.header("Authorization", "Bearer YOUR_TOKEN")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}PHP
<?php
$curl = curl_init();
$data = [
"name" => "测试租户_会员5",
"email" => "ema1il@xx.com",
"phone" => "186151681144",
"password" => "123456",
"password_confirmation" => "123456",
"tenant_id" => "f2d216a3-9ea5-4f1d-a170-ce9ebed49eaf"
];
curl_setopt_array($curl, [
CURLOPT_URL => "https://ai.api.longlonglong.cn/users",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Authorization: Bearer YOUR_TOKEN"
],
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;Python
import requests
import json
url = "https://ai.api.longlonglong.cn/users"
data = {
"name": "测试租户_会员5",
"email": "ema1il@xx.com",
"phone": "186151681144",
"password": "123456",
"password_confirmation": "123456",
"tenant_id": "f2d216a3-9ea5-4f1d-a170-ce9ebed49eaf"
}
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_TOKEN"
}
response = requests.post(url, data=json.dumps(data), headers=headers)
print(response.json())C++
#include <iostream>
#include <curl/curl.h>
#include <string>
size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp) {
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
int main() {
CURL* curl;
CURLcode res;
std::string readBuffer;
curl = curl_easy_init();
if(curl) {
struct curl_slist* headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "Authorization: Bearer YOUR_TOKEN");
const char* data = "{\"name\":\"测试租户_会员5\",\"email\":\"ema1il@xx.com\",\"phone\":\"186151681144\",\"password\":\"123456\",\"password_confirmation\":\"123456\",\"tenant_id\":\"f2d216a3-9ea5-4f1d-a170-ce9ebed49eaf\"}";
curl_easy_setopt(curl, CURLOPT_URL, "https://ai.api.longlonglong.cn/users");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
else
std::cout << readBuffer << std::endl;
curl_easy_cleanup(curl);
}
return 0;
}成功响应
条件: 鉴权通过,且数据正确。
状态码: 200 OK
响应示例: 响应会将新增该账户,并返回该账户的主要信息:
json
{
"code": 200,
"status": "success",
"message": "添加用户成功",
"data": {
"id": "5b458904-4194-4c83-af8a-774d95a6e327",
"name": "测试租户_会员5",
"email": "ema1il@xx.com",
"phone": "186151681144"
}
}返回的id是这个新增用户的id,如有登录的需求请保存在自己的数据库中
错误响应
错误1
条件: 号码 / 手机已存在 / 密码输入不一致。
状态码: 200 OK
响应示例:
json
{
"code": 422,
"status": "error",
"message": {
"email": [
"邮箱 已经存在。"
],
"phone": [
"手机 已经存在。"
],
"password": [
"密码 两次输入不一致。"
]
},
"data": []
}错误2
条件: 云节点不存在。
状态码: 200 OK
响应示例:
json
{
"code": 1004,
"status": "error",
"message": "云节点不存在",
"data": []
}