Commit 64d8089f by 苗权威

2.14

parent 73a61fb7
This source diff could not be displayed because it is too large. You can view the blob instead.
package ai.qiwu.tmall.spirit.controller; package ai.qiwu.tmall.spirit.controller;
import ai.qiwu.tmall.spirit.po.CookieUpdate;
import ai.qiwu.tmall.spirit.service.SpiritService; import ai.qiwu.tmall.spirit.service.SpiritService;
import ai.qiwu.tmall.spirit.spirit.SpiritAudioUpload; import ai.qiwu.tmall.spirit.spirit.SpiritAudioUpload;
import com.alibaba.da.coin.ide.spi.standard.ResultModel; import com.alibaba.da.coin.ide.spi.standard.ResultModel;
...@@ -128,6 +129,14 @@ public class SpiritController { ...@@ -128,6 +129,14 @@ public class SpiritController {
return "success"; return "success";
} }
@PostMapping("update")
public void updateCookie(@RequestBody CookieUpdate data) {
SpiritAudioUpload.token = data.getToken();
SpiritAudioUpload.cookie = data.getToken();
SpiritAudioUpload.csrfToken = data.getCsrToken();
System.out.println("token:"+SpiritAudioUpload.token);
}
@GetMapping("/del") @GetMapping("/del")
public void del(String filepath, Long skillId) { public void del(String filepath, Long skillId) {
spiritAudioUpload.deleteAudio(filepath, skillId); spiritAudioUpload.deleteAudio(filepath, skillId);
......
package ai.qiwu.tmall.spirit.po;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
public class CookieUpdate {
private String cookie;
private String token;
private String csrToken;
}
...@@ -50,9 +50,9 @@ public class SpiritAudioUpload { ...@@ -50,9 +50,9 @@ public class SpiritAudioUpload {
@Value("${csvDicForBotChange}") @Value("${csvDicForBotChange}")
private String csvDicForBotChange; private String csvDicForBotChange;
private volatile String cookie = "dnk=tb13503054; t=f7d06d2e248fc07aa83289307aa4a764; tracknick=tb13503054; enc=nxqSx7%2Bh17LC3JcQmuWryBEA3g%2BBQXPR5Yjzs%2FgXE1NL3ugqfFWtSRIPXXeSIBbLjdMyJYXMRxPVk65RKEod0Q%3D%3D; _tb_token_=e373f335bb333; cookie2=144d7e656949f09b0f5432fa8fccc24a; cna=J1ApEybNe0UCAXQeRp7gOjrr; UM_distinctid=16ec8f74975752-01cfeaef5bdb6d-2393f61-e1000-16ec8f74976888; uc1=existShop=false&cookie14=UoTbmEhZbnUtCA%3D%3D&cart_m=0&cookie16=URm48syIJ1yk0MX2J7mAAEhTuw%3D%3D&pas=0&cookie15=UIHiLt3xD8xYTw%3D%3D&cookie21=VFC%2FuZ9ainBZ&tag=8&lng=zh_CN; _l_g_=Ug%3D%3D; unb=1038446007; cookie1=UNMubI1eQ0gVOzLdxFCJj7hzIKFouglcA%2BlE1IYgcZQ%3D; login=true; cookie17=UoH8Vd06g9TEfA%3D%3D; _nk_=tb13503054; sg=47f; csg=53964595; accountId=52463; accountType=TB; confirmProtocolVersion=1; ctoken=N6keiCTfw7DOtJ76KUHLnsoG; token=xe4nPWfClphv5+4SD5I8ocz/Km7t9hyNdXLKagm/jAk=; EGG_SESS=OG910qv3Q3gsrSK4yqRmX3-1-P_ARlUIzlqweqLqnRF5dKELPTe4hiVT80Slz3WPDCsXS99IeB9EJ08mKe1fnP_VI-r_CiXhigB24HUxJr2EAADqCPIuCrvinUugwUDdbQvx-ay8eof1QwEUukNH_zunLzRWU6aVqoN1ul2_uxG8FPkfVbnawQ6PePgZ2cUELrwNbcWjnHP0ZLLi24iOmdBLx_YbBF0QP4Okdq_EwdFH8aX3a0LQBQXzsSHl8nMpEIjz6-xe5ZAOYqvqBfOIoK49xcaVf3GDp7_k8DeYlqFyB9L0W8d1pjh6MN2nkh9PVoGsrZZ2r0dLBFv6of2yqocpMBv1rLwQS4dPwzlAFYnQ14QwsAv7PK1fElkRid4nhbOzs8YxwZYd0GBUOlKO1kukxu5n2JTcfbsFGD_uFc19GNnO2eH2oM6wQo2iMaeCuWHmDSs9AwHkK4ZZ7p7lNHLSjvSRNA2HH3XIPRRJcgc5w3H2626pQ8yvprnetQ-JzzoxsAM17tDZLIoUlhNZQrrcWW4RYz3cI5E6J5z-jcGKRtD4r0dTpSwUVsYp6a6-PNU71NynGTk1jzilhmwCXogo4K73iFIx0x7BJroamqlfe00a8BRFdpAqqvpcEk243NL8axaQacUFzhSFvJ8M91KPlH-PTMfQysaOx4GT9raVhqsJcePK22hH7PYG6PoMlK7ePw_wriHaHGB2KVPZbFW9pj20VH4UrcRUclVis0kQ5cnbCo3zIkK7ZAhFenMHe-XBf-E9RJ1qKf2Se8CJSzAjeuUb2xrF-qd8V1AqZ245Lb9scttIfohdjLGAF6Ou-Jw-8fCy1J4D_8P1VqLjz5vnwp0kkn3TZyTPC7-AfXkYOgBkd97LugAYpbZu0TY3_nYGUQVdNNlKLRcveVr1inGfDknqQXJZMs694Cr1swf_vX-ttoz3Sd4R0Ctyu2KbeldstqdZoU2jvTKMCNAXcyzwNyKFO_NkdKPH8ks_Yj6mQmz2Ow8f-l8eSSc5hzkcNBfNhZb1p26mFYAyVA5D1tFOBbMBybiLoYZXiQH7cm7YPow2yQbMtEz5mpKNisVV8rLAO9DGI88vEgJRyKvoiEqBzPVhfEiguuYa-XXMA2xXGnDBp7zwK3P2kaiJ63uvfbNhEQhve4reBfH2ojRJG4RXODXO_O9_s6lZy0yRUneBzY5S38kK2AyWl5gWOwKDWCZWHqxcYOy2qmcxYCAJfMV_We8WaUJjlP6eTN8P5rS0WXjCdQ3p7yBOXKdkEYXm6ysuoNxxoGB9QznmWJsaMxtRG00Wz0SCdI13TzQ1lfSbBVvILYw1BfG4qlvnxbO4r-tDR4eZClg3t_C6eHdWowgYy4G3Nnln9asw8IW4MhNjZLEekL7IVDtzdDlLf3nTANLIIckJMrQ-JCWwcb-Igwh7nvussBt0C8trJXACcWwct3M4VVUgOz53wz-pHHO-i2wK8eCarxtnwmAnppIbpHiePF5HZA5lIrFucbbWg6bCARAKfBgOgpNoD-Er52UKvjD9qu-R1Q3sggnEsqk_8SGIlx-pfPSaq9Y6A42ilqHZv2UyRUU5GmUO3i7JTNjzuvx22jBV0gl3vFg7vYdtuzAKj_8OJy5hF_iYy1RFj05IsGbwmUOC6p5xi-rQYgK0OTybeBovfsxxrApymMsTlLTVDvtSbSfe5b8piSACkGk73E-1SgE5X7NhdBVVlqhwM-TiNlVVzY5AyPWB0pc2U3_GFIZ56mtboU129YtpMhJGgm4YZ2znJV7sSU8AbXy8TKcvPUohUgf_5koZzByOiKrIoho2iiLkpqK5DzNrzk2H3loI8SWAydCzJg-7dCR2_s_3wMFXXWZNCpHadVgXpx1Nwd0RRN4eflamebFKlsPTx70naCDSdReR6oGjHliwBELuGb_tkKOYwfMNXEzCCHWkASYtFmHf0u3YK8VUyK9fgWnSh7bkrlh6zoOU1izX1fwDexI7CF9BE0LxqkaLC_nn295kZeIYlQO6Pk9-EP01Wjdvwqc9emWahrfOEMVEU6wdV_gO4_sHel8gAamUaWVRua7-Kl1u6igUm_hNwptHnBisAtCNtqV0WDZJ-oirGMpFqt4aghE9Wy9XiGwOJ3_I1wunKP2ddnxfSayg3iLVlH9RCPRxNR2atC9sQ3Nv__8QCa020V2EFU1LpwVU0lC5mxUACm8yuTzfa-aeiz7Qj2HJHTVLUI6yttmO66AlfAGfUPE63Z7Yseps2uReX6SRsKEDP5px59ufi5jrWpeGZ57Uh9oRJZv9fBZR7Q-Ajy0MJqUZEWYIKkpQ6D2ObDh0_nHxjvbBb4ZrQMQit5PehnXgoIwAExjk3L3y_3dLP_-lurBaV5LSMIiAj0B3IQ==; CNZZDATA1261708326=42777204-1575329673-https%253A%252F%252Fwww.aligenie.com%252F%7C1580998884; _cnzz_CV1261708326=52463%7C%F0%9F%8C%8E%20common%2F%E8%8E%B7%E5%8F%96%20oss%20token%7Cp; isg=BFpa7Yf70Gmj-18cC8krhnz9qwB8i95lub9gaWTZ0u1Z1-4RTxqDdaxhp6PLB1b9"; public static volatile String cookie = "dnk=tb13503054; t=f7d06d2e248fc07aa83289307aa4a764; tracknick=tb13503054; enc=nxqSx7%2Bh17LC3JcQmuWryBEA3g%2BBQXPR5Yjzs%2FgXE1NL3ugqfFWtSRIPXXeSIBbLjdMyJYXMRxPVk65RKEod0Q%3D%3D; _tb_token_=e373f335bb333; cookie2=144d7e656949f09b0f5432fa8fccc24a; cna=J1ApEybNe0UCAXQeRp7gOjrr; UM_distinctid=16ec8f74975752-01cfeaef5bdb6d-2393f61-e1000-16ec8f74976888; uc1=existShop=false&cookie14=UoTbmEhZbnUtCA%3D%3D&cart_m=0&cookie16=URm48syIJ1yk0MX2J7mAAEhTuw%3D%3D&pas=0&cookie15=UIHiLt3xD8xYTw%3D%3D&cookie21=VFC%2FuZ9ainBZ&tag=8&lng=zh_CN; _l_g_=Ug%3D%3D; unb=1038446007; cookie1=UNMubI1eQ0gVOzLdxFCJj7hzIKFouglcA%2BlE1IYgcZQ%3D; login=true; cookie17=UoH8Vd06g9TEfA%3D%3D; _nk_=tb13503054; sg=47f; csg=53964595; accountType=TB; confirmProtocolVersion=1; ctoken=H460GyYx-d_1r1t5zC0LhPP7; accountId=52463; token=zjt4ePdjCjC0+y8U0tLxO5oJUpZH3daOn0fd0pQPSnc=; EGG_SESS=OG910qv3Q3gsrSK4yqRmX3-1-P_ARlUIzlqweqLqnRF5dKELPTe4hiVT80Slz3WPDCsXS99IeB9EJ08mKe1fnD7BTdYqw-7V1GkCKaIWHFLLeVSSS9jC13moc0W1SH9GDhePuBh5f9kfoSaqb6ChWf2z3kPbuCXMqsQpt0mvozK3CjPA2OnZRJzYc3QAIZaD8oDUq67fFPm4DGnaQFab2jVgz9JVx5qZt9SoQEpna51P1ygHPTjj6Urx7ohFYxYfw-IZhgsuRReO258QICdLaMjDOPHv1eYb7fde6sbTgcrU23_ECAu5h_XKmEzbS8HJ30xr6SX7EMC8H0WkXPByYUtDcYt9hOyhdw35xbZrz_KEhwuyVfG3Dn_qPIsrWBPiGBG56iFRD-bQKGpNGDIzOvJRrBdjmeoYGT-WmuRG-RAO-pwxrAbJeZ4watqlg8HnZF3VnDgtiYxE3FCPPSXUTnzHhbJr6I-JZ4X-Y-rI1EFhaQx_vAPImlBSOCO1IdXEl9--pe2jDORiNc3sVeZ_HvWx2LU3A9_nSOdvcNV2tfyvPDSR7DOIQjcBoxwnA9hZF0rKxLHTlLf6U3Q5MzRiE3izczdM9CuSfXA9QbDtSybB9DjaOGP-JvkBdDbI3C4auNT5H_-XfcrIlXI9Es8MV35V9OEdFSVdTZ0H2hydc4IMFcXk5cPxWcHSFsYcca968nkfzeL2LGs7uyBm9XOLs3K7whXrt0OAMIxcRQ91Yun7jtp-7KXfpdyGdjkY9cfgGt9GsuQDCKLU0xaKcwn3qju74OhKZmWHlBH0YBxTtlLBe6kCSzkQ0g9KxZTpPqN8UB0cIyma4yNH8oVGxjP3p8v5OwzRZJggMITh86LjDUuf0AXRH9Wczu_0ZFA3ubGeCISJCb6axoYIayC_QIPsJWlUvCcuuepJLsHvB178iyoRpUvafcfrt2l8LETrnEmBwtBInyTduP4UIGOmT79t4t-HnwAuQbfP0LVyX5-3vD_g_SwXgFiMtTTHSjnKOm7XqCfcsPA_QFRYwmLy4x23d6YHGL_OdenBNtIofnUKB8dUaDTdnAXG9n1zXmNVi5qh3kvK2w5D6oWkS3ck2nn01agnKqBM4ynbxo81xdAmpiIMIZeUh8rXEH0iCTyydTPAL-CYTMasdMkROYdBSaVVx3r2W5rmVF1QIjr_LjBY7GJM_3yl7h30WHPIfv5sVo4HdaV-ZtgjvE-pdSuhueeI9vBrYTlWowcVBYSguuY4SS8VQWGSQNd8qA1pllGlcLmplrCZgAtFKqqJoyxmNLDq4P_8QfeoTDiYVkImx3pxVmGdXwQm4krsxCos7jbw9BX1oukl2abhtU_zgKjoVveu4kTxsFUUSoxFqHrxl5pfi_epBOamnnUaA2XpAXe9cbaNLwLy0k81jb8fqQK9ITIzgu5n--pPC-eEoWi6nD3DmmWZ4eOWEh06xImnwBHM4cPwLiun_J8FpbykIo7-wFcEyQsEZYsrUzvfad5ATrXoLqp82qCagUO1vuUkVsSMWD1llZXD4AhiG8AIdDBy114Zc9Y8QTT27sPsANCCRNnu-VOdXCY-3O3BwgKbgXIVtQLgc-3_dnNBRkgiUn5MNZEwTjyQPfsu5LBCFC64Z502ms2HtgS7h-mv9oLcrIhAo_V4FG6DsNN6qbvmhE3Ww5PFQ0ZlB-tYLf_-lchNrQQsonnXO7pUuvha9eNTF23S98uqHi7pmQ4viRNCojkZr9shfz6YMcAOwdeM_6CRwaG3_ZxWlZB1EyxYdYXx7aYTGoLKmcFlh1Tntjw5PCOkAQWKwWVfpU4Xr5tf8OShheRTVZyPjopQzMByz9HT07voshh_CGMWrQ75pOQ4KmR-vSa4FNsb_vfstjcGm7dptPOYgvLkkhpnbMgsk4qTkwO-kK6E6hCCcRntVMIub_Oy0jvEuCtC6MoauzN2oWMmm33XXOVnxZZZv_lph292z29zGjwv3i40XG9zNfQANJjMQ21II7cei8QAoxa8d-pCeZeiQfS4VFavWxS65xcYQSz2Gg0dxd_pN0yBVyCqwRKZ1iE1QkWWipdJJOBHE42cPkMUG2s2w0wXtx_0HuWeJdea-xoReB1O1l0Zyr_nUXZUJiZulOgcVs-ZnvRwflYQuWMva-847t3nmzMQcrVh6zAahcbO87kvqSzXW16pRe08nVpyyIy4ahEZE95w3yCygTrzmrPKEAAmIJlySA7y_C8X51q-qoQKgs0ajbKndIBNavYmtR2xbHXWF18hZff0k2hdsuP0km40fB1uBltd1jE6LqWaQ6_eO0zPhMjwSRYlfVyCdba3t7ikqKU_P_cwuPuvXFePY6KRf0pZuIj9lY6n6YlryK74E67A9XGxcZ_78dzGNA==; CNZZDATA1261708326=42777204-1575329673-https%253A%252F%252Fwww.aligenie.com%252F%7C1581151796; _cnzz_CV1261708326=52463%7C%F0%9F%8C%8E%20skill%2F%E6%9F%A5%E8%AF%A2%E6%8A%80%E8%83%BD%7Cp; isg=BP__k6UqnQggYZrPHnaWBXFqjtOJ5FOGn_kryZHPyq7joBcinLS61zH24nBe-Cv-";
private volatile String token = "xe4nPWfClphv5+4SD5I8ocz/Km7t9hyNdXLKagm/jAk="; public static volatile String token = "zjt4ePdjCjC0+y8U0tLxO5oJUpZH3daOn0fd0pQPSnc=";
private volatile String csrfToken = "N6keiCTfw7DOtJ76KUHLnsoG"; public static volatile String csrfToken = "H460GyYx-d_1r1t5zC0LhPP7";
public void updateCookie(String cookie) { public void updateCookie(String cookie) {
this.cookie = cookie; this.cookie = cookie;
......
...@@ -7,6 +7,7 @@ import ai.qiwu.com.tts_service.service.Initialize; ...@@ -7,6 +7,7 @@ import ai.qiwu.com.tts_service.service.Initialize;
import ai.qiwu.com.tts_service.service.LieHuSchedule; import ai.qiwu.com.tts_service.service.LieHuSchedule;
import ai.qiwu.com.tts_service.service.TTService; import ai.qiwu.com.tts_service.service.TTService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -240,4 +241,12 @@ public class TTSController { ...@@ -240,4 +241,12 @@ public class TTSController {
// ttService.apiAudioGet(type, path, response, request); // ttService.apiAudioGet(type, path, response, request);
ttService.apiAudioGetNoRange(type, path, response); ttService.apiAudioGetNoRange(type, path, response);
} }
@PostMapping("/api/update/xiaoai")
public void xiaoaiCallbackUpdate(String callbackUrl, String secret) {
if ("mqwXiaoAi.".equals(secret) && StringUtils.isNotBlank(callbackUrl) && callbackUrl.contains("xiaoai/audio/play")) {
Initialize.audioUrl = callbackUrl;
log.warn("小爱回调地址更新:"+callbackUrl);
}
}
} }
...@@ -21,6 +21,8 @@ import java.util.*; ...@@ -21,6 +21,8 @@ import java.util.*;
@Component @Component
@Slf4j @Slf4j
public class Initialize implements InitializingBean { public class Initialize implements InitializingBean {
public static volatile String audioUrl = Config.getProperty("audioCallBack","https://didi-gz4.jiaoyou365.com/xiaoai/audio/play?userId=");
/** /**
* 默认person * 默认person
*/ */
......
...@@ -89,9 +89,6 @@ public class TTService { ...@@ -89,9 +89,6 @@ public class TTService {
this.stringRedisTemplate = stringRedisTemplate; this.stringRedisTemplate = stringRedisTemplate;
} }
@Value("${audioUrl}")
private String audioUrl;
// /** // /**
// * 退出请求的处理/返回TTS_test.mp3文件的下载链接 // * 退出请求的处理/返回TTS_test.mp3文件的下载链接
// * @param request // * @param request
...@@ -2203,10 +2200,20 @@ public class TTService { ...@@ -2203,10 +2200,20 @@ public class TTService {
public void apiAudioGetNoRange(String type, String path, HttpServletResponse response) { public void apiAudioGetNoRange(String type, String path, HttpServletResponse response) {
boolean xiaoAi = StringUtils.isNotBlank(type); boolean xiaoAi = StringUtils.isNotBlank(type);
if (xiaoAi) { if (xiaoAi) {
OkHttp3Utils.backPostAsync(audioUrl+type); OkHttp3Utils.backPostAsync(Initialize.audioUrl+type);
} }
int count = 0; int count = 0;
log.info("apiAudioGetNoRange: path->"+path); // log.info("apiAudioGetNoRange: path->"+path);
if (!path.startsWith("a")) {
if (Files.exists(Paths.get(path))) {
TTServiceUtil.buildMp3ResponseForAudioNoRange(response, path, xiaoAi);
return;
} else {
log.warn("path start with a but not exist:"+path);
return;
}
}
path = path.substring(1);
Path pt = Paths.get(path); Path pt = Paths.get(path);
boolean fileExist; boolean fileExist;
while (!(fileExist=Files.exists(pt)) && count < 15) { while (!(fileExist=Files.exists(pt)) && count < 15) {
...@@ -2240,6 +2247,7 @@ public class TTService { ...@@ -2240,6 +2247,7 @@ public class TTService {
else if (StringUtils.isBlank(botName)) { else if (StringUtils.isBlank(botName)) {
return "null"; return "null";
} }
boolean allExist = true;
final List<Future<ResponseCodeWithData>> futures = new ArrayList<>(); final List<Future<ResponseCodeWithData>> futures = new ArrayList<>();
final List<String> file_ls = new ArrayList<>(); final List<String> file_ls = new ArrayList<>();
String rootFolderRoot = new StringBuilder(Initialize.getAudioDir()).append(File.separator).append(botName).append(File.separator).toString(); String rootFolderRoot = new StringBuilder(Initialize.getAudioDir()).append(File.separator).append(botName).append(File.separator).toString();
...@@ -2321,6 +2329,7 @@ public class TTService { ...@@ -2321,6 +2329,7 @@ public class TTService {
} }
if (!TTSUtils.doesFileExist(filepath)) { if (!TTSUtils.doesFileExist(filepath)) {
allExist = false;
//log.info("不存在地址:{},text:{}, botname:{}, tone:{}, person:{}",filepath, text, botName, tone, person); //log.info("不存在地址:{},text:{}, botname:{}, tone:{}, person:{}",filepath, text, botName, tone, person);
final GeneralMP3Data data = new GeneralMP3Data(Initialize.getServerName(), text, final GeneralMP3Data data = new GeneralMP3Data(Initialize.getServerName(), text,
person, tone, botName, true, volume, speed, pitch); person, tone, botName, true, volume, speed, pitch);
...@@ -2370,29 +2379,37 @@ public class TTService { ...@@ -2370,29 +2379,37 @@ public class TTService {
// 小爱平台的请求,我们会讲所有mp3文件合在一起,文件路径为(audio_dir)/botname/xiaoai/xxx.mp3, // 小爱平台的请求,我们会讲所有mp3文件合在一起,文件路径为(audio_dir)/botname/xiaoai/xxx.mp3,
// 成功则构建请求get_audio接口的请求url,包括参数信息,返回该url // 成功则构建请求get_audio接口的请求url,包括参数信息,返回该url
String temp;
if (file_ls.size() == 1) { if (file_ls.size() == 1) {
final String tmp_audio_name = file_ls.get(0); final String tmp_audio_name = file_ls.get(0);
POOL.submit(() -> task(futures, tmp_audio_name, file_ls, null)); if (!allExist) {
POOL.submit(() -> task(futures, tmp_audio_name, file_ls));
}
String result;
try { try {
return URLEncoder.encode(tmp_audio_name, "UTF-8"); result = URLEncoder.encode(tmp_audio_name, "UTF-8");
} catch (Exception e) { } catch (Exception e) {
return URLEncoder.encode(tmp_audio_name); log.warn("apiAudio URLEncoder fail");
result = URLEncoder.encode(tmp_audio_name);
} }
if (allExist) return result;
else return "a"+result;
} else { } else {
temp = TTSUtils.pythonlistToStr(file_ls); String temp = TTSUtils.pythonlistToStr(file_ls);
// String dirs = String.format("[%s,xiaoai]", botName); // String dirs = String.format("[%s,xiaoai]", botName);
final String folder = StringUtils.join(new String[]{Initialize.getAudioDir(), botName, "xiaoai"}, File.separator); final String tmp_audio_name = StringUtils.join(new String[]{Initialize.getAudioDir(), botName, "xiaoai",temp}, File.separator);
final String tmp_audio_name = new StringBuilder(folder).append(File.separator).append(temp).toString(); if (!TTSUtils.doesFileExist(tmp_audio_name)) {
POOL.submit(() -> task(futures, tmp_audio_name, file_ls, folder)); POOL.submit(() -> task(futures, tmp_audio_name, file_ls));
return "a"+tmp_audio_name;
} else {
return tmp_audio_name; return tmp_audio_name;
} }
} }
}
return "null"; return "null";
} }
private void task(List<Future<ResponseCodeWithData>> futures, String tmp_audio_name, private void task(List<Future<ResponseCodeWithData>> futures, String tmp_audio_name,
List<String> file_ls, String folder) { List<String> file_ls) {
try { try {
// 阻塞等待mp3文件生成成功 // 阻塞等待mp3文件生成成功
//log.info("196:file list:{}", file_ls); //log.info("196:file list:{}", file_ls);
...@@ -2406,6 +2423,10 @@ public class TTService { ...@@ -2406,6 +2423,10 @@ public class TTService {
} }
else if (data.getCode() != 200) { else if (data.getCode() != 200) {
if (data.getCode() == 8) { if (data.getCode() == 8) {
if (file_ls.size() == 1) {
log.info("音箱,单个,不存在,竞争:"+tmp_audio_name);
return;
}
log.info("task:出现竞争情况->"+data.getRes()); log.info("task:出现竞争情况->"+data.getRes());
if (data.getRes() != null) { if (data.getRes() != null) {
int count = 0; int count = 0;
...@@ -2416,6 +2437,7 @@ public class TTService { ...@@ -2416,6 +2437,7 @@ public class TTService {
++count; ++count;
} }
if (count == 20 && Boolean.TRUE.equals(stringRedisTemplate.hasKey(data.getRes()))) { if (count == 20 && Boolean.TRUE.equals(stringRedisTemplate.hasKey(data.getRes()))) {
log.info("task:等待10仍未等到对方完成该任务->"+data.getRes());
return; return;
} }
} }
...@@ -2425,16 +2447,16 @@ public class TTService { ...@@ -2425,16 +2447,16 @@ public class TTService {
return; return;
} }
} catch (Exception e) { } catch (Exception e) {
log.error("tts_ls获取结果出错:{}", ExceptionUtils.getStackTrace(e)); log.error("task 获取结果出错:{}", ExceptionUtils.getStackTrace(e));
return; return;
} }
} }
if (folder != null && !TTSUtils.doesFileExist(tmp_audio_name)) { if (!TTSUtils.doesFileExist(tmp_audio_name)) {
boolean addSuccess = false; boolean addSuccess = false;
try { try {
if ((addSuccess=Boolean.TRUE.equals(stringRedisTemplate.opsForValue() if ((addSuccess=Boolean.TRUE.equals(stringRedisTemplate.opsForValue()
.setIfAbsent(tmp_audio_name, "1", 20, TimeUnit.SECONDS)))) { .setIfAbsent(tmp_audio_name, "1", 20, TimeUnit.SECONDS)))) {
TTSUtils.makedir(folder); Files.createDirectories(Paths.get(tmp_audio_name.substring(0, tmp_audio_name.lastIndexOf(File.separator))));
TTSUtils.combineMp3File(file_ls, tmp_audio_name); TTSUtils.combineMp3File(file_ls, tmp_audio_name);
if (!TTSUtils.doesFileExist(tmp_audio_name)) { if (!TTSUtils.doesFileExist(tmp_audio_name)) {
log.error("小爱平台的请求,聚合mp3文件失败"); log.error("小爱平台的请求,聚合mp3文件失败");
......
...@@ -54,6 +54,7 @@ public interface Constants { ...@@ -54,6 +54,7 @@ public interface Constants {
String COLLECT_IMAGE_ID = "collectImage"; String COLLECT_IMAGE_ID = "collectImage";
String COLLECT_TEXT_ID = "collectText"; String COLLECT_TEXT_ID = "collectText";
String BACK_TRACE = "trace"; String BACK_TRACE = "trace";
String NEXT_PAGE_INDEX = "comCnt";
String PRE_CATEGORY = "categ"; String PRE_CATEGORY = "categ";
String PRE_FUNNY_IMG = "funny"; String PRE_FUNNY_IMG = "funny";
...@@ -112,10 +113,12 @@ public interface Constants { ...@@ -112,10 +113,12 @@ public interface Constants {
String WELCOME_SMART_FORMAT = "欢迎来到晓悟智能故事。与可爱的角色们自由对话,畅游不同的故事世界。我们新上线了%s,你可以说打开%s。或者说,推荐其它作品。"; String WELCOME_SMART_FORMAT = "欢迎来到晓悟智能故事。与可爱的角色们自由对话,畅游不同的故事世界。我们新上线了%s,你可以说打开%s。或者说,推荐其它作品。";
String WELCOME_SMART_FORMAT_AI = "欢迎来到晓悟智能故事。推荐我们新上线的%s,你可以说打开%s。或者说,推荐其它作品。"; String WELCOME_SMART_FORMAT_AI = "欢迎来到晓悟智能故事。推荐我们新上线的%s,你可以说打开%s。或者说,推荐其它作品。";
String SKILL_SMART = "智能故事"; String SKILL_SMART = "智能故事";
String XIAOWU_SKILL_SMART = "晓悟智能故事";
// 与剧情人物自由对话,带您体验不同的人生和情怀。 // 与剧情人物自由对话,带您体验不同的人生和情怀。
String WELCOME_NOVEL = "欢迎来到晓悟智能小说。向您推荐新上线的妖刀异闻录,您可以说打开妖刀异闻录。或者说,推荐其它作品。"; String WELCOME_NOVEL = "欢迎来到晓悟智能小说。向您推荐新上线的妖刀异闻录,您可以说打开妖刀异闻录。或者说,推荐其它作品。";
String WELCOME_NOVEL_FORMAT = "欢迎来到晓悟智能小说。与剧情人物自由对话,带您体验不同的人生和情怀。向您推荐新上线的%s,您可以说打开%s。或者说,推荐其它作品。"; String WELCOME_NOVEL_FORMAT = "欢迎来到晓悟智能小说。与剧情人物自由对话,带您体验不同的人生和情怀。向您推荐新上线的%s,您可以说打开%s。或者说,推荐其它作品。";
String SKILL_NOVEL = "智能小说"; String SKILL_NOVEL = "智能小说";
String XIAOWU_SKILL_NOVEL = "晓悟智能小说";
String WELCOME_LITERATURE = "欢迎来到互动文艺,你可以说推荐作品给我"; String WELCOME_LITERATURE = "欢迎来到互动文艺,你可以说推荐作品给我";
String SKILL_LITERATURE = "互动文艺"; String SKILL_LITERATURE = "互动文艺";
String WELCOME_STORY = "小朋友你好,欢迎来到交互故事,你可以对我说有什么好玩的吗"; String WELCOME_STORY = "小朋友你好,欢迎来到交互故事,你可以对我说有什么好玩的吗";
...@@ -130,7 +133,9 @@ public interface Constants { ...@@ -130,7 +133,9 @@ public interface Constants {
String BYE_BYE = "我们的作品库在不断的扩充,欢迎下次再来玩"; String BYE_BYE = "我们的作品库在不断的扩充,欢迎下次再来玩";
String END_BYE_CHILD = "再见啦小朋友,记得下次再来玩哦"; String END_BYE_CHILD = "再见啦小朋友,记得下次再来玩哦";
String END_BYE_NOVEL = "后续有更多作品上线,欢迎常来访问智能小说。"; // smart novel String END_BYE_NOVEL = "后续有更多作品上线,欢迎常来访问智能小说。"; // smart novel
String XIAOWU_END_BYE_NOVEL = "后续有更多作品上线,欢迎常来访问晓悟智能小说。"; // smart novel
String END_BYE_STORY = "智能故事后续会有更多作品上线,欢迎常来"; // smart story String END_BYE_STORY = "智能故事后续会有更多作品上线,欢迎常来"; // smart story
String XIAOWU_END_BYE_STORY = "晓悟智能故事后续会有更多作品上线,欢迎常来"; // smart story
String END_BYE_JIAOYOU = "交游天下后续会有更多作品上线,欢迎常来"; String END_BYE_JIAOYOU = "交游天下后续会有更多作品上线,欢迎常来";
String END_BYE_DEFAULT = "后续会有更多作品上线,欢迎常来我们的技能"; String END_BYE_DEFAULT = "后续会有更多作品上线,欢迎常来我们的技能";
String END_BYE_Adult = "再见啦,记得下次再来玩哦"; String END_BYE_Adult = "再见啦,记得下次再来玩哦";
...@@ -168,10 +173,12 @@ public interface Constants { ...@@ -168,10 +173,12 @@ public interface Constants {
interface XIAOWU_API { interface XIAOWU_API {
String BASIC_PREFIX = "Basic "; String BASIC_PREFIX = "Basic ";
String BEARER = "Bearer "; String BEARER = "Bearer ";
String CAPTCHA_SMS = "https://account-center-test.chewrobot.com/api/captcha/sms"; //https://account-center-test.chewrobot.com/api/captcha/sms
String CAPTCHA_SMS = "https://account-center-test.chewrobot.com/api/sdk/captcha/sms";
String REFRESH_TOKEN = "https://account-center-test.chewrobot.com/api/sdk/token"; String REFRESH_TOKEN = "https://account-center-test.chewrobot.com/api/sdk/token";
String SDK_TOKEN = "https://account-center-test.chewrobot.com/api/sdk/token"; String SDK_TOKEN = "https://account-center-test.chewrobot.com/api/sdk/token";
String GET_USER_INFO_BY_TOKEN ="https://account-center-test.chewrobot.com/api/sdk/user/info"; String GET_USER_INFO_BY_TOKEN ="https://account-center-test.chewrobot.com/api/sdk/user/info";
String FLOWER_INTERFACE = "http://aws-nx2.chewrobot.com:18082/api/flower/count"; String FLOWER_INTERFACE = "http://aws-nx2.chewrobot.com:18082/api/flower/count";
String USER_CLOOEC_LIST = "http://aliyun-hz1.chewrobot.com:18082/api/favorite"; String USER_CLOOEC_LIST = "http://aliyun-hz1.chewrobot.com:18082/api/favorite";
String USER_ID_BY_TOKEN = "https://account-center-test.chewrobot.com/api/sdk/user/info"; String USER_ID_BY_TOKEN = "https://account-center-test.chewrobot.com/api/sdk/user/info";
......
...@@ -239,6 +239,44 @@ public class OkHttp3Utils { ...@@ -239,6 +239,44 @@ public class OkHttp3Utils {
}); });
} }
public static void tmallBackPostAsync(String url, String requestJsonStr, Integer type) {
String header = "tianmao-jiaoyou-audio-adult-test";
if (type != null) {
switch (type) {
case 2:
case 4: header = "tianmao-jiaoyou-audio-child-test";break;
case 3:
case 5: header= "tianmao-jiaoyou-audio-adult-test";break;
default: header = "tianmao-jiaoyou-audio-test";
}
}
Request request = new Request.Builder()
.url(url)
.post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), requestJsonStr))
.header("App-Channel-Id", header)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
log.info("退出失败");
}
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
try (ResponseBody body = response.body()){
// body.string();
log.info("退出成功:{}", body.string());
} catch (SocketTimeoutException e) {
log.error("捕获到SocketTimeoutException:{}", e.toString());
client.dispatcher().cancelAll();
client.connectionPool().evictAll();
} catch (Exception e) {
log.error(ExceptionUtils.getStackTrace(e));
}
}
});
}
public static void postAsync(String url, String requestJsonStr) { public static void postAsync(String url, String requestJsonStr) {
Request request = new Request.Builder() Request request = new Request.Builder()
.url(url) .url(url)
......
...@@ -4,6 +4,7 @@ import ai.qiwu.com.xiaoduhome.pojo.dpl.Event; ...@@ -4,6 +4,7 @@ import ai.qiwu.com.xiaoduhome.pojo.dpl.Event;
import ai.qiwu.com.xiaoduhome.pojo.pageData.HistoryData; import ai.qiwu.com.xiaoduhome.pojo.pageData.HistoryData;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
...@@ -69,16 +70,25 @@ public class CollectHistoryUtils { ...@@ -69,16 +70,25 @@ public class CollectHistoryUtils {
main.setWidth("100%"); main.setWidth("100%");
main.setMarginBottom("20dp"); main.setMarginBottom("20dp");
main.setFlexDirection("row"); main.setFlexDirection("row");
// main.setJustifyContent("center");
// main.setAlignItems("center");
main.setComponentId("${data.botAccountId}"); main.setComponentId("${data.botAccountId}");
main.setOnClick(Collections.singletonList(new Event("SendEvent", "${data.botAccountId}"))); main.setOnClick(Collections.singletonList(new Event("SendEvent", "${data.botAccountId}")));
// num // num
CollectHistoryPagePojo numContainer = new CollectHistoryPagePojo();
numContainer.setType("Container");
numContainer.setWidth("100dp");
numContainer.setJustifyContent("center");
numContainer.setAlignItems("center");
numContainer.setMarginTop("7dp");
CollectHistoryPagePojo num = new CollectHistoryPagePojo(); CollectHistoryPagePojo num = new CollectHistoryPagePojo();
num.setType("Text"); num.setType("Text");
num.setFontSize("40dp"); num.setFontSize("40dp");
num.setMarginLeft("40dp"); // num.setMarginLeft("40dp");
num.setMarginTop("7dp"); // num.setMarginTop("7dp");
num.setText("${data.collectPageLeftNum}"); num.setText("${data.collectPageLeftNum}");
numContainer.setItems(Collections.singletonList(num));
// image // image
CollectHistoryPagePojo image = new CollectHistoryPagePojo(); CollectHistoryPagePojo image = new CollectHistoryPagePojo();
...@@ -130,7 +140,7 @@ public class CollectHistoryUtils { ...@@ -130,7 +140,7 @@ public class CollectHistoryUtils {
// divide.setBorderColor("rgba(255,255,255,0.3)"); // divide.setBorderColor("rgba(255,255,255,0.3)");
// divide.setBorderWidth("0.5dp"); // divide.setBorderWidth("0.5dp");
main.setItems(Arrays.asList(num,image, nameIntroCon, author)); main.setItems(Arrays.asList(numContainer,image, nameIntroCon, author));
return main; return main;
} }
......
...@@ -19,7 +19,7 @@ public class LunchUtils { ...@@ -19,7 +19,7 @@ public class LunchUtils {
private static final LunchPojo LUNCH_LIST_CON = buildImgFrmTxtContainer(); private static final LunchPojo LUNCH_LIST_CON = buildImgFrmTxtContainer();
private static final LunchPojo LUNCH_LIST_CATEGORY_CON = buildCategoryList(); private static final LunchPojo LUNCH_LIST_CATEGORY_CON = buildCategoryList();
private static final LunchPojo LUNCH_HEAD = buildLunchHead(); // private static final LunchPojo LUNCH_HEAD = buildLunchHead();
private static final LunchPojo LUNCH_BACK_IMG = buildLunchBackgroundImg(); private static final LunchPojo LUNCH_BACK_IMG = buildLunchBackgroundImg();
private static final LunchPojo FOOTER = buildHomeFooter(); private static final LunchPojo FOOTER = buildHomeFooter();
private static final LunchPojo CATEGORY_FOOTER = buildCategoryFooter(); private static final LunchPojo CATEGORY_FOOTER = buildCategoryFooter();
...@@ -63,11 +63,11 @@ public class LunchUtils { ...@@ -63,11 +63,11 @@ public class LunchUtils {
if (all) { if (all) {
scroll = buildLunchScroll(); scroll = buildLunchScroll();
scroll.setItems(list); scroll.setItems(list);
mainTemplate.getItems().addAll(Arrays.asList(LUNCH_BACK_IMG,LUNCH_HEAD,scroll,FOOTER)); mainTemplate.getItems().addAll(Arrays.asList(LUNCH_BACK_IMG,scroll,FOOTER));
} else { } else {
scroll = buildLunchPartContainer(); scroll = buildLunchPartContainer();
scroll.setItems(list); scroll.setItems(list);
mainTemplate.getItems().addAll(Arrays.asList(LUNCH_BACK_IMG,LUNCH_HEAD,scroll)); mainTemplate.getItems().addAll(Arrays.asList(LUNCH_BACK_IMG,scroll));
} }
// mainTemplate.getItems().addAll(Arrays.asList(LUNCH_BACK_IMG,LUNCH_HEAD,LUNCH_LOGO_IMG,LUNCH_HSITORY_IMG,LUNCH_COLLECT_IMG,scroll)); // mainTemplate.getItems().addAll(Arrays.asList(LUNCH_BACK_IMG,LUNCH_HEAD,LUNCH_LOGO_IMG,LUNCH_HSITORY_IMG,LUNCH_COLLECT_IMG,scroll));
...@@ -110,7 +110,7 @@ public class LunchUtils { ...@@ -110,7 +110,7 @@ public class LunchUtils {
scroll.setMarginTop("240dp"); scroll.setMarginTop("240dp");
scroll.setItems(Arrays.asList(firstRow,secondRow)); scroll.setItems(Arrays.asList(firstRow,secondRow));
mainTemplate.getItems().addAll(Arrays.asList(LUNCH_BACK_IMG,LUNCH_HEAD,scroll,CATEGORY_FOOTER)); mainTemplate.getItems().addAll(Arrays.asList(LUNCH_BACK_IMG,scroll,CATEGORY_FOOTER));
return document; return document;
} }
...@@ -263,7 +263,8 @@ public class LunchUtils { ...@@ -263,7 +263,8 @@ public class LunchUtils {
backGroundImg.setPosition("absolute"); backGroundImg.setPosition("absolute");
backGroundImg.setTop("0dp"); backGroundImg.setTop("0dp");
backGroundImg.setLeft("0dp"); backGroundImg.setLeft("0dp");
backGroundImg.setSrc("https://didi-gz5.jiaoyou365.com/duai/image/backNew.jpg"); // backGroundImg.setSrc("https://didi-gz5.jiaoyou365.com/duai/image/backNew.jpg");
backGroundImg.setSrc("https://didi-gz5.jiaoyou365.com/duai/image/headImg.jpg");
backGroundImg.setHeight("100%"); backGroundImg.setHeight("100%");
backGroundImg.setScaleType("fitXY"); backGroundImg.setScaleType("fitXY");
backGroundImg.setWidth("100%"); backGroundImg.setWidth("100%");
...@@ -299,7 +300,7 @@ public class LunchUtils { ...@@ -299,7 +300,7 @@ public class LunchUtils {
LunchPojo footer = new LunchPojo(); LunchPojo footer = new LunchPojo();
footer.setType("Footer"); footer.setType("Footer");
footer.setHints(Arrays.asList("打开第一个","打开排行榜","打开历史记录","打开分类","打开收藏","推荐作品")); footer.setHints(Arrays.asList("打开第一个","打开排行榜","打开分类","退出","打开历史记录","打开收藏","推荐作品", "登陆"));
footerCon.setItems(Collections.singletonList(footer)); footerCon.setItems(Collections.singletonList(footer));
......
...@@ -448,7 +448,7 @@ public class PlayUtils { ...@@ -448,7 +448,7 @@ public class PlayUtils {
PlayPojo footer = new PlayPojo(); PlayPojo footer = new PlayPojo();
footer.setType("Footer"); footer.setType("Footer");
footer.setHints(Arrays.asList("我要送花", "收藏", "退出作品")); footer.setHints(Arrays.asList("我要送花", "收藏", "退出作品", "重新开始"));
footerCon.setItems(Collections.singletonList(footer)); footerCon.setItems(Collections.singletonList(footer));
......
...@@ -226,7 +226,7 @@ public class RecommendUtil { ...@@ -226,7 +226,7 @@ public class RecommendUtil {
public static RecommandDocument getFunnyDocument(List<ProjectData> bots, String audio) { public static RecommandDocument getFunnyDocument(List<ProjectData> bots, String audio) {
RecommandDocument document = new RecommandDocument(); RecommandDocument document = new RecommandDocument();
document.setDuration(90000); document.setDuration(240000);
RecommandMainTemplate mainTemplate = new RecommandMainTemplate(); RecommandMainTemplate mainTemplate = new RecommandMainTemplate();
document.setMainTemplate(mainTemplate); document.setMainTemplate(mainTemplate);
......
package ai.qiwu.com.xiaoduhome.controller; package ai.qiwu.com.xiaoduhome.controller;
import ai.qiwu.com.xiaoduhome.common.Constants;
import ai.qiwu.com.xiaoduhome.spirit.SpiritRedisService; import ai.qiwu.com.xiaoduhome.spirit.SpiritRedisService;
import ai.qiwu.com.xiaoduhome.spirit.SpiritService; import ai.qiwu.com.xiaoduhome.spirit.SpiritService;
import com.alibaba.da.coin.ide.spi.meta.AskedInfoMsg;
import com.alibaba.da.coin.ide.spi.meta.ExecuteCode;
import com.alibaba.da.coin.ide.spi.meta.ResultType;
import com.alibaba.da.coin.ide.spi.security.RSAUtil;
import com.alibaba.da.coin.ide.spi.standard.ResultModel; import com.alibaba.da.coin.ide.spi.standard.ResultModel;
import com.alibaba.da.coin.ide.spi.standard.SecurityWrapperTaskQuery;
import com.alibaba.da.coin.ide.spi.standard.TaskQuery; import com.alibaba.da.coin.ide.spi.standard.TaskQuery;
import com.alibaba.da.coin.ide.spi.standard.TaskResult; import com.alibaba.da.coin.ide.spi.standard.TaskResult;
import com.alibaba.da.coin.ide.spi.trans.MetaFormat; import com.alibaba.da.coin.ide.spi.trans.MetaFormat;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.Collections;
import static ai.qiwu.com.xiaoduhome.common.Constants.PRIVATE_KEY;
/** /**
* @author 苗权威 * @author 苗权威
* @dateTime 19-12-6 上午10:31 * @dateTime 19-12-6 上午10:31
...@@ -26,6 +37,8 @@ public class SpiritController { ...@@ -26,6 +37,8 @@ public class SpiritController {
private final SpiritRedisService spiritRedisService; private final SpiritRedisService spiritRedisService;
private static volatile Integer openRSA = 1;
@Autowired @Autowired
public SpiritController(SpiritService spiritService, SpiritRedisService spiritRedisService) { public SpiritController(SpiritService spiritService, SpiritRedisService spiritRedisService) {
this.spiritService = spiritService; this.spiritService = spiritService;
...@@ -43,13 +56,21 @@ public class SpiritController { ...@@ -43,13 +56,21 @@ public class SpiritController {
@PostMapping(value = "/") //智能小说 @PostMapping(value = "/") //智能小说
public ResultModel<TaskResult> getResponse(@RequestBody String taskQuery) { public ResultModel<TaskResult> getResponse(@RequestBody String taskQuery) {
// log.info("天猫请求信息:{}",taskQuery); // log.info("天猫请求信息:{}",taskQuery);
TaskQuery query = MetaFormat.parseToQuery(taskQuery); TaskResult result;
try {
SecurityWrapperTaskQuery wrapperTaskQuery = MetaFormat.parseToWrapperQuery(taskQuery);
String decryptStr = RSAUtil.decryptByPrivateKey(wrapperTaskQuery.getSecurityQuery(), PRIVATE_KEY);
TaskQuery query = MetaFormat.parseToQuery(decryptStr);
result = spiritRedisService.getResponse(query, 5);
} catch (Exception e) {
log.warn(ExceptionUtils.getStackTrace(e));
result = bottomResponse(54808L);
}
// build response // build response
ResultModel<TaskResult> resultModel = new ResultModel<>(); ResultModel<TaskResult> resultModel = new ResultModel<>();
TaskResult taskResult = spiritRedisService.getResponse(query, 5);
resultModel.setReturnCode("0"); resultModel.setReturnCode("0");
resultModel.setReturnValue(taskResult); resultModel.setReturnValue(result);
// log.info("天猫响应信息:"+ JSON.toJSONString(resultModel)); // log.info("天猫响应信息:"+ JSON.toJSONString(resultModel));
return resultModel; return resultModel;
...@@ -58,14 +79,37 @@ public class SpiritController { ...@@ -58,14 +79,37 @@ public class SpiritController {
@PostMapping(value = "/smart") // 智能故事 @PostMapping(value = "/smart") // 智能故事
public ResultModel<TaskResult> smart(@RequestBody String taskQuery) { public ResultModel<TaskResult> smart(@RequestBody String taskQuery) {
// log.info("TaskQuery:{}",taskQuery); // log.info("TaskQuery:{}",taskQuery);
TaskQuery query = MetaFormat.parseToQuery(taskQuery); TaskResult result;
// if (openRSA != 1) {
// try {
// SecurityWrapperTaskQuery wrapperTaskQuery = MetaFormat.parseToWrapperQuery(taskQuery);
// String decryptStr = RSAUtil.decryptByPrivateKey(wrapperTaskQuery.getSecurityQuery(), PRIVATE_KEY);
// TaskQuery query = MetaFormat.parseToQuery(decryptStr);
// result = spiritRedisService.getResponse(query, 4);
// } catch (Exception e) {
// log.warn(ExceptionUtils.getStackTrace(e));
// result = bottomResponse(37076L);
// }
// } else {
// TaskQuery query = MetaFormat.parseToQuery(taskQuery);
// result = spiritRedisService.getResponse(query,4);
// }
try {
SecurityWrapperTaskQuery wrapperTaskQuery = MetaFormat.parseToWrapperQuery(taskQuery);
String decryptStr = RSAUtil.decryptByPrivateKey(wrapperTaskQuery.getSecurityQuery(), PRIVATE_KEY);
TaskQuery query = MetaFormat.parseToQuery(decryptStr);
result = spiritRedisService.getResponse(query, 4);
} catch (Exception e) {
log.warn(ExceptionUtils.getStackTrace(e));
result = bottomResponse(37076L);
}
// build response // build response
ResultModel<TaskResult> resultModel = new ResultModel<>(); ResultModel<TaskResult> resultModel = new ResultModel<>();
TaskResult taskResult = spiritRedisService.getResponse(query,4);
// logger.info("taskResult:"+taskResult); // logger.info("taskResult:"+taskResult);
resultModel.setReturnCode("0"); resultModel.setReturnCode("0");
resultModel.setReturnValue(taskResult); resultModel.setReturnValue(result);
return resultModel; return resultModel;
} }
...@@ -115,13 +159,34 @@ public class SpiritController { ...@@ -115,13 +159,34 @@ public class SpiritController {
return resultModel; return resultModel;
} }
@PostMapping("/update/{one}") @GetMapping("/update/{one}")
public void updateCsvMap(@RequestBody String secId, @PathVariable String one) { public void updateCsvMap(String secId, @PathVariable String one) {
if ("qiwuAudioMqw123.".equals(secId)) { if ("qiwuAudioMqw123.".equals(secId)) {
if (one.equals(num)) { if (one.equals(num)) {
spiritService.updateSpiritCsv(); spiritRedisService.updateSpiritCsv();
}
}
}
@GetMapping("/mark")
public void updateMark(Integer type, Integer mark) {
if (type != null) {
switch (type) {
case 1: SpiritController.openRSA = mark; break;// 1 open
// case 2: SpiritRedisService.mark = mark;break;
// case 3: SpiritRedisService.manyId = mark;break;
}
} }
} }
private static TaskResult bottomResponse(Long intentId) {
TaskResult result = new TaskResult();
result.setReply(Constants.ErrorMsg.SORRY_UNCATCH);
result.setResultType(ResultType.ASK_INF);
result.setExecuteCode(ExecuteCode.SUCCESS);
result.setAskedInfos(Collections.singletonList(new AskedInfoMsg("any", intentId)));
return result;
} }
} }
...@@ -44,7 +44,7 @@ public class XiaoAiController { ...@@ -44,7 +44,7 @@ public class XiaoAiController {
*/ */
@PostMapping("/") @PostMapping("/")
public XiaoAiResponse xiaoai(@RequestBody XiaoAiRequest request,HttpServletRequest servletRequest) { // 交游天下 public XiaoAiResponse xiaoai(@RequestBody XiaoAiRequest request,HttpServletRequest servletRequest) { // 交游天下
log.info("请求:"+request); // log.info("请求:"+request);
// log.info("响应:"+response); // log.info("响应:"+response);
try { try {
if (!Utils.encry(5, servletRequest)) { if (!Utils.encry(5, servletRequest)) {
...@@ -52,7 +52,7 @@ public class XiaoAiController { ...@@ -52,7 +52,7 @@ public class XiaoAiController {
return null; return null;
} }
request.setType(5); request.setType(5);
return xiaoAiService.getResponse(request); return xiaoAiServiceRedis.getResponse(request);
} catch (Exception e) { } catch (Exception e) {
log.error("controller xiaoai:"+e); log.error("controller xiaoai:"+e);
} }
...@@ -60,6 +60,24 @@ public class XiaoAiController { ...@@ -60,6 +60,24 @@ public class XiaoAiController {
// return xiaoAiService.getResponse(request); // return xiaoAiService.getResponse(request);
} }
@PostMapping("/adult")
public XiaoAiResponse xiaoaiAdult(@RequestBody XiaoAiRequest request, HttpServletRequest servletRequest) { // 智能小说
//log.info("请求:"+request);
try {
if (!Utils.encry(2, servletRequest)) {
log.error("验证没通过:2");
return null;
}
request.setType(2);
// log.info("响应:"+response);
return xiaoAiService.getResponse(request);
} catch (Exception e) {
log.error("controller xiaoaiAdult:"+e);
}
return buildTextResponse(SORRY_REPEAT);
// return xiaoAiService.getResponse(request);
}
@PostMapping("/child") @PostMapping("/child")
public XiaoAiResponse xiaoaiChild(@RequestBody XiaoAiRequest request,HttpServletRequest servletRequest) { // 智能故事 public XiaoAiResponse xiaoaiChild(@RequestBody XiaoAiRequest request,HttpServletRequest servletRequest) { // 智能故事
//log.info("请求:"+request); //log.info("请求:"+request);
...@@ -70,7 +88,7 @@ public class XiaoAiController { ...@@ -70,7 +88,7 @@ public class XiaoAiController {
} }
request.setType(1); request.setType(1);
// log.info("响应:"+response); // log.info("响应:"+response);
return xiaoAiService.getResponse(request); return xiaoAiServiceRedis.getResponse(request);
} catch (Exception e) { } catch (Exception e) {
log.error("controller xiaoaiChild:"+e); log.error("controller xiaoaiChild:"+e);
} }
...@@ -80,36 +98,34 @@ public class XiaoAiController { ...@@ -80,36 +98,34 @@ public class XiaoAiController {
@PostMapping("/story") //互动故事 @PostMapping("/story") //互动故事
// @RequestBody XiaoAiRequest request, // @RequestBody XiaoAiRequest request,
public XiaoAiResponse xiaoaiChildStory(HttpServletRequest servletRequest) { public XiaoAiResponse xiaoaiChildStory(@RequestBody XiaoAiRequest request) {
// long start = System.currentTimeMillis(); // long start = System.currentTimeMillis();
// if (!Utils.encry(3, servletRequest)) return null; // if (!Utils.encry(3, servletRequest)) return null;
// log.info("encry:"+(System.currentTimeMillis()-start)); // log.info("encry:"+(System.currentTimeMillis()-start));
try (InputStream stream = servletRequest.getInputStream()){ // try (InputStream stream = servletRequest.getInputStream()){
StringBuilder sb = new StringBuilder(); // StringBuilder sb = new StringBuilder();
byte[] b = new byte[4096]; // byte[] b = new byte[4096];
for (int n; (n = stream.read(b)) != -1;) // for (int n; (n = stream.read(b)) != -1;)
{ // {
sb.append(new String(b, 0, n)); // sb.append(new String(b, 0, n));
} // }
String str = sb.toString(); // String str = sb.toString();
log.info("请求:"+str); // log.info("请求:"+str);
XiaoAiRequest request = JSON.parseObject(str, XiaoAiRequest.class); // XiaoAiRequest request = JSON.parseObject(str, XiaoAiRequest.class);
request.setType(5);
XiaoAiResponse response = xiaoAiServiceRedis.getResponse(request);
log.info("响应:"+response);
return response;
} catch (Exception e) {
}
return null;
// log.info("请求:"+request);
// request.setType(5); // request.setType(5);
// XiaoAiResponse response = xiaoAiService.getResponse(request); // XiaoAiResponse response = xiaoAiServiceRedis.getResponse(request);
// log.info("响应:"+response); // log.info("响应:"+response);
// return response; // return response;
// return xiaoAiService.getResponse(request); // } catch (Exception e) {
//
// }
// return null;
// log.info("请求:"+request);
request.setType(5);
// log.info("响应:"+response);
return xiaoAiServiceRedis.getResponse(request);
} }
@PostMapping("/phone") //互动故事 @PostMapping("/phone") //互动故事
...@@ -139,24 +155,6 @@ public class XiaoAiController { ...@@ -139,24 +155,6 @@ public class XiaoAiController {
return null; return null;
} }
@PostMapping("/adult")
public XiaoAiResponse xiaoaiAdult(@RequestBody XiaoAiRequest request, HttpServletRequest servletRequest) { // 智能小说
//log.info("请求:"+request);
try {
if (!Utils.encry(2, servletRequest)) {
log.error("验证没通过:2");
return null;
}
request.setType(2);
// log.info("响应:"+response);
return xiaoAiService.getResponse(request);
} catch (Exception e) {
log.error("controller xiaoaiAdult:"+e);
}
return buildTextResponse(SORRY_REPEAT);
// return xiaoAiService.getResponse(request);
}
// @PostMapping("/literature") // 互动文艺 // @PostMapping("/literature") // 互动文艺
public XiaoAiResponse xiaoaiAdultLiterature(@RequestBody XiaoAiRequest request) { public XiaoAiResponse xiaoaiAdultLiterature(@RequestBody XiaoAiRequest request) {
//log.info("请求:"+request); //log.info("请求:"+request);
...@@ -167,14 +165,14 @@ public class XiaoAiController { ...@@ -167,14 +165,14 @@ public class XiaoAiController {
// return xiaoAiService.getResponse(request); // return xiaoAiService.getResponse(request);
} }
@GetMapping("/audio/play") // @GetMapping("/audio/play")
public void xiaoaiPlayed(String userId) { // public void xiaoaiPlayed(String userId) {
if (StringUtils.isNotBlank(userId)) { // if (StringUtils.isNotBlank(userId)) {
log.info("小爱确认音频播放:"+userId); // log.info("小爱确认音频播放:"+userId);
xiaoAiServiceRedis.theAudioAlreadyPlay(userId); // xiaoAiServiceRedis.theAudioAlreadyPlay(userId);
} // }
else log.error("/xiaoai/audio/play userId is null"); // else log.error("/xiaoai/audio/play userId is null");
} // }
private XiaoAiResponse buildResponse() { private XiaoAiResponse buildResponse() {
XiaoAiResponse response = new XiaoAiResponse(); XiaoAiResponse response = new XiaoAiResponse();
......
...@@ -120,9 +120,9 @@ public class XiaoDuHomeController { ...@@ -120,9 +120,9 @@ public class XiaoDuHomeController {
//log.info("--------------分界线-------------------"); //log.info("--------------分界线-------------------");
// DplBotService service = new DplBotService(Utils.getHttpServletRequest(), 5); // DplBotService service = new DplBotService(Utils.getHttpServletRequest(), 5);
log.info("=================================="); log.info("==================================");
DplBotServiceBoth service = new DplBotServiceBoth(request, 6, stringRedisTemplate); DplBotServiceBoth service = new DplBotServiceBoth(request, 5, stringRedisTemplate);
log.info("请求信息中的attributes:{}", service.getRequest().getSession().getAttributes());
// log.info(service.getStrRequest()); // log.info(service.getStrRequest());
log.info("请求信息中的attributes:{}", service.getRequest().getSession().getAttributes());
//service.disableVerify(); //service.disableVerify();
service.enableVerify(); service.enableVerify();
String str = service.run(); String str = service.run();
......
...@@ -132,6 +132,7 @@ public class DplbotServiceUtil { ...@@ -132,6 +132,7 @@ public class DplbotServiceUtil {
} catch (Exception e) { } catch (Exception e) {
log.error("获取郊游天下用户id出错:{}", ExceptionUtils.getStackTrace(e)); log.error("获取郊游天下用户id出错:{}", ExceptionUtils.getStackTrace(e));
} }
return null; return null;
} }
...@@ -204,7 +205,7 @@ public class DplbotServiceUtil { ...@@ -204,7 +205,7 @@ public class DplbotServiceUtil {
Map<String, Long> map = new HashMap<>(); Map<String, Long> map = new HashMap<>();
for (XiaoDuHistoryTB xiaoDuHistoryTB: historyTBS) { for (XiaoDuHistoryTB xiaoDuHistoryTB: historyTBS) {
if (StringUtils.isBlank(jytId)) jytId = xiaoDuHistoryTB.getJytUserId(); if (StringUtils.isBlank(jytId)) jytId = xiaoDuHistoryTB.getJytUserId();
String botAccount = ScheduleServiceNew.getWorkNameByBotAccount(xiaoDuHistoryTB.getWorkName()); String botAccount = ScheduleServiceNew.getBotAccountByWorkname(xiaoDuHistoryTB.getWorkName());
if (StringUtils.isNotBlank(botAccount)) map.put(botAccount, xiaoDuHistoryTB.getUpdateTime().getTime()); if (StringUtils.isNotBlank(botAccount)) map.put(botAccount, xiaoDuHistoryTB.getUpdateTime().getTime());
else log.warn("onLunchFillUserBehaviorDataInMaster: 历史数据库存储信息与缓存不一致"); else log.warn("onLunchFillUserBehaviorDataInMaster: 历史数据库存储信息与缓存不一致");
} }
...@@ -225,7 +226,7 @@ public class DplbotServiceUtil { ...@@ -225,7 +226,7 @@ public class DplbotServiceUtil {
Map<String, Long> map = new HashMap<>(); Map<String, Long> map = new HashMap<>();
for (XiaoDuOrderTB xiaoDuOrderTB: orderTBS) { for (XiaoDuOrderTB xiaoDuOrderTB: orderTBS) {
if (StringUtils.isBlank(jytId)) jytId = xiaoDuOrderTB.getAppUserId(); if (StringUtils.isBlank(jytId)) jytId = xiaoDuOrderTB.getAppUserId();
String botAccount = ScheduleServiceNew.getWorkNameByBotAccount(xiaoDuOrderTB.getWorkName()); String botAccount = ScheduleServiceNew.getBotAccountByWorkname(xiaoDuOrderTB.getWorkName());
if (StringUtils.isNotBlank(botAccount)) map.put(botAccount, xiaoDuOrderTB.getNumber()); if (StringUtils.isNotBlank(botAccount)) map.put(botAccount, xiaoDuOrderTB.getNumber());
else log.warn("onLunchFillUserBehaviorDataInMaster: 送花数据库存储信息与缓存不一致"); else log.warn("onLunchFillUserBehaviorDataInMaster: 送花数据库存储信息与缓存不一致");
} }
...@@ -413,7 +414,8 @@ public class DplbotServiceUtil { ...@@ -413,7 +414,8 @@ public class DplbotServiceUtil {
} }
String botId; String botId;
if (trace != null && trace.length() > 2) { if (trace != null && trace.length() > 2) {
if (StringUtils.endsWith(trace, File.separator)) { boolean inPlay;
if ((inPlay=StringUtils.endsWith(trace, File.separator))) {
botId = trace.substring(2, trace.length()-1); botId = trace.substring(2, trace.length()-1);
}else { }else {
botId = trace.substring(2); botId = trace.substring(2);
...@@ -429,7 +431,7 @@ public class DplbotServiceUtil { ...@@ -429,7 +431,7 @@ public class DplbotServiceUtil {
if (name != null) desc = new StringBuilder("感谢您赏赐给").append(name) if (name != null) desc = new StringBuilder("感谢您赏赐给").append(name)
.append("的").append(1).append("朵鲜花").toString(); .append("的").append(1).append("朵鲜花").toString();
Charge charge = new Charge(amount, orderId, "鲜花", desc); Charge charge = new Charge(amount, orderId, "鲜花", desc);
charge.setToken(new StringBuilder(botId).append(File.separator).append(1).toString()); charge.setToken(new StringBuilder(botId).append(File.separator).append(1).append(File.separator).append(inPlay ? 1 : 0).toString());
return charge; return charge;
} else { } else {
log.error("订单没有插入到xioadu_order_tb"); log.error("订单没有插入到xioadu_order_tb");
...@@ -519,19 +521,18 @@ public class DplbotServiceUtil { ...@@ -519,19 +521,18 @@ public class DplbotServiceUtil {
} }
} }
static boolean dealChargeCallback(ChargeEvent chargeEvent, final String userId, final String accessToken, static Boolean dealChargeCallback(ChargeEvent chargeEvent, final String userId, final String accessToken,
final String jytUserId, String workName, String channelId) { final String jytUserId, String workName, String channelId) {
Payload payload = chargeEvent.getPayload(); Payload payload = chargeEvent.getPayload();
final String chOrderId = chargeEvent.getSellerOrderId(); final String chOrderId = chargeEvent.getSellerOrderId();
String token = chargeEvent.getToken(); String[] tokens = chargeEvent.getToken().split(File.separator);
int sepIndex = token.indexOf(File.separator); final String botAccount = tokens[0];
final String botAccount = token.substring(0, sepIndex);
if (payload.getPurchaseResult().equals("SUCCESS")) { if (payload.getPurchaseResult().equals("SUCCESS")) {
// createTimestamp字段与baiduOrderReferenceId字段与之后百度方进行结算使用, // createTimestamp字段与baiduOrderReferenceId字段与之后百度方进行结算使用,
// 现在createTimestamp由于百度方的bug需等到九月份才能获取到 // 现在createTimestamp由于百度方的bug需等到九月份才能获取到
final String baiduOrderReferenceId = payload.getBaiduOrderReferenceId(); final String baiduOrderReferenceId = payload.getBaiduOrderReferenceId();
final String createTimestamp = payload.getAuthorizationDetails().getCreationTimestamp(); final String createTimestamp = payload.getAuthorizationDetails().getCreationTimestamp();
final String num = token.substring(sepIndex+1); final String num = tokens[1];
POOL.submit(() -> { POOL.submit(() -> {
XiaoDuOrderTbRepository repository = BaseHolder.getBean("xiaoDuOrderTbRepository"); XiaoDuOrderTbRepository repository = BaseHolder.getBean("xiaoDuOrderTbRepository");
...@@ -590,11 +591,11 @@ public class DplbotServiceUtil { ...@@ -590,11 +591,11 @@ public class DplbotServiceUtil {
if (StringUtils.isAnyBlank(botAccount, userId)) return; if (StringUtils.isAnyBlank(botAccount, userId)) return;
UserBehaviorData data = USER_HISTORY.get(userId); UserBehaviorData data = USER_HISTORY.get(userId);
if (data != null) { if (data != null) {
log.info("updateTheUserBehaviorDataMark: data is null");
data.setMark(1); data.setMark(1);
data.getUserBotId2History().put(botAccount, curTime); data.getUserBotId2History().put(botAccount, curTime);
noticeOtherServer(1, botAccount, ScheduleServiceNew.curTime, false, userId, jytUserId, channel, accessToken!= null); noticeOtherServer(1, botAccount, ScheduleServiceNew.curTime, false, userId, jytUserId, channel, accessToken!= null);
} else { } else {
log.info("updateTheUserBehaviorDataMark: data is null");
data = onLunchFillUserBehaviorDataInMaster(userId, channel, jytUserId, accessToken != null); data = onLunchFillUserBehaviorDataInMaster(userId, channel, jytUserId, accessToken != null);
if (data != null) { if (data != null) {
data.getUserBotId2History().put(botAccount, curTime); data.getUserBotId2History().put(botAccount, curTime);
...@@ -616,6 +617,7 @@ public class DplbotServiceUtil { ...@@ -616,6 +617,7 @@ public class DplbotServiceUtil {
} }
static CollectHistoryDocument getCollectPage(String userId, String accessToken, String jytId, int start, String channelId) { static CollectHistoryDocument getCollectPage(String userId, String accessToken, String jytId, int start, String channelId) {
log.info("getCollectPage:start->"+start);
UserBehaviorData behaviorData = USER_HISTORY.get(userId); UserBehaviorData behaviorData = USER_HISTORY.get(userId);
int pageNum; int pageNum;
if (behaviorData == null) { if (behaviorData == null) {
...@@ -635,13 +637,14 @@ public class DplbotServiceUtil { ...@@ -635,13 +637,14 @@ public class DplbotServiceUtil {
return null; return null;
} }
pageNum = bound/CO_HI_PAGE_SIZE + (bound%CO_HI_PAGE_SIZE == 0 ? 0 : 1); pageNum = bound/CO_HI_PAGE_SIZE + (bound%CO_HI_PAGE_SIZE == 0 ? 0 : 1);
log.info("getCollectPage:pageNum->"+pageNum);
// log.info("collect/history: pagesize:{},bound{}",pageNum,bound); // log.info("collect/history: pagesize:{},bound{}",pageNum,bound);
TreeMap<Long, String> order = new TreeMap<>((o1, o2) -> (o1 < o2) ? 1 : ((o1.equals(o2)) ? 0 : -1)); TreeMap<Long, String> order = new TreeMap<>((o1, o2) -> (o1 < o2) ? 1 : ((o1.equals(o2)) ? 0 : -1));
for (Map.Entry<String, Long> entry: userBotId2Collected.entrySet()) { for (Map.Entry<String, Long> entry: userBotId2Collected.entrySet()) {
order.put(entry.getValue(), entry.getKey()); order.put(entry.getValue(), entry.getKey());
} }
List<String> favoriteProducts = new ArrayList<>(); List<String> favoriteProducts = new ArrayList<>();
int i = 0, e = start+CO_HI_PAGE_SIZE; int i = 0, e = start+CO_HI_PAGE_SIZE >= bound ? bound : start+CO_HI_PAGE_SIZE;
for (Map.Entry<Long, String> entry: order.entrySet()) { for (Map.Entry<Long, String> entry: order.entrySet()) {
if (i == e) break; if (i == e) break;
if (i++ >= start) { if (i++ >= start) {
...@@ -679,6 +682,7 @@ public class DplbotServiceUtil { ...@@ -679,6 +682,7 @@ public class DplbotServiceUtil {
} }
static CollectHistoryDocument getHistory(String userId, String accessToken,String jytUserId, int start, String channelId) { static CollectHistoryDocument getHistory(String userId, String accessToken,String jytUserId, int start, String channelId) {
log.info("getHistory:start->"+start);
List<XiaoDuHistoryBotIdTime> historyProducts = new ArrayList<>(); List<XiaoDuHistoryBotIdTime> historyProducts = new ArrayList<>();
UserBehaviorData behaviorData = USER_HISTORY.get(userId); UserBehaviorData behaviorData = USER_HISTORY.get(userId);
int pageNum = 0; int pageNum = 0;
...@@ -699,6 +703,7 @@ public class DplbotServiceUtil { ...@@ -699,6 +703,7 @@ public class DplbotServiceUtil {
return null; return null;
} }
pageNum = bound/CO_HI_PAGE_SIZE + (bound%CO_HI_PAGE_SIZE == 0 ? 0 : 1); pageNum = bound/CO_HI_PAGE_SIZE + (bound%CO_HI_PAGE_SIZE == 0 ? 0 : 1);
log.info("getHistory:pageNum->"+pageNum);
TreeMap<Long, String> order = new TreeMap<>((o1, o2) -> (o1 < o2) ? 1 : ((o1.equals(o2)) ? 0 : -1)); TreeMap<Long, String> order = new TreeMap<>((o1, o2) -> (o1 < o2) ? 1 : ((o1.equals(o2)) ? 0 : -1));
for (Map.Entry<String, Long> entry: behaviorData.getUserBotId2History().entrySet()) { for (Map.Entry<String, Long> entry: behaviorData.getUserBotId2History().entrySet()) {
order.put(entry.getValue(), entry.getKey()); order.put(entry.getValue(), entry.getKey());
...@@ -815,7 +820,14 @@ public class DplbotServiceUtil { ...@@ -815,7 +820,14 @@ public class DplbotServiceUtil {
switch (type) { switch (type) {
case 1 : behaviorData.getUserBotId2History().put(data.getBotAccount(), data.getTimeOrCount()); break; case 1 : behaviorData.getUserBotId2History().put(data.getBotAccount(), data.getTimeOrCount()); break;
case 2 : behaviorData.getUserBotId2Flowers().put(data.getBotAccount(), data.getTimeOrCount()); break; case 2 : behaviorData.getUserBotId2Flowers().put(data.getBotAccount(), data.getTimeOrCount()); break;
case 3 : behaviorData.getUserBotId2Collected().put(data.getBotAccount(), data.getTimeOrCount()); break; case 3 : {
if (Boolean.TRUE.equals(data.getCollect())) {
behaviorData.getUserBotId2Collected().put(data.getBotAccount(), data.getTimeOrCount());
} else {
behaviorData.getUserBotId2Collected().remove(data.getBotAccount());
}
break;
}
} }
} }
......
...@@ -207,7 +207,20 @@ public class LoadBySMS { ...@@ -207,7 +207,20 @@ public class LoadBySMS {
// return ACCESSTOKEN_PHONENUM; // return ACCESSTOKEN_PHONENUM;
// } // }
public static void main(String[] args) { public static void main(String[] args) throws IOException {
System.out.println(getTokenByRefreshToken("4e929ca8-6db1-4224-be1e-e8f5a4f6bdb5")); // HashMap<String, String> headers = new HashMap<>();
// headers.put("App-Channel-Id", "JIAOYOUTIANXIA");
// headers.put("Content-Type", "application/json;charset=utf-8");
// headers.put("Authorization", Utils.tokenAuthorization("13922841032", "7210"));
// String tokenStr = OkHttp3Utils.doGet(XIAOWU_API.SDK_TOKEN, new HashMap<>(), headers);
//// log.info("获取Token返回");
// System.out.println(tokenStr);
HashMap<String, String> headers = new HashMap<>();
headers.put("App-Channel-Id", "JIAOYOUTIANXIA");
headers.put("Content-Type", "application/json;charset=utf-8");
headers.put("Authorization", Utils.captchaAuthorization("13410129349"));
String smsStr = OkHttp3Utils.doGet(XIAOWU_API.CAPTCHA_SMS, new HashMap<>(), headers);
System.out.println(smsStr);
} }
} }
...@@ -53,7 +53,7 @@ class RequestTerminal { ...@@ -53,7 +53,7 @@ class RequestTerminal {
// default: headers.put("App-Channel-Id", "jiaoyou-audio-test"); // default: headers.put("App-Channel-Id", "jiaoyou-audio-test");
// } // }
// return OkHttp3Utils.doPostJsonStr(Constants.QI_WU_INTERFACE, requestJsonStr, headers); // return OkHttp3Utils.doPostJsonStr(Constants.QI_WU_INTERFACE, requestJsonStr, headers);
return OkHttp3Utils.doPostJsonStr("http://didi-gz5.jiaoyou365.com:8070/api/chat2", requestJsonStr, headers); return OkHttp3Utils.doPostJsonStr(ScheduleServiceNew.BASE_HOST_URL+"8070/api/chat2", requestJsonStr, headers);
} }
static QiWuResponse requestTerminate(String userWord, String userId, int type) throws IOException { static QiWuResponse requestTerminate(String userWord, String userId, int type) throws IOException {
...@@ -105,7 +105,7 @@ class RequestTerminal { ...@@ -105,7 +105,7 @@ class RequestTerminal {
requestPojo.setUid(userId); requestPojo.setUid(userId);
requestPojo.setMsg("退出"); requestPojo.setMsg("退出");
String requestJsonStr = JSON.toJSONString(requestPojo); String requestJsonStr = JSON.toJSONString(requestPojo);
OkHttp3Utils.backPostAsync("http://didi-gz5.jiaoyou365.com:8070/api/chat2", requestJsonStr, type); OkHttp3Utils.backPostAsync(ScheduleServiceNew.BASE_HOST_URL+"8070/api/chat2", requestJsonStr, type);
// OkHttp3Utils.backPostAsync(Constants.QI_WU_INTERFACE, requestJsonStr, type); // OkHttp3Utils.backPostAsync(Constants.QI_WU_INTERFACE, requestJsonStr, type);
} }
......
...@@ -50,6 +50,8 @@ public class ScheduleServiceNew implements InitializingBean { ...@@ -50,6 +50,8 @@ public class ScheduleServiceNew implements InitializingBean {
private static volatile Map<String, String> channelId2RecommendBotAcc = new HashMap<>(); private static volatile Map<String, String> channelId2RecommendBotAcc = new HashMap<>();
public static volatile String BASE_HOST_URL = Config.getProperty("baseHostUrl", "http://didi-gz2.jiaoyou365.com:");;
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
getAllProjects(); getAllProjects();
...@@ -135,7 +137,7 @@ public class ScheduleServiceNew implements InitializingBean { ...@@ -135,7 +137,7 @@ public class ScheduleServiceNew implements InitializingBean {
@Scheduled(cron = "0 */2 * * * ?") @Scheduled(cron = "0 */2 * * * ?")
public void updateTheCurTime() { public void updateTheCurTime() {
log.info("updateTheCurTime start"); // log.info("updateTheCurTime start");
curTime = System.currentTimeMillis(); curTime = System.currentTimeMillis();
} }
......
...@@ -18,6 +18,6 @@ import java.util.List; ...@@ -18,6 +18,6 @@ import java.util.List;
public class SpiritTerminateResponse { public class SpiritTerminateResponse {
private String aipioneerUsername; private String aipioneerUsername;
private List<Dialog> dialogs; private List<Dialog> dialogs;
private String extraChatKey; // private String extraChatKey;
private String mainChatKey; // private String mainChatKey;
} }
package ai.qiwu.com.xiaoduhome.xiaoai.common; package ai.qiwu.com.xiaoduhome.xiaoai.common;
import ai.qiwu.com.xiaoduhome.common.OkHttp3Utils; import ai.qiwu.com.xiaoduhome.common.OkHttp3Utils;
import ai.qiwu.com.xiaoduhome.service.ScheduleServiceNew;
import ai.qiwu.com.xiaoduhome.spirit.SpiritTerminateRequest; import ai.qiwu.com.xiaoduhome.spirit.SpiritTerminateRequest;
import ai.qiwu.com.xiaoduhome.xiaoai.model.QiWuRequest; import ai.qiwu.com.xiaoduhome.xiaoai.model.QiWuRequest;
import ai.qiwu.com.xiaoduhome.xiaoai.model.QiWuResponse; import ai.qiwu.com.xiaoduhome.xiaoai.model.QiWuResponse;
...@@ -55,7 +56,7 @@ public class RequestTerminal { ...@@ -55,7 +56,7 @@ public class RequestTerminal {
default: headers = ALL_HEADERS; break; default: headers = ALL_HEADERS; break;
} }
// String resStr = OkHttp3Utils.doPostJsonStr(XiaoAiConstants.QI_WU_TERMINATE_DIDI, requestJsonStr, headers);; // String resStr = OkHttp3Utils.doPostJsonStr(XiaoAiConstants.QI_WU_TERMINATE_DIDI, requestJsonStr, headers);;
String resStr = OkHttp3Utils.doPostJsonStr("http://didi-gz5.jiaoyou365.com:8070/api/chat2", requestJsonStr, headers);; String resStr = OkHttp3Utils.doPostJsonStr(ScheduleServiceNew.BASE_HOST_URL+"8070/api/chat2", requestJsonStr, headers);;
// if (userId.equals(XiaoAiService.deviceId)) { // if (userId.equals(XiaoAiService.deviceId)) {
// resStr = OkHttp3Utils.doPostJsonStr(XiaoAiConstants.QI_WU_TERMINATE_DIDI, requestJsonStr, headers); // resStr = OkHttp3Utils.doPostJsonStr(XiaoAiConstants.QI_WU_TERMINATE_DIDI, requestJsonStr, headers);
// }else { // }else {
...@@ -69,7 +70,20 @@ public class RequestTerminal { ...@@ -69,7 +70,20 @@ public class RequestTerminal {
requestPojo.setUid(userId); requestPojo.setUid(userId);
requestPojo.setMsg(XiaoAiConstants.TTS.END_WORD); requestPojo.setMsg(XiaoAiConstants.TTS.END_WORD);
String requestJsonStr = JSON.toJSONString(requestPojo); String requestJsonStr = JSON.toJSONString(requestPojo);
OkHttp3Utils.xiaoaiBackPostAsync(XiaoAiConstants.QI_WU_TERMINATE_DIDI, requestJsonStr, type); OkHttp3Utils.xiaoaiBackPostAsync(ScheduleServiceNew.BASE_HOST_URL+"8070/api/chat2", requestJsonStr, type);
// if (userId.equals(XiaoAiService.deviceId)) {
// OkHttp3Utils.backPostAsync(XiaoAiConstants.QI_WU_TERMINATE_DIDI, requestJsonStr, type);
// }else {
// OkHttp3Utils.backPostAsync(XiaoAiConstants.QI_WU_TERMINATE_DIDI, requestJsonStr, type);
// }
}
public static void tmallLunchCancelRequest(String userId, Integer type) {
SpiritTerminateRequest requestPojo = new SpiritTerminateRequest();
requestPojo.setUid(userId);
requestPojo.setMsg(XiaoAiConstants.TTS.END_WORD);
String requestJsonStr = JSON.toJSONString(requestPojo);
OkHttp3Utils.tmallBackPostAsync(ScheduleServiceNew.BASE_HOST_URL+"8070/api/chat2", requestJsonStr, type);
// if (userId.equals(XiaoAiService.deviceId)) { // if (userId.equals(XiaoAiService.deviceId)) {
// OkHttp3Utils.backPostAsync(XiaoAiConstants.QI_WU_TERMINATE_DIDI, requestJsonStr, type); // OkHttp3Utils.backPostAsync(XiaoAiConstants.QI_WU_TERMINATE_DIDI, requestJsonStr, type);
// }else { // }else {
......
...@@ -3,6 +3,7 @@ package ai.qiwu.com.xiaoduhome.xiaoai.service; ...@@ -3,6 +3,7 @@ package ai.qiwu.com.xiaoduhome.xiaoai.service;
import ai.qiwu.com.xiaoduhome.common.Constants; import ai.qiwu.com.xiaoduhome.common.Constants;
import ai.qiwu.com.xiaoduhome.common.OkHttp3Utils; import ai.qiwu.com.xiaoduhome.common.OkHttp3Utils;
import ai.qiwu.com.xiaoduhome.service.DplbotServiceUtil; import ai.qiwu.com.xiaoduhome.service.DplbotServiceUtil;
import ai.qiwu.com.xiaoduhome.service.ScheduleServiceNew;
import ai.qiwu.com.xiaoduhome.spirit.SpiritRedisService; import ai.qiwu.com.xiaoduhome.spirit.SpiritRedisService;
import ai.qiwu.com.xiaoduhome.xiaoai.common.RequestTerminal; import ai.qiwu.com.xiaoduhome.xiaoai.common.RequestTerminal;
import ai.qiwu.com.xiaoduhome.xiaoai.common.RequestWordNullException; import ai.qiwu.com.xiaoduhome.xiaoai.common.RequestWordNullException;
...@@ -26,12 +27,12 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -26,12 +27,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.*; import java.util.concurrent.*;
import static ai.qiwu.com.xiaoduhome.common.Constants.TTS_DIDI3_GET_XIAOAI;
import static ai.qiwu.com.xiaoduhome.common.Constants.WelcomeWord.*; import static ai.qiwu.com.xiaoduhome.common.Constants.WelcomeWord.*;
import static ai.qiwu.com.xiaoduhome.service.ScheduleService.jiaoyouChannel2Bots; import static ai.qiwu.com.xiaoduhome.service.ScheduleService.jiaoyouChannel2Bots;
import static ai.qiwu.com.xiaoduhome.xiaoai.common.XiaoAiConstants.ERROR_MSG.SORRY_REPEAT; import static ai.qiwu.com.xiaoduhome.xiaoai.common.XiaoAiConstants.ERROR_MSG.SORRY_REPEAT;
...@@ -230,27 +231,28 @@ public class XiaoAiServiceRedis { ...@@ -230,27 +231,28 @@ public class XiaoAiServiceRedis {
String redisId = SpiritRedisService.PREFIX_REDIS+userId; String redisId = SpiritRedisService.PREFIX_REDIS+userId;
try { try {
// long start = System.currentTimeMillis(); // long start = System.currentTimeMillis();
String data = stringRedisTemplate.opsForValue().get(redisId);
// log.info("redis get cost:"+(System.currentTimeMillis()-start)); // log.info("redis get cost:"+(System.currentTimeMillis()-start));
if (StringUtils.isNotBlank(data)) { if (Boolean.TRUE.equals(stringRedisTemplate.hasKey(redisId))) {
String data = stringRedisTemplate.opsForValue().get(redisId);
log.info("超时redis获取信息:"+data); log.info("超时redis获取信息:"+data);
if (StringUtils.isNotBlank(data)) {
String redisIdleId = SpiritRedisService.PREFIX_REDIS_IDLE+userId; String redisIdleId = SpiritRedisService.PREFIX_REDIS_IDLE+userId;
if (data.equals("out")) { if (data.equals("out")) {
String idleNum = stringRedisTemplate.opsForValue().get(redisIdleId); String idleNum = stringRedisTemplate.opsForValue().get(redisIdleId);
boolean firstIdle; boolean firstIdle;
if ((firstIdle = StringUtils.isBlank(idleNum)) || idleNum.equals("1")) { if ((firstIdle = StringUtils.isBlank(idleNum)) || idleNum.equals("1")) {
try { try {
Thread.sleep(1000); Thread.sleep(1500);
} catch (Exception e){} } catch (Exception e){}
data = stringRedisTemplate.opsForValue().get(redisId); // data = stringRedisTemplate.opsForValue().get(redisId);
if (StringUtils.isNotBlank(data) && !data.equals("out")) { // if (!data.equals("out")) {
stringRedisTemplate.delete(redisIdleId); // stringRedisTemplate.delete(redisIdleId);
stringRedisTemplate.delete(redisId); // stringRedisTemplate.delete(redisId);
return buildAudioResponse(changeAudioUrl(data, userId)); // return buildAudioResponse(changeAudioUrl(data, userId));
} // }
if (firstIdle) idleNum = "1"; if (firstIdle) idleNum = "1";
else idleNum = "2"; else idleNum = "2";
stringRedisTemplate.opsForValue().set(redisIdleId, idleNum, 10, TimeUnit.SECONDS); stringRedisTemplate.opsForValue().set(redisIdleId, idleNum, 15, TimeUnit.SECONDS);
return buildTextResponse((RandomUtils.nextInt() & 1) == 1 ? XiaoAiConstants.TTS.WAIT_WORD_1 : return buildTextResponse((RandomUtils.nextInt() & 1) == 1 ? XiaoAiConstants.TTS.WAIT_WORD_1 :
XiaoAiConstants.TTS.WAIT_WORD_2); XiaoAiConstants.TTS.WAIT_WORD_2);
} else { } else {
...@@ -258,11 +260,12 @@ public class XiaoAiServiceRedis { ...@@ -258,11 +260,12 @@ public class XiaoAiServiceRedis {
stringRedisTemplate.delete(redisId); stringRedisTemplate.delete(redisId);
} }
} else { } else {
stringRedisTemplate.delete(redisIdleId); if (Boolean.TRUE.equals(stringRedisTemplate.hasKey(redisIdleId))) stringRedisTemplate.delete(redisIdleId);
stringRedisTemplate.delete(redisId); stringRedisTemplate.delete(redisId);
return buildAudioResponse(changeAudioUrl(data, userId)); return buildAudioResponse(changeAudioUrl(data, userId));
} }
} }
}
} catch (Exception e) { } catch (Exception e) {
log.error("xiaoai redis error:"+e); log.error("xiaoai redis error:"+e);
} }
...@@ -284,8 +287,8 @@ public class XiaoAiServiceRedis { ...@@ -284,8 +287,8 @@ public class XiaoAiServiceRedis {
log.error("获取任务执行结果出错:{}", e.toString()); log.error("获取任务执行结果出错:{}", e.toString());
return buildTextResponse(SORRY_REPEAT); return buildTextResponse(SORRY_REPEAT);
} catch (TimeoutException e) { } catch (TimeoutException e) {
log.info("超时,让用户再说一遍:{}",e.toString()); log.info("超时,让用户再说一遍");
stringRedisTemplate.opsForValue().setIfAbsent(redisId, "out", 10, TimeUnit.SECONDS); stringRedisTemplate.opsForValue().setIfAbsent(redisId, "out", 15, TimeUnit.SECONDS);
return buildTextResponse(XiaoAiConstants.ERROR_MSG.TIME_OUT); return buildTextResponse(XiaoAiConstants.ERROR_MSG.TIME_OUT);
} catch (Exception all) { } catch (Exception all) {
log.error("任务执行发生了错误:{}", all.toString()); log.error("任务执行发生了错误:{}", all.toString());
...@@ -345,7 +348,7 @@ public class XiaoAiServiceRedis { ...@@ -345,7 +348,7 @@ public class XiaoAiServiceRedis {
String response; String response;
try { try {
response = RequestTerminal.requestTerminate(userId, userWord, type); response = RequestTerminal.requestTerminate(userId, userWord, type);
log.info("小爱,小悟返回:{}", response); // log.info("小爱,小悟返回:{}", response);
} catch (Exception e) { } catch (Exception e) {
log.error("向终端发出的请求信息失败:{}", e.toString()); log.error("向终端发出的请求信息失败:{}", e.toString());
return buildTextResponse(SORRY_REPEAT); return buildTextResponse(SORRY_REPEAT);
...@@ -408,14 +411,16 @@ public class XiaoAiServiceRedis { ...@@ -408,14 +411,16 @@ public class XiaoAiServiceRedis {
String path; String path;
try { try {
// path = OkHttp3Utils.doPostJsonStr(XiaoAiConstants.TTS_DIDI3, response); // path = OkHttp3Utils.doPostJsonStr(XiaoAiConstants.TTS_DIDI3, response);
path = OkHttp3Utils.doPostJsonStr("http://didi-gz5.jiaoyou365.com:9663/api/audio", response); path = OkHttp3Utils.doPostJsonStr(ScheduleServiceNew.BASE_HOST_URL+"9663/api/audio", response);
if (StringUtils.isBlank(path) || path.equals("null")) { if (StringUtils.isBlank(path) || path.equals("null")) {
log.error("没有获取到TTS返回的路径path"); log.error("没有获取到TTS返回的路径path");
return buildTextResponse(SORRY_REPEAT); return buildTextResponse(SORRY_REPEAT);
} }
xiaoAiResponse = buildAudioResponse(changeAudioUrl(path, userId)); xiaoAiResponse = buildAudioResponse(changeAudioUrl(path, userId));
log.info("Redis 写入:"+path); if (Boolean.TRUE.equals(stringRedisTemplate.opsForValue()
stringRedisTemplate.opsForValue().set(SpiritRedisService.PREFIX_REDIS+userId, path, 10, TimeUnit.SECONDS); .setIfPresent(SpiritRedisService.PREFIX_REDIS+userId, path, 15, TimeUnit.SECONDS))) {
log.info("xiaoai 超时redis存储成功");
}
// LAST_AUDIO_PLAY.put(userId, path); // LAST_AUDIO_PLAY.put(userId, path);
} catch (Exception e) { } catch (Exception e) {
log.error("没有获取到TTS返回的路径path"); log.error("没有获取到TTS返回的路径path");
...@@ -426,13 +431,23 @@ public class XiaoAiServiceRedis { ...@@ -426,13 +431,23 @@ public class XiaoAiServiceRedis {
} }
private String changeAudioUrl(String path, String userId) { private String changeAudioUrl(String path, String userId) {
path = path.replaceAll("%2F", "/"); // path = path.replaceAll("%2F", "/");
// return new StringBuilder(TTS_DIDI3_GET_XIAOAI).append(userId).append("&path=").append(path).toString(); // return new StringBuilder(TTS_DIDI3_GET_XIAOAI).append(userId).append("&path=").append(path).toString();
return new StringBuilder("http://didi-gz5.jiaoyou365.com:9663/api/audio/get?type=").append(userId).append("&path=").append(path).toString(); return new StringBuilder(ScheduleServiceNew.BASE_HOST_URL).append("9663/api/audio/get?type=").append(userId).append("&path=").append(path).toString();
} }
public void theAudioAlreadyPlay(String userId) { public void theAudioAlreadyPlay(String userId) {
try {
userId = URLEncoder.encode(userId, "UTF-8");
} catch (Exception e){
log.warn("theAudioAlreadyPlay encode userId failed");
userId = URLEncoder.encode(userId);
}
Boolean result = stringRedisTemplate.delete(SpiritRedisService.PREFIX_REDIS+userId); Boolean result = stringRedisTemplate.delete(SpiritRedisService.PREFIX_REDIS+userId);
log.info("回调删除:"+result); log.info("回调删除:"+result);
} }
public static void main(String[] args) throws UnsupportedEncodingException {
System.out.println(URLEncoder.encode("XIAOAI_ScfTGmNbhns8KXMJfZY4nQ==", "UTF-8"));
}
} }
...@@ -634,6 +634,6 @@ public class XiaoAiTestService { ...@@ -634,6 +634,6 @@ public class XiaoAiTestService {
public static void main(String[] args) throws UnsupportedEncodingException { public static void main(String[] args) throws UnsupportedEncodingException {
XiaoAiTestService service = new XiaoAiTestService(); XiaoAiTestService service = new XiaoAiTestService();
System.out.println(JSON.toJSONString(service.dealWithLaunchRequestPhone2())); System.out.println(JSON.toJSONString(service.dealWithLaunchRequestPhone()));
} }
} }
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