| @@ -336,6 +336,11 @@ public enum ErrorCode{ | |||
| SHOP_IS_RENT(22001,"商铺已出租"), | |||
| WIWIDE_INFO_NOT_FOUND(23001,"迈外迪信息未找到"), | |||
| /** | |||
| * 微信第三方 | |||
| */ | |||
| APP_NOT_AUTH(24000, "app未授权"), | |||
| ; | |||
| private int code; | |||
| @@ -42,6 +42,14 @@ public interface WxAuthorizerInfoService { | |||
| * @return | |||
| */ | |||
| 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); | |||
| } | |||
| @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; | |||
| @@ -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); | |||
| @@ -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<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()); | |||
| 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); | |||
| @@ -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<String, String> 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(); | |||
| @@ -82,6 +82,7 @@ jasypt: | |||
| fm: | |||
| exception: false | |||
| delay: 1 | |||
| logging: | |||
| level: | |||
| @@ -76,6 +76,7 @@ wechat: | |||
| fm: | |||
| exception: true | |||
| delay: 3 | |||
| logging: | |||
| level: | |||
| @@ -76,6 +76,7 @@ wechat: | |||
| fm: | |||
| exception: true | |||
| delay: 2 | |||
| logging: | |||
| level: | |||