Browse Source

第三方代码上传

dev
zhaoqifeng 5 years ago
parent
commit
d60e8d8acc
  1. 8
      epmet-commons/epmet-commons-tools/pom.xml
  2. 27
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java
  3. 53
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/MultipartFileToFileUtils.java
  4. 91
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/CodeExtDTO.java
  5. 19
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/MediaUploadFormDTO.java
  6. 17
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/MediaUploadResultDTO.java
  7. 2
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/TemplateListResultDTO.java
  8. 33
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/CodeController.java
  9. 84
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/CodeExtController.java
  10. 54
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/CodeExtDao.java
  11. 61
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/CodeExtEntity.java
  12. 47
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/redis/CodeExtRedis.java
  13. 116
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/CodeExtService.java
  14. 25
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/CodeService.java
  15. 114
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/CodeExtServiceImpl.java
  16. 121
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/CodeServiceImpl.java
  17. 15
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/constant/WxMaCodeConstant.java
  18. 44
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/param/WxMaModifyDomainReq.java
  19. 29
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/param/WxMaSetWebviewDomainReq.java
  20. 2
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/result/WxMaGetCategoryResult.java
  21. 25
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/result/WxMaUploadMediaResult.java
  22. 35
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/service/WxMaCodeService.java
  23. 109
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/service/impl/WxMaCodeServiceImpl.java
  24. 13
      epmet-module/epmet-third/epmet-third-server/src/main/resources/bootstrap.yml
  25. 41
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/CodeExtDao.xml

8
epmet-commons/epmet-commons-tools/pom.xml

@ -129,6 +129,14 @@
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
</dependency>
</dependencies>
<build>

27
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java

