From c5f5d548df5d7416779bb0645b7f6436edb3bf08 Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Wed, 20 Feb 2019 10:55:42 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=BE=AE=E4=BF=A1=E5=BC=80=E5=8F=91=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0][=E4=BF=AE=E6=94=B9]:=E9=83=A8=E7=BD=B2=E5=8C=BA?= =?UTF-8?q?=E5=88=AB=EF=BC=8C=E6=9C=AA=E6=8E=88=E6=9D=83=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/iformall/common/ErrorCode.java | 5 ++ .../service/WxAuthorizerInfoService.java | 8 +++ .../impl/WxAuthorizerInfoServiceImpl.java | 14 +++++ .../com/iformall/WechatOpenApplication.java | 8 +++ .../controller/WechatWeappCodeController.java | 62 ++++++++++++++++++- .../controller/WxWeappInfoController.java | 34 ++++++---- .../src/main/resources/application-dev.yml | 1 + .../src/main/resources/application-prod.yml | 1 + .../src/main/resources/application-test.yml | 1 + 9 files changed, 121 insertions(+), 13 deletions(-) diff --git a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java index 6abbd47dd..de815705a 100644 --- a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java +++ b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java @@ -336,6 +336,11 @@ public enum ErrorCode{ SHOP_IS_RENT(22001,"商铺已出租"), WIWIDE_INFO_NOT_FOUND(23001,"迈外迪信息未找到"), + + /** + * 微信第三方 + */ + APP_NOT_AUTH(24000, "app未授权"), ; private int code; diff --git a/mallinkService/src/main/java/com/iformall/service/WxAuthorizerInfoService.java b/mallinkService/src/main/java/com/iformall/service/WxAuthorizerInfoService.java index b2d3c3652..cfb41ef75 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxAuthorizerInfoService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxAuthorizerInfoService.java @@ -42,6 +42,14 @@ public interface WxAuthorizerInfoService { * @return */ WxAuthorizerInfo getById(Long id); + + /** + * 根据appId获得实体 + * + * @param appId + * @return + */ + WxAuthorizerInfo getByAppId(String appId); /** * 保存或更新实体 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 1d9026202..afdf20478 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxAuthorizerInfoServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxAuthorizerInfoServiceImpl.java @@ -53,10 +53,24 @@ public class WxAuthorizerInfoServiceImpl implements WxAuthorizerInfoService { return authorizerInfoMapper.selectByPrimaryKey(id); } + @Override + public WxAuthorizerInfo getByAppId(String appId) { + WxAuthorizerInfo authQ = new WxAuthorizerInfo(); + authQ.setAuthorizerAppid(appId); + try { + WxAuthorizerInfo authorizerInfo = authorizerInfoMapper.selectOne(authQ); + return authorizerInfo; + } catch (Exception e) { + logger.error(e.getMessage()); + } + return null; + } + @Override public void saveOrUpdate(WxAuthorizerInfo record) { // 1. 添加到wx_authorizer_info表中 // 2. 同时在wx_weapp_ext_set中添加一条记录 + // 3. 同时在wx_weapp_code_status中添加一条记录 Date curDate = new Date(); logger.info(record.toString()); WxAuthorizerInfo authorizerInfo = null; diff --git a/mallinkWechatOpen/src/main/java/com/iformall/WechatOpenApplication.java b/mallinkWechatOpen/src/main/java/com/iformall/WechatOpenApplication.java index 65f505c8a..18a87a75f 100644 --- a/mallinkWechatOpen/src/main/java/com/iformall/WechatOpenApplication.java +++ b/mallinkWechatOpen/src/main/java/com/iformall/WechatOpenApplication.java @@ -1,6 +1,7 @@ package com.iformall; import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; +import io.swagger.models.auth.In; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -26,6 +27,13 @@ public class WechatOpenApplication { return fmException; } + @Value("${fm.delay}") + private Integer fmDelay; + + @Bean + public Integer getFmDelay() { return fmDelay; } + + public static void main(String[] args) { SpringApplication.run(WechatOpenApplication.class, args); diff --git a/mallinkWechatOpen/src/main/java/com/iformall/controller/WechatWeappCodeController.java b/mallinkWechatOpen/src/main/java/com/iformall/controller/WechatWeappCodeController.java index a617d9927..2bebceb6c 100644 --- a/mallinkWechatOpen/src/main/java/com/iformall/controller/WechatWeappCodeController.java +++ b/mallinkWechatOpen/src/main/java/com/iformall/controller/WechatWeappCodeController.java @@ -4,11 +4,18 @@ import com.alibaba.fastjson.JSON; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; +import com.iformall.common.ErrorCode; import com.iformall.common.Result; import com.iformall.common.ResultData; +import com.iformall.domain.po.WxAppinfo; +import com.iformall.domain.po.WxAuthorizerInfo; import com.iformall.domain.po.WxWeappCodeStatus; import com.iformall.enums.EnumWeappAuditStatus; +import com.iformall.enums.EnumWeappCodeCommitStatus; import com.iformall.enums.EnumWeappReleaseStatus; +import com.iformall.enums.EnumWxAuthorizationStatus; +import com.iformall.service.WxAppinfoService; +import com.iformall.service.WxAuthorizerInfoService; import com.iformall.service.WxWeappCodeStatusService; import com.iformall.service.wechat.WxOpenService; import io.swagger.annotations.Api; @@ -31,6 +38,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URLEncoder; +import java.util.Date; import java.util.Map; /** @@ -47,16 +55,66 @@ public class WechatWeappCodeController { @Autowired private WxWeappCodeStatusService weappCodeStatusService; + @Autowired + private WxAppinfoService appinfoService; + + @Autowired + private WxAuthorizerInfoService authorizerInfoService; + @ApiOperation(value = "为授权的小程序帐号上传小程序代码", notes = "extInfo参考https://mp.weixin.qq.com/debug/wxadoc/dev/framework/config.html") @PostMapping("/codeCommit") public ResultData codeCommit(Long templateId, String userVersion, String userDesc, String extInfoStr) { try { Gson gson= new GsonBuilder().create(); WxMaOpenCommitExtInfo extInfo = gson.fromJson(extInfoStr, new TypeToken() { }.getType()); - WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(extInfo.getExtAppid()); + String appId = extInfo.getExtAppid(); + // 检查appId是否已授权 + WxAuthorizerInfo authorizerInfo = authorizerInfoService.getByAppId(appId); + if(authorizerInfo == null) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "扩展设置中appId未设置"); + } + if(!authorizerInfo.getAuthorizationStatus().equals(EnumWxAuthorizationStatus.AUTHORIZED.getCode())) { + return new ResultData(ErrorCode.APP_NOT_AUTH); + } + // code提交 + WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); logger.info(extInfo.toString()); WxOpenResult openRet = openMaService.codeCommit(templateId, userVersion, userDesc, extInfo); logger.info(openRet.toString()); + boolean codeCommitStatus = false; + if (openRet.isSuccess()) { + codeCommitStatus = true; + } + WxWeappCodeStatus codeStatus = weappCodeStatusService.getByAppId(appId); + if (codeStatus == null) { + WxAppinfo appinfo = appinfoService.getByAppId(appId); + codeStatus = new WxWeappCodeStatus(); + codeStatus.setAppId(appId); + if (appinfo != null) { + codeStatus.setType(appinfo.getType()); + } + codeStatus.setUserVersion(userVersion); + codeStatus.setVersionDesc(userDesc); + if(codeCommitStatus) { + codeStatus.setCodeStatus(EnumWeappCodeCommitStatus.SUCCESS.getCode()); + } else { + codeStatus.setCodeStatus(EnumWeappCodeCommitStatus.FAIL.getCode()); + } + codeStatus.setCodeErrCode(Integer.valueOf(openRet.getErrcode())); + codeStatus.setCodeTime(new Date()); + weappCodeStatusService.saveOrUpdate(codeStatus); + } else { + codeStatus.setUserVersion(userVersion); + codeStatus.setVersionDesc(userDesc); + if(codeCommitStatus) { + codeStatus.setCodeStatus(EnumWeappCodeCommitStatus.SUCCESS.getCode()); + } else { + codeStatus.setCodeStatus(EnumWeappCodeCommitStatus.FAIL.getCode()); + } + codeStatus.setCodeErrCode(Integer.valueOf(openRet.getErrcode())); + codeStatus.setCodeTime(new Date()); + weappCodeStatusService.updateCodeCommitStatus(codeStatus); + } return new ResultData(openRet); } catch (WxErrorException e) { logger.error(e.getMessage()); @@ -200,7 +258,7 @@ public class WechatWeappCodeController { } @ApiOperation("发布已通过审核的小程序") - @PostMapping("/releaesAudited") + @PostMapping("/releaseAudited") public ResultData releaesAudited(String appId) { try { WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); diff --git a/mallinkWechatOpen/src/main/java/com/iformall/controller/WxWeappInfoController.java b/mallinkWechatOpen/src/main/java/com/iformall/controller/WxWeappInfoController.java index e46afe6b4..23df8e78f 100644 --- a/mallinkWechatOpen/src/main/java/com/iformall/controller/WxWeappInfoController.java +++ b/mallinkWechatOpen/src/main/java/com/iformall/controller/WxWeappInfoController.java @@ -48,6 +48,9 @@ import java.util.*; public class WxWeappInfoController extends BaseController { private final Logger logger = LoggerFactory.getLogger(getClass()); + @Autowired + private Integer getFmDelay; + @Autowired private WxAuthorizerInfoService authorizerInfoService; @@ -93,28 +96,23 @@ public class WxWeappInfoController extends BaseController { return new ResultData(list); } - @ApiOperation(value = "APPs基础设置(服务器域名、业务域名、基础版本、微信模板)", notes = "{\"apps\":\"appid,appid\",\"type\":\"String\",\"deploy\":\"String\"}") + @ApiOperation(value = "APPs基础设置(服务器域名、业务域名、基础版本、微信模板)", notes = "{\"apps\":\"appid,appid\",\"type\":\"String\"}") @PostMapping("batchBasicSet") public ResultData batchSet(@RequestBody Map params) { logger.debug("[" + getIpAddr() + "] WxWeappInfoController::batchBasicSet"); String appsStr = params.get("apps"); String typeStr = params.get("type"); - String deployStr = params.get("deploy"); - Integer type = 0, deploy = 0; + Integer type = 0; try { type = Integer.parseInt(typeStr); } catch (Exception e) { return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); } - try { - deploy = Integer.parseInt(deployStr); - } catch (Exception e) { - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); - } + // 检查基础配置参数 WxWeappBasicSet weappBasicSetQ = new WxWeappBasicSet(); weappBasicSetQ.setType(type); - weappBasicSetQ.setDeploy(deploy); + weappBasicSetQ.setDeploy(getFmDelay); WxWeappBasicSet weappBasicSet = weappBasicSetService.getByTypeAndDeploy(weappBasicSetQ); if(weappBasicSet == null) { logger.error("未找到相关的基础设置参数"); @@ -131,11 +129,17 @@ public class WxWeappInfoController extends BaseController { // 逐一设置app配置 String [] apps = appsStr.split(","); for(String appId: apps) { + // 检查appId是否已授权 + WxAuthorizerInfo authorizerInfo = authorizerInfoService.getByAppId(appId); + if(authorizerInfo == null) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); + } + if(!authorizerInfo.getAuthorizationStatus().equals(EnumWxAuthorizationStatus.AUTHORIZED.getCode())) { + return new ResultData(ErrorCode.APP_NOT_AUTH); + } ResultData openRet = setBasicForAppId(appId, weappBasicSet, domainObj, templeObj); if (openRet != null) return openRet; } - - return new ResultData(); } @@ -266,6 +270,14 @@ public class WxWeappInfoController extends BaseController { } // 逐一设置app配置 for(String appId: apps) { + // 检查appId是否已授权 + WxAuthorizerInfo authorizerInfo = authorizerInfoService.getByAppId(appId); + if(authorizerInfo == null) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); + } + if(!authorizerInfo.getAuthorizationStatus().equals(EnumWxAuthorizationStatus.AUTHORIZED.getCode())) { + return new ResultData(ErrorCode.APP_NOT_AUTH); + } codeOperation(appId, userVersion, userDesc, templateId); } return new ResultData(); diff --git a/mallinkWechatOpen/src/main/resources/application-dev.yml b/mallinkWechatOpen/src/main/resources/application-dev.yml index 842eed229..1e9a333e1 100644 --- a/mallinkWechatOpen/src/main/resources/application-dev.yml +++ b/mallinkWechatOpen/src/main/resources/application-dev.yml @@ -82,6 +82,7 @@ jasypt: fm: exception: false + delay: 1 logging: level: diff --git a/mallinkWechatOpen/src/main/resources/application-prod.yml b/mallinkWechatOpen/src/main/resources/application-prod.yml index 7eead9053..a8c102a18 100644 --- a/mallinkWechatOpen/src/main/resources/application-prod.yml +++ b/mallinkWechatOpen/src/main/resources/application-prod.yml @@ -76,6 +76,7 @@ wechat: fm: exception: true + delay: 3 logging: level: diff --git a/mallinkWechatOpen/src/main/resources/application-test.yml b/mallinkWechatOpen/src/main/resources/application-test.yml index ab6d58017..22724d49a 100644 --- a/mallinkWechatOpen/src/main/resources/application-test.yml +++ b/mallinkWechatOpen/src/main/resources/application-test.yml @@ -76,6 +76,7 @@ wechat: fm: exception: true + delay: 2 logging: level: