共享 API 文档
统一登录与用户中心
注册、登录、资料、绑定、地址簿都用平台账号体系,登录后拿到的 token 可复用于其它能力。
接入后可以直接使用平台账号体系,不必自建注册、登录、资料、绑定与地址簿。用户登录后拿到的 token 可复用于实人认证、用户资料和业务接口。
登录方式
| 路由 | 登录方式 | 请求字段 | 说明 |
|---|---|---|---|
POST /login/system |
用户名 / 手机 / 邮箱 + 密码 | identifier、credential |
密码 6–12 位 |
POST /login/mobile |
手机 + 验证码 | mobile、code |
先调 /code/sendmobile |
POST /login/email |
邮箱 + 验证码 | email、code |
先调 /code/sendemail |
POST /login/wechat |
微信小程序 | code、app_id |
多小程序必须传自己的 app_id,见「多小程序绑定同一用户」 |
注册与资料
| 路由 | 用途 | 关键字段 |
|---|---|---|
POST /user/create |
注册用户 | auth_id、identifier、credential、email、mobile、nick_name、sex、birthday、grade_id、code |
POST /user/info |
查询指定用户 | 按在线文档传用户标识 |
POST /user/myinfo |
查询当前登录用户 | 用户 token |
POST /user/update |
修改资料 | user_id、nick_name、birthday、code |
POST /user/avatar |
修改头像 | 用户 token + 头像文件 |
POST /user/resetpassword |
重置密码 | user_id、credential、email、mobile、code |
- 注册前先取邮箱或手机验证码;
code为数字验证码。 - 资料与头像接口都要带用户 token。
SSO 短码(跨端免登)
- 已登录的一端调
POST /login/getCode,传state,拿到 6 位tempCode。 - 把
tempCode与state交给另一端。 - 另一端调
POST /login/changeToken,传tempCode、state,换回用户 token。
短码 60 秒有效、一次性;state 由你方生成并校验,防止串号。
地址簿
| 路由 | 用途 |
|---|---|
POST /address/create |
新增地址 |
POST /address/list |
地址列表 |
POST /address/info |
地址详情 |
POST /address/update |
修改地址 |
POST /address/delete |
删除地址 |
新增地址字段:user_name、user_phone、province、city、district、address_detail、address_default(0 / 1)、lat、lng。其余接口按地址 ID 操作。
登录态
- 登录成功后,如果响应头返回
token,保存并替换旧 token;当天获取的 token 当天可直接使用。 50001–50004:未登录、过期、验签失败、旧 token 或黑名单,清本地登录态回登录页。10403:网关未放行,不要按登录态失效处理。
调用示例
curl -sS -X POST "https://api.micro.lck.yn.cn/login/system" \ -H "Content-Type: application/json" \
-H "X-App-Id: $APP_ID" \
-H "X-App-Token: $APP_TOKEN" \
-d '{"identifier":"你的账号","credential":"你的密码"}'<?php
$body = '{"identifier":"你的账号","credential":"你的密码"}';
$headers = [
'Content-Type: application/json',
'X-App-Id: ' . getenv('APP_ID'),
'X-App-Token: ' . getenv('APP_TOKEN'),
];
$ctx = stream_context_create(['http' => [
'method' => 'POST',
'header' => implode("\r\n", $headers) . "\r\n",
'content' => $body,
'timeout' => 10,
]]);
$resp = file_get_contents('https://api.micro.lck.yn.cn/login/system', false, $ctx);
if ($resp === false) { fwrite(STDERR, "request failed\n"); exit(1); }
echo $resp, PHP_EOL;const res = await fetch('https://api.micro.lck.yn.cn/login/system', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-App-Id': process.env.APP_ID,
'X-App-Token': process.env.APP_TOKEN,
},
body: '{"identifier":"你的账号","credential":"你的密码"}'
});
if (!res.ok) throw new Error('HTTP ' + res.status);
console.log(await res.text());import os, urllib.request
req = urllib.request.Request(
'https://api.micro.lck.yn.cn/login/system',
data='{"identifier":"你的账号","credential":"你的密码"}'.encode('utf-8'),
headers={
'Content-Type': 'application/json',
'X-App-Id': os.environ['APP_ID'],
'X-App-Token': os.environ['APP_TOKEN'],
},
method='POST',
)
with urllib.request.urlopen(req, timeout=10) as resp:
print(resp.read().decode('utf-8'))package main
import (
"fmt"
"io"
"net/http"
"strings"
"os"
)
func main() {
req, err := http.NewRequest("POST", "https://api.micro.lck.yn.cn/login/system", strings.NewReader(`{"identifier":"你的账号","credential":"你的密码"}`))
if err != nil { panic(err) }
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-App-Id", os.Getenv("APP_ID"))
req.Header.Set("X-App-Token", os.Getenv("APP_TOKEN"))
resp, err := http.DefaultClient.Do(req)
if err != nil { panic(err) }
defer resp.Body.Close()
data, _ := io.ReadAll(resp.Body)
fmt.Println(string(data))
}import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Demo {
public static void main(String[] args) throws Exception {
HttpRequest req = HttpRequest.newBuilder(URI.create("https://api.micro.lck.yn.cn/login/system"))
.header("Content-Type", "application/json")
.header("X-App-Id", System.getenv("APP_ID"))
.header("X-App-Token", System.getenv("APP_TOKEN"))
.POST(HttpRequest.BodyPublishers.ofString("{\"identifier\":\"你的账号\",\"credential\":\"你的密码\"}"))
.build();
HttpResponse<String> res = HttpClient.newHttpClient()
.send(req, HttpResponse.BodyHandlers.ofString());
System.out.println(res.body());
}
}// 安全:appId 由平台下发;appToken 由你方服务端换取并缓存中转,
// 不要写进小程序代码,AppSecret 更不能放前端。
const APP_ID = '(由你方服务端下发,勿硬编码)'
const APP_TOKEN = '(由你方服务端换取并缓存,勿下发前端)'
wx.request({
url: 'https://api.micro.lck.yn.cn/login/system',
method: 'POST',
data: {"identifier":"你的账号","credential":"你的密码"},
header: {
'content-type': 'application/json',
'X-App-Id': APP_ID,
'X-App-Token': APP_TOKEN
},
success(res) { console.log(res.data) },
fail(err) { console.error(err) }
})// Flutter:pubspec.yaml 加 http 依赖。
// 安全:appId/appToken 由你方服务端下发并缓存中转,不要硬编码在 APP 包体内。
const appIdFromServer = '由服务端注入' // 勿硬编码
const tokenFromServer = '由服务端换取并缓存' // 勿下发前端
import 'package:http/http.dart' as http;
Future<void> main() async {
final res = await http.post(
Uri.parse('https://api.micro.lck.yn.cn/login/system'),
headers: {
'Content-Type': 'application/json',
'X-App-Id': appIdFromServer,
'X-App-Token': tokenFromServer,
},
body: r'{"identifier":"你的账号","credential":"你的密码"}',
);
print(res.body);
}