@ -10,6 +10,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
@ -20,6 +21,8 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
@ -124,6 +127,30 @@ public class HttpClientManager {
}
/**
* 上传临时素材
* @author zhaoqifeng
* @date 2020/7/17 14:33
* @param url
* @param file
* @return com.epmet.commons.tools.utils.Result<java.lang.String>
*/
public Result<String> uploadWxMedia(String url, File file) {
try {
HttpPost httppost = new HttpPost(url);
httppost.setConfig(requestConfig);
httppost.addHeader("Content-Type", "application/json; charset=utf-8");
FileBody fileBody = new FileBody(file);
HttpEntity reqEntity = MultipartEntityBuilder.create()
.addPart("media", fileBody).build();
httppost.setEntity(reqEntity);
return execute(httppost);
} catch (Exception e) {
log.error("send exception", e);
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg());
}
}
/**
* desc: 发送钉钉群消息 简版
* param: url,jsonStrParam

53
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/MultipartFileToFileUtils.java

@ -0,0 +1,53 @@
package com.epmet.commons.tools.utils;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
/**
* @author zhaoqifeng
* @dscription
* @date 2020/7/17 14:01
*/
public class MultipartFileToFileUtils {
/**
* MultipartFile File
*
* @param file
* @throws Exception
*/
public static File multipartFileToFile(MultipartFile file) throws Exception {
File toFile = null;
if (("").equals(file) || file.getSize() <= 0) {
file = null;
} else {
InputStream ins = null;
ins = file.getInputStream();
toFile = new File(file.getOriginalFilename());
toFile = inputStreamToFile(ins, toFile);
ins.close();
}
return toFile;
}
private static File inputStreamToFile(InputStream ins, File file) {
try {
OutputStream os = new FileOutputStream(file);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
os.close();
ins.close();
return file;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

91
epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/CodeExtDTO.java

@ -0,0 +1,91 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.dto;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
* 代码第三方配置
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2020-07-17
*/
@Data
public class CodeExtDTO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
private String id;
/**
* 客户ID
*/
private String customerId;
/**
* 所属端 居民的resi,工作端work
*/
private String clientType;
/**
* APPID
*/
private String appId;
/**
* 自定义配置
*/
private String extJson;
/**
* 乐观锁
*/
private Integer revision;
/**
* 是否删除
*/
private String delFlag;
/**
* 创建人
*/
private String createdBy;
/**
* 创建时间
*/
private Date createdTime;
/**
* 更新人
*/
private String updatedBy;
/**
* 更新时间
*/
private Date updatedTime;
}

19
epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/MediaUploadFormDTO.java

@ -0,0 +1,19 @@
package com.epmet.dto.form;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
import java.io.Serializable;
/**
* @author zhaoqifeng
* @dscription
* @date 2020/7/17 11:15
*/
@Data
public class MediaUploadFormDTO implements Serializable {
private static final long serialVersionUID = -7342624180676221309L;
private String codeId;
private String type;
private MultipartFile media;
}

17
epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/MediaUploadResultDTO.java

@ -0,0 +1,17 @@
package com.epmet.dto.result;
import lombok.Data;
import java.io.Serializable;
/**
* @author zhaoqifeng
* @dscription
* @date 2020/7/17 11:17
*/
@Data
public class MediaUploadResultDTO implements Serializable {
private static final long serialVersionUID = -8462768939270515547L;
private String id;
private String name;
}

2
epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/TemplateListResultDTO.java

@ -18,7 +18,7 @@ public class TemplateListResultDTO implements Serializable {
/**
* 模板 id
*/
private String templateId;
private String id;
/**
* 模板描述
*/

33
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/CodeController.java

@ -3,10 +3,7 @@ package com.epmet.controller;
import com.baomidou.mybatisplus.extension.api.R;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.form.CodeCommonFormDTO;
import com.epmet.dto.form.CodeUploadFormDTO;
import com.epmet.dto.form.SubmitAuditFormDTO;
import com.epmet.dto.form.UploadListFormDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.result.*;
import com.epmet.service.CodeService;
import oracle.jdbc.proxy.annotation.Post;
@ -43,6 +40,20 @@ public class CodeController {
return new Result<List<TemplateListResultDTO>>().ok(list);
}
/**
* 获取客户第三方配置
*
* @param formDTO
* @return com.epmet.commons.tools.utils.Result<java.lang.String>
* @author zhaoqifeng
* @date 2020/7/17 16:22
*/
@PostMapping("getextjson")
public Result<String> getExtJson(CodeUploadFormDTO formDTO) {
String extJson = codeService.getExtJson(formDTO);
return new Result<String>().ok(extJson);
}
/**
* 代码上传
*
@ -154,4 +165,18 @@ public class CodeController {
PageData result = codeService.history(formDTO);
return new Result<PageData>().ok(result);
}
/**
* 上传临时素材
*
* @param formDTO
* @return com.epmet.commons.tools.utils.Result<java.util.List < com.epmet.dto.result.MediaUploadResultDTO>>
* @author zhaoqifeng
* @date 2020/7/17 11:20
*/
@PostMapping("mediaupload")
public Result<String> mediaUpload(@RequestBody MediaUploadFormDTO formDTO) {
String result = codeService.mediaUpload(formDTO);
return new Result<String>().ok(result);
}
}

84
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/CodeExtController.java

@ -0,0 +1,84 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.controller;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.AssertUtils;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.commons.tools.validator.group.AddGroup;
import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.commons.tools.validator.group.UpdateGroup;
import com.epmet.dto.CodeExtDTO;
import com.epmet.service.CodeExtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* 代码第三方配置
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2020-07-17
*/
@RestController
@RequestMapping("codeext")
public class CodeExtController {
@Autowired
private CodeExtService codeExtService;
@GetMapping("page")
public Result<PageData<CodeExtDTO>> page(@RequestParam Map<String, Object> params){
PageData<CodeExtDTO> page = codeExtService.page(params);
return new Result<PageData<CodeExtDTO>>().ok(page);
}
@GetMapping("{id}")
public Result<CodeExtDTO> get(@PathVariable("id") String id){
CodeExtDTO data = codeExtService.get(id);
return new Result<CodeExtDTO>().ok(data);
}
@PostMapping
public Result save(@RequestBody CodeExtDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
codeExtService.save(dto);
return new Result();
}
@PutMapping
public Result update(@RequestBody CodeExtDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
codeExtService.update(dto);
return new Result();
}
@DeleteMapping
public Result delete(@RequestBody String[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
codeExtService.delete(ids);
return new Result();
}
}

54
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/CodeExtDao.java

@ -0,0 +1,54 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.CodeExtDTO;
import com.epmet.entity.CodeExtEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 代码第三方配置
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2020-07-17
*/
@Mapper
public interface CodeExtDao extends BaseDao<CodeExtEntity> {
/**
* 获取第三方配置模板
* @author zhaoqifeng
* @date 2020/7/17 15:25
* @param
* @return java.lang.String
*/
String selectExtTemplate(@Param("clientType") String clientType);
/**
* 获取客户的第三方配置
* @author zhaoqifeng
* @date 2020/7/17 15:26
* @param customerId
* @param clientType
* @return java.lang.String
*/
CodeExtDTO selectExtByCustomerId(@Param("customerId") String customerId, @Param("clientType") String clientType);
}

61
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/CodeExtEntity.java

@ -0,0 +1,61 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.epmet.commons.mybatis.entity.BaseEpmetEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* 代码第三方配置
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2020-07-17
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("code_ext")
public class CodeExtEntity extends BaseEpmetEntity {
private static final long serialVersionUID = 1L;
/**
* 客户ID
*/
private String customerId;
/**
* 所属端 居民的resi,工作端work
*/
private String clientType;
/**
* APPID
*/
private String appId;
/**
* 自定义配置
*/
private String extJson;
}

47
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/redis/CodeExtRedis.java

@ -0,0 +1,47 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.redis;
import com.epmet.commons.tools.redis.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* 代码第三方配置
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2020-07-17
*/
@Component
public class CodeExtRedis {
@Autowired
private RedisUtils redisUtils;
public void delete(Object[] ids) {
}
public void set(){
}
public String get(String id){
return null;
}
}

116
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/CodeExtService.java

@ -0,0 +1,116 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.service;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.commons.tools.page.PageData;
import com.epmet.dto.CodeExtDTO;
import com.epmet.entity.CodeExtEntity;
import java.util.List;
import java.util.Map;
/**
* 代码第三方配置
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2020-07-17
*/
public interface CodeExtService extends BaseService<CodeExtEntity> {
/**
* 默认分页
*
* @param params
* @return PageData<CodeExtDTO>
* @author generator
* @date 2020-07-17
*/
PageData<CodeExtDTO> page(Map<String, Object> params);
/**
* 默认查询
*
* @param params
* @return java.util.List<CodeExtDTO>
* @author generator
* @date 2020-07-17
*/
List<CodeExtDTO> list(Map<String, Object> params);
/**
* 单条查询
*
* @param id
* @return CodeExtDTO
* @author generator
* @date 2020-07-17
*/
CodeExtDTO get(String id);
/**
* 默认保存
*
* @param dto
* @return void
* @author generator
* @date 2020-07-17
*/
void save(CodeExtDTO dto);
/**
* 默认更新
*
* @param dto
* @return void
* @author generator
* @date 2020-07-17
*/
void update(CodeExtDTO dto);
/**
* 批量删除
*
* @param ids
* @return void
* @author generator
* @date 2020-07-17
*/
void delete(String[] ids);
/**
* 获取配置模板
*
* @param clientType
* @return java.lang.String
* @author zhaoqifeng
* @date 2020/7/17 15:29
*/
String getExtTemplate(String clientType);
/**
* 获取客户第三方配置
*
* @param customerId
* @param clientType
* @return java.lang.String
* @author zhaoqifeng
* @date 2020/7/17 15:29
*/
CodeExtDTO getExtByCustomer(String customerId, String clientType);
}

25
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/CodeService.java

@ -2,10 +2,7 @@ package com.epmet.service;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.form.CodeCommonFormDTO;
import com.epmet.dto.form.CodeUploadFormDTO;
import com.epmet.dto.form.SubmitAuditFormDTO;
import com.epmet.dto.form.UploadListFormDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.result.*;
import java.util.List;
@ -26,6 +23,16 @@ public interface CodeService {
*/
List<TemplateListResultDTO> templateList();
/**
* 获取第三方配置
*
* @param formDTO 参数
* @return java.lang.String
* @author zhaoqifeng
* @date 2020/7/17 16:04
*/
String getExtJson(CodeUploadFormDTO formDTO);
/**
* 代码上传
*
@ -101,4 +108,14 @@ public interface CodeService {
* @date 2020/7/16 10:16
*/
PageData history(CodeCommonFormDTO formDTO);
/**
* 上传临时素材
*
* @param formDTO 参数
* @return java.util.List<com.epmet.dto.result.MediaUploadResultDTO>
* @author zhaoqifeng
* @date 2020/7/17 11:20
*/
String mediaUpload(MediaUploadFormDTO formDTO);
}

114
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/CodeExtServiceImpl.java

@ -0,0 +1,114 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.dao.CodeExtDao;
import com.epmet.dto.CodeExtDTO;
import com.epmet.entity.CodeExtEntity;
import com.epmet.redis.CodeExtRedis;
import com.epmet.service.CodeExtService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* 代码第三方配置
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2020-07-17
*/
@Service
public class CodeExtServiceImpl extends BaseServiceImpl<CodeExtDao, CodeExtEntity> implements CodeExtService {
@Autowired
private CodeExtRedis codeExtRedis;
@Override
public PageData<CodeExtDTO> page(Map<String, Object> params) {
IPage<CodeExtEntity> page = baseDao.selectPage(
getPage(params, FieldConstant.CREATED_TIME, false),
getWrapper(params)
);
return getPageData(page, CodeExtDTO.class);
}
@Override
public List<CodeExtDTO> list(Map<String, Object> params) {
List<CodeExtEntity> entityList = baseDao.selectList(getWrapper(params));
return ConvertUtils.sourceToTarget(entityList, CodeExtDTO.class);
}
private QueryWrapper<CodeExtEntity> getWrapper(Map<String, Object> params){
String id = (String)params.get(FieldConstant.ID_HUMP);
QueryWrapper<CodeExtEntity> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id);
return wrapper;
}
@Override
public CodeExtDTO get(String id) {
CodeExtEntity entity = baseDao.selectById(id);
return ConvertUtils.sourceToTarget(entity, CodeExtDTO.class);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(CodeExtDTO dto) {
CodeExtEntity entity = ConvertUtils.sourceToTarget(dto, CodeExtEntity.class);
insert(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(CodeExtDTO dto) {
CodeExtEntity entity = ConvertUtils.sourceToTarget(dto, CodeExtEntity.class);
updateById(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(String[] ids) {
// 逻辑删除(@TableLogic 注解)
baseDao.deleteBatchIds(Arrays.asList(ids));
}
@Override
public String getExtTemplate(String clientType) {
return baseDao.selectExtTemplate(clientType);
}
@Override
public CodeExtDTO getExtByCustomer(String customerId, String clientType) {
return baseDao.selectExtByCustomerId(customerId, clientType);
}
}

121
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/CodeServiceImpl.java

@ -1,19 +1,18 @@
package com.epmet.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.commons.tools.utils.MultipartFileToFileUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.constant.CodeConstant;
import com.epmet.dao.AuthorizationInfoDao;
import com.epmet.dao.ComponentAccessTokenDao;
import com.epmet.dto.*;
import com.epmet.dto.form.CodeCommonFormDTO;
import com.epmet.dto.form.CodeUploadFormDTO;
import com.epmet.dto.form.SubmitAuditFormDTO;
import com.epmet.dto.form.UploadListFormDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.result.*;
import com.epmet.feign.OperCrmOpenFeignClient;
import com.epmet.service.*;
@ -21,17 +20,17 @@ import com.epmet.wxapi.param.WxMaCodeAuditStatusReq;
import com.epmet.wxapi.param.WxMaCodeCommitReq;
import com.epmet.wxapi.param.WxMaCodeSubmitAuditRequest;
import com.epmet.wxapi.param.WxMaNewsReq;
import com.epmet.wxapi.result.WxMaAuditStatusResult;
import com.epmet.wxapi.result.WxMaNewsResult;
import com.epmet.wxapi.result.WxMaTemplateResult;
import com.epmet.wxapi.result.WxResult;
import com.epmet.wxapi.result.*;
import com.epmet.wxapi.service.WxMaCodeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -60,6 +59,10 @@ public class CodeServiceImpl implements CodeService {
private CustomerMpService customerMpService;
@Autowired
private CodeOperationHistoryService codeOperationHistoryService;
@Autowired
private CodeMediaService codeMediaService;
@Autowired
private CodeExtService codeExtService;
@Override
public List<TemplateListResultDTO> templateList() {
@ -76,7 +79,7 @@ public class CodeServiceImpl implements CodeService {
}
wxResult.getData().forEach(temp -> {
TemplateListResultDTO dto = new TemplateListResultDTO();
dto.setTemplateId(temp.getTemplateId());
dto.setId(temp.getTemplateId());
dto.setUserVersion(temp.getUserVersion());
dto.setUserDesc(temp.getUserDesc());
dto.setCreateTime(DateUtils.formatTimestamp(temp.getCreateTime(), DateUtils.DATE_PATTERN));
@ -85,6 +88,15 @@ public class CodeServiceImpl implements CodeService {
return resultList;
}
@Override
public String getExtJson(CodeUploadFormDTO formDTO) {
CodeExtDTO codeExtDTO = codeExtService.getExtByCustomer(formDTO.getCustomerId(), formDTO.getClientType());
if (null == codeExtDTO) {
return codeExtService.getExtTemplate(formDTO.getClientType());
}
return codeExtDTO.getExtJson();
}
@Override
@Transactional(rollbackFor = Exception.class)
public void upload(CodeUploadFormDTO formDTO) {
@ -97,11 +109,24 @@ public class CodeServiceImpl implements CodeService {
if (null == authInfo) {
throw new RenException("未授权");
}
//TODO 获取第三方自定义配置
String extJson = "{}";
if (!isJson(formDTO.getExtJson())) {
throw new RenException("第三方配置不是有效的Json");
}
CodeExtDTO codeExtDTO = codeExtService.getExtByCustomer(formDTO.getCustomerId(), formDTO.getClientType());
if (null == codeExtDTO) {
codeExtDTO = new CodeExtDTO();
codeExtDTO.setCustomerId(formDTO.getCustomerId());
codeExtDTO.setClientType(formDTO.getClientType());
codeExtDTO.setAppId(authInfo.getAuthorizerAppid());
codeExtDTO.setExtJson(formDTO.getExtJson());
codeExtService.save(codeExtDTO);
}
codeExtDTO.setExtJson(formDTO.getExtJson());
codeExtService.update(codeExtDTO);
WxMaCodeCommitReq request = ConvertUtils.sourceToTarget(formDTO, WxMaCodeCommitReq.class);
request.setExtJson(extJson);
request.setExtJson(formDTO.getExtJson());
//调用微信API上传代码
WxResult wxResult = wxMaCodeService.commit(authInfo.getAuthorizerAccessToken(), request);
//上传失败,抛出异常
@ -122,7 +147,7 @@ public class CodeServiceImpl implements CodeService {
//将上传信息存入表中
CodeCustomerDTO codeCustomerDTO = ConvertUtils.sourceToTarget(formDTO, CodeCustomerDTO.class);
codeCustomerDTO.setCustomerName(customerInfo.getData().getCustomerName());
codeCustomerDTO.setExtJson(extJson);
codeCustomerDTO.setExtJson(formDTO.getExtJson());
codeCustomerDTO.setStatus(CodeConstant.UNAUDITED);
codeCustomerService.save(codeCustomerDTO);
@ -133,6 +158,9 @@ public class CodeServiceImpl implements CodeService {
public PageData uploadList(UploadListFormDTO formDTO) {
//获取小程序调用令牌
AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(formDTO.getCustomerId(), formDTO.getClientType());
if (null == authInfo) {
throw new RenException("未授权");
}
List<CodeCustomerDTO> auditingList = codeCustomerService.getAuditingCodeList();
auditingList.forEach(code -> {
//获取审核结果信息
@ -143,16 +171,16 @@ public class CodeServiceImpl implements CodeService {
WxResult<WxMaAuditStatusResult> wxAuditResult = wxMaCodeService.getAuditStatus(authInfo.getAuthorizerAccessToken(), request);
if (wxAuditResult.success()) {
WxMaAuditStatusResult result = wxAuditResult.getData();
if(result.getStatus() == NumConstant.ZERO) {
if (result.getStatus() == NumConstant.ZERO) {
code.setStatus(CodeConstant.AUDIT_SUCCESS);
auditResult.setResult(CodeConstant.AUDIT_SUCCESS);
codeOperationHistoryService.updateDescribe(code.getId(), "审核成功");
} else if(result.getStatus() == NumConstant.ONE) {
} else if (result.getStatus() == NumConstant.ONE) {
code.setStatus(CodeConstant.AUDIT_FAILED);
auditResult.setResult(CodeConstant.AUDIT_FAILED);
auditResult.setReason(result.getReason());
codeOperationHistoryService.updateDescribe(code.getId(), result.getReason());
} else if(result.getStatus() == NumConstant.FOUR) {
} else if (result.getStatus() == NumConstant.FOUR) {
code.setStatus(CodeConstant.DELAY);
auditResult.setResult(CodeConstant.DELAY);
codeOperationHistoryService.updateDescribe(code.getId(), "审核延后");
@ -174,6 +202,9 @@ public class CodeServiceImpl implements CodeService {
}
//获取小程序调用令牌
AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType());
if (null == authInfo) {
throw new RenException("未授权");
}
//调用微信API上提交审核
WxMaCodeSubmitAuditRequest request = ConvertUtils.sourceToTarget(formDTO, WxMaCodeSubmitAuditRequest.class);
WxResult<String> wxResult = wxMaCodeService.submitAudit(authInfo.getAuthorizerAccessToken(), request);
@ -208,11 +239,14 @@ public class CodeServiceImpl implements CodeService {
CodeAuditResultDTO codeAuditResultDTO = codeAuditResultService.getAuditResultByCodeId(formDTO.getCodeId());
//获取小程序调用令牌
AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType());
if (null == authInfo) {
throw new RenException("未授权");
}
//调用微信API获取最新审核状态
WxMaCodeAuditStatusReq request = new WxMaCodeAuditStatusReq();
request.setAuditId(codeAuditResultDTO.getAuditId());
WxResult<WxMaAuditStatusResult> wxAuditResult = wxMaCodeService.getAuditStatus(authInfo.getAuthorizerAccessToken(), request);
if (!wxAuditResult.success() ) {
if (!wxAuditResult.success()) {
throw new RenException(wxAuditResult.getErrorCode(), wxAuditResult.getErrorMsg());
}
if (wxAuditResult.getData().getStatus() != NumConstant.TWO) {
@ -248,6 +282,9 @@ public class CodeServiceImpl implements CodeService {
}
//获取小程序调用令牌
AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType());
if (null == authInfo) {
throw new RenException("未授权");
}
//调用微信API发布代码
WxResult wxResult = wxMaCodeService.release(authInfo.getAuthorizerAccessToken());
if (!wxResult.success()) {
@ -274,13 +311,15 @@ public class CodeServiceImpl implements CodeService {
if (customerMpService.getAuthFlag(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType())) {
throw new RenException("未授权");
}
//TODO 获取小程序调用令牌
AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType());
if (null == authInfo) {
throw new RenException("未授权");
}
//获取审核结果信息
CodeAuditResultDTO codeAuditResultDTO = codeAuditResultService.getAuditResultByCodeId(formDTO.getCodeId());
result.setReason(codeAuditResultDTO.getReason());
String[] mediaIds = codeAuditResultDTO.getScreenShot().split("[|]");
List<String> mediaIdList = new ArrayList<>(mediaIds.length);
List<String> mediaIdList = new ArrayList<>(mediaIds.length);
Collections.addAll(mediaIdList, mediaIds);
List<String> urlList = new ArrayList<>();
mediaIdList.forEach(mediaId -> {
@ -328,6 +367,32 @@ public class CodeServiceImpl implements CodeService {
return new PageData<>(list, pageInfo.getTotal());
}
@Override
public String mediaUpload(MediaUploadFormDTO formDTO) {
try {
File file = MultipartFileToFileUtils.multipartFileToFile(formDTO.getMedia());
//获取上传代码信息
CodeCustomerDTO codeCustomerDTO = codeCustomerService.get(formDTO.getCodeId());
//获取小程序调用令牌
AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType());
WxResult<WxMaUploadMediaResult> wxResult = wxMaCodeService.uploadMedia(authInfo.getAuthorizerAccessToken(), formDTO.getType(), file);
if (!wxResult.success()) {
throw new RenException(wxResult.getErrorCode(), wxResult.getErrorMsg());
}
//将素材信息存入数据库表中
CodeMediaDTO codeMediaDTO = new CodeMediaDTO();
codeMediaDTO.setCodeId(formDTO.getCodeId());
codeMediaDTO.setMediaId(wxResult.getData().getMediaId());
codeMediaDTO.setMediaName(formDTO.getMedia().getName());
codeMediaDTO.setMediaType(wxResult.getData().getType());
codeMediaService.save(codeMediaDTO);
return wxResult.getData().getMediaId();
} catch (Exception e) {
throw new RenException("上传失败");
}
}
private void saveOperation(String customerId, String codeId, String version, String operation, String describe) {
CodeOperationHistoryDTO operationDTO = new CodeOperationHistoryDTO();
operationDTO.setCustomerId(customerId);
@ -338,4 +403,22 @@ public class CodeServiceImpl implements CodeService {
codeOperationHistoryService.save(operationDTO);
}
/**
* 校验是否是Json
*
* @param content
* @return boolean
* @author zhaoqifeng
* @date 2020/7/17 15:43
*/
private boolean isJson(String content) {
try {
JSONObject jsonStr = JSONObject.parseObject(content);
return true;
} catch (Exception e) {
return false;
}
}
}

15
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/constant/WxMaCodeConstant.java

@ -127,4 +127,19 @@ public interface WxMaCodeConstant {
* 获取永久素材
*/
String GET_MATERIAL_URL = "https://api.weixin.qq.com/cgi-bin/material/get_material";
/**
* 设置服务器域名
*/
String MODIFY_DOMAIN_URL = "https://api.weixin.qq.com/wxa/modify_domain";
/**
* 设置业务域名
*/
String SET_WEBVIEW_DOMAIN_URL = "https://api.weixin.qq.com/wxa/setwebviewdomain";
/**
* 新增临时素材
*/
String MEDIA_UPLOAD_URL = "https://api.weixin.qq.com/wxa/setwebviewdomain";
}

44
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/param/WxMaModifyDomainReq.java

@ -0,0 +1,44 @@
package com.epmet.wxapi.param;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
/**
* @author zhaoqifeng
* @dscription
* @date 2020/7/16 17:28
*/
@NoArgsConstructor
@Data
public class WxMaModifyDomainReq implements Serializable {
private static final long serialVersionUID = 2768949609300541671L;
/**
* 操作类型
*/
private String action;
/**
* request 合法域名
*/
@SerializedName("requestdomain")
private List<String> requestDomain;
/**
* socket 合法域名
*/
@SerializedName("wsrequestdomain")
private List<String> wsRequestDomain;
/**
* uploadFile 合法域名
*/
@SerializedName("uploaddomain")
private List<String> uploadDomain;
/**
* downloadFile 合法域名
*/
@SerializedName("downloaddomain")
private List<String> downloadDomain;
}

29
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/param/WxMaSetWebviewDomainReq.java

@ -0,0 +1,29 @@
package com.epmet.wxapi.param;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
/**
* @author zhaoqifeng
* @dscription
* @date 2020/7/16 17:31
*/
@NoArgsConstructor
@Data
public class WxMaSetWebviewDomainReq implements Serializable {
private static final long serialVersionUID = 4560145267553484959L;
/**
* 操作类型
*/
private String action;
/**
* 小程序业务域名
*/
@SerializedName("webviewdomain")
private List<String> webViewDomain;
}

2
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/result/WxMaGetCategoryResult.java

@ -1,5 +1,6 @@
package com.epmet.wxapi.result;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import java.io.Serializable;
@ -24,5 +25,6 @@ public class WxMaGetCategoryResult implements Serializable {
/**
* 可填选的类目信息列表
*/
@SerializedName("category_list")
private List<WxMaCategoryResult> categoryList;
}

25
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/result/WxMaUploadMediaResult.java

@ -0,0 +1,25 @@
package com.epmet.wxapi.result;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import java.io.Serializable;
/**
* @author zhaoqifeng
* @dscription
* @date 2020/7/17 14:10
*/
@Data
public class WxMaUploadMediaResult implements Serializable {
private static final long serialVersionUID = 7258823761146570668L;
@SerializedName("errcode")
private Integer errCode = 0;
@SerializedName("errmsg")
private String errMsg;
private String type;
@SerializedName("media_id")
private String mediaId;
@SerializedName("created_at")
private String createdAt;
}

35
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/service/WxMaCodeService.java

@ -4,11 +4,9 @@ import com.epmet.wxapi.param.WxMaCodeAuditStatusReq;
import com.epmet.wxapi.param.WxMaCodeCommitReq;
import com.epmet.wxapi.param.WxMaCodeSubmitAuditRequest;
import com.epmet.wxapi.param.WxMaNewsReq;
import com.epmet.wxapi.result.WxMaAuditStatusResult;
import com.epmet.wxapi.result.WxMaNewsResult;
import com.epmet.wxapi.result.WxMaTemplateResult;
import com.epmet.wxapi.result.WxResult;
import com.epmet.wxapi.result.*;
import java.io.File;
import java.util.List;
/**
@ -114,7 +112,32 @@ public interface WxMaCodeService {
*/
WxResult<WxMaNewsResult> getMaterial(String accessToken, WxMaNewsReq request);
//TODO 设置服务器域名
/**
* 设置服务器郁闷
* @author zhaoqifeng
* @date 2020/7/16 17:21
* @param accessToken
* @return com.epmet.wxapi.result.WxResult
*/
WxResult modifyDomain(String accessToken);
/**
* 设置业务域名
* @author zhaoqifeng
* @date 2020/7/16 17:22
* @param accessToken
* @return com.epmet.wxapi.result.WxResult
*/
WxResult setWebviewDomain(String accessToken);
//TODO 设置业务域名
/**
* 上传临时素材
* @author zhaoqifeng
* @date 2020/7/17 10:27
* @param accessToken
* @param type
* @param file
* @return com.epmet.wxapi.result.WxResult
*/
WxResult<WxMaUploadMediaResult> uploadMedia(String accessToken, String type, File file);
}

109
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/service/impl/WxMaCodeServiceImpl.java

@ -4,17 +4,17 @@ import com.alibaba.fastjson.JSONObject;
import com.epmet.commons.tools.utils.HttpClientManager;
import com.epmet.commons.tools.utils.Result;
import com.epmet.wxapi.constant.WxMaCodeConstant;
import com.epmet.wxapi.param.WxMaCodeAuditStatusReq;
import com.epmet.wxapi.param.WxMaCodeCommitReq;
import com.epmet.wxapi.param.WxMaCodeSubmitAuditRequest;
import com.epmet.wxapi.param.WxMaNewsReq;
import com.epmet.wxapi.enums.WxMaErrorMsgEnum;
import com.epmet.wxapi.param.*;
import com.epmet.wxapi.result.*;
import com.epmet.wxapi.service.WxMaCodeService;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
@ -30,6 +30,16 @@ import java.util.List;
public class WxMaCodeServiceImpl implements WxMaCodeService {
private static final String ERR_CODE = "errcode";
private static final String ERR_MSG = "errmsg";
@Value("${third.domain.requestdomain}")
private List<String> requestDomain;
@Value("${third.domain.wsrequestdomain}")
private List<String> wsRequestDomain;
@Value("${third.domain.uploaddomain}")
private List<String> uploadDomain;
@Value("${third.domain.downloaddomain}")
private List<String> downloadDomain;
@Value("${third.domain.webviewdomain}")
private List<String> webviewDomain;
@Override
public WxResult<List<WxMaTemplateResult>> getTemplateList(String accessToken) {
@ -42,7 +52,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
return result;
}
Gson gson = new Gson();
WxMaTemplateListResult templateList = new Gson().fromJson(templateListResult.getData(), WxMaTemplateListResult.class);
WxMaTemplateListResult templateList = gson.fromJson(templateListResult.getData(), WxMaTemplateListResult.class);
result.setErrorCode(templateList.getErrCode());
result.setErrorMsg(templateList.getErrMsg());
result.setData(templateList.getTemplateList());
@ -61,7 +71,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
}
JSONObject jsonObject = JSONObject.parseObject(commitResult.getData());
result.setErrorCode(jsonObject.getInteger(ERR_CODE));
result.setErrorMsg(jsonObject.getString(ERR_MSG));
result.setErrorMsg(WxMaErrorMsgEnum.findMsgByCode(jsonObject.getInteger(ERR_CODE)));
return result;
}
@ -79,7 +89,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
Result<Byte[]> qrCodeResult = HttpClientManager.getInstance().sendGetFile(url.toString(), null);
if (!qrCodeResult.success()) {
result.setErrorCode(qrCodeResult.getCode());
result.setErrorMsg(qrCodeResult.getMsg());
result.setErrorMsg(WxMaErrorMsgEnum.findMsgByCode(qrCodeResult.getCode()));
return result;
}
@ -98,9 +108,10 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
result.setErrorMsg(getCategoryResult.getMsg());
return result;
}
WxMaGetCategoryResult categoryResult = JSONObject.parseObject(getCategoryResult.getData(), WxMaGetCategoryResult.class);
Gson gson = new Gson();
WxMaGetCategoryResult categoryResult = gson.fromJson(getCategoryResult.getData(), WxMaGetCategoryResult.class);
result.setErrorCode(categoryResult.getErrcode());
result.setErrorMsg(categoryResult.getErrmsg());
result.setErrorMsg(WxMaErrorMsgEnum.findMsgByCode(categoryResult.getErrcode()));
result.setData(categoryResult.getCategoryList());
return result;
}
@ -117,7 +128,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
}
WxMaGetPageResult pageResult = JSONObject.parseObject(getPageResult.getData(), WxMaGetPageResult.class);
result.setErrorCode(pageResult.getErrcode());
result.setErrorMsg(pageResult.getErrmsg());
result.setErrorMsg(WxMaErrorMsgEnum.findMsgByCode(pageResult.getErrcode()));
result.setData(pageResult.getPageList());
return result;
}
@ -134,7 +145,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
}
JSONObject jsonObject = JSONObject.parseObject(submitResult.getData());
result.setErrorCode(jsonObject.getInteger(ERR_CODE));
result.setErrorMsg(jsonObject.getString(ERR_MSG));
result.setErrorMsg(WxMaErrorMsgEnum.findMsgByCode(jsonObject.getInteger(ERR_CODE)));
result.setData(jsonObject.getString("auditid"));
return result;
}
@ -152,7 +163,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
WxMaAuditStatusResult auditStatusResult = JSONObject.parseObject(statusResult.getData(), WxMaAuditStatusResult.class);
if (!auditStatusResult.success()){
result.setErrorCode(auditStatusResult.getErrcode());
result.setErrorMsg(auditStatusResult.getErrmsg());
result.setErrorMsg(WxMaErrorMsgEnum.findMsgByCode(auditStatusResult.getErrcode()));
return result;
}
result.ok(auditStatusResult);
@ -171,7 +182,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
}
JSONObject jsonObject = JSONObject.parseObject(releaseResult.getData());
result.setErrorCode(jsonObject.getInteger(ERR_CODE));
result.setErrorMsg(jsonObject.getString(ERR_MSG));
result.setErrorMsg(WxMaErrorMsgEnum.findMsgByCode(jsonObject.getInteger(ERR_CODE)));
return result;
}
@ -187,7 +198,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
}
JSONObject jsonObject = JSONObject.parseObject(undoResult.getData());
result.setErrorCode(jsonObject.getInteger(ERR_CODE));
result.setErrorMsg(jsonObject.getString(ERR_MSG));
result.setErrorMsg(WxMaErrorMsgEnum.findMsgByCode(jsonObject.getInteger(ERR_CODE)));
return result;
}
@ -201,22 +212,68 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
result.setErrorMsg(statusResult.getMsg());
return result;
}
WxMaNewsResult newsResult = JSONObject.parseObject(statusResult.getData(), WxMaNewsResult.class);
Gson gson = new Gson();
WxMaNewsResult newsResult = gson.fromJson(statusResult.getData(), WxMaNewsResult.class);
result.ok(newsResult);
return result;
}
public static void main(String[] args) {
String url = "{\"errcode\":0,\"errmsg\":\"ok\",\"category_list\":[{\"first_class\":\"工具\",\"second_class\":\"备忘录\",\"first_id\":1,\"second_id\":2,}\n" +
"{\"first_class\":\"教育\",\"second_class\":\"学历教育\",\"third_class\":\"高等\",\"first_id\":3,\"second_id\":4,\"third_id\":5,}]}";
WxMaGetCategoryResult video = JSONObject.parseObject(url, WxMaGetCategoryResult.class);
WxResult<List<WxMaCategoryResult>> result = new WxResult<>();
result.setErrorCode(video.getErrcode());
result.setErrorMsg(video.getErrmsg());
result.setData(video.getCategoryList());
System.out.println(result);
WxMaCodeSubmitAuditRequest request = new WxMaCodeSubmitAuditRequest();
request.setVersionDesc("aasdf");
@Override
public WxResult modifyDomain(String accessToken) {
WxResult result = new WxResult();
String url = WxMaCodeConstant.MODIFY_DOMAIN_URL + "?" + "access_token=" + accessToken;
WxMaModifyDomainReq request = new WxMaModifyDomainReq();
request.setAction("set");
request.setRequestDomain(requestDomain);
request.setUploadDomain(uploadDomain);
request.setWsRequestDomain(wsRequestDomain);
request.setDownloadDomain(downloadDomain);
Result<String> modifyResult = HttpClientManager.getInstance().sendPostByJSON(url, toJson(request));
if (!modifyResult.success()) {
result.setErrorCode(modifyResult.getCode());
result.setErrorMsg(modifyResult.getMsg());
return result;
}
JSONObject jsonObject = JSONObject.parseObject(modifyResult.getData());
result.setErrorCode(jsonObject.getInteger(ERR_CODE));
result.setErrorMsg(WxMaErrorMsgEnum.findMsgByCode(jsonObject.getInteger(ERR_CODE)));
return result;
}
@Override
public WxResult setWebviewDomain(String accessToken) {
WxResult result = new WxResult();
String url = WxMaCodeConstant.SET_WEBVIEW_DOMAIN_URL + "?" + "access_token=" + accessToken;
WxMaSetWebviewDomainReq request = new WxMaSetWebviewDomainReq();
request.setAction("set");
request.setWebViewDomain(webviewDomain);
Result<String> modifyResult = HttpClientManager.getInstance().sendPostByJSON(url, toJson(request));
if (!modifyResult.success()) {
result.setErrorCode(modifyResult.getCode());
result.setErrorMsg(modifyResult.getMsg());
return result;
}
JSONObject jsonObject = JSONObject.parseObject(modifyResult.getData());
result.setErrorCode(jsonObject.getInteger(ERR_CODE));
result.setErrorMsg(WxMaErrorMsgEnum.findMsgByCode(jsonObject.getInteger(ERR_CODE)));
return result;
}
@Override
public WxResult<WxMaUploadMediaResult> uploadMedia(String accessToken, String type, File file) {
WxResult<WxMaUploadMediaResult> result = new WxResult<>();
String url = WxMaCodeConstant.MEDIA_UPLOAD_URL + "?" + "access_token=" + accessToken + "&type=" + type;
Result<String> mediaResult = HttpClientManager.getInstance().uploadWxMedia(url, file);
if (!mediaResult.success()) {
result.setErrorCode(mediaResult.getCode());
result.setErrorMsg(mediaResult.getMsg());
return result;
}
Gson gson = new Gson();
WxMaUploadMediaResult mediaInfo = gson.fromJson(mediaResult.getData(), WxMaUploadMediaResult.class);
result.setErrorCode(mediaInfo.getErrCode());
result.setErrorMsg(WxMaErrorMsgEnum.findMsgByCode(mediaInfo.getErrCode()));
return result;
}
private String toJson(Object object) {

13
epmet-module/epmet-third/epmet-third-server/src/main/resources/bootstrap.yml

@ -103,4 +103,15 @@ third:
appId: wxd63ff476314c7c3e
appSecret: 4733aa5ba6dfe0efc569ebac7c4fe56b
aesKey: d6dbde92c67e11eabac1c03fd56f7847qazxswedcvg
token: 1ae5f230c67f11eabac1c03fd56f7847
token: 1ae5f230c67f11eabac1c03fd56f7847
domain:
requestdomain:
- "https://epmet-cloud.elinkservice.cn"
wsrequestdomain:
- "https://epmet-cloud.elinkservice.cn"
uploaddomain:
- "https://epmet-cloud.elinkservice.cn"
downloaddomain:
- "https://epmet-cloud.elinkservice.cn"
webviewdomain:
- "https://epmet-cloud.elinkservice.cn"

41
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/CodeExtDao.xml

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.epmet.dao.CodeExtDao">
<resultMap type="com.epmet.entity.CodeExtEntity" id="codeExtMap">
<result property="id" column="ID"/>
<result property="customerId" column="CUSTOMER_ID"/>
<result property="clientType" column="CLIENT_TYPE"/>
<result property="appId" column="APP_ID"/>
<result property="extJson" column="EXT_JSON"/>
<result property="revision" column="REVISION"/>
<result property="delFlag" column="DEL_FLAG"/>
<result property="createdBy" column="CREATED_BY"/>
<result property="createdTime" column="CREATED_TIME"/>
<result property="updatedBy" column="UPDATED_BY"/>
<result property="updatedTime" column="UPDATED_TIME"/>
</resultMap>
<select id="selectExtTemplate" resultType="java.lang.String">
SELECT
EXT_JSON
FROM
code_ext
WHERE
DEL_FLAG = '0'
AND CUSTOMER_ID = '*'
AND CLIENT_TYPE = #{clientType}
</select>
<select id="selectExtByCustomerId" resultType="com.epmet.dto.CodeExtDTO">
SELECT
*
FROM
code_ext
WHERE
DEL_FLAG = '0'
AND CUSTOMER_ID = #{customerId}
AND CLIENT_TYPE = #{clientType}
</select>
</mapper>
Loading…
Cancel
Save