Compare commits
No commits in common. "324008472cc50fd90c2087a06735feb8b821c624" and "817f368522fc946c4af842afc4f64780dd21ce28" have entirely different histories.
324008472c
...
817f368522
|
|
@ -13,10 +13,6 @@ import * as crypto from 'crypto';
|
||||||
import { SiteService } from '../service/site.service';
|
import { SiteService } from '../service/site.service';
|
||||||
import { OrderService } from '../service/order.service';
|
import { OrderService } from '../service/order.service';
|
||||||
|
|
||||||
import {
|
|
||||||
UnifiedOrderDTO,
|
|
||||||
} from '../dto/site-api.dto';
|
|
||||||
|
|
||||||
@Controller('/webhook')
|
@Controller('/webhook')
|
||||||
export class WebhookController {
|
export class WebhookController {
|
||||||
private secret = 'YOONE24kd$kjcdjflddd';
|
private secret = 'YOONE24kd$kjcdjflddd';
|
||||||
|
|
@ -120,88 +116,4 @@ export class WebhookController {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Post('/shoppy')
|
|
||||||
async handleShoppyWebhook(
|
|
||||||
@Body() body: any,
|
|
||||||
@Query('siteId') siteIdStr: string,
|
|
||||||
@Query('signature') signature: string,
|
|
||||||
@Headers() header: any
|
|
||||||
) {
|
|
||||||
const topic = header['x-oemsaas-event-type'];
|
|
||||||
// const source = header['x-oemsaas-shop-domain'];
|
|
||||||
const siteId = Number(siteIdStr);
|
|
||||||
const bodys = new UnifiedOrderDTO();
|
|
||||||
Object.assign(bodys, body);
|
|
||||||
// 从数据库获取站点配置
|
|
||||||
const site = await this.siteService.get(siteId, true);
|
|
||||||
|
|
||||||
// if (!site || !source?.includes(site.websiteUrl)) {
|
|
||||||
if (!site) {
|
|
||||||
console.log('domain not match');
|
|
||||||
return {
|
|
||||||
code: HttpStatus.BAD_REQUEST,
|
|
||||||
success: false,
|
|
||||||
message: 'domain not match',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
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');
|
|
||||||
try {
|
|
||||||
if (this.secret === signature) {
|
|
||||||
switch (topic) {
|
|
||||||
case 'product.created':
|
|
||||||
case 'product.updated':
|
|
||||||
// 不再写入本地,平台事件仅确认接收
|
|
||||||
break;
|
|
||||||
case 'product.deleted':
|
|
||||||
// 不再写入本地,平台事件仅确认接收
|
|
||||||
break;
|
|
||||||
case 'orders/create':
|
|
||||||
case 'orders/update':
|
|
||||||
await this.orderService.syncSingleOrder(siteId, bodys);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,7 @@ export class Site {
|
||||||
apiUrl: string;
|
apiUrl: string;
|
||||||
|
|
||||||
@Column({ name: 'website_url', length: 255, nullable: true })
|
@Column({ name: 'website_url', length: 255, nullable: true })
|
||||||
websiteUrl?: string;
|
websiteUrl: string;
|
||||||
|
|
||||||
@Column({ name: 'webhook_url', length: 255, nullable: true })
|
|
||||||
webhookUrl?: string;
|
|
||||||
|
|
||||||
@Column({ length: 255, nullable: true })
|
@Column({ length: 255, nullable: true })
|
||||||
consumerKey?: string;
|
consumerKey?: string;
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ export class AuthMiddleware implements IMiddleware<Context, NextFunction> {
|
||||||
whiteList = [
|
whiteList = [
|
||||||
'/user/login',
|
'/user/login',
|
||||||
'/webhook/woocommerce',
|
'/webhook/woocommerce',
|
||||||
'/webhook/shoppy',
|
|
||||||
'/logistics/getTrackingNumber',
|
'/logistics/getTrackingNumber',
|
||||||
'/logistics/getListByTrackingId',
|
'/logistics/getListByTrackingId',
|
||||||
'/product/categories/all',
|
'/product/categories/all',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue