@Test public void testTranslate() throws WxErrorException { final String responseContent = this.wxService.getAiOpenService() .translate(AiLangType.zh_CN, AiLangType.en_US, "微信文档很坑爹"); System.out.println(responseContent); }
@Override public String translate(AiLangType langFrom, AiLangType langTo, String content) throws WxErrorException { final String responseContent = this.wxMpService.post(String.format(TRANSLATE_URL, langFrom.getCode(), langTo.getCode()), content); final JsonObject jsonObject = new JsonParser().parse(responseContent).getAsJsonObject(); if (jsonObject.get("errcode") == null || jsonObject.get("errcode").getAsInt() == 0) { return jsonObject.get("to_content").getAsString(); } throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP)); }
WxMpAiOpenServiceImpl implements WxMpAiOpenService { @Override public String translate(AiLangType langFrom, AiLangType langTo, String content) throws WxErrorException { final String responseContent = this.wxMpService.post(String.format(TRANSLATE_URL, langFrom.getCode(), langTo.getCode()), content); final JsonObject jsonObject = new JsonParser().parse(responseContent).getAsJsonObject(); if (jsonObject.get("errcode") == null || jsonObject.get("errcode").getAsInt() == 0) { return jsonObject.get("to_content").getAsString(); } throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP)); } }
WxMpAiOpenServiceImpl implements WxMpAiOpenService { @Override public String translate(AiLangType langFrom, AiLangType langTo, String content) throws WxErrorException { final String responseContent = this.wxMpService.post(String.format(TRANSLATE_URL, langFrom.getCode(), langTo.getCode()), content); final JsonObject jsonObject = new JsonParser().parse(responseContent).getAsJsonObject(); if (jsonObject.get("errcode") == null || jsonObject.get("errcode").getAsInt() == 0) { return jsonObject.get("to_content").getAsString(); } throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP)); } WxMpAiOpenServiceImpl(WxMpService wxMpService); }
WxMpAiOpenServiceImpl implements WxMpAiOpenService { @Override public String translate(AiLangType langFrom, AiLangType langTo, String content) throws WxErrorException { final String responseContent = this.wxMpService.post(String.format(TRANSLATE_URL, langFrom.getCode(), langTo.getCode()), content); final JsonObject jsonObject = new JsonParser().parse(responseContent).getAsJsonObject(); if (jsonObject.get("errcode") == null || jsonObject.get("errcode").getAsInt() == 0) { return jsonObject.get("to_content").getAsString(); } throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP)); } WxMpAiOpenServiceImpl(WxMpService wxMpService); @Override void uploadVoice(String voiceId, AiLangType lang, File voiceFile); @Override String recogniseVoice(String voiceId, AiLangType lang, File voiceFile); @Override String translate(AiLangType langFrom, AiLangType langTo, String content); @Override String queryRecognitionResult(String voiceId, AiLangType lang); }
WxMpAiOpenServiceImpl implements WxMpAiOpenService { @Override public String translate(AiLangType langFrom, AiLangType langTo, String content) throws WxErrorException { final String responseContent = this.wxMpService.post(String.format(TRANSLATE_URL, langFrom.getCode(), langTo.getCode()), content); final JsonObject jsonObject = new JsonParser().parse(responseContent).getAsJsonObject(); if (jsonObject.get("errcode") == null || jsonObject.get("errcode").getAsInt() == 0) { return jsonObject.get("to_content").getAsString(); } throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP)); } WxMpAiOpenServiceImpl(WxMpService wxMpService); @Override void uploadVoice(String voiceId, AiLangType lang, File voiceFile); @Override String recogniseVoice(String voiceId, AiLangType lang, File voiceFile); @Override String translate(AiLangType langFrom, AiLangType langTo, String content); @Override String queryRecognitionResult(String voiceId, AiLangType lang); static final String TRANSLATE_URL; }