feat:增加语音日志

This commit is contained in:
dzc committed 2026-08-06 09:44:52 +08:00
1 parent f8f938b04c
commit be3be6179f
1 file changed
+26 -9
@@ -3,7 +3,8 @@ package com.bsd.pjcloud.hard.service.impl.yyx;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -40,6 +41,7 @@ public class YyxServiceImpl implements YyxService {
public void send(Long mchId, Integer payPrice, String phone) {
try {
if (!ObjectUtil.isAllNotEmpty(mchId, payPrice, phone)) {
log.warn("|{}|发送语音跳过,参数不完整,mchId:|{}|payPrice:|{}|phone:|{}|", TAG, mchId, payPrice, phone);
return;
}
// 查询商户绑定的云音箱设备
@@ -47,6 +49,7 @@ public class YyxServiceImpl implements YyxService {
.in(HardManagerEntity::getType, List.of(HardTypeEnum.YYX.getType(), HardTypeEnum.YYX_WIFI.getType()))
);
if (ObjectUtil.isEmpty(yyxList)) {
log.info("|{}|发送语音跳过,商户未绑定云音箱,mchId:|{}|payPrice:|{}|phone:|{}|", TAG, mchId, payPrice, phone);
return;
}
@@ -71,13 +74,17 @@ public class YyxServiceImpl implements YyxService {
}
});
} catch (Exception e) {
log.error("|{}|发送失败,异常:{}", TAG, e.getMessage());
log.error("|{}|发送语音异常,mchId:|{}|payPrice:|{}|phone:|{}|", TAG, mchId, payPrice, phone, e);
}
}
// 发送语音
private boolean yyx4gHttpSend(String deviceId, String msg) {
String msgid = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC) + RandomUtil.randomString(8);
String url = yyxConf.getUrl();
String requestBody = null;
String responseBody = null;
long startTime = System.currentTimeMillis();
try {
HashMap<String, Object> data = new HashMap<>();
data.put("cmd", "voice");
@@ -88,20 +95,30 @@ public class YyxServiceImpl implements YyxService {
body.put("sbx_id", deviceId);
body.put("agent_id", JSONUtil.toJsonStr(data));
String res = HttpUtil.post(yyxConf.getUrl(), JSONUtil.toJsonStr(body));
if (ObjectUtil.isEmpty(res)) {
log.error("|{}|4G版云音箱发送语音,发送失败,返回结果为空", TAG);
requestBody = JSONUtil.toJsonStr(body);
log.info("|{}|4G版云音箱发送语音,请求开始,url:|{}|deviceId:|{}|msgid:|{}|msg:|{}|requestBody:|{}|", TAG, url, deviceId, msgid, msg, requestBody);
try (HttpResponse response = HttpRequest.post(url).body(requestBody).execute()) {
responseBody = response.body();
log.info("|{}|4G版云音箱发送语音,请求完成,url:|{}|deviceId:|{}|msgid:|{}|httpStatus:|{}|contentType:|{}|timeConsumingMs:|{}|responseBody:|{}|", TAG, url, deviceId, msgid, response.getStatus(), response.header("Content-Type"), System.currentTimeMillis() - startTime, responseBody);
if (!response.isOk()) {
log.error("|{}|4G版云音箱发送语音,HTTP请求失败,url:|{}|deviceId:|{}|msgid:|{}|httpStatus:|{}|responseBody:|{}|", TAG, url, deviceId, msgid, response.getStatus(), responseBody);
return false;
}
}
if (ObjectUtil.isEmpty(responseBody)) {
log.error("|{}|4G版云音箱发送语音,发送失败,返回结果为空,url:|{}|deviceId:|{}|msgid:|{}|requestBody:|{}|", TAG, url, deviceId, msgid, requestBody);
return false;
}
JSON resJson = JSONUtil.parse(res);
JSON resJson = JSONUtil.parse(responseBody);
String requestId = resJson.getByPath("RequestId", String.class);
if (ObjectUtil.isEmpty(requestId)) {
log.error("|{}|4G版云音箱发送语音,发送失败,返回结果错误res:|{}|", res, TAG);
log.error("|{}|4G版云音箱发送语音,发送失败,响应缺少RequestId,url:|{}|deviceId:|{}|msgid:|{}|requestBody:|{}|responseBody:|{}|", TAG, url, deviceId, msgid, requestBody, responseBody);
}
return true;
} catch (Exception e) {
e.printStackTrace();
log.error("|{}|4G版云音箱发送语音,发送失败,异常:{}", TAG, e.getMessage());
log.error("|{}|4G版云音箱发送语音异常,url:|{}|deviceId:|{}|msgid:|{}|msg:|{}|requestBody:|{}|responseBody:|{}|timeConsumingMs:|{}|", TAG, url, deviceId, msgid, msg, requestBody, responseBody, System.currentTimeMillis() - startTime, e);
return false;
}
}