Commit 15d47443 by 苗权威

11.07

parent 4675c212
...@@ -272,13 +272,14 @@ public class OkHttp3Utils { ...@@ -272,13 +272,14 @@ public class OkHttp3Utils {
* @return 状态码 * @return 状态码
* @throws IOException * @throws IOException
*/ */
public static Integer doPostJsonStrReturnCode(String url, String requestJsonStr) throws IOException { public static Integer doPostJsonStrReturnCode(String url, String requestJsonStr, HashMap<String, String> headers) throws IOException {
Request.Builder builder = new Request.Builder(); Request.Builder builder = new Request.Builder();
Request request = builder.url(url).build(); Request request = builder.url(url).build();
Headers.Builder headBuilder = request.headers().newBuilder(); Headers.Builder headBuilder = request.headers().newBuilder();
headBuilder.add("Content-Type","application/json; charset=utf-8"); Iterator<Map.Entry<String, String>> headIterator = headers.entrySet().iterator();
headIterator.forEachRemaining(e -> headBuilder.add(e.getKey(), e.getValue()));
builder.headers(headBuilder.build()).post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), requestJsonStr)); builder.headers(headBuilder.build()).post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), requestJsonStr));
Response response = client.newCall(builder.build()).execute(); Response response = client.newCall(builder.build()).execute();
......
...@@ -39,8 +39,6 @@ public interface TTSConstants { ...@@ -39,8 +39,6 @@ public interface TTSConstants {
} }
interface TENCENT_AUDIO_ID { interface TENCENT_AUDIO_ID {
// String APP_ID = "2159149523";
// String App_Key_WITH_PREFIX = "&app_key=lqpqxEo6p2xQSILQ";
String APP_ID = "2159448906"; String APP_ID = "2159448906";
String App_Key_WITH_PREFIX = "&app_key=7Ab1JbKljViyyXhf"; String App_Key_WITH_PREFIX = "&app_key=7Ab1JbKljViyyXhf";
} }
......
...@@ -86,8 +86,11 @@ public class TTSController { ...@@ -86,8 +86,11 @@ public class TTSController {
* @param response 响应信息 * @param response 响应信息
*/ */
@DeleteMapping("/online_cache") @DeleteMapping("/online_cache")
public void online_cache(@RequestBody OnlineCache onlineCache, HttpServletResponse response) { public void online_cache(@RequestBody OnlineCache onlineCache, HttpServletResponse response, HttpServletRequest request) {
ttService.online_cache(onlineCache, response); String autho = request.getHeader("Authorization");
String groupId = request.getHeader("groupId");
String botAccount = request.getHeader("botAccount");
ttService.online_cache(onlineCache, response, autho, groupId, botAccount);
} }
/** /**
...@@ -303,7 +306,7 @@ public class TTSController { ...@@ -303,7 +306,7 @@ public class TTSController {
data.setBitRate(bitRate); data.setBitRate(bitRate);
data.setSampleRate(StringUtils.isBlank(sampleRate) ? 44100 : Integer.parseInt(sampleRate)); data.setSampleRate(StringUtils.isBlank(sampleRate) ? 44100 : Integer.parseInt(sampleRate));
ttService.uploadOneSen(data, response, request.getHeader("Authorization")); ttService.uploadOneSen(data, response, request.getHeader("Authorization"), request.getHeader("groupId"), request.getHeader("botAccount"));
} }
@PutMapping("/api/upload/record/one_sen") @PutMapping("/api/upload/record/one_sen")
...@@ -436,8 +439,10 @@ public class TTSController { ...@@ -436,8 +439,10 @@ public class TTSController {
*/ */
@DeleteMapping("/api/delete/record/one_sen") @DeleteMapping("/api/delete/record/one_sen")
public void deleteOneSen(@RequestBody UploadOneSenData data,HttpServletResponse response,HttpServletRequest request) { public void deleteOneSen(@RequestBody UploadOneSenData data,HttpServletResponse response,HttpServletRequest request) {
String head = request.getHeader("Authorization"); String autho = request.getHeader("Authorization");
ttService.delOneSen(data, response, head); String groupId = request.getHeader("groupId");
String botAccount = request.getHeader("botAccount");
ttService.delOneSen(data, response, autho, groupId, botAccount);
} }
@DeleteMapping("/api/delete/one/audio") @DeleteMapping("/api/delete/one/audio")
......
...@@ -112,7 +112,7 @@ public class TTService { ...@@ -112,7 +112,7 @@ public class TTService {
* @param onlineCache 包括botname,sever服务器标识 * @param onlineCache 包括botname,sever服务器标识
* @param response 响应信息 * @param response 响应信息
*/ */
public void online_cache(OnlineCache onlineCache, HttpServletResponse response) { public void online_cache(OnlineCache onlineCache, HttpServletResponse response, String autho, String groupId, String botAccount) {
String botName = onlineCache.getBotname(); String botName = onlineCache.getBotname();
if (StringUtils.isBlank(botName)) { if (StringUtils.isBlank(botName)) {
TTServiceUtil.buildOnlineCacheResponse(response, new TTSResponse(401, "no botName"), 401); TTServiceUtil.buildOnlineCacheResponse(response, new TTSResponse(401, "no botName"), 401);
...@@ -164,7 +164,12 @@ public class TTService { ...@@ -164,7 +164,12 @@ public class TTService {
//deleteOfflineResCode = OkHttp3Utils.doPostReturnCode(Initialize.getDelCacheCallbackUrl(), new HashMap<>()); //deleteOfflineResCode = OkHttp3Utils.doPostReturnCode(Initialize.getDelCacheCallbackUrl(), new HashMap<>());
DelCacheCallbackUrlRequest request = new DelCacheCallbackUrlRequest(); DelCacheCallbackUrlRequest request = new DelCacheCallbackUrlRequest();
request.setBotname(botName); request.setBotname(botName);
deleteOfflineResCode = OkHttp3Utils.doPostJsonStrReturnCode(Initialize.getDelCacheCallbackUrl(), JSON.toJSONString(request)); HashMap<String, String> headers = new HashMap<>();
headers.put("Authorization", autho);
headers.put("groupId", groupId);
headers.put("botAccount", botAccount);
headers.put("Content-Type","application/json; charset=utf-8");
deleteOfflineResCode = OkHttp3Utils.doPostJsonStrReturnCode(Initialize.getDelCacheCallbackUrl(), JSON.toJSONString(request), headers);
if (deleteOfflineResCode == null) deleteOfflineResCode = 556; if (deleteOfflineResCode == null) deleteOfflineResCode = 556;
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -1633,7 +1638,7 @@ public class TTService { ...@@ -1633,7 +1638,7 @@ public class TTService {
* @param data 请求信息 * @param data 请求信息
* @param response 响应信息 * @param response 响应信息
*/ */
public void uploadOneSen(UploadOneSenData data, HttpServletResponse response, String head) { public void uploadOneSen(UploadOneSenData data, HttpServletResponse response, String head, String groupId, String botAccount) {
// tid,botName,npcName,text,file皆不能为空,否则返回400 // tid,botName,npcName,text,file皆不能为空,否则返回400
// log.info("UploadOneSenData:{}",data); // log.info("UploadOneSenData:{}",data);
if (StringUtils.isAnyBlank(String.valueOf(data.getTid()),data.getBotName(), data.getNpcName(), data.getText()) || data.getFile().getName() == null) { if (StringUtils.isAnyBlank(String.valueOf(data.getTid()),data.getBotName(), data.getNpcName(), data.getText()) || data.getFile().getName() == null) {
...@@ -1695,6 +1700,8 @@ public class TTService { ...@@ -1695,6 +1700,8 @@ public class TTService {
try { try {
HashMap<String, String> headers = new HashMap<>(); HashMap<String, String> headers = new HashMap<>();
headers.put("Authorization", head); headers.put("Authorization", head);
headers.put("groupId", groupId);
headers.put("botAccount", botAccount);
headers.put("Content-Type","application/json; charset=utf-8"); headers.put("Content-Type","application/json; charset=utf-8");
// String jsonData = JSON.toJSONString(new int[]{data.getTid()}); // String jsonData = JSON.toJSONString(new int[]{data.getTid()});
// log.warn("getRecord_callback_url json data:{}, url:{}",jsonData, Initialize.getRecord_callback_url()); // log.warn("getRecord_callback_url json data:{}, url:{}",jsonData, Initialize.getRecord_callback_url());
...@@ -2240,7 +2247,7 @@ public class TTService { ...@@ -2240,7 +2247,7 @@ public class TTService {
* @param data * @param data
* @param response * @param response
*/ */
public void delOneSen(UploadOneSenData data, HttpServletResponse response, String head) { public void delOneSen(UploadOneSenData data, HttpServletResponse response, String head, String groupId, String botAccount) {
// 四个参数都不能为空 // 四个参数都不能为空
if (StringUtils.isAnyBlank(data.getBotName(),data.getNpcName(),data.getText()) || data.getTid() == null) { if (StringUtils.isAnyBlank(data.getBotName(),data.getNpcName(),data.getText()) || data.getTid() == null) {
TTServiceUtil.buildUploadResponse(response, new TTSResponse(400, "参数不对"), 400); TTServiceUtil.buildUploadResponse(response, new TTSResponse(400, "参数不对"), 400);
...@@ -2267,6 +2274,8 @@ public class TTService { ...@@ -2267,6 +2274,8 @@ public class TTService {
try { try {
HashMap<String, String> headers = new HashMap<>(); HashMap<String, String> headers = new HashMap<>();
headers.put("Authorization", head); headers.put("Authorization", head);
headers.put("groupId", groupId);
headers.put("botAccount", botAccount);
headers.put("Content-Type","application/json; charset=utf-8"); headers.put("Content-Type","application/json; charset=utf-8");
String tid; String tid;
if (Boolean.TRUE.equals(data.getCustomText())) { if (Boolean.TRUE.equals(data.getCustomText())) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment