| @@ -7,6 +7,7 @@ import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxAuthorizerInfo; | import com.iformall.domain.po.WxAuthorizerInfo; | ||||
| import com.iformall.domain.po.WxWeappBasicSet; | import com.iformall.domain.po.WxWeappBasicSet; | ||||
| import com.iformall.domain.vo.WxWeappInfo; | |||||
| import com.iformall.enums.EnumAppType; | import com.iformall.enums.EnumAppType; | ||||
| import com.iformall.enums.EnumEnableType; | import com.iformall.enums.EnumEnableType; | ||||
| import com.iformall.enums.EnumWxAuthorizationStatus; | import com.iformall.enums.EnumWxAuthorizationStatus; | ||||
| @@ -17,6 +18,7 @@ import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.open.api.WxOpenMaService; | import me.chanjar.weixin.open.api.WxOpenMaService; | ||||
| import me.chanjar.weixin.open.bean.ma.WxOpenMaApplyInterface; | |||||
| import me.chanjar.weixin.open.bean.ma.privacy.GetPrivacySettingResult; | import me.chanjar.weixin.open.bean.ma.privacy.GetPrivacySettingResult; | ||||
| import me.chanjar.weixin.open.bean.ma.privacy.PrivacyOwnerSetting; | import me.chanjar.weixin.open.bean.ma.privacy.PrivacyOwnerSetting; | ||||
| import me.chanjar.weixin.open.bean.ma.privacy.SetPrivacySetting; | import me.chanjar.weixin.open.bean.ma.privacy.SetPrivacySetting; | ||||
| @@ -316,4 +318,140 @@ public class WechatWeappSetController { | |||||
| return new ResultData(Result.ERROR); | return new ResultData(Result.ERROR); | ||||
| } | } | ||||
| @ApiOperation(value = "查询小程序隐私接口", notes = "{\n" + | |||||
| " }") | |||||
| @GetMapping("/getPrivacyInterface") | |||||
| public ResultData getPrivacyInterface(String 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(!EnumAppType.B.getCode().equals(authorizerInfo.getType()) && !EnumAppType.C.getCode().equals(authorizerInfo.getType())){ | |||||
| return new ResultData(ErrorCode.WEAPP_BASIC_NO_SUPPORT); | |||||
| } | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxOpenMaInterfaceListResult privacyInterface = openMaService.getPrivacyInterface(); | |||||
| return new ResultData(privacyInterface); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| @ApiOperation(value = "申请小程序隐私接口", notes = "{\n" + | |||||
| " }") | |||||
| @PostMapping("/applyPrivacyInterface") | |||||
| public ResultData applyPrivacyInterface(@RequestBody Map<String, Object> params) { | |||||
| String appId,apiName,content; | |||||
| List<String> urlList,picList,videoList; | |||||
| try{ | |||||
| appId = (String) params.get("appId"); | |||||
| apiName = (String) params.get("apiName"); | |||||
| content = (String) params.get("content"); | |||||
| urlList = (List<String>) params.get("urlList"); | |||||
| picList = (List<String>) params.get("picList"); | |||||
| videoList = (List<String>) params.get("videoList"); | |||||
| }catch(Exception e){ | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| } | |||||
| if(StringUtils.isBlank(appId) || StringUtils.isBlank(apiName) || StringUtils.isBlank(content)){ | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| 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(!EnumAppType.B.getCode().equals(authorizerInfo.getType()) && !EnumAppType.C.getCode().equals(authorizerInfo.getType())){ | |||||
| return new ResultData(ErrorCode.WEAPP_BASIC_NO_SUPPORT); | |||||
| } | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxOpenMaApplyInterface applyInterface = new WxOpenMaApplyInterface(); | |||||
| applyInterface.setApiName(apiName); | |||||
| applyInterface.setContent(content); | |||||
| applyInterface.setUrlList(urlList); | |||||
| applyInterface.setPicList(picList); | |||||
| applyInterface.setVideoList(videoList); | |||||
| WxOpenResult wxOpenResult = openMaService.applyPrivacyInterface(applyInterface); | |||||
| if(wxOpenResult.isSuccess()){ | |||||
| return new ResultData(); | |||||
| }else{ | |||||
| return new ResultData(ErrorCode.WEAPP_AUDIT_ERR.getCode(),wxOpenResult.getErrmsg()); | |||||
| } | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| @ApiOperation(value = "批量申请小程序隐私接口", notes = "{\n" + | |||||
| " }") | |||||
| @PostMapping("/allsApplyPrivacyInterface") | |||||
| public ResultData allsApplyPrivacyInterface(@RequestBody Map<String, Object> params) { | |||||
| String apiName,content; | |||||
| List<String> urlList,picList,videoList; | |||||
| try{ | |||||
| apiName = (String) params.get("apiName"); | |||||
| content = (String) params.get("content"); | |||||
| urlList = (List<String>) params.get("urlList"); | |||||
| picList = (List<String>) params.get("picList"); | |||||
| videoList = (List<String>) params.get("videoList"); | |||||
| }catch(Exception e){ | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| } | |||||
| if(StringUtils.isBlank(apiName) || StringUtils.isBlank(content)){ | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| List<WxWeappInfo> applist = authorizerInfoService.getList(new WxWeappInfo()); | |||||
| for (WxWeappInfo info:applist) { | |||||
| String appId = info.getAuthorizerAppid(); | |||||
| WxAuthorizerInfo authorizerInfo = authorizerInfoService.getByAppId(appId); | |||||
| if(authorizerInfo == null) { | |||||
| logger.error(info.getName()+"("+appId+")申请("+apiName+")失败{}"+ErrorCode.WEAPP_APPID_NOT_AUTH.getMessage()); | |||||
| continue; | |||||
| } | |||||
| if(!authorizerInfo.getAuthorizationStatus().equals(EnumWxAuthorizationStatus.AUTHORIZED.getCode())) { | |||||
| logger.error(info.getName()+"("+appId+")申请("+apiName+")失败{}"+ErrorCode.WEAPP_APPID_NOT_AUTH.getMessage()); | |||||
| continue; | |||||
| } | |||||
| if(!EnumAppType.B.getCode().equals(authorizerInfo.getType()) && !EnumAppType.C.getCode().equals(authorizerInfo.getType())){ | |||||
| logger.error(info.getName()+"("+appId+")申请("+apiName+")失败{}"+ErrorCode.WEAPP_BASIC_NO_SUPPORT.getMessage()); | |||||
| continue; | |||||
| } | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxOpenMaApplyInterface applyInterface = new WxOpenMaApplyInterface(); | |||||
| applyInterface.setApiName(apiName); | |||||
| applyInterface.setContent(content); | |||||
| applyInterface.setUrlList(urlList); | |||||
| applyInterface.setPicList(picList); | |||||
| applyInterface.setVideoList(videoList); | |||||
| WxOpenResult wxOpenResult = openMaService.applyPrivacyInterface(applyInterface); | |||||
| if(wxOpenResult.isSuccess()){ | |||||
| logger.info(info.getName()+"("+appId+")申请("+apiName+")成功"); | |||||
| }else{ | |||||
| logger.error(info.getName()+"("+appId+")申请("+apiName+")失败{}"+wxOpenResult.getErrmsg()); | |||||
| } | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(info.getName()+"("+appId+")申请("+apiName+")失败{}"+e.getMessage()); | |||||
| } | |||||
| } | |||||
| return new ResultData(); | |||||
| } | |||||
| } | } | ||||