| @@ -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); | |||
| } | |||
| @@ -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); | |||
| } | |||
| @@ -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<Integer> keywordIdList) { | |||
| public ResultData addTemplate(String appId, String id, List<Integer> 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()); | |||
| } | |||
| @@ -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<String> requestDomain, List<String> wsrequestdomain, | |||
| List<String> uploaddomain, List<String> 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<String> 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不能为空"); | |||
| } | |||
| @@ -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<String> 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()); | |||
| } | |||
| } | |||