共享 API 文档
验证码(手机 / 邮箱)
登录、注册、绑定手机或邮箱前,先发验证码,再校验。
登录、注册、绑定手机或邮箱、重置密码前,都先发验证码再校验。两种通道的字段与校验方式一致,只是载体不同。
| 路由 | 用途 | 请求字段 | 说明 |
|---|---|---|---|
POST /code/sendemail |
发送邮箱验证码 | email |
邮箱验证码可直接使用 |
POST /code/checkemail |
校验邮箱验证码 | email、code |
code 为数字 |
POST /code/sendmobile |
发送手机验证码 | mobile |
需平台开通短信通道与模板配额 |
POST /code/checkmobile |
校验手机验证码 | mobile、code |
code 为数字 |
你方需要准备
- 网关
appId、appToken。 - 手机通道:平台已开通短信通道与模板配额,未开通时只能先用邮箱。
平台会交付
- 可用的发送通道、单号码/单邮箱的频率上限与每日配额。
- 发送接口有频率限制,触发时返回
90000,退避重试,不要密集压测。 - 验证码一次性使用;校验失败按
msg提示,不要自动重复发送。 - 手机验证码依赖平台短信通道,开通范围与配额以平台交付为准;邮箱验证码可直接使用。
发送邮箱验证码
curl -sS -X POST "https://api.micro.lck.yn.cn/code/sendemail" \ -H "Content-Type: application/json" \
-H "X-App-Id: $APP_ID" \
-H "X-App-Token: $APP_TOKEN" \
-d '{"email":"you@example.com"}'<?php
$body = '{"email":"you@example.com"}';
$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/code/sendemail', 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/code/sendemail', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-App-Id': process.env.APP_ID,
'X-App-Token': process.env.APP_TOKEN,
},
body: '{"email":"you@example.com"}'
});
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/code/sendemail',
data='{"email":"you@example.com"}'.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/code/sendemail", strings.NewReader(`{"email":"you@example.com"}`))
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/code/sendemail"))
.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("{\"email\":\"you@example.com\"}"))
.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/code/sendemail',
method: 'POST',
data: {"email":"you@example.com"},
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/code/sendemail'),
headers: {
'Content-Type': 'application/json',
'X-App-Id': appIdFromServer,
'X-App-Token': tokenFromServer,
},
body: r'{"email":"you@example.com"}',
);
print(res.body);
}校验邮箱验证码
POST /code/checkemail,传 email 与 code;code 为数字。
发送手机验证码
curl -sS -X POST "https://api.micro.lck.yn.cn/code/sendmobile" \ -H "Content-Type: application/json" \
-H "X-App-Id: $APP_ID" \
-H "X-App-Token: $APP_TOKEN" \
-d '{"mobile":"13800000000"}'<?php
$body = '{"mobile":"13800000000"}';
$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/code/sendmobile', 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/code/sendmobile', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-App-Id': process.env.APP_ID,
'X-App-Token': process.env.APP_TOKEN,
},
body: '{"mobile":"13800000000"}'
});
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/code/sendmobile',
data='{"mobile":"13800000000"}'.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/code/sendmobile", strings.NewReader(`{"mobile":"13800000000"}`))
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/code/sendmobile"))
.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("{\"mobile\":\"13800000000\"}"))
.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/code/sendmobile',
method: 'POST',
data: {"mobile":"13800000000"},
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/code/sendmobile'),
headers: {
'Content-Type': 'application/json',
'X-App-Id': appIdFromServer,
'X-App-Token': tokenFromServer,
},
body: r'{"mobile":"13800000000"}',
);
print(res.body);
}校验手机验证码
POST /code/checkmobile,传 mobile 与 code;code 为数字。