diff options
Diffstat (limited to 'vnext')
-rw-r--r-- | vnext/server/hms.js | 28 |
1 files 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)}`) } } |