Compare commits
2 Commits
032dd1b215
...
ae703091d4
| Author | SHA1 | Date | |
|---|---|---|---|
| ae703091d4 | |||
| 8daea722bd |
@ -57,42 +57,70 @@ async function request<T>(path: string, options: RequestOptions): Promise<T> {
|
||||
timeout: options.timeout || timeout
|
||||
};
|
||||
|
||||
console.log('[HTTP] 请求详情:', {
|
||||
url: url.toString(),
|
||||
method: options.method,
|
||||
headers: requestOptions.headers,
|
||||
hasToken: !!token,
|
||||
body: options.body
|
||||
});
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = httpModule.request(requestOptions, (res) => {
|
||||
let data = '';
|
||||
|
||||
console.log('[HTTP] 响应状态码:', res.statusCode);
|
||||
console.log('[HTTP] 响应头:', res.headers);
|
||||
|
||||
res.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
console.log('[HTTP] 响应体:', data);
|
||||
try {
|
||||
const json = JSON.parse(data);
|
||||
console.log('[HTTP] 解析后的响应:', JSON.stringify(json, null, 2));
|
||||
|
||||
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
|
||||
console.log('[HTTP] 请求成功');
|
||||
resolve(json as T);
|
||||
} else {
|
||||
reject(new Error(json.error || json.message || `HTTP ${res.statusCode}`));
|
||||
console.error('[HTTP] 请求失败:', {
|
||||
statusCode: res.statusCode,
|
||||
error: json.error,
|
||||
message: json.message,
|
||||
msg: json.msg
|
||||
});
|
||||
reject(new Error(json.error || json.message || json.msg || `HTTP ${res.statusCode}`));
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[HTTP] 解析响应失败:', e);
|
||||
console.error('[HTTP] 原始响应:', data);
|
||||
reject(new Error(`解析响应失败: ${data}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (error) => {
|
||||
console.error('[HTTP] 请求错误:', error);
|
||||
reject(error);
|
||||
});
|
||||
|
||||
req.on('timeout', () => {
|
||||
console.error('[HTTP] 请求超时');
|
||||
req.destroy();
|
||||
reject(new Error('请求超时'));
|
||||
});
|
||||
|
||||
if (options.body) {
|
||||
req.write(JSON.stringify(options.body));
|
||||
const bodyStr = JSON.stringify(options.body);
|
||||
console.log('[HTTP] 发送请求体:', bodyStr);
|
||||
req.write(bodyStr);
|
||||
}
|
||||
|
||||
req.end();
|
||||
console.log('[HTTP] 请求已发送');
|
||||
});
|
||||
}
|
||||
|
||||
@ -266,12 +294,22 @@ export async function getCreditBalance(userId: string): Promise<CreditBalanceRes
|
||||
* POST /api/invitation/verify
|
||||
*/
|
||||
export async function verifyInvitationCode(code: string): Promise<InvitationVerifyResponse> {
|
||||
console.log('[API] 验证邀请码');
|
||||
console.log('[API] 验证邀请码 - 开始');
|
||||
console.log('[API] 邀请码:', code);
|
||||
const body: InvitationVerifyRequest = { code };
|
||||
return request<InvitationVerifyResponse>('/api/invitation/verify', {
|
||||
method: 'POST',
|
||||
body
|
||||
});
|
||||
console.log('[API] 请求体:', JSON.stringify(body));
|
||||
|
||||
try {
|
||||
const response = await request<InvitationVerifyResponse>('/api/invitation/verify', {
|
||||
method: 'POST',
|
||||
body
|
||||
});
|
||||
console.log('[API] 验证邀请码 - 响应:', JSON.stringify(response));
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error('[API] 验证邀请码 - 错误:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -22,22 +22,35 @@ export class InvitationService {
|
||||
*/
|
||||
static async verifyCode(code: string): Promise<{ success: boolean; message: string }> {
|
||||
try {
|
||||
console.log('[InvitationService] 验证邀请码:', code);
|
||||
console.log('[InvitationService] ========== 开始验证邀请码 ==========');
|
||||
console.log('[InvitationService] 邀请码:', code);
|
||||
console.log('[InvitationService] 邀请码长度:', code.length);
|
||||
|
||||
const response = await verifyInvitationCode(code);
|
||||
|
||||
console.log('[InvitationService] 收到响应:', JSON.stringify(response, null, 2));
|
||||
console.log('[InvitationService] 响应代码:', response.code);
|
||||
console.log('[InvitationService] 响应消息:', response.msg);
|
||||
console.log('[InvitationService] 验证结果:', response.data?.verified);
|
||||
|
||||
if (response.code === 200 && response.data?.verified) {
|
||||
console.log('[InvitationService] ✓ 验证成功');
|
||||
return {
|
||||
success: true,
|
||||
message: response.msg || '验证成功'
|
||||
};
|
||||
} else {
|
||||
console.log('[InvitationService] ✗ 验证失败');
|
||||
return {
|
||||
success: false,
|
||||
message: response.msg || '验证失败'
|
||||
};
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('[InvitationService] 验证邀请码失败:', error);
|
||||
console.error('[InvitationService] ========== 验证邀请码异常 ==========');
|
||||
console.error('[InvitationService] 错误类型:', error.constructor.name);
|
||||
console.error('[InvitationService] 错误消息:', error.message);
|
||||
console.error('[InvitationService] 错误堆栈:', error.stack);
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || '网络连接失败,请检查网络后重试'
|
||||
|
||||
@ -11,13 +11,14 @@ export function getInvitationModalContent(qrCodeUri?: string): string {
|
||||
<div id="invitationModal" class="invitation-modal" style="display: none;">
|
||||
<div class="invitation-modal-overlay"></div>
|
||||
<div class="invitation-modal-content">
|
||||
<button id="invitationCloseBtn" class="invitation-close-btn" title="关闭">×</button>
|
||||
<div class="invitation-modal-header">
|
||||
<h2>验证邀请码</h2>
|
||||
<p class="invitation-modal-subtitle">仅供企业端用户和内部人员使用</p>
|
||||
</div>
|
||||
<div class="invitation-modal-body">
|
||||
<div class="invitation-qrcode-section">
|
||||
<p class="invitation-qrcode-text">欢迎企业端用户扫码添加微信获取邀请码</p>
|
||||
<p class="invitation-qrcode-text">欢迎扫码添加微信获取邀请码</p>
|
||||
<img src="${qrCodeUri}" alt="微信二维码" class="invitation-qrcode-image" />
|
||||
</div>
|
||||
<div class="invitation-input-section">
|
||||
@ -80,6 +81,36 @@ export function getInvitationModalStyles(): string {
|
||||
animation: modalSlideIn 0.3s ease-out;
|
||||
}
|
||||
|
||||
.invitation-close-btn {
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
right: 12px;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--vscode-foreground);
|
||||
font-size: 24px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.2s;
|
||||
opacity: 0.6;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.invitation-close-btn:hover {
|
||||
opacity: 1;
|
||||
background: var(--vscode-toolbar-hoverBackground);
|
||||
}
|
||||
|
||||
.invitation-close-btn:active {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
@keyframes modalSlideIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
@ -216,6 +247,7 @@ export function getInvitationModalScript(): string {
|
||||
const modal = document.getElementById('invitationModal');
|
||||
const input = document.getElementById('invitationCodeInput');
|
||||
const submitBtn = document.getElementById('invitationSubmitBtn');
|
||||
const closeBtn = document.getElementById('invitationCloseBtn');
|
||||
const errorDiv = document.getElementById('invitationError');
|
||||
|
||||
// 显示邀请码弹窗
|
||||
@ -270,6 +302,11 @@ export function getInvitationModalScript(): string {
|
||||
// 点击提交按钮
|
||||
submitBtn.addEventListener('click', submitInvitationCode);
|
||||
|
||||
// 点击关闭按钮
|
||||
closeBtn.addEventListener('click', function() {
|
||||
hideInvitationModal();
|
||||
});
|
||||
|
||||
// 回车键提交
|
||||
input.addEventListener('keypress', function(e) {
|
||||
if (e.key === 'Enter') {
|
||||
@ -277,6 +314,11 @@ export function getInvitationModalScript(): string {
|
||||
}
|
||||
});
|
||||
|
||||
// 点击遮罩层关闭弹窗
|
||||
document.querySelector('.invitation-modal-overlay').addEventListener('click', function() {
|
||||
hideInvitationModal();
|
||||
});
|
||||
|
||||
// 阻止点击弹窗内容时关闭
|
||||
document.querySelector('.invitation-modal-content').addEventListener('click', function(e) {
|
||||
e.stopPropagation();
|
||||
|
||||
Reference in New Issue
Block a user