#532 实现微信AI开放接口的三个接口:语音上传、查询识别结果和微信翻译功能

This commit is contained in:
Binary Wang
2018-06-10 11:54:45 +08:00
parent 0daaa011ef
commit 5b5dada0fe
12 changed files with 377 additions and 6 deletions

View File

@ -0,0 +1,47 @@
package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.AiLangType;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.test.ApiTestModule;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import java.io.File;
/**
* <pre>
* Created by BinaryWang on 2018/6/10.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Test
@Guice(modules = ApiTestModule.class)
public class WxMpAiOpenServiceImplTest {
@Inject
protected WxMpService wxService;
@Test
public void testUploadVoice() throws WxErrorException {
String voiceId = System.currentTimeMillis() + "a";
AiLangType lang = AiLangType.zh_CN;
this.wxService.getAiOpenService().uploadVoice(voiceId, lang, new File("d:\\t.mp3"));
}
@Test
public void testRecogniseVoice() throws WxErrorException {
String voiceId = System.currentTimeMillis() + "a";
AiLangType lang = AiLangType.zh_CN;
final String result = this.wxService.getAiOpenService().recogniseVoice(voiceId, lang, new File("d:\\t.mp3"));
System.out.println(result);
}
@Test
public void testTranslate() throws WxErrorException {
final String responseContent = this.wxService.getAiOpenService()
.translate(AiLangType.zh_CN, AiLangType.en_US, "微信文档很坑爹");
System.out.println(responseContent);
}
}

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.locks.ReentrantLock;
import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -28,7 +29,7 @@ public class ApiTestModule implements Module {
TestConfigStorage config = this.fromXml(TestConfigStorage.class, inputStream);
config.setAccessTokenLock(new ReentrantLock());
WxMpService wxService = new WxMpServiceOkHttpImpl();
WxMpService wxService = new WxMpServiceHttpClientImpl();
wxService.setWxMpConfigStorage(config);
binder.bind(WxMpService.class).toInstance(wxService);