aboutsummaryrefslogtreecommitdiff
path: root/vnext
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2024-03-14 19:08:15 +0300
committerGravatar Vitaly Takmazov2024-03-14 19:08:15 +0300
commit9af545e76ce95a3b5a5be14310530716d1b8060f (patch)
treebc76040644259adcc20d6efc046afb7a6c7f9e60 /vnext
parenta78b3e51745fb5530d3b45db28abe862376e09ab (diff)
vnext: fix HMS
Diffstat (limited to 'vnext')
-rw-r--r--vnext/server/hms.js28
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)}`)
}
}