| @@ -336,6 +336,11 @@ public enum ErrorCode{ | |||||
| SHOP_IS_RENT(22001,"商铺已出租"), | SHOP_IS_RENT(22001,"商铺已出租"), | ||||
| WIWIDE_INFO_NOT_FOUND(23001,"迈外迪信息未找到"), | WIWIDE_INFO_NOT_FOUND(23001,"迈外迪信息未找到"), | ||||
| /** | |||||
| * 微信第三方 | |||||
| */ | |||||
| APP_NOT_AUTH(24000, "app未授权"), | |||||
| ; | ; | ||||
| private int code; | private int code; | ||||
| @@ -42,6 +42,14 @@ public interface WxAuthorizerInfoService { | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| WxAuthorizerInfo getById(Long id); | WxAuthorizerInfo getById(Long id); | ||||
| /** | |||||
| * 根据appId获得实体 | |||||
| * | |||||
| * @param appId | |||||
| * @return | |||||
| */ | |||||
| WxAuthorizerInfo getByAppId(String appId); | |||||
| /** | /** | ||||
| * 保存或更新实体 | * 保存或更新实体 | ||||
| @@ -53,10 +53,24 @@ public class WxAuthorizerInfoServiceImpl implements WxAuthorizerInfoService { | |||||
| return authorizerInfoMapper.selectByPrimaryKey(id); | 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 | @Override | ||||
| public void saveOrUpdate(WxAuthorizerInfo record) { | public void saveOrUpdate(WxAuthorizerInfo record) { | ||||
| // 1. 添加到wx_authorizer_info表中 | // 1. 添加到wx_authorizer_info表中 | ||||
| // 2. 同时在wx_weapp_ext_set中添加一条记录 | // 2. 同时在wx_weapp_ext_set中添加一条记录 | ||||
| // 3. 同时在wx_weapp_code_status中添加一条记录 | |||||
| Date curDate = new Date(); | Date curDate = new Date(); | ||||
| logger.info(record.toString()); | logger.info(record.toString()); | ||||
| WxAuthorizerInfo authorizerInfo = null; | WxAuthorizerInfo authorizerInfo = null; | ||||
| @@ -1,6 +1,7 @@ | |||||
| package com.iformall; | package com.iformall; | ||||
| import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; | import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; | ||||
| import io.swagger.models.auth.In; | |||||
| import org.springframework.beans.factory.annotation.Value; | import org.springframework.beans.factory.annotation.Value; | ||||
| import org.springframework.boot.SpringApplication; | import org.springframework.boot.SpringApplication; | ||||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | import org.springframework.boot.autoconfigure.SpringBootApplication; | ||||
| @@ -26,6 +27,13 @@ public class WechatOpenApplication { | |||||
| return fmException; | return fmException; | ||||
| } | } | ||||
| @Value("${fm.delay}") | |||||
| private Integer fmDelay; | |||||
| @Bean | |||||
| public Integer getFmDelay() { return fmDelay; } | |||||
| public static void main(String[] args) { | public static void main(String[] args) { | ||||
| SpringApplication.run(WechatOpenApplication.class, args); | SpringApplication.run(WechatOpenApplication.class, args); | ||||
| @@ -4,11 +4,18 @@ import com.alibaba.fastjson.JSON; | |||||
| import com.google.gson.Gson; | import com.google.gson.Gson; | ||||
| import com.google.gson.GsonBuilder; | import com.google.gson.GsonBuilder; | ||||
| import com.google.gson.reflect.TypeToken; | import com.google.gson.reflect.TypeToken; | ||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | 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.domain.po.WxWeappCodeStatus; | ||||
| import com.iformall.enums.EnumWeappAuditStatus; | import com.iformall.enums.EnumWeappAuditStatus; | ||||
| import com.iformall.enums.EnumWeappCodeCommitStatus; | |||||
| import com.iformall.enums.EnumWeappReleaseStatus; | 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.WxWeappCodeStatusService; | ||||
| import com.iformall.service.wechat.WxOpenService; | import com.iformall.service.wechat.WxOpenService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| @@ -31,6 +38,7 @@ import java.io.FileInputStream; | |||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.io.InputStream; | import java.io.InputStream; | ||||
| import java.net.URLEncoder; | import java.net.URLEncoder; | ||||
| import java.util.Date; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| /** | /** | ||||
| @@ -47,16 +55,66 @@ public class WechatWeappCodeController { | |||||
| @Autowired | @Autowired | ||||
| private WxWeappCodeStatusService weappCodeStatusService; | 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") | @ApiOperation(value = "为授权的小程序帐号上传小程序代码", notes = "extInfo参考https://mp.weixin.qq.com/debug/wxadoc/dev/framework/config.html") | ||||
| @PostMapping("/codeCommit") | @PostMapping("/codeCommit") | ||||
| public ResultData codeCommit(Long templateId, String userVersion, String userDesc, String extInfoStr) { | public ResultData codeCommit(Long templateId, String userVersion, String userDesc, String extInfoStr) { | ||||
| try { | try { | ||||
| Gson gson= new GsonBuilder().create(); | Gson gson= new GsonBuilder().create(); | ||||
| WxMaOpenCommitExtInfo extInfo = gson.fromJson(extInfoStr, new TypeToken<WxMaOpenCommitExtInfo>() { }.getType()); | WxMaOpenCommitExtInfo extInfo = gson.fromJson(extInfoStr, new TypeToken<WxMaOpenCommitExtInfo>() { }.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()); | logger.info(extInfo.toString()); | ||||
| WxOpenResult openRet = openMaService.codeCommit(templateId, userVersion, userDesc, extInfo); | WxOpenResult openRet = openMaService.codeCommit(templateId, userVersion, userDesc, extInfo); | ||||
| logger.info(openRet.toString()); | 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); | return new ResultData(openRet); | ||||
| } catch (WxErrorException e) { | } catch (WxErrorException e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -200,7 +258,7 @@ public class WechatWeappCodeController { | |||||
| } | } | ||||
| @ApiOperation("发布已通过审核的小程序") | @ApiOperation("发布已通过审核的小程序") | ||||
| @PostMapping("/releaesAudited") | |||||
| @PostMapping("/releaseAudited") | |||||
| public ResultData releaesAudited(String appId) { | public ResultData releaesAudited(String appId) { | ||||
| try { | try { | ||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | ||||
| @@ -48,6 +48,9 @@ import java.util.*; | |||||
| public class WxWeappInfoController extends BaseController { | public class WxWeappInfoController extends BaseController { | ||||
| private final Logger logger = LoggerFactory.getLogger(getClass()); | private final Logger logger = LoggerFactory.getLogger(getClass()); | ||||
| @Autowired | |||||
| private Integer getFmDelay; | |||||
| @Autowired | @Autowired | ||||
| private WxAuthorizerInfoService authorizerInfoService; | private WxAuthorizerInfoService authorizerInfoService; | ||||
| @@ -93,28 +96,23 @@ public class WxWeappInfoController extends BaseController { | |||||
| return new ResultData(list); | 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") | @PostMapping("batchBasicSet") | ||||
| public ResultData batchSet(@RequestBody Map<String, String> params) { | public ResultData batchSet(@RequestBody Map<String, String> params) { | ||||
| logger.debug("[" + getIpAddr() + "] WxWeappInfoController::batchBasicSet"); | logger.debug("[" + getIpAddr() + "] WxWeappInfoController::batchBasicSet"); | ||||
| String appsStr = params.get("apps"); | String appsStr = params.get("apps"); | ||||
| String typeStr = params.get("type"); | String typeStr = params.get("type"); | ||||
| String deployStr = params.get("deploy"); | |||||
| Integer type = 0, deploy = 0; | |||||
| Integer type = 0; | |||||
| try { | try { | ||||
| type = Integer.parseInt(typeStr); | type = Integer.parseInt(typeStr); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | 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(); | WxWeappBasicSet weappBasicSetQ = new WxWeappBasicSet(); | ||||
| weappBasicSetQ.setType(type); | weappBasicSetQ.setType(type); | ||||
| weappBasicSetQ.setDeploy(deploy); | |||||
| weappBasicSetQ.setDeploy(getFmDelay); | |||||
| WxWeappBasicSet weappBasicSet = weappBasicSetService.getByTypeAndDeploy(weappBasicSetQ); | WxWeappBasicSet weappBasicSet = weappBasicSetService.getByTypeAndDeploy(weappBasicSetQ); | ||||
| if(weappBasicSet == null) { | if(weappBasicSet == null) { | ||||
| logger.error("未找到相关的基础设置参数"); | logger.error("未找到相关的基础设置参数"); | ||||
| @@ -131,11 +129,17 @@ public class WxWeappInfoController extends BaseController { | |||||
| // 逐一设置app配置 | // 逐一设置app配置 | ||||
| String [] apps = appsStr.split(","); | String [] apps = appsStr.split(","); | ||||
| for(String appId: apps) { | 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); | ResultData openRet = setBasicForAppId(appId, weappBasicSet, domainObj, templeObj); | ||||
| if (openRet != null) return openRet; | if (openRet != null) return openRet; | ||||
| } | } | ||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @@ -266,6 +270,14 @@ public class WxWeappInfoController extends BaseController { | |||||
| } | } | ||||
| // 逐一设置app配置 | // 逐一设置app配置 | ||||
| for(String appId: apps) { | 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); | codeOperation(appId, userVersion, userDesc, templateId); | ||||
| } | } | ||||
| return new ResultData(); | return new ResultData(); | ||||
| @@ -82,6 +82,7 @@ jasypt: | |||||
| fm: | fm: | ||||
| exception: false | exception: false | ||||
| delay: 1 | |||||
| logging: | logging: | ||||
| level: | level: | ||||
| @@ -76,6 +76,7 @@ wechat: | |||||
| fm: | fm: | ||||
| exception: true | exception: true | ||||
| delay: 3 | |||||
| logging: | logging: | ||||
| level: | level: | ||||
| @@ -76,6 +76,7 @@ wechat: | |||||
| fm: | fm: | ||||
| exception: true | exception: true | ||||
| delay: 2 | |||||
| logging: | logging: | ||||
| level: | level: | ||||