diff --git a/cweb/src/main/java/com/cweb/controller/TestController.java b/cweb/src/main/java/com/cweb/controller/TestController.java index 88136e3..0a5be32 100644 --- a/cweb/src/main/java/com/cweb/controller/TestController.java +++ b/cweb/src/main/java/com/cweb/controller/TestController.java @@ -656,16 +656,18 @@ public class TestController { @RequestMapping(value="/uniPush",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "uniPush") - public ResponseData uniPush(@RequestParam(name = "cid", required = true) String cid) { + public ResponseData uniPush(@RequestParam(name = "storeId", required = true) Long storeId,@RequestParam(name = "price", required = true) BigDecimal price) { try { + JSONObject object = new JSONObject(); - object.put("storeId" , 136); - object.put("price" , "283.82"); + object.put("price", price); + object.put("storeId", storeId); bsStoreCidService.storePush(object); + return ResponseMsgUtil.success("成功"); } catch (Exception e) { diff --git a/service/src/main/java/com/hfkj/common/Base64Util.java b/service/src/main/java/com/hfkj/common/Base64Util.java index 9c0d71e..32142f1 100644 --- a/service/src/main/java/com/hfkj/common/Base64Util.java +++ b/service/src/main/java/com/hfkj/common/Base64Util.java @@ -1,6 +1,11 @@ package com.hfkj.common; +import com.hfkj.common.utils.DateUtil; +import com.hfkj.common.utils.IDGenerator; + import java.util.Base64; +import java.util.Date; +import java.util.Random; public class Base64Util { /** @@ -17,6 +22,17 @@ public class Base64Util { return safeBase64Str.replaceAll("\\s*", ""); } + public static String generateOrderNo(){ + try { + // 5位随机数 + 1位线程生成数 + String randomNum = (new Random().nextInt(8999) + 1000) + IDGenerator.nextId(1); + // 生成订单号 + return DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + randomNum; + } catch (Exception e) { + return null; + } + } + /** * @param safeBase64Str * @return str diff --git a/service/src/main/java/com/hfkj/service/impl/BsStoreCidServiceImpl.java b/service/src/main/java/com/hfkj/service/impl/BsStoreCidServiceImpl.java index b7b8a3f..169d68d 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsStoreCidServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsStoreCidServiceImpl.java @@ -1,9 +1,11 @@ package com.hfkj.service.impl; import com.alibaba.fastjson.JSONObject; +import com.hfkj.common.Base64Util; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; +import com.hfkj.config.CommonSysConst; import com.hfkj.dao.BsStoreCidMapper; import com.hfkj.dao.BsStorePushRecordMapper; import com.hfkj.entity.BsStoreCid; @@ -20,6 +22,7 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -92,6 +95,7 @@ public class BsStoreCidServiceImpl implements BsStoreCidService { if (bsStoreCid == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "不存在推送关系"); } + // 获取语音播报地址 String auditPath = HWYunSisService.ttsCustomDemo(object); @@ -99,9 +103,22 @@ public class BsStoreCidServiceImpl implements BsStoreCidService { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "生成语音失败"); } + String taskNo = Base64Util.generateOrderNo(); + object.put("taskNo", taskNo); object.put("cid", bsStoreCid.getCid()); - object.put("body", auditPath); - UniPushService.pushToSingleByCid(object); + String msg = CommonSysConst.getSysConfig().getDomainName() + auditPath + "!@#PUSH#@!" + taskNo; + object.put("body", msg); + if (UniPushService.pushToSingleByCid(object)) { + BsStorePushRecord storePushRecord = new BsStorePushRecord(); + storePushRecord.setStoreId(object.getLong("storeId")); + storePushRecord.setCreateTime(new Date()); + storePushRecord.setUpdateTime(new Date()); + storePushRecord.setStatus(2); + storePushRecord.setExt1(taskNo); + storePushRecord.setVoiceUrl(msg); + insertStorePushRecord(storePushRecord); + } + } catch (Exception e) { @@ -110,6 +127,8 @@ public class BsStoreCidServiceImpl implements BsStoreCidService { } + + private void getPushRecord(Long storeId) { Map map = new HashMap<>(); @@ -130,6 +149,7 @@ public class BsStoreCidServiceImpl implements BsStoreCidService { if (storePushRecord != null) { JSONObject object = new JSONObject(); object.put("cid", bsStoreCid.getCid()); + object.put("storeId", bsStoreCid.getCid()); object.put("body", storePushRecord.getVoiceUrl()); UniPushService.pushToSingleByCid(object); } @@ -144,8 +164,10 @@ public class BsStoreCidServiceImpl implements BsStoreCidService { pushMap.put("status" , 2); BsStorePushRecord storePushRecord = findPushRecordByMap(pushMap); - storePushRecord.setStatus(1); - storePushRecordMapper.updateByPrimaryKey(storePushRecord); + if (storePushRecord != null) { + storePushRecord.setStatus(1); + storePushRecordMapper.updateByPrimaryKey(storePushRecord); + } getPushRecord(storeId); } diff --git a/service/src/main/java/com/hfkj/tts/HWYunSisService.java b/service/src/main/java/com/hfkj/tts/HWYunSisService.java index f773873..07eb48b 100644 --- a/service/src/main/java/com/hfkj/tts/HWYunSisService.java +++ b/service/src/main/java/com/hfkj/tts/HWYunSisService.java @@ -100,7 +100,8 @@ public class HWYunSisService { File file = new File(path); if (file.exists()) { - return path; + log.info("返回服务器语音内容 " + JSON.toJSONString(path)); + return "/filesystem/tts/" + object.getString("price") + ".mp3"; } // 2. 配置请求 TtsCustomRequest request = new TtsCustomRequest(text); @@ -113,7 +114,7 @@ public class HWYunSisService { log.info("华为云-参数: " + JSON.toJSONString(response)); if (response.getResult().getData() != null) { - return response.getSavePath(); + return "/filesystem/tts/" + object.getString("price") + ".mp3"; } return null; diff --git a/service/src/main/java/com/hfkj/unipush/UniPushService.java b/service/src/main/java/com/hfkj/unipush/UniPushService.java index cd77e08..dcc2af6 100644 --- a/service/src/main/java/com/hfkj/unipush/UniPushService.java +++ b/service/src/main/java/com/hfkj/unipush/UniPushService.java @@ -9,18 +9,10 @@ import com.getui.push.v2.sdk.common.ApiResult; import com.getui.push.v2.sdk.dto.req.Audience; import com.getui.push.v2.sdk.dto.req.message.PushDTO; import com.getui.push.v2.sdk.dto.req.message.PushMessage; -import com.hfkj.common.utils.DateUtil; -import com.hfkj.common.utils.IDGenerator; -import com.hfkj.config.CommonSysConst; -import com.hfkj.entity.BsStorePushRecord; -import com.hfkj.service.BsStoreCidService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Resource; -import java.util.Date; import java.util.Map; -import java.util.Random; /** * @author sum1dream @@ -28,9 +20,6 @@ import java.util.Random; public class UniPushService { private static Logger log = LoggerFactory.getLogger(UniPushService.class); - @Resource - private static BsStoreCidService bsStoreCidService; - /** * 创建请求 * @return @@ -60,10 +49,11 @@ public class UniPushService { * @Param [uniPushModel] * @Return void */ - public static void pushToSingleByCid(JSONObject object) { + public static Boolean pushToSingleByCid(JSONObject object) { log.info("========= START 个推手机端推送 START ==========="); + PushApi pushApi = createClient(); //根据cid进行单推 @@ -85,28 +75,12 @@ public class UniPushService { log.info("========= END 个推手机端推送 END ==========="); if (apiResult.isSuccess()) { - if (apiResult.getData().toString().contains("successed_online")) { - BsStorePushRecord storePushRecord = new BsStorePushRecord(); - storePushRecord.setStoreId(object.getLong("storeid")); - storePushRecord.setCreateTime(new Date()); - storePushRecord.setUpdateTime(new Date()); - storePushRecord.setStatus(2); - storePushRecord.setExt1(generateOrderNo()); - storePushRecord.setVoiceUrl(CommonSysConst.getSysConfig().getDomainName() + object.getString("body") + "!@#PUSH#@!" + storePushRecord.getExt1()); - bsStoreCidService.insertStorePushRecord(storePushRecord); - } + return apiResult.getData().toString().contains("successed_online"); + } else { + return false; } } - public static String generateOrderNo(){ - try { - // 5位随机数 + 1位线程生成数 - String randomNum = (new Random().nextInt(8999) + 1000) + IDGenerator.nextId(1); - // 生成订单号 - return DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + randomNum; - } catch (Exception e) { - return null; - } - } + }