|
@@ -58,7 +58,7 @@ export class NoahPayAdapter {
|
|
|
/**
|
|
|
* Creates a JWT token for authenticating API requests.
|
|
|
* https://docs.noah.com/api-concepts/signing
|
|
|
- *
|
|
|
+ *
|
|
|
* @param opts - Options for JWT creation.
|
|
|
* @param opts.body - A buffer made from the body of the request. Important to use the exact same body buffer in the request.
|
|
|
* @param opts.method - The HTTP method of the request, e.g., GET, POST, PUT, DELETE.
|
|
@@ -88,8 +88,22 @@ export class NoahPayAdapter {
|
|
|
queryParams,
|
|
|
};
|
|
|
|
|
|
+ // apikey_sandbox_F8XfF9TwNj7ZB5YwCtd2L9K4zN7g6UZRiTQLSfAqCDKm
|
|
|
+
|
|
|
// ES384 is recommended but the algorithm can also be ES256
|
|
|
- const token = jwt.sign(payload, privateKey, {
|
|
|
+ const privateKeyMock = '-----BEGIN EC PRIVATE KEY-----\n'+
|
|
|
+ 'MIGkAgEBBDBgCvOnvqRgyWmdXDss+whk/lhHrCAOADqKtxm32KF76bDdiHI4JWwvPe1heRzDc3ugBwYFK4EEACKhZANiAASWmBOMkyHHq7cH9UMSnLbCPN4ikdgEsMaYGwN+2/5YMF22OwVeorF3+Pp15WYK1zvE4sqxBTqFWzGD/OoTx8RAhh0YIMXljyAtYlOpTLuIBMupVUJLtidqST71CyPpdYc=\n'+
|
|
|
+ '-----END EC PRIVATE KEY-----'
|
|
|
+ // 使用 PUBLIC KEY
|
|
|
+// const privateKeyMock = '-----BEGIN PUBLIC KEY-----\n'+
|
|
|
+// 'MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAElpgTjJMhx6u3B/VDEpy2wjzeIpHYBLDG'+
|
|
|
+// 'mBsDftv+WDBdtjsFXqKxd/j6deVmCtc7xOLKsQU6hVsxg/zqE8fEQIYdGCDF5Y8g'+
|
|
|
+// 'LWJTqUy7iATLqVVCS7Ynakk+9Qsj6XWH\n'+
|
|
|
+ // '-----END PUBLIC KEY-----'
|
|
|
+
|
|
|
+
|
|
|
+ // console.log('payload-=-=-=',payload,privateKeyMock)
|
|
|
+ const token = jwt.sign(payload, privateKeyMock, {
|
|
|
algorithm: 'ES384',
|
|
|
audience: this.config.apiUrl,
|
|
|
// use a short expiry time, less than 15m
|
|
@@ -122,11 +136,13 @@ export class NoahPayAdapter {
|
|
|
* 发送请求到 NoahPay API
|
|
|
*/
|
|
|
async request(method: string, endpoint: string, data?: any) {
|
|
|
+ const xApiKey = 'apikey_sandbox_F8XfF9TwNj7ZB5YwCtd2L9K4zN7g6UZRiTQLSfAqCDKm'
|
|
|
await this.initConfig();
|
|
|
let url = this.config.apiUrl;
|
|
|
try {
|
|
|
url = `${url}${endpoint.replace('/api/open/v4', '')}`;
|
|
|
- const signature = this.getAccessToken(method, url, data);
|
|
|
+ const signature = await this.getAccessToken(method, url, data);
|
|
|
+ console.log('signature-=-=',signature)
|
|
|
const axiosParams: any = {
|
|
|
method,
|
|
|
url,
|
|
@@ -135,6 +151,7 @@ export class NoahPayAdapter {
|
|
|
headers: {
|
|
|
'Content-Type': 'application/json',
|
|
|
'Api-Signature': signature,
|
|
|
+ 'X-Api-Key': xApiKey
|
|
|
},
|
|
|
};
|
|
|
this.logger.info('向noahPay发送请求', axiosParams);
|