|
@@ -4,11 +4,11 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.management.platform.controller.WeiXinCorpController;
|
|
|
import com.management.platform.entity.*;
|
|
|
import com.management.platform.mapper.*;
|
|
|
import com.management.platform.service.TimeTypeService;
|
|
|
-import com.management.platform.service.UserService;
|
|
|
import com.management.platform.service.WxCorpInfoService;
|
|
|
import com.management.platform.service.WxCorpTemplateService;
|
|
|
import com.management.platform.task.SFTPAsyncUploader;
|
|
@@ -28,7 +28,8 @@ import org.springframework.web.util.UriComponentsBuilder;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.io.*;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.net.URI;
|
|
|
import java.text.SimpleDateFormat;
|
|
@@ -108,6 +109,8 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
public static final int TEXT_CARD_MSG_EXPENSE_AGREE = 21;//费用报销审核通过
|
|
|
public static final int TEXT_CARD_MSG_EXPENSE_DENY = 22;//费用报销审核驳回
|
|
|
|
|
|
+ public static final int TEXT_CARD_MSG__ASYNC_DWONLOAD = 23;//文件异步下载
|
|
|
+
|
|
|
private static Object userLock = new Object();
|
|
|
|
|
|
@Value("${suitId}")
|
|
@@ -195,15 +198,16 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
//获取上传转移文件 获得的media_ia
|
|
|
@Override
|
|
|
public String getTranslationMediaId(String fileName) throws Exception {
|
|
|
+ System.out.println("in getTranslationMediaId method");
|
|
|
String media_id="";
|
|
|
URI url = UriComponentsBuilder.fromHttpUrl("https://qyapi.weixin.qq.com/cgi-bin/service/media/upload")
|
|
|
.queryParam("provider_access_token", getProviderAccessToken())
|
|
|
.queryParam("type", "file")
|
|
|
.build().toUri();
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
|
|
//然后处理文件 通讯录id转译
|
|
|
FileSystemResource fileSystemResource = new FileSystemResource(path+fileName);
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
|
|
ContentDisposition build = ContentDisposition.builder("form-data").filename(fileSystemResource.getFilename()).build();
|
|
|
headers.setContentDisposition(build);
|
|
|
MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
|
|
@@ -220,9 +224,44 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
throw new Exception(json.toJSONString());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ System.out.println("end getTranslationMediaId method");
|
|
|
return media_id;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String getTranslationJobId(String fileName, WxCorpInfo wxCorpInfo) throws Exception {
|
|
|
+ System.out.println("in getTranslationJobId method");
|
|
|
+ String jobId="";
|
|
|
+ //然后处理文件 通讯录id转译
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ Map<String,Object> params = new HashMap<>();
|
|
|
+ params.put("scene",1);
|
|
|
+ params.put("type","file");
|
|
|
+ params.put("filename",fileName);
|
|
|
+ params.put("url","https://worktime.ttkuaiban.com/upload/"+fileName);
|
|
|
+ params.put("md5","MD5");
|
|
|
+ String requestBody = JSONObject.toJSONString(params);
|
|
|
+ HttpEntity<String> entity = new HttpEntity<>(requestBody, headers);
|
|
|
+ String apiUrl = "https://qyapi.weixin.qq.com/cgi-bin/media/upload_by_url?access_token="+getCorpAccessToken(wxCorpInfo);
|
|
|
+ ResponseEntity<String> responseEntity = restTemplate.exchange(apiUrl, HttpMethod.POST, entity, String.class);
|
|
|
+
|
|
|
+ String responseBody = responseEntity.getBody();
|
|
|
+ System.out.println("getTranslationJobId Response from API: " + responseBody);
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Map responseObj = objectMapper.readValue(responseBody, Map.class);
|
|
|
+ if (responseEntity.getStatusCode() == HttpStatus.OK){
|
|
|
+ if(null != responseObj.get("errcode") && 0 == Integer.parseInt(responseObj.get("errcode").toString())){
|
|
|
+ jobId = responseObj.get("job_id").toString();
|
|
|
+ }else{
|
|
|
+ System.out.println("error Trans====== "+responseObj.get("errmsg").toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("end getTranslationJobId method");
|
|
|
+ return jobId;
|
|
|
+ }
|
|
|
+
|
|
|
//异步通讯录id转译
|
|
|
@Override
|
|
|
public String syncTranslation(String authCorpid, String mediaId,String outPutFileName,String outputFileFormat) throws Exception {
|
|
@@ -509,6 +548,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
|
|
|
//获取第三方应用临时凭证
|
|
|
private String getSuiteAccessToken() {
|
|
|
+ System.out.println("in getSuiteAccessToken=== ");
|
|
|
if (WeiXinCorpController.SUITE_ACCESS_TOKEN == null || WeiXinCorpController.suiteTokenExpireTime < System.currentTimeMillis()) {
|
|
|
//失效了,需要重新获取
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
@@ -526,7 +566,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
HttpMethod.POST, requestEntity, String.class);
|
|
|
if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
String resp = responseEntity.getBody();
|
|
|
- System.out.println(resp);
|
|
|
+ System.out.println("getSuiteAccessToken resp ==="+resp);
|
|
|
JSONObject obj = JSONObject.parseObject(resp);
|
|
|
if (obj.getIntValue("errcode") == 0) {
|
|
|
WeiXinCorpController.SUITE_ACCESS_TOKEN = obj.getString("suite_access_token");
|
|
@@ -571,6 +611,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
|
|
|
//获取企业AccessToken
|
|
|
private String getCorpAccessToken(WxCorpInfo corpInfo) throws Exception {
|
|
|
+ System.out.println("in getCorpAccessToken=== ");
|
|
|
if (corpInfo.getExpireTime().isBefore(LocalDateTime.now())) {
|
|
|
String url = WeiXinCorpController.GET_CORP_ACCESSTOKEN_URL.replace("SUITE_ACCESS_TOKEN", getSuiteAccessToken());
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
@@ -582,12 +623,15 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
// System.out.println("CompanyId为:"+corpInfo.getCompanyId());
|
|
|
// System.out.println("Corpid为:"+corpInfo.getCorpid());
|
|
|
// System.out.println("PermanentCode为:"+corpInfo.getPermanentCode());
|
|
|
+
|
|
|
+ System.out.println("getCorpAccessToken url=== "+url);
|
|
|
HttpEntity<String> requestEntity = new HttpEntity<String>(reqParam.toJSONString(), headers);
|
|
|
ResponseEntity<String> responseEntity = this.restTemplate.exchange(url,
|
|
|
HttpMethod.POST, requestEntity, String.class);
|
|
|
if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
String resp = responseEntity.getBody();
|
|
|
JSONObject json = JSONObject.parseObject(resp);
|
|
|
+ System.out.println("getCorpAccessToken Response from API: " + resp);
|
|
|
if (json.getIntValue("errcode") == 0) {
|
|
|
String access_token = json.getString("access_token");
|
|
|
corpInfo.setAccessToken(access_token);
|