|
@@ -174,6 +174,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
//获取服务商provider_access_token
|
|
//获取服务商provider_access_token
|
|
@Override
|
|
@Override
|
|
public String getProviderAccessToken() throws Exception {
|
|
public String getProviderAccessToken() throws Exception {
|
|
|
|
+ System.out.println("in getProviderAccessToken method");
|
|
String access_token="";
|
|
String access_token="";
|
|
String url = "https://qyapi.weixin.qq.com/cgi-bin/service/get_provider_token";
|
|
String url = "https://qyapi.weixin.qq.com/cgi-bin/service/get_provider_token";
|
|
HttpHeaders headers = new HttpHeaders();
|
|
HttpHeaders headers = new HttpHeaders();
|
|
@@ -192,6 +193,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
}
|
|
}
|
|
access_token= json.getString("provider_access_token");
|
|
access_token= json.getString("provider_access_token");
|
|
}
|
|
}
|
|
|
|
+ System.out.println("end getProviderAccessToken method");
|
|
return access_token;
|
|
return access_token;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -230,7 +232,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public String getTranslationJobId(String fileName, WxCorpInfo wxCorpInfo) throws Exception {
|
|
|
|
|
|
+ public String getTranslationJobId(String fileName,String md5, WxCorpInfo wxCorpInfo) throws Exception {
|
|
System.out.println("in getTranslationJobId method");
|
|
System.out.println("in getTranslationJobId method");
|
|
String jobId="";
|
|
String jobId="";
|
|
//然后处理文件 通讯录id转译
|
|
//然后处理文件 通讯录id转译
|
|
@@ -240,8 +242,10 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
params.put("scene",1);
|
|
params.put("scene",1);
|
|
params.put("type","file");
|
|
params.put("type","file");
|
|
params.put("filename",fileName);
|
|
params.put("filename",fileName);
|
|
- params.put("url","https://worktime.ttkuaiban.com/upload/"+fileName);
|
|
|
|
- params.put("md5","MD5");
|
|
|
|
|
|
+// params.put("url","https://worktime.ttkuaiban.com/upload/"+fileName);
|
|
|
|
+ params.put("url","http://47.101.180.183:9097/upload/"+fileName);
|
|
|
|
+// System.out.println("uploadJobFileUrl=== "+"http://47.101.180.183:9097/upload/"+fileName);
|
|
|
|
+ params.put("md5",md5);
|
|
String requestBody = JSONObject.toJSONString(params);
|
|
String requestBody = JSONObject.toJSONString(params);
|
|
HttpEntity<String> entity = new HttpEntity<>(requestBody, headers);
|
|
HttpEntity<String> entity = new HttpEntity<>(requestBody, headers);
|
|
String apiUrl = "https://qyapi.weixin.qq.com/cgi-bin/media/upload_by_url?access_token="+getCorpAccessToken(wxCorpInfo);
|
|
String apiUrl = "https://qyapi.weixin.qq.com/cgi-bin/media/upload_by_url?access_token="+getCorpAccessToken(wxCorpInfo);
|
|
@@ -253,7 +257,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
Map responseObj = objectMapper.readValue(responseBody, Map.class);
|
|
Map responseObj = objectMapper.readValue(responseBody, Map.class);
|
|
if (responseEntity.getStatusCode() == HttpStatus.OK){
|
|
if (responseEntity.getStatusCode() == HttpStatus.OK){
|
|
if(null != responseObj.get("errcode") && 0 == Integer.parseInt(responseObj.get("errcode").toString())){
|
|
if(null != responseObj.get("errcode") && 0 == Integer.parseInt(responseObj.get("errcode").toString())){
|
|
- jobId = responseObj.get("job_id").toString();
|
|
|
|
|
|
+ jobId = responseObj.get("jobid").toString();
|
|
}else{
|
|
}else{
|
|
System.out.println("error Trans====== "+responseObj.get("errmsg").toString());
|
|
System.out.println("error Trans====== "+responseObj.get("errmsg").toString());
|
|
}
|
|
}
|
|
@@ -2574,4 +2578,62 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
}
|
|
}
|
|
return "";
|
|
return "";
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String getAsyncJobResult(String tmpFileJobId,WxCorpInfo wxCorpInfo) throws Exception{
|
|
|
|
+ System.out.println("in getAsyncJobResult method");
|
|
|
|
+ String mediaId = "";
|
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
|
+ Map<String,Object> params = new HashMap<>();
|
|
|
|
+ params.put("jobid",tmpFileJobId);
|
|
|
|
+ String requestBody = JSONObject.toJSONString(params);
|
|
|
|
+ HttpEntity<String> entity = new HttpEntity<>(requestBody, headers);
|
|
|
|
+ String apiUrl = "https://qyapi.weixin.qq.com/cgi-bin/media/get_upload_by_url_result?access_token="+getCorpAccessToken(wxCorpInfo);
|
|
|
|
+
|
|
|
|
+ int i = 0;
|
|
|
|
+ while(i < 100){
|
|
|
|
+ if (i < 10) {
|
|
|
|
+ Thread.sleep(300);
|
|
|
|
+ } else if (i < 20){
|
|
|
|
+ Thread.sleep(1000);
|
|
|
|
+ } else {
|
|
|
|
+ Thread.sleep(3000);
|
|
|
|
+ }
|
|
|
|
+ System.out.println("i=="+i+", "+LocalDateTime.now());
|
|
|
|
+ ResponseEntity<String> responseEntity = restTemplate.exchange(apiUrl, HttpMethod.POST, entity, String.class);
|
|
|
|
+ String responseBody = responseEntity.getBody();
|
|
|
|
+ System.out.println("getAsyncJobResult Response from API: " + responseBody);
|
|
|
|
+ JSONObject jsonRes = JSONObject.parseObject(responseBody);
|
|
|
|
+ if (responseEntity.getStatusCode() == HttpStatus.OK){
|
|
|
|
+ if(null != jsonRes.get("errcode") && 0 == Integer.parseInt(jsonRes.get("errcode").toString())){
|
|
|
|
+ String status = jsonRes.get("status").toString();
|
|
|
|
+ if("1".equals(status)){
|
|
|
|
+ //处理中
|
|
|
|
+ } else if ("2".equals(status)) {
|
|
|
|
+ //已完成
|
|
|
|
+ String detailStr = jsonRes.getString("detail");
|
|
|
|
+ JSONObject detailJson = JSONObject.parseObject(detailStr);
|
|
|
|
+ mediaId = detailJson.getString("media_id");
|
|
|
|
+ break;
|
|
|
|
+ } else if ("3".equals(status)) {
|
|
|
|
+ //报错了
|
|
|
|
+ String detailStr = jsonRes.getString("detail");
|
|
|
|
+ System.out.println("detailStr==="+detailStr);
|
|
|
|
+ JSONObject detailJson = JSONObject.parseObject(detailStr);
|
|
|
|
+ System.out.println("企业微信转译报错:"+detailJson.getString("errmsg"));
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ System.out.println("error Trans====== "+jsonRes.get("errmsg").toString());
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ i++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ System.out.println("end getAsyncJobResult method");
|
|
|
|
+ return mediaId;
|
|
|
|
+ }
|
|
}
|
|
}
|