From 9af545e76ce95a3b5a5be14310530716d1b8060f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 14 Mar 2024 19:08:15 +0300 Subject: vnext: fix HMS --- vnext/server/hms.js | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/vnext/server/hms.js b/vnext/server/hms.js index 66bbad82..14f69236 100644 --- a/vnext/server/hms.js +++ b/vnext/server/hms.js @@ -3,7 +3,7 @@ import config from 'config' import debug from 'debug' var log = debug('hms') -const { client_id, client_secret } = config.has('service.hms') ? config.get('service.hms') : {} +const { client_id, client_secret, project_id } = config.has('service.hms') ? config.get('service.hms') : {} const refreshToken = async () => { if (client_id) { @@ -27,32 +27,28 @@ const refreshToken = async () => { export const send = async (msg, tokenList = []) => { const adminToken = await refreshToken() + console.log(`admin token: ${adminToken}, tokenlist: ${tokenList}`) if (adminToken) { - const response = await axios.post(`https://push-api.cloud.huawei.com/v1/${client_id}/messages:send`, { - headers: { - 'Authorization': adminToken, - 'Content-Type': 'application/json' - }, - body: { + const payload = { + 'message': msg + } + const response = await axios.post(`https://push-api.cloud.huawei.com/v2/${project_id}/messages:send`, { 'validate_only': false, 'message': { 'android': { 'fast_app_target': 2 }, - 'data': { - 'pushtype': 1, - 'pushbody': { - 'custom': { - 'message': msg - } - } - }, + 'data': JSON.stringify(payload), 'priority': 'high', 'delayWhileIdle': false, 'token': tokenList } + }, { + headers: { + 'Authorization': `Bearer ${adminToken}`, + 'Content-Type': 'application/json' } }).catch(log) - log(`hcm: ${response.status}`) + log(`hcm: ${response.status} ${JSON.stringify(response.data)}`) } } -- cgit v1.2.3