diff --git a/mallinkService/src/main/java/com/iformall/service/WxAuthorizerInfoService.java b/mallinkService/src/main/java/com/iformall/service/WxAuthorizerInfoService.java index cfb41ef75..6faaf948f 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxAuthorizerInfoService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxAuthorizerInfoService.java @@ -64,12 +64,16 @@ public interface WxAuthorizerInfoService { * @param id */ void deleteById(Long id); - - - - - - + + void updateReleaseVersion(WxAuthorizerInfo record); + + void updateBaseVersion(WxAuthorizerInfo record); + + void updateDomainUrl(WxAuthorizerInfo record); + + void updateWebDomainUrl(WxAuthorizerInfo record); + + void updateTemplate(WxAuthorizerInfo record); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxAuthorizerInfoServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxAuthorizerInfoServiceImpl.java index afdf20478..8c54ccb5d 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxAuthorizerInfoServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxAuthorizerInfoServiceImpl.java @@ -116,8 +116,55 @@ public class WxAuthorizerInfoServiceImpl implements WxAuthorizerInfoService { public void deleteById(Long id) { authorizerInfoMapper.deleteByPrimaryKey(id); } - - + + @Override + public void updateReleaseVersion(WxAuthorizerInfo record) { + authorizerInfoMapper.updateReleaseInfo(record); + } + + @Override + public void updateBaseVersion(WxAuthorizerInfo record) { + Date curDate = new Date(); + WxAuthorizerInfo info = new WxAuthorizerInfo(); + info.setId(record.getId()); + info.setBaseStatus(record.getBaseStatus()); + info.setBaseTime(curDate); + info.setUpdateTime(curDate); + authorizerInfoMapper.updateByPrimaryKeySelective(record); + } + + @Override + public void updateDomainUrl(WxAuthorizerInfo record) { + Date curDate = new Date(); + WxAuthorizerInfo info = new WxAuthorizerInfo(); + info.setId(record.getId()); + info.setDomainStatus(record.getDomainStatus()); + info.setDomainTime(curDate); + info.setUpdateTime(curDate); + authorizerInfoMapper.updateByPrimaryKeySelective(record); + } + + @Override + public void updateWebDomainUrl(WxAuthorizerInfo record) { + Date curDate = new Date(); + WxAuthorizerInfo info = new WxAuthorizerInfo(); + info.setId(record.getId()); + info.setWebdomainStatus(record.getWebdomainStatus()); + info.setWebdomainTime(curDate); + info.setUpdateTime(curDate); + authorizerInfoMapper.updateByPrimaryKeySelective(record); + } + + @Override + public void updateTemplate(WxAuthorizerInfo record) { + Date curDate = new Date(); + WxAuthorizerInfo info = new WxAuthorizerInfo(); + info.setId(record.getId()); + info.setTemplateStatus(record.getTemplateStatus()); + info.setTemplateTime(curDate); + info.setUpdateTime(curDate); + authorizerInfoMapper.updateByPrimaryKeySelective(record); + } diff --git a/mallinkWechatOpen/src/main/java/com/iformall/controller/WechatWeappMsgTemplateController.java b/mallinkWechatOpen/src/main/java/com/iformall/controller/WechatWeappMsgTemplateController.java index b62b9a5c1..16e663cbb 100644 --- a/mallinkWechatOpen/src/main/java/com/iformall/controller/WechatWeappMsgTemplateController.java +++ b/mallinkWechatOpen/src/main/java/com/iformall/controller/WechatWeappMsgTemplateController.java @@ -5,8 +5,12 @@ import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateAddResult; import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateLibraryGetResult; import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateLibraryListResult; import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateListResult; +import com.iformall.common.ErrorCode; import com.iformall.common.Result; import com.iformall.common.ResultData; +import com.iformall.domain.po.WxAuthorizerInfo; +import com.iformall.enums.EnumWxAuthorizationStatus; +import com.iformall.service.WxAuthorizerInfoService; import com.iformall.service.wechat.WxOpenService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -18,6 +22,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.Date; import java.util.List; /** @@ -31,6 +36,9 @@ public class WechatWeappMsgTemplateController { @Autowired private WxOpenService openService; + @Autowired + private WxAuthorizerInfoService authorizerInfoService; + @ApiOperation("获取小程序模板库标题列表") @GetMapping("getTmpLibList") @ApiImplicitParams({ @@ -67,16 +75,28 @@ public class WechatWeappMsgTemplateController { @ApiOperation("组合模板并添加至帐号下的个人模板库") @PostMapping("addTemplate") - public ResultData addTemplate( - @RequestParam(value = "appId") String appId, - @RequestParam(value = "id") String id, - @RequestParam(value = "keywordIdList")List keywordIdList) { + public ResultData addTemplate(String appId, String id, List keywordIdList) { + WxAuthorizerInfo authorizerInfo = authorizerInfoService.getByAppId(appId); + if(authorizerInfo == null) { + return new ResultData(ErrorCode.WEAPP_APPID_NOT_AUTH); + } + if(authorizerInfo.getAuthorizationStatus().equals(EnumWxAuthorizationStatus.AUTHORIZED.getCode())) { + return new ResultData(ErrorCode.WEAPP_APPID_NOT_AUTH); + } try { WxMaService maService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); WxMaTemplateAddResult ret = maService.getTemplateService().addTemplate(id, keywordIdList); + authorizerInfo.setTemplateStatus(0); + authorizerInfo.setTemplateTime(new Date()); + authorizerInfo.setUpdateTime(new Date()); + authorizerInfoService.updateTemplate(authorizerInfo); return new ResultData(ret); } catch (WxErrorException e) { logger.error(e.getMessage()); + authorizerInfo.setTemplateStatus(1); + authorizerInfo.setTemplateTime(new Date()); + authorizerInfo.setUpdateTime(new Date()); + authorizerInfoService.updateTemplate(authorizerInfo); return new ResultData(Result.ERROR, e.getMessage()); } diff --git a/mallinkWechatOpen/src/main/java/com/iformall/controller/WechatWeappSetController.java b/mallinkWechatOpen/src/main/java/com/iformall/controller/WechatWeappSetController.java index 972d3210d..5424ff539 100644 --- a/mallinkWechatOpen/src/main/java/com/iformall/controller/WechatWeappSetController.java +++ b/mallinkWechatOpen/src/main/java/com/iformall/controller/WechatWeappSetController.java @@ -1,8 +1,13 @@ package com.iformall.controller; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.iformall.common.ErrorCode; import com.iformall.common.Result; import com.iformall.common.ResultData; +import com.iformall.domain.po.WxAuthorizerInfo; +import com.iformall.enums.EnumWxAuthorizationStatus; +import com.iformall.service.WxAuthorizerInfoService; import com.iformall.service.wechat.WxOpenService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -15,6 +20,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.Date; import java.util.List; import java.util.Map; @@ -29,6 +35,9 @@ public class WechatWeappSetController { @Autowired private WxOpenService openService; + @Autowired + private WxAuthorizerInfoService authorizerInfoService; + @ApiOperation("获取小程序的信息") @GetMapping("/getInfo") public ResultData getAccountBasicInfo(String appId) { @@ -83,12 +92,32 @@ public class WechatWeappSetController { public ResultData modifyDomain(String appId, String action, List requestDomain, List wsrequestdomain, List uploaddomain, List downloaddomain) { + WxAuthorizerInfo authorizerInfo = authorizerInfoService.getByAppId(appId); + if(authorizerInfo == null) { + return new ResultData(ErrorCode.WEAPP_APPID_NOT_AUTH); + } + if(authorizerInfo.getAuthorizationStatus().equals(EnumWxAuthorizationStatus.AUTHORIZED.getCode())) { + return new ResultData(ErrorCode.WEAPP_APPID_NOT_AUTH); + } try { WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); WxOpenMaDomainResult openRet = openMaService.modifyDomain(action, requestDomain, wsrequestdomain, uploaddomain, downloaddomain); logger.info(openRet.toString()); + if(openRet.isSuccess()) { + logger.info("设置服务器域名成功"); + authorizerInfo.setDomainStatus(0); + authorizerInfo.setDomainTime(new Date()); + authorizerInfo.setUpdateTime(new Date()); + + } else { + logger.info("设置服务器域名成功"); + authorizerInfo.setDomainStatus(1); + authorizerInfo.setDomainTime(new Date()); + authorizerInfo.setUpdateTime(new Date()); + } + authorizerInfoService.updateDomainUrl(authorizerInfo); return new ResultData(openRet); } catch (WxErrorException e) { logger.error(e.getMessage()); @@ -103,10 +132,30 @@ public class WechatWeappSetController { @PostMapping("/modifyWebViewDomain") public ResultData modifyWebViewDomain(String appId, String action, List urlList) { + WxAuthorizerInfo authorizerInfo = authorizerInfoService.getByAppId(appId); + if(authorizerInfo == null) { + return new ResultData(ErrorCode.WEAPP_APPID_NOT_AUTH); + } + if(authorizerInfo.getAuthorizationStatus().equals(EnumWxAuthorizationStatus.AUTHORIZED.getCode())) { + return new ResultData(ErrorCode.WEAPP_APPID_NOT_AUTH); + } try { WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); String openRet = openMaService.setWebViewDomain(action, urlList); logger.info(openRet); + JSONObject webRetObj = JSON.parseObject(openRet); + if(webRetObj.getInteger("errcode").equals(0)) { + logger.info("设置服务器业务域名成功"); + authorizerInfo.setWebdomainStatus(0); + authorizerInfo.setWebdomainTime(new Date()); + authorizerInfo.setUpdateTime(new Date()); + } else { + logger.info("设置服务器业务域名失败"); + authorizerInfo.setWebdomainStatus(1); + authorizerInfo.setWebdomainTime(new Date()); + authorizerInfo.setUpdateTime(new Date()); + } + authorizerInfoService.updateWebDomainUrl(authorizerInfo); return new ResultData(openRet); } catch (WxErrorException e) { logger.error(e.getMessage()); @@ -122,6 +171,13 @@ public class WechatWeappSetController { if(StringUtils.isBlank(appId)) { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "appId不能为空"); } + WxAuthorizerInfo authorizerInfo = authorizerInfoService.getByAppId(appId); + if(authorizerInfo == null) { + return new ResultData(ErrorCode.WEAPP_APPID_NOT_AUTH); + } + if(authorizerInfo.getAuthorizationStatus().equals(EnumWxAuthorizationStatus.AUTHORIZED.getCode())) { + return new ResultData(ErrorCode.WEAPP_APPID_NOT_AUTH); + } if(StringUtils.isBlank(wechatId)) { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "wechatId不能为空"); } diff --git a/mallinkWechatOpen/src/main/java/com/iformall/controller/WxWeappInfoController.java b/mallinkWechatOpen/src/main/java/com/iformall/controller/WxWeappInfoController.java index d54700e69..17144bb6a 100644 --- a/mallinkWechatOpen/src/main/java/com/iformall/controller/WxWeappInfoController.java +++ b/mallinkWechatOpen/src/main/java/com/iformall/controller/WxWeappInfoController.java @@ -158,10 +158,25 @@ public class WxWeappInfoController extends BaseController { } private ResultData setBasicForAppId(String appId, WxWeappBasicSet weappBasicSet, JSONObject domainObj, JSONObject templeObj) { + WxAuthorizerInfo authorizerInfo = authorizerInfoService.getByAppId(appId); + if(authorizerInfo == null) { + return new ResultData(ErrorCode.WEAPP_APPID_NOT_AUTH); + } try { WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); // 设置基础版本 - openMaService.setSupportVersion(weappBasicSet.getVersion()); + String versionRet = openMaService.setSupportVersion(weappBasicSet.getVersion()); + logger.info(versionRet); + JSONObject verObj = JSON.parseObject(versionRet); + if(verObj.getInteger("errcode").equals(0)) { + authorizerInfo.setBaseStatus(0); + } else { + authorizerInfo.setBaseStatus(1); + } + authorizerInfo.setBaseTime(new Date()); + authorizerInfo.setUpdateTime(new Date()); + authorizerInfoService.updateBaseVersion(authorizerInfo); + // 服务器域名 String action = "set"; JSONObject urlObj = domainObj.getJSONObject("url"); @@ -175,18 +190,40 @@ public class WxWeappInfoController extends BaseController { logger.info(openRet.toString()); if(openRet.isSuccess()) { logger.info("设置服务器域名成功"); + authorizerInfo.setDomainStatus(0); + authorizerInfo.setDomainTime(new Date()); + authorizerInfo.setUpdateTime(new Date()); + + } else { + logger.info("设置服务器域名成功"); + authorizerInfo.setDomainStatus(1); + authorizerInfo.setDomainTime(new Date()); + authorizerInfo.setUpdateTime(new Date()); } + authorizerInfoService.updateDomainUrl(authorizerInfo); // 业务域名 JSONObject webObj = domainObj.getJSONObject("web"); List urlList = getUrlList(webObj.getJSONArray("webviewdomain")); String openRet1 = openMaService.setWebViewDomain(action, urlList); logger.info(openRet1); + JSONObject webRetObj = JSON.parseObject(openRet1); + if(webRetObj.getInteger("errcode").equals(0)) { + logger.info("设置服务器业务域名成功"); + authorizerInfo.setWebdomainStatus(0); + authorizerInfo.setWebdomainTime(new Date()); + authorizerInfo.setUpdateTime(new Date()); + } else { + logger.info("设置服务器业务域名失败"); + authorizerInfo.setWebdomainStatus(1); + authorizerInfo.setWebdomainTime(new Date()); + authorizerInfo.setUpdateTime(new Date()); + } + authorizerInfoService.updateWebDomainUrl(authorizerInfo); } catch (WxErrorException e) { logger.error(e.getMessage()); return new ResultData(Result.ERROR, e.getMessage()); } - // 设置微信模板 if(weappBasicSet.getType().equals(EnumAppType.C.getCode())) { WxAppinfo appinfo = appinfoService.getByAppId(appId); @@ -230,8 +267,19 @@ public class WxWeappInfoController extends BaseController { templateMsgService.saveOrUpdate(templateMsgQ); } } + + // 更新状态 + authorizerInfo.setTemplateStatus(0); + authorizerInfo.setTemplateTime(new Date()); + authorizerInfo.setUpdateTime(new Date()); + authorizerInfoService.updateTemplate(authorizerInfo); } catch (WxErrorException e) { logger.error(e.getMessage()); + // 更新状态 + authorizerInfo.setTemplateStatus(1); + authorizerInfo.setTemplateTime(new Date()); + authorizerInfo.setUpdateTime(new Date()); + authorizerInfoService.updateTemplate(authorizerInfo); return new ResultData(Result.ERROR, e.getMessage()); } }