From d5573788ad787837e2dcea7feecf033ecd8ca53e Mon Sep 17 00:00:00 2001 From: Sum1Dream <418471657@qq.com> Date: Sun, 25 Jun 2023 13:58:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=9F=A5=E8=AF=A2=E9=97=A8?= =?UTF-8?q?=E5=BA=97=E5=92=8C=E7=A7=AF=E5=88=86=E8=BF=94=E5=88=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/cweb/controller/TestController.java | 47 ++++++++++++++++--- .../hfkj/model/HwPushModel/HwPushBody.java | 37 +++++++++++++++ .../hfkj/model/HwPushModel/HwPushMessage.java | 35 ++++++++++++++ 3 files changed, 112 insertions(+), 7 deletions(-) create mode 100644 service/src/main/java/com/hfkj/model/HwPushModel/HwPushBody.java create mode 100644 service/src/main/java/com/hfkj/model/HwPushModel/HwPushMessage.java diff --git a/cweb/src/main/java/com/cweb/controller/TestController.java b/cweb/src/main/java/com/cweb/controller/TestController.java index 503dcd1..8c05040 100644 --- a/cweb/src/main/java/com/cweb/controller/TestController.java +++ b/cweb/src/main/java/com/cweb/controller/TestController.java @@ -20,6 +20,7 @@ import com.hfkj.config.CommonSysConst; import com.hfkj.config.device.SoundService; import com.hfkj.config.mqtt.MqttProviderService; import com.hfkj.entity.*; +import com.hfkj.model.HwPushModel.HwPushMessage; import com.hfkj.model.MerBasisModel; import com.hfkj.model.ResponseData; import com.hfkj.service.*; @@ -27,7 +28,6 @@ import com.hfkj.sysenum.MerStatusEnum; import com.hfkj.sysenum.PlatformTypeEnum; import com.hfkj.sysenum.StoreCreateTypeEnum; import com.hfkj.sysenum.StoreStatusEnum; -import com.hfkj.tts.HWYunSisService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.collections4.MapUtils; @@ -640,16 +640,21 @@ public class TestController { } - @RequestMapping(value="/ttsCustomDemo",method = RequestMethod.GET) + @RequestMapping(value="/getHwToken",method = RequestMethod.GET) @ResponseBody - @ApiOperation(value = "ttsCustomDemo") - public ResponseData ttsCustomDemo() { + @ApiOperation(value = "getHwToken") + public ResponseData getHwToken() { try { - JSONObject object = new JSONObject(); - object.put("price" , "374.87"); + Map object = new HashMap<>(); + + object.put("grant_type" , "client_credentials"); + object.put("client_id" , "108509887"); + object.put("client_secret" , "e40883f0edf09d1083b497d4e994eafbbdb5517ae548449c5b44977640a75d9a"); - return ResponseMsgUtil.success(HWYunSisService.ttsCustomDemo(object)); + JSONObject post = HttpsUtils.doPost("https://oauth-login.cloud.huawei.com/oauth2/v3/token" , object); + + return ResponseMsgUtil.success(post); } catch (Exception e) { log.error(e.getMessage(), e); @@ -657,6 +662,34 @@ public class TestController { } } + @RequestMapping(value="/getHwPushMsg",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "getHwPushMsg") + public ResponseData getHwPushMsg(@RequestParam(name = "token", required = true) String token , @RequestParam(name = "hwToken", required = true) String hwToken ) { + try { + + HwPushMessage pushMessage = new HwPushMessage(); + pushMessage.setData("测试数据"); + String[] pushToken = {hwToken}; + pushMessage.setToken(pushToken); + + Map map = new HashMap<>(); + map.put("setValidate_only" , true); + map.put("message" , pushMessage); + + // 头部参数 + Map heard = new HashMap<>(); + heard.put("Authorization", token); + + JSONObject post = HttpsUtils.doPost("https://push-api.cloud.huawei.com/v2/388421841221523062/messages:send" , map , heard); + + return ResponseMsgUtil.success(post); + + } catch (Exception e) { + log.error(e.getMessage(), e); + return ResponseMsgUtil.exception(e); + } + } @RequestMapping(value="/uniPush",method = RequestMethod.GET) @ResponseBody diff --git a/service/src/main/java/com/hfkj/model/HwPushModel/HwPushBody.java b/service/src/main/java/com/hfkj/model/HwPushModel/HwPushBody.java new file mode 100644 index 0000000..b04069c --- /dev/null +++ b/service/src/main/java/com/hfkj/model/HwPushModel/HwPushBody.java @@ -0,0 +1,37 @@ +package com.hfkj.model.HwPushModel; + +/** + * @author sum1dream + */ +public class HwPushBody { + + /** + * @Author Sum1Dream + * @Description // 控制当前是否为测试消息,测试消息只做格式合法性校验,不会推送给用户设备,取值如下: + * true:测试消息 + * false:正式消息(默认值) + */ + private Boolean validate_only; + + /** + * @Author Sum1Dream + * @Description // 推送消息结构体,message结构体中必须存在有效消息负载以及有效发送目标 + */ + private HwPushMessage hwPushMessage; + + public Boolean getValidate_only() { + return validate_only; + } + + public void setValidate_only(Boolean validate_only) { + this.validate_only = validate_only; + } + + public HwPushMessage getHwPushMessage() { + return hwPushMessage; + } + + public void setHwPushMessage(HwPushMessage hwPushMessage) { + this.hwPushMessage = hwPushMessage; + } +} diff --git a/service/src/main/java/com/hfkj/model/HwPushModel/HwPushMessage.java b/service/src/main/java/com/hfkj/model/HwPushModel/HwPushMessage.java new file mode 100644 index 0000000..23fb136 --- /dev/null +++ b/service/src/main/java/com/hfkj/model/HwPushModel/HwPushMessage.java @@ -0,0 +1,35 @@ +package com.hfkj.model.HwPushModel; + +/** + * @author sum1dream + */ +public class HwPushMessage { + + /** + * @Author Sum1Dream + * @Description // 自定义消息负载,通知栏消息支持JSON格式字符串,透传消息支持普通字符串或者JSON格式字符串。 + */ + private String data; + + /** + * @Author Sum1Dream + * @Description // 按照Token向目标用户推消息。 + */ + private String[] token; + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public String[] getToken() { + return token; + } + + public void setToken(String[] token) { + this.token = token; + } +}