Browse Source

微信第三方平台-类型转换修改

dev_shibei_match
zxc 5 years ago
parent
commit
15f45579df
  1. 10
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/AppLetAuthorizationServiceImpl.java
  2. 40
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java
  3. 7
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java

10
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/AppLetAuthorizationServiceImpl.java

@ -5,12 +5,12 @@ import com.alibaba.fastjson.JSONObject;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.HttpClientManager;
import com.epmet.constant.ModuleConstant;
import com.epmet.dao.BindingAccountDao;
import com.epmet.dao.CustomerMpDao;
import com.epmet.dao.OpenPlatformAccountDao;
import com.epmet.dao.PaCustomerAgencyDao;
import com.epmet.dto.form.GoToAuthFormDTO;
import com.epmet.dto.form.OpenAppIdFormDTO;
import com.epmet.dto.form.RemoveBindFormDTO;
@ -35,13 +35,9 @@ import java.util.Map;
@Service
public class AppLetAuthorizationServiceImpl implements AppLetAuthorizationService {
@Autowired
private PaCustomerAgencyDao paCustomerAgencyDao;
@Autowired
private ComponentVerifyTicketService componentVerifyTicketService;
@Autowired
private ComponentVerifyTicketServiceImpl componentVerifyTicketServiceImpl;
@Autowired
private OpenPlatformAccountDao openPlatformAccountDao;
@Autowired
private CustomerMpDao customerMpDao;
@ -85,7 +81,7 @@ public class AppLetAuthorizationServiceImpl implements AppLetAuthorizationServic
//查询appId
String authAppId = customerMpDao.getAppId(customerId, clientType);
Map<String, Object> authInfo = redisThird.getAuthInfo(customerId, clientType);
AuthorizationInfoResultDTO authorizationInfo = componentVerifyTicketServiceImpl.mapToEntity(authInfo, AuthorizationInfoResultDTO.class);
AuthorizationInfoResultDTO authorizationInfo = ConvertUtils.mapToEntity(authInfo, AuthorizationInfoResultDTO.class);
JSONObject jsonObject = new JSONObject();
jsonObject.put(ModuleConstant.LOW_APP_ID,authAppId);
jsonObject.put(ModuleConstant.OPEN_APP_ID,openAppId);
@ -110,7 +106,7 @@ public class AppLetAuthorizationServiceImpl implements AppLetAuthorizationServic
String clientType = formDTO.getClientType();
String authAppId = customerMpDao.getAppId(customerId, clientType);
Map<String, Object> authInfo = redisThird.getAuthInfo(customerId, clientType);
AuthorizationInfoResultDTO authorizationInfo = componentVerifyTicketServiceImpl.mapToEntity(authInfo, AuthorizationInfoResultDTO.class);
AuthorizationInfoResultDTO authorizationInfo = ConvertUtils.mapToEntity(authInfo, AuthorizationInfoResultDTO.class);
JSONObject jsonObject = new JSONObject();
jsonObject.put(ModuleConstant.LOW_APP_ID,authAppId);
String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.UN_BIND + authorizationInfo.getAuthorizer_access_token(), JSON.toJSONString(jsonObject)).getData();

40
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java

