Đăng Ký Tài Khoản Mini App
API đăng ký tài khoản cho ứng dụng Mini App sử dụng thông tin từ Zalo.
Người dùng có thể đăng ký bằng thông tin Zalo của họ.
POST https://api.socdo.vn/mini-app/v1/register
Request Headers
Content-Type: application/json
Token-Seller: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
Shop-ID: 23933
Request Body
{
"zalo_user_id": "123456789",
"name": "Nguyễn Văn A",
"avatar": "https://example.com/avatar.jpg",
"gender": "male",
"email": "[email protected]",
"mobile": "0123456789"
}
Tham số
| Tham số |
Loại |
Bắt buộc |
Mô tả |
Token-Seller |
header |
✓ |
JWT token từ API get-token-seller |
Shop-ID |
header |
✓ |
ID của shop (số) |
zalo_user_id |
string |
✓ |
ID người dùng từ Zalo |
name |
string |
✓ |
Tên người dùng |
avatar |
string |
- |
URL ảnh đại diện |
gender |
string |
- |
Giới tính (male/female) |
email |
string |
- |
Email người dùng |
mobile |
string |
- |
Số điện thoại |
Response thành công (201)
{
"success": true,
"message": "Đăng ký Zalo thành công",
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
"data": {
"user_id": 123,
"zalo_user_id": "123456789",
"name": "Nguyễn Văn A",
"username": "zalo_123456789",
"email": "[email protected]",
"mobile": "0123456789",
"avatar": "https://example.com/avatar.jpg",
"gender": "male",
"user_money": 0,
"user_money2": 0,
"doitac": "zalo",
"seller_id": 23933,
"shop_id": 23933
}
}
Response lỗi (409 - Tài khoản đã tồn tại)
{
"success": false,
"message": "Tài khoản Zalo đã được đăng ký. Vui lòng đăng nhập.",
"need_login": true,
"zalo_user_id": "123456789"
}
Response lỗi (400 - Thiếu thông tin)
{
"success": false,
"message": "Vui lòng cung cấp đầy đủ thông tin Zalo (zalo_user_id, name)"
}
Ví dụ JavaScript
// Đăng ký tài khoản Mini App
async function registerMiniApp(userData) {
try {
const response = await fetch('https://api.socdo.vn/mini-app/v1/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(userData)
});
const result = await response.json();
if (result.success) {
// Lưu token để sử dụng cho các request tiếp theo
localStorage.setItem('auth_token', result.token);
console.log('Đăng ký thành công:', result.data);
return result;
} else {
console.error('Lỗi đăng ký:', result.message);
return result;
}
} catch (error) {
console.error('Lỗi kết nối:', error);
return { success: false, message: 'Lỗi kết nối mạng' };
}
}
// Sử dụng
const userData = {
zalo_user_id: "123456789",
name: "Nguyễn Văn A",
avatar: "https://example.com/avatar.jpg",
gender: "male",
email: "[email protected]",
mobile: "0123456789"
};
registerMiniApp(userData).then(result => {
if (result.success) {
// Chuyển hướng đến trang chính của app
window.location.href = '/dashboard';
} else if (result.need_login) {
// Chuyển hướng đến trang đăng nhập
window.location.href = '/login';
}
});
Lưu ý quan trọng
- Username tự động: Username sẽ được tạo tự động theo format
zalo_{zalo_user_id}
- Password tự động: Password sẽ được tạo tự động, không cần thiết cho Zalo login
- JWT Token: Token có thời hạn 1 năm, lưu trữ để sử dụng cho các API khác
- Kiểm tra trùng lặp: Nếu tài khoản đã tồn tại, API sẽ trả về lỗi 409 với
need_login: true
- Token-Seller Required: API yêu cầu Token-Seller header để phân biệt shop
- Shop-ID Required: API yêu cầu Shop-ID header để set user_info.shop
- Shop Integration: Token chứa seller_id và shop_id để liên kết với shop