forked from yoone/API
1
0
Fork 0

refactor(webhook): 移除未使用的shoppy webhook处理逻辑

This commit is contained in:
zhuotianyuan 2026-01-09 14:08:26 +08:00
parent 56ed3437c3
commit af10bbe704
1 changed files with 1 additions and 75 deletions

View File

@ -14,9 +14,7 @@ import { SiteService } from '../service/site.service';
import { OrderService } from '../service/order.service';
import { SiteApiService } from '../service/site-api.service';
import {
UnifiedOrderDTO,
} from '../dto/site-api.dto';
@Controller('/webhook')
export class WebhookController {
@ -192,76 +190,4 @@ export class WebhookController {
}
}
@Post('/shoppy')
async handleShoppyWebhook(
@Body() body: any,
@Query('siteId') siteIdStr: string,
@Query('signature') signature: string,
@Headers() header: any
) {
console.log(`webhook shoppy`, siteIdStr, body, header)
const topic = header['x-oemsaas-event-type'];
// const source = header['x-oemsaas-shop-domain'];
const siteId = Number(siteIdStr);
if (!signature) {
return {
code: HttpStatus.BAD_REQUEST,
success: false,
message: 'Signature missing',
};
}
//shopyy 无法提供加密字段校验,注释校验逻辑
// const rawBody = this.ctx.request.rawBody;
// const hash = crypto
// .createHmac('sha256', this.secret)
// .update(rawBody)
// .digest('base64');
const adapter = await this.siteApiService.getAdapter(siteId);
try {
if (this.secret === signature) {
switch (topic) {
case 'product.created':
case 'product.updated':
// 不再写入本地,平台事件仅确认接收
break;
case 'product.deleted':
// 不再写入本地,平台事件仅确认接收
break;
case 'orders/create':
case 'orders/update':
const order = adapter.mapOrder(body)
await this.orderService.syncSingleOrder(siteId, order);
break;
case 'orders/delete':
break;
case 'customer.created':
break;
case 'customer.updated':
break;
case 'customer.deleted':
break;
default:
console.log('Unhandled event:', topic);
}
return {
code: 200,
success: true,
message: 'Webhook processed successfully',
};
} else {
return {
code: 403,
success: false,
message: 'Webhook verification failed',
};
}
} catch (error) {
console.log(error);
}
}
}