@ -6,6 +6,7 @@ import com.alibaba.nacos.client.config.utils.IOUtils;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.HttpClientManager;
import com.epmet.constant.ModuleConstant;
import com.epmet.constant.ThirdRedisKeyConstant;
@ -31,7 +32,6 @@ import org.springframework.web.bind.annotation.RequestBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.*;
import static com.epmet.constant.ModuleConstant.COMPONENT_ACCESS_TOKEN;
@ -175,7 +175,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
public void disposeAuthResult(Map<String,String> result){
Map tempMap = result;
Map<String,Object> data = tempMap;
AuthResultRecordFormDTO authResultRecord = mapToEntity(data, AuthResultRecordFormDTO.class);
AuthResultRecordFormDTO authResultRecord = ConvertUtils.mapToEntity(data, AuthResultRecordFormDTO.class);
authResultRecord.setWechatCreateTime(this.sToDate(result.get(ModuleConstant.CREATE_TIME)));
if (result.containsKey(ModuleConstant.AUTHORIZATION_CODE_EXPIRED_TIME)) {
authResultRecord.setExpiredTime(this.sToDate(result.get(ModuleConstant.AUTHORIZATION_CODE_EXPIRED_TIME)));
@ -285,7 +285,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
String authInfo = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_QUERY_AUTH_URL + accessToken, JSON.toJSONString(jsonObject)).getData();
HashMap<String,Map> hashMap = JSON.parseObject(authInfo, HashMap.class);
Map map = hashMap.get(ModuleConstant.AUTHORIZATION_INFO);
authorizationInfoResultDTO = mapToEntity(map, AuthorizationInfoResultDTO.class);
authorizationInfoResultDTO = ConvertUtils.mapToEntity(map, AuthorizationInfoResultDTO.class);
String authAppId = authorizationInfoResultDTO.getAuthorizer_appid();
log.info("授权信息:"+map);
String expiresIn = authorizationInfoResultDTO.getExpires_in().toString();
@ -433,7 +433,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
boolean keyExist = authorizerInfo.containsKey(ModuleConstant.MINI_PROGRAM_INFO);
if (keyExist == true){
log.info("授权方为小程序 并 开始插入信息");
MiniInfoFormDTO miniInfoFormDTO = this.mapToEntity(authorizerInfo, MiniInfoFormDTO.class);
MiniInfoFormDTO miniInfoFormDTO = ConvertUtils.mapToEntity(authorizerInfo, MiniInfoFormDTO.class);
miniInfoFormDTO.setCustomerId(customerId);
miniInfoFormDTO.setClientType(clientType);
//基础信息插入
@ -485,7 +485,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
}
}else {
log.info("授权方为公众号 并 开始插入信息");
PaInfoFormDTO paInfoFormDTO = this.mapToEntity(authorizerInfo, PaInfoFormDTO.class);
PaInfoFormDTO paInfoFormDTO = ConvertUtils.mapToEntity(authorizerInfo, PaInfoFormDTO.class);
//公众号基本信息插入
paInfoDao.insertPaInfo(paInfoFormDTO);
String primaryId = paInfoFormDTO.getId();
@ -611,36 +611,6 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
}
}
/**
* @Description map Entity
* @param map
* @param entity
* @author zxc
*/
public <T> T mapToEntity(Map<String, Object> map, Class<T> entity) {
T t = null;
try {
t = entity.newInstance();
for(Field field : entity.getDeclaredFields()) {
if (map.containsKey(field.getName())) {
boolean flag = field.isAccessible();
field.setAccessible(true);
Object object = map.get(field.getName());
if (object!= null && field.getType().isAssignableFrom(object.getClass())) {
field.set(t, object);
}
field.setAccessible(flag);
}
}
return t;
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return t;
}
/**
* @Description 转换过期时间
* @param expiresIn

7
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java

@ -1,6 +1,7 @@
package com.epmet.service.impl;
import com.alibaba.nacos.client.config.utils.IOUtils;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.constant.ModuleConstant;
import com.epmet.constant.ThirdRunTimeInfoConstant;
import com.epmet.dao.*;
@ -44,8 +45,6 @@ public class WarrantServiceImpl implements WarrantService {
@Value("${third.platform.token}")
private String token;
@Autowired
private ComponentVerifyTicketServiceImpl componentVerifyTicketService;
@Autowired
private CodeAuditRecordDao codeAuditRecordDao;
@Autowired
private MiniInfoDao miniInfoDao;
@ -96,7 +95,7 @@ public class WarrantServiceImpl implements WarrantService {
if (xml.get(ModuleConstant.MSG_TYPE).equals(ModuleConstant.EVENT_LOW)) {
// TODO 目前来看,msgType = ‘event’ 的是代码审核结果
Long createTime = Long.valueOf(xml.get(ModuleConstant.CREATE_TIME).toString());
CodeAuditRecordFormDTO codeAuditRecord = componentVerifyTicketService.mapToEntity(xml, CodeAuditRecordFormDTO.class);
CodeAuditRecordFormDTO codeAuditRecord = ConvertUtils.mapToEntity(xml, CodeAuditRecordFormDTO.class);
codeAuditRecord.setWechatCreateTime(componentVerifyTicketServiceImpl.sToDate(createTime.toString()));
String toUserName = codeAuditRecord.getToUserName();//小程序原始ID
CustomerIdAndClientResultDTO customerIdAndClientResultDTO = miniInfoDao.selectCustomerIdAndClientByToUserName(toUserName);
@ -130,7 +129,7 @@ public class WarrantServiceImpl implements WarrantService {
codeAuditResultDao.updateAuditResult(customerId, codeCustomerId, codeResult);
}else if (xml.get(ModuleConstant.MSG_TYPE).equals(ModuleConstant.TEXT)){
// TODO 公众号回复消息
MessagePushTextFormDTO messagePushTextFormDTO = componentVerifyTicketService.mapToEntity(xml, MessagePushTextFormDTO.class);
MessagePushTextFormDTO messagePushTextFormDTO = ConvertUtils.mapToEntity(xml, MessagePushTextFormDTO.class);
Object createTime = xml.get(ModuleConstant.CREATE_TIME);
Date date = componentVerifyTicketServiceImpl.sToDate(createTime.toString());
messagePushTextFormDTO.setWeChatCreateTime(date);

Loading…
Cancel
Save