diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthorizerAccessTokenFormDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthorizerAccessTokenFormDTO.java index 2e5528ea64..08f038f317 100644 --- a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthorizerAccessTokenFormDTO.java +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/AuthorizerAccessTokenFormDTO.java @@ -34,6 +34,11 @@ public class AuthorizerAccessTokenFormDTO implements Serializable { */ private String authAppid; + /** + * 客户端类型:resi居民端,work:工作端 + */ + private String clientType; + /** * 客户ID */ diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/SubmitAuditFormDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/SubmitAuditFormDTO.java index e88d58e3f9..82867159cf 100644 --- a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/SubmitAuditFormDTO.java +++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/SubmitAuditFormDTO.java @@ -43,84 +43,100 @@ public class SubmitAuditFormDTO implements Serializable { /** * 用户生成内容场景(UGC)信息安全声明 */ - private List ugcDeclare; + private UgcDeclareBean ugcDeclare; @NoArgsConstructor @Data - private static class ItemListBean { + public static class ItemListBean { /** * 小程序的页面,可通过获取小程序的页面列表接口获得 */ + @SerializedName("address") private String address; /** * 小程序的标签,用空格分隔,标签至多 10 个,标签长度至多 20 */ + @SerializedName("tag") private String tag; /** * 一级类目名称 */ + @SerializedName("first_class") private String firstClass; /** * 二级类目名称 */ + @SerializedName("second_class") private String secondClass; /** * 三级类目名称 */ + @SerializedName("third_class") private String thirdClass; /** * 一级类目的 ID */ + @SerializedName("first_id") private String firstId; /** * 二级类目的 ID */ + @SerializedName("second_id") private String secondId; /** * 三级类目的 ID */ + @SerializedName("third_id") private String thirdId; /** * 小程序页面的标题,标题长度至多 32 */ + @SerializedName("title") private String title; } @NoArgsConstructor @Data - private static class PreviewInfoBean { + public static class PreviewInfoBean { /** * 录屏mediaid列表,可以通过提审素材上传接口获得 */ + @SerializedName("Video_id_list") private List videoIdList; /** * 截屏mediaid列表,可以通过提审素材上传接口获得 */ + @SerializedName("pic_id_list") private List picIdList; } @NoArgsConstructor @Data - private static class UgcDeclareBean { + public static class UgcDeclareBean { /** * UGC场景 0,不涉及用户生成内容, 1.用户资料,2.图片,3.视频,4.文本,5其他, 可多选,当scene填0时无需填写下列字段 */ + @SerializedName("scene") private List scene; /** * 当scene选其他时的说明,不超时256字 */ + @SerializedName("other_scene_desc") private String otherSceneDesc; /** * 内容安全机制 1.使用平台建议的内容安全API,2.使用其他的内容审核产品,3.通过人工审核把关,4.未做内容审核把关 */ + @SerializedName("method") private List method; /** * 是否有审核团队, 0.无,1.有,默认0 */ + @SerializedName("has_audit_team") private Integer hasAuditTeam; /** * 说明当前对UGC内容的审核机制,不超过256字 */ + @SerializedName("audit_desc") private String auditDesc; } } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/CustomerMpDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/CustomerMpDao.java index 593194e2c7..b6c9376f6d 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/CustomerMpDao.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/CustomerMpDao.java @@ -58,7 +58,7 @@ public interface CustomerMpDao extends BaseDao { * @param customerId * @author zxc */ - Integer selectAuthCount(@Param("customerId")String customerId); + List selectAuthCount(@Param("customerId")String customerId); /** * @Description 回填customer_mp的appId diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/CodeServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/CodeServiceImpl.java index da2474e2f9..8e18dadcbf 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/CodeServiceImpl.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/CodeServiceImpl.java @@ -161,11 +161,11 @@ public class CodeServiceImpl implements CodeService { @Override public PageData uploadList(UploadListFormDTO formDTO) { - //获取小程序调用令牌 - AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(formDTO.getCustomerId(), formDTO.getClientType()); - if (null != authInfo) { - List auditingList = codeCustomerService.getAuditingCodeList(); + List auditingList = codeCustomerService.getAuditingCodeList(); + if (null != auditingList && auditingList.size() > NumConstant.ZERO) { auditingList.forEach(code -> { + //获取小程序调用令牌 + AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(code.getCustomerId(), code.getClientType()); //获取审核结果信息 CodeAuditResultDTO auditResult = codeAuditResultService.getAuditResultByCodeId(code.getId()); //调用微信API获取最新审核状态 @@ -182,10 +182,12 @@ public class CodeServiceImpl implements CodeService { code.setStatus(CodeConstant.AUDIT_FAILED); auditResult.setResult(CodeConstant.AUDIT_FAILED); auditResult.setReason(result.getReason()); + auditResult.setScreenShot(result.getScreenshot()); codeOperationHistoryService.updateDescribe(code.getId(), result.getReason()); } else if (result.getStatus() == NumConstant.FOUR) { code.setStatus(CodeConstant.DELAY); auditResult.setResult(CodeConstant.DELAY); + auditResult.setReason(result.getReason()); codeOperationHistoryService.updateDescribe(code.getId(), "审核延后"); } codeCustomerService.update(code); @@ -210,7 +212,13 @@ public class CodeServiceImpl implements CodeService { throw new RenException("未授权"); } //调用微信API上提交审核 - WxMaCodeSubmitAuditRequest request = ConvertUtils.sourceToTarget(formDTO, WxMaCodeSubmitAuditRequest.class); + WxMaCodeSubmitAuditRequest request = new WxMaCodeSubmitAuditRequest(); + request.setVersionDesc(formDTO.getVersionDesc()); + request.setFeedbackInfo(formDTO.getFeedbackInfo()); + request.setFeedbackStuff(formDTO.getFeedbackStuff()); + request.setItemList(formDTO.getItemList()); + request.setPreviewInfo(formDTO.getPreviewInfo()); + request.setUgcDeclare(formDTO.getUgcDeclare()); WxResult wxResult = wxMaCodeService.submitAudit(authInfo.getAuthorizerAccessToken(), request); if (!wxResult.success()) { saveOperation(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getId(), codeCustomerDTO.getUserVersion(), CodeConstant.OPER_SUBMIT, @@ -374,6 +382,7 @@ public class CodeServiceImpl implements CodeService { @Override public String mediaUpload(MediaUploadFormDTO formDTO) { try { +// Result uploadDTOResult = ossFeignClient.upload(formDTO.getMedia()); File file = MultipartFileToFileUtils.multipartFileToFile(formDTO.getMedia()); //获取上传代码信息 CodeCustomerDTO codeCustomerDTO = codeCustomerService.get(formDTO.getCodeId()); diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java index 2204c77aa4..b96ba88280 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java @@ -143,7 +143,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe AuthCodeResultDTO authCodeResultDTO = authorizationInfoDao.selectCustomerIdByAuthAppId(authAppId); String clientType = authCodeResultDTO.getClientType(); String customerId = authCodeResultDTO.getCustomerId(); - this.updateCustomerMpAppIdAndCreateOpenPlatform(customerId,authAppId,clientType); + this.createAndBindOpenAccount(customerId,authAppId,clientType); + this.updateCustomerMpAppId(customerId,authAppId,clientType); authCodeDao.updateAppId(customerId,clientType,authAppId); this.saveAuthAccountInfo(customerId,authAppId,clientType); break; @@ -349,8 +350,9 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe formDTO.setExpiresInTime(expiresInTime); formDTO.setCustomerId(customerId); formDTO.setAuthAppid(authAppId); + formDTO.setClientType(clientType); //先逻辑删除,在插入 - authorizationInfoDao.updateOldAuthorizerAccessToken(willOverDueDTO.getCustomerId(),clientType); + authorizationInfoDao.updateOldAuthorizerAccessToken(customerId,clientType); authorizationInfoDao.insertAuthorizerAccessToken(formDTO); //缓存 refreshAuthorizerAccessToken @@ -495,7 +497,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe * @author zxc */ @Transactional(rollbackFor = Exception.class) - public void updateCustomerMpAppIdAndCreateOpenPlatform(String customerId,String authAppId,String clientType){ + public void updateCustomerMpAppId(String customerId,String authAppId,String clientType){ log.info("==========回填customer_mp开始=========="); AuthCodeFormDTO formDTO = new AuthCodeFormDTO(); formDTO.setClientType(clientType); @@ -506,6 +508,82 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe log.info("==========回填customer_mp结束=========="); } + public void createAndBindOpenAccount(String customerId,String authAppId,String clientType){ + log.info("开始创建开放平台账号并绑定"); + List authCount = customerMpDao.selectAuthCount(customerId); + String openPlatformId = null; + if (authCount.size()>0){ + openPlatformId = openPlatformAccountDao.selectOpenAppIdByCustomerId(customerId); + } + Map authorizerRefreshToken = redisThird.getAuthorizerRefreshToken(customerId + ThirdRedisKeyConstant.COLON + clientType); + String authorizerAccessToken = authorizerRefreshToken.get("authorizerAccessToken").toString(); + if (authCount.size()==NumConstant.ZERO){ + log.info("未查询到该客户授权信息,先创建开放平台账号,再绑定"); + //没有任何一个小程序/公众号授权,【先创建,再绑定】 + JSONObject jsonObject = new JSONObject(); + jsonObject.put(ModuleConstant.LOW_APP_ID,authAppId); + // 此处的 access_token 为 【authorizer_access_token】 + String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_CREATE_OPEN + authorizerAccessToken, JSON.toJSONString(jsonObject)).getData(); + Map map = JSON.parseObject(data, Map.class); + openPlatformId = map.get(ModuleConstant.OPEN_APP_ID).toString(); + CreateOpenResultDTO createOpen = new CreateOpenResultDTO(); + createOpen.setErrCode((Integer)map.get(ModuleConstant.ERR_CODE)); + createOpen.setErrMsg(map.get(ModuleConstant.ERR_MSG).toString()); + createOpen.setOpenAppId(map.get(ModuleConstant.OPEN_APP_ID).toString()); + switch (createOpen.getErrCode()){ + case NumConstant.ZERO: + log.info(CREATE_AND_BIND_SUCCESS); + CreateOpenFormDTO coForm = new CreateOpenFormDTO(); + coForm.setOpenid(map.get(ModuleConstant.OPEN_APP_ID).toString()); + coForm.setCustomerId(customerId); + //插入 open_platform_account 表 + openPlatformAccountDao.insertOpenPlatFormAccount(coForm); + break; + case NumConstant.ONE_NEG: + throw new RenException(SYSTEM_ERROR); + case ModuleConstant.FORTY_THOUSAND_AND_THIRTEEN: + throw new RenException(INVALID_APP_ID); + case ModuleConstant.EIGHTY_NINE_THOUSAND: + throw new RenException(ACCOUNT_HAS_BOUND_OPEN); + } + }else if (authCount.size()>NumConstant.ZERO && !authCount.contains(authAppId)){ + log.info("该客户已创建过开放平台账号,直接绑定"); + JSONObject jsonObject = new JSONObject(); + jsonObject.put(ModuleConstant.LOW_APP_ID,authAppId); + jsonObject.put(ModuleConstant.OPEN_APP_ID,openPlatformId); + String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_BIND_OPEN + authorizerAccessToken, JSON.toJSONString(jsonObject)).getData(); + Map map = JSON.parseObject(data, Map.class); + CreateOpenResultDTO createOpen = new CreateOpenResultDTO(); + createOpen.setErrCode((Integer)map.get(ModuleConstant.ERR_CODE)); + createOpen.setErrMsg(map.get(ModuleConstant.ERR_MSG).toString()); + switch (createOpen.getErrCode()){ + case NumConstant.ZERO: + log.info(BIND_SUCCESS); + break; + case NumConstant.ONE_NEG: + throw new RenException(SYSTEM_ERROR); + case ModuleConstant.FORTY_THOUSAND_AND_THIRTEEN: + throw new RenException(INVALID_APP_ID); + case ModuleConstant.EIGHTY_NINE_THOUSAND: + throw new RenException(ACCOUNT_HAS_BOUND_OPEN); + case ModuleConstant.EIGHTY_NINE_THOUSAND_AND_ONE: + throw new RenException(NOT_SAME_CONTRACTOR); + case ModuleConstant.EIGHTY_NINE_THOUSAND_AND_THREE: + throw new RenException(NOT_ALLOWED_OPERATE); + case ModuleConstant.EIGHTY_NINE_THOUSAND_AND_FOUR: + throw new RenException(TO_LIMIT); + } + } + //插入 binding_account + BindingAccountFormDTO bindingAccount = new BindingAccountFormDTO(); + bindingAccount.setOpenPlatformAccountId(openPlatformId); + bindingAccount.setAuthAppId(authAppId); + bindingAccount.setClientType(clientType); + bindingAccount.setCustomerId(customerId); + bindingAccountDao.insertBindingAccount(bindingAccount); + log.info("创建绑定账号结束"); + } + /** * @Description map 转 Entity * @param map diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/param/WxMaCodeSubmitAuditRequest.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/param/WxMaCodeSubmitAuditRequest.java index c9fa07b8e4..1c63b9ed3a 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/param/WxMaCodeSubmitAuditRequest.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/param/WxMaCodeSubmitAuditRequest.java @@ -1,5 +1,6 @@ package com.epmet.wxapi.param; +import com.epmet.dto.form.SubmitAuditFormDTO; import com.google.gson.annotations.SerializedName; import lombok.Data; import lombok.NoArgsConstructor; @@ -36,110 +37,16 @@ public class WxMaCodeSubmitAuditRequest implements Serializable { * 审核项列表(选填,至多填写 5 项) */ @SerializedName("item_list") - private List itemList; + private List itemList; /** * 预览信息(小程序页面截图和操作录屏) */ @SerializedName("preview_info") - private List previewInfo; + private List previewInfo; /** * 用户生成内容场景(UGC)信息安全声明 */ @SerializedName("ugc_declare") - private List ugcDeclare; + private SubmitAuditFormDTO.UgcDeclareBean ugcDeclare; - @NoArgsConstructor - @Data - private static class ItemListBean { - /** - * 小程序的页面,可通过获取小程序的页面列表接口获得 - */ - @SerializedName("address") - private String address; - /** - * 小程序的标签,用空格分隔,标签至多 10 个,标签长度至多 20 - */ - @SerializedName("tag") - private String tag; - /** - * 一级类目名称 - */ - @SerializedName("first_class") - private String firstClass; - /** - * 二级类目名称 - */ - @SerializedName("second_class") - private String secondClass; - /** - * 三级类目名称 - */ - @SerializedName("third_class") - private String thirdClass; - /** - * 一级类目的 ID - */ - @SerializedName("first_id") - private String firstId; - /** - * 二级类目的 ID - */ - @SerializedName("second_id") - private String secondId; - /** - * 三级类目的 ID - */ - @SerializedName("third_id") - private String thirdId; - /** - * 小程序页面的标题,标题长度至多 32 - */ - @SerializedName("title") - private String title; - } - - @NoArgsConstructor - @Data - private static class PreviewInfoBean { - /** - * 录屏mediaid列表,可以通过提审素材上传接口获得 - */ - @SerializedName("Video_id_list") - private List videoIdList; - /** - * 截屏mediaid列表,可以通过提审素材上传接口获得 - */ - @SerializedName("pic_id_list") - private List picIdList; - } - - @NoArgsConstructor - @Data - private static class UgcDeclareBean { - /** - * UGC场景 0,不涉及用户生成内容, 1.用户资料,2.图片,3.视频,4.文本,5其他, 可多选,当scene填0时无需填写下列字段 - */ - @SerializedName("scene") - private List scene; - /** - * 当scene选其他时的说明,不超时256字 - */ - @SerializedName("other_scene_desc") - private String otherSceneDesc; - /** - * 内容安全机制 1.使用平台建议的内容安全API,2.使用其他的内容审核产品,3.通过人工审核把关,4.未做内容审核把关 - */ - @SerializedName("method") - private List method; - /** - * 是否有审核团队, 0.无,1.有,默认0 - */ - @SerializedName("has_audit_team") - private Integer hasAuditTeam; - /** - * 说明当前对UGC内容的审核机制,不超过256字 - */ - @SerializedName("audit_desc") - private String auditDesc; - } } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/service/impl/WxMaCodeServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/service/impl/WxMaCodeServiceImpl.java index 3ffe8aa295..e0ae3823e5 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/service/impl/WxMaCodeServiceImpl.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/service/impl/WxMaCodeServiceImpl.java @@ -10,12 +10,14 @@ import com.epmet.wxapi.result.*; import com.epmet.wxapi.service.WxMaCodeService; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.io.File; +import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; @@ -149,7 +151,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { @Override public WxResult getAuditStatus(String accessToken, WxMaCodeAuditStatusReq request) { WxResult result = new WxResult<>(); - String url = WxMaCodeConstant.COMMIT_URL + "?" + "access_token=" + accessToken; + String url = WxMaCodeConstant.GET_AUDIT_STATUS_URL + "?" + "access_token=" + accessToken; Result statusResult = HttpClientManager.getInstance().sendPostByJSON(url, toJson(request)); if (!statusResult.success()) { result.setErrorCode(statusResult.getCode()); @@ -209,6 +211,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService { return result; } Gson gson = new Gson(); + InputStream inputStream = gson.fromJson(statusResult.getData(), InputStream.class); WxMaNewsResult newsResult = gson.fromJson(statusResult.getData(), WxMaNewsResult.class); result.ok(newsResult); return result; diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizationInfoDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizationInfoDao.xml index cee136fb42..cc9a4ecaf3 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizationInfoDao.xml +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizationInfoDao.xml @@ -41,7 +41,6 @@ WHERE del_flag = 0 AND (UNIX_TIMESTAMP(expires_in_time) - UNIX_TIMESTAMP(NOW())) 900 - AND (UNIX_TIMESTAMP(expires_in_time) - UNIX_TIMESTAMP(NOW())) > 0 @@ -68,6 +67,7 @@ update authorization_info set del_flag = 1 where customer_id = #{customerId} AND client_type = #{clientType} + - SELECT - COUNT(*) AS notAuthCount + app_id AS authAppId FROM customer_mp WHERE diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/OpenFlatformAccountDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/OpenFlatformAccountDao.xml index efaa55adad..3cc916bb31 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/OpenFlatformAccountDao.xml +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/OpenFlatformAccountDao.xml @@ -12,7 +12,7 @@ VALUES ( REPLACE ( UUID(), '-', '' ), - #{openAppId}, + #{openid}, #{customerId}, #{delFlag}, #{revision}, @@ -28,7 +28,7 @@ SELECT open_app_id AS openAppId FROM - open_flatform_account + open_platform_account WHERE del_flag = 0 AND customer_id = #{customerId}