Commit 15d47443 by 苗权威

11.07

parent 4675c212
......@@ -272,13 +272,14 @@ public class OkHttp3Utils {
* @return 状态码
* @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 request = builder.url(url).build();
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));
Response response = client.newCall(builder.build()).execute();
......
......@@ -39,8 +39,6 @@ public interface TTSConstants {
}
interface TENCENT_AUDIO_ID {
// String APP_ID = "2159149523";
// String App_Key_WITH_PREFIX = "&app_key=lqpqxEo6p2xQSILQ";
String APP_ID = "2159448906";
String App_Key_WITH_PREFIX = "&app_key=7Ab1JbKljViyyXhf";
}
......
......@@ -86,8 +86,11 @@ public class TTSController {
* @param response 响应信息
*/
@DeleteMapping("/online_cache")
public void online_cache(@RequestBody OnlineCache onlineCache, HttpServletResponse response) {
ttService.online_cache(onlineCache, response);
public void online_cache(@RequestBody OnlineCache onlineCache, HttpServletResponse response, HttpServletRequest request) {
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 {
data.setBitRate(bitRate);
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")
......@@ -436,8 +439,10 @@ public class TTSController {
*/
@DeleteMapping("/api/delete/record/one_sen")
public void deleteOneSen(@RequestBody UploadOneSenData data,HttpServletResponse response,HttpServletRequest request) {
String head = request.getHeader("Authorization");
ttService.delOneSen(data, response, head);
String autho = request.getHeader("Authorization");
String groupId = request.getHeader("groupId");
String botAccount = request.getHeader("botAccount");
ttService.delOneSen(data, response, autho, groupId, botAccount);
}
@DeleteMapping("/api/delete/one/audio")
......
......@@ -112,7 +112,7 @@ public class TTService {
* @param onlineCache 包括botname,sever服务器标识
* @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();
if (StringUtils.isBlank(botName)) {
TTServiceUtil.buildOnlineCacheResponse(response, new TTSResponse(401, "no botName"), 401);
......@@ -164,7 +164,12 @@ public class TTService {
//deleteOfflineResCode = OkHttp3Utils.doPostReturnCode(Initialize.getDelCacheCallbackUrl(), new HashMap<>());
DelCacheCallbackUrlRequest request = new DelCacheCallbackUrlRequest();
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;
}
} catch (Exception e) {
......@@ -1633,7 +1638,7 @@ public class TTService {
* @param data 请求信息
* @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
// log.info("UploadOneSenData:{}",data);
if (StringUtils.isAnyBlank(String.valueOf(data.getTid()),data.getBotName(), data.getNpcName(), data.getText()) || data.getFile().getName() == null) {
......@@ -1695,6 +1700,8 @@ public class TTService {
try {
HashMap<String, String> headers = new HashMap<>();
headers.put("Authorization", head);
headers.put("groupId", groupId);
headers.put("botAccount", botAccount);
headers.put("Content-Type","application/json; charset=utf-8");
// String jsonData = JSON.toJSONString(new int[]{data.getTid()});
// log.warn("getRecord_callback_url json data:{}, url:{}",jsonData, Initialize.getRecord_callback_url());
......@@ -2240,7 +2247,7 @@ public class TTService {
* @param data
* @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) {
TTServiceUtil.buildUploadResponse(response, new TTSResponse(400, "参数不对"), 400);
......@@ -2267,6 +2274,8 @@ public class TTService {
try {
HashMap<String, String> headers = new HashMap<>();
headers.put("Authorization", head);
headers.put("groupId", groupId);
headers.put("botAccount", botAccount);
headers.put("Content-Type","application/json; charset=utf-8");
String tid;
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