小飞侠接口对接

This commit is contained in:
2026-06-30 23:44:31 +08:00
parent 6e047dc0a5
commit ed1845c0ba
14 changed files with 653 additions and 2 deletions
@@ -0,0 +1,61 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { CourierProviderCode } from './courier.constants';
export type XiaofeixiaSignType = 'MD5' | 'HMAC-SHA256';
export interface XiaofeixiaConfig {
apiUrl: string;
appId?: string;
mchId: string;
apiKey: string;
signType: XiaofeixiaSignType;
}
export interface CourierIntegrationConfig {
provider: CourierProviderCode;
xiaofeixia: XiaofeixiaConfig;
}
@Injectable()
export class CourierConfigService {
constructor(private readonly config: ConfigService) {}
load(): CourierIntegrationConfig {
const providerRaw = (this.config.get<string>('COURIER_PROVIDER') ?? 'xiaofeixia').toLowerCase();
const provider = this.resolveProvider(providerRaw);
return {
provider,
xiaofeixia: {
apiUrl:
this.config.get<string>('XIAOFEIXIA_API_URL') ??
'https://beta.51xiaoju.cn/app/api/interface.do',
appId: this.config.get<string>('XIAOFEIXIA_APP_ID') || undefined,
mchId: this.config.get<string>('XIAOFEIXIA_MCH_ID') ?? '',
apiKey: this.config.get<string>('XIAOFEIXIA_API_KEY') ?? '',
signType: this.resolveSignType(this.config.get<string>('XIAOFEIXIA_SIGN_TYPE')),
},
};
}
private resolveProvider(raw: string): CourierProviderCode {
switch (raw) {
case 'xiaofeixia':
return CourierProviderCode.XIAOFEIXIA;
case 'sf':
return CourierProviderCode.SF;
case 'jd':
return CourierProviderCode.JD;
default:
throw new Error(`Unsupported COURIER_PROVIDER: ${raw}`);
}
}
private resolveSignType(raw?: string): XiaofeixiaSignType {
if (raw?.toUpperCase() === 'HMAC-SHA256') {
return 'HMAC-SHA256';
}
return 'MD5';
}
}