| @@ -129,7 +129,7 @@ public interface TtOpenMaService extends TtMaService { | |||||
| /** | /** | ||||
| * 5. 将第三方提交的代码包提交审核(仅供第三方开发者代小程序调用) | * 5. 将第三方提交的代码包提交审核(仅供第三方开发者代小程序调用) | ||||
| */ | */ | ||||
| String API_SUBMIT_AUDIT = "https://api.weixin.qq.com/wxa/submit_audit"; | |||||
| String API_SUBMIT_AUDIT = "https://open.microapp.bytedance.com/openapi/v2/microapp/package/audit"; | |||||
| /** | /** | ||||
| * 7. 查询某个指定版本的审核状态(仅供第三方代小程序调用) | * 7. 查询某个指定版本的审核状态(仅供第三方代小程序调用) | ||||
| @@ -144,7 +144,7 @@ public interface TtOpenMaService extends TtMaService { | |||||
| /** | /** | ||||
| * 9. 发布已通过审核的小程序(仅供第三方代小程序调用) | * 9. 发布已通过审核的小程序(仅供第三方代小程序调用) | ||||
| */ | */ | ||||
| String API_RELEASE = "https://api.weixin.qq.com/wxa/release"; | |||||
| String API_RELEASE = "https://open.microapp.bytedance.com/openapi/v1/microapp/package/release"; | |||||
| /** | /** | ||||
| * 10. 修改小程序线上代码的可见状态(仅供第三方代小程序调用) | * 10. 修改小程序线上代码的可见状态(仅供第三方代小程序调用) | ||||
| @@ -371,7 +371,7 @@ public interface TtOpenMaService extends TtMaService { | |||||
| /** | /** | ||||
| * 将第三方提交的代码包提交审核(仅供第三方开发者代小程序调用) | * 将第三方提交的代码包提交审核(仅供第三方开发者代小程序调用) | ||||
| */ | */ | ||||
| WxOpenMaSubmitAuditResult submitAudit(WxOpenMaSubmitAuditMessage submitAuditMessage) throws WxErrorException; | |||||
| TtOpenResult submitAudit() throws WxErrorException; | |||||
| /** | /** | ||||
| * 查询某个指定版本的审核状态(仅供第三方代小程序调用) | * 查询某个指定版本的审核状态(仅供第三方代小程序调用) | ||||
| @@ -386,7 +386,7 @@ public interface TtOpenMaService extends TtMaService { | |||||
| /** | /** | ||||
| * 发布已通过审核的小程序(仅供第三方代小程序调用). | * 发布已通过审核的小程序(仅供第三方代小程序调用). | ||||
| */ | */ | ||||
| WxOpenResult releaesAudited() throws WxErrorException; | |||||
| TtOpenResult releaesAudited() throws WxErrorException; | |||||
| /** | /** | ||||
| * 10. 修改小程序线上代码的可见状态(仅供第三方代小程序调用) | * 10. 修改小程序线上代码的可见状态(仅供第三方代小程序调用) | ||||
| @@ -1,5 +1,6 @@ | |||||
| package com.iformall.service.toutiao.api.bean; | package com.iformall.service.toutiao.api.bean; | ||||
| import com.google.gson.JsonArray; | |||||
| import lombok.*; | import lombok.*; | ||||
| import java.io.Serializable; | import java.io.Serializable; | ||||
| @@ -29,6 +30,7 @@ public class TtOpenNotifyMsg implements Serializable { | |||||
| * AUTHORIZED ------ 授权通知 | * AUTHORIZED ------ 授权通知 | ||||
| * UNAUTHORIZED ----- 解除授权通知 | * UNAUTHORIZED ----- 解除授权通知 | ||||
| * UPDATE_AUTHORIZED ------- 找回授权码通知 | * UPDATE_AUTHORIZED ------- 找回授权码通知 | ||||
| * PACKAGE_AUDIT ------审核结果通知 | |||||
| */ | */ | ||||
| private String event; | private String event; | ||||
| @@ -48,6 +50,8 @@ public class TtOpenNotifyMsg implements Serializable { | |||||
| private String authorizationCode;//授权码 | private String authorizationCode;//授权码 | ||||
| private Integer authorizationCodeExpiresIn;//授权码有效期 | private Integer authorizationCodeExpiresIn;//授权码有效期 | ||||
| private JsonArray auditResults;//审核结果 | |||||
| public static TtOpenNotifyMsg fromJson(String json) { | public static TtOpenNotifyMsg fromJson(String json) { | ||||
| return TtOpenGsonBuilder.create().fromJson(json, TtOpenNotifyMsg.class); | return TtOpenGsonBuilder.create().fromJson(json, TtOpenNotifyMsg.class); | ||||
| @@ -30,6 +30,8 @@ public class TtOpenNotifyMsgGsonAdapter implements JsonDeserializer<TtOpenNotify | |||||
| openTicket.setEventTime(GsonHelper.getString(json,"EventTime")); | openTicket.setEventTime(GsonHelper.getString(json,"EventTime")); | ||||
| openTicket.setAuthorizationCode(GsonHelper.getString(json,"AuthorizationCode")); | openTicket.setAuthorizationCode(GsonHelper.getString(json,"AuthorizationCode")); | ||||
| openTicket.setAuthorizationCodeExpiresIn(GsonHelper.getInteger(json,"AuthorizationCodeExpiresIn")); | openTicket.setAuthorizationCodeExpiresIn(GsonHelper.getInteger(json,"AuthorizationCodeExpiresIn")); | ||||
| openTicket.setAuditResults(json.getAsJsonArray("AuditResults")); | |||||
| return openTicket; | return openTicket; | ||||
| } | } | ||||
| @@ -351,14 +351,19 @@ public class TtOpenMaServiceImpl extends TtMaServiceImpl implements TtOpenMaServ | |||||
| /** | /** | ||||
| * 将第三方提交的代码包提交审核(仅供第三方开发者代小程序调用) | * 将第三方提交的代码包提交审核(仅供第三方开发者代小程序调用) | ||||
| * | * | ||||
| * @param submitAuditMessage | |||||
| * @param | |||||
| * @return | * @return | ||||
| * @throws WxErrorException | * @throws WxErrorException | ||||
| */ | */ | ||||
| @Override | @Override | ||||
| public WxOpenMaSubmitAuditResult submitAudit(WxOpenMaSubmitAuditMessage submitAuditMessage) throws WxErrorException { | |||||
| String response = post(API_SUBMIT_AUDIT, GSON.toJson(submitAuditMessage)); | |||||
| return WxMaGsonBuilder.create().fromJson(response, WxOpenMaSubmitAuditResult.class); | |||||
| public TtOpenResult submitAudit() throws WxErrorException { | |||||
| String uri = API_SUBMIT_AUDIT + "?component_appid=" + ttOpenComponentService.getWxOpenConfigStorage().getComponentAppId(); | |||||
| JsonObject params = new JsonObject(); | |||||
| JsonArray array = new JsonArray(); | |||||
| array.add("douyin"); | |||||
| params.add("hostNames",array); | |||||
| String response = ttOpenComponentService.postByAppAccessToken(appId,uri,GSON.toJson(params),"authorizer_access_token"); | |||||
| return TtOpenGsonBuilder.create().fromJson(response, TtOpenResult.class); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -398,10 +403,10 @@ public class TtOpenMaServiceImpl extends TtMaServiceImpl implements TtOpenMaServ | |||||
| * @throws WxErrorException | * @throws WxErrorException | ||||
| */ | */ | ||||
| @Override | @Override | ||||
| public WxOpenResult releaesAudited() throws WxErrorException { | |||||
| JsonObject params = new JsonObject(); | |||||
| String response = post(API_RELEASE, GSON.toJson(params)); | |||||
| return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class); | |||||
| public TtOpenResult releaesAudited() throws WxErrorException { | |||||
| String uri = API_RELEASE + "?component_appid=" + ttOpenComponentService.getWxOpenConfigStorage().getComponentAppId(); | |||||
| String response = ttOpenComponentService.postByAppAccessToken(appId,uri,null,"authorizer_access_token"); | |||||
| return TtOpenGsonBuilder.create().fromJson(response, TtOpenResult.class); | |||||
| } | } | ||||
| @@ -1,15 +1,22 @@ | |||||
| package com.iformall.controller; | package com.iformall.controller; | ||||
| import com.google.gson.JsonArray; | |||||
| import com.google.gson.JsonElement; | |||||
| import com.google.gson.JsonObject; | |||||
| import com.iformall.controller.base.BaseController; | import com.iformall.controller.base.BaseController; | ||||
| import com.iformall.domain.po.WxAppinfo; | |||||
| import com.iformall.domain.po.WxComponentVerifyTicket; | import com.iformall.domain.po.WxComponentVerifyTicket; | ||||
| import com.iformall.service.WxAuthorizerInfoService; | |||||
| import com.iformall.service.WxComponentVerifyTicketService; | |||||
| import com.iformall.domain.po.WxWeappAuditStatus; | |||||
| import com.iformall.enums.EnumAppType; | |||||
| import com.iformall.enums.EnumWeappAuditStatus; | |||||
| import com.iformall.service.*; | |||||
| import com.iformall.service.toutiao.FmTtOpenService; | import com.iformall.service.toutiao.FmTtOpenService; | ||||
| import com.iformall.service.toutiao.api.bean.TtOpenNotifyMsg; | import com.iformall.service.toutiao.api.bean.TtOpenNotifyMsg; | ||||
| import com.iformall.utils.DateUtils; | import com.iformall.utils.DateUtils; | ||||
| import io.swagger.annotations.Api; | 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.common.util.json.GsonHelper; | |||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| @@ -21,6 +28,7 @@ import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.io.PrintWriter; | import java.io.PrintWriter; | ||||
| import java.text.SimpleDateFormat; | |||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.Map; | import java.util.Map; | ||||
| @@ -39,6 +47,18 @@ public class TtCalllbackController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxAuthorizerInfoService authorizerInfoService; | private WxAuthorizerInfoService authorizerInfoService; | ||||
| @Autowired | |||||
| private WxWeappAuditStatusService weappAuditStatusService; | |||||
| @Autowired | |||||
| private WxAppinfoService appinfoService; | |||||
| @Autowired | |||||
| private MailService mailService; | |||||
| @Autowired | |||||
| private String fmAuditEmails; | |||||
| @PostMapping(value = "/notify") | @PostMapping(value = "/notify") | ||||
| @ApiOperation("接收ticket回调") | @ApiOperation("接收ticket回调") | ||||
| @ResponseBody | @ResponseBody | ||||
| @@ -93,45 +113,87 @@ public class TtCalllbackController extends BaseController { | |||||
| }else if(StringUtils.isNotBlank(ticket.getEvent()) && StringUtils.equalsIgnoreCase(ticket.getEvent(), "UPDATE_AUTHORIZED")){ | }else if(StringUtils.isNotBlank(ticket.getEvent()) && StringUtils.equalsIgnoreCase(ticket.getEvent(), "UPDATE_AUTHORIZED")){ | ||||
| logger.info("------------找回授权码通知"); | logger.info("------------找回授权码通知"); | ||||
| }else if(StringUtils.isNotBlank(ticket.getEvent()) && StringUtils.equalsIgnoreCase(ticket.getEvent(), "PACKAGE_AUDIT")){ | |||||
| logger.info("------------审核结果通知"); | |||||
| handleWeappAuditedMessage(ticket); | |||||
| }else{ | }else{ | ||||
| logger.info("------------未知通知"); | logger.info("------------未知通知"); | ||||
| } | } | ||||
| } | } | ||||
| // /** | |||||
| // * 处理小程序审核消息 | |||||
| // * @param inMessage | |||||
| // * @return | |||||
| // */ | |||||
| // private boolean handleWeappAuditedMessage(WxOpenXmlMessage inMessage) { | |||||
| // // 审核通过 | |||||
| // try { | |||||
| // WxOpenQueryAuthResult queryAuthResult = openService.getWxOpenComponentService().getQueryAuth(inMessage.getAuthorizationCode()); | |||||
| // logger.info("getQueryAuth", queryAuthResult); | |||||
| // | |||||
| // WxOpenAuthorizerInfoResult openAuthorizerInfoResult = openService.getWxOpenComponentService().getAuthorizerInfo( | |||||
| // queryAuthResult.getAuthorizationInfo().getAuthorizerAppid()); | |||||
| // logger.info(openAuthorizerInfoResult.toString()); | |||||
| // // save auth info | |||||
| // authorizerInfoService.saveOrUpdate(new WxAuthorizerInfo() { | |||||
| // { | |||||
| // setAuthorizerAppid(openAuthorizerInfoResult.getAuthorizationInfo().getAuthorizerAppid()); | |||||
| // setAlias(openAuthorizerInfoResult.getAuthorizerInfo().getAlias()); | |||||
| // setHeadImg(openAuthorizerInfoResult.getAuthorizerInfo().getHeadImg()); | |||||
| // setQrcodeUrl(openAuthorizerInfoResult.getAuthorizerInfo().getQrcodeUrl()); | |||||
| // setRefreshToken(openAuthorizerInfoResult.getAuthorizationInfo().getAuthorizerRefreshToken()); | |||||
| // setAccessToken(openAuthorizerInfoResult.getAuthorizationInfo().getAuthorizerAccessToken()); | |||||
| // setAccessTokenExpire(new Date(Long.valueOf(System.currentTimeMillis() + openAuthorizerInfoResult.getAuthorizationInfo().getExpiresIn()*1000))); | |||||
| // setAuthorizationStatus(EnumWxAuthorizationStatus.AUTHORIZED.getCode()); | |||||
| // setAuthTime(new Date()); | |||||
| // } | |||||
| // }); | |||||
| // return true; | |||||
| // } catch (WxErrorException e) { | |||||
| // logger.error(e.getMessage()); | |||||
| // } | |||||
| // return false; | |||||
| // } | |||||
| /** | |||||
| * 处理小程序审核消息 | |||||
| * @param | |||||
| * @return | |||||
| */ | |||||
| private boolean handleWeappAuditedMessage(TtOpenNotifyMsg notifyMsg) { | |||||
| WxWeappAuditStatus auditStatus = weappAuditStatusService.getByAppId(notifyMsg.getAppId()); | |||||
| if(auditStatus == null){ | |||||
| logger.error("------------审核结果通知未找到审核小程序 "+notifyMsg.getAppId()); | |||||
| } | |||||
| JsonArray auditResults = notifyMsg.getAuditResults(); | |||||
| int status = 0; | |||||
| String reason = ""; | |||||
| for (int i = 0;i < auditResults.size(); i++) { | |||||
| JsonObject obj = auditResults.get(i).getAsJsonObject(); | |||||
| if(("toutiao").equals(GsonHelper.getString(obj,"hostName"))){ | |||||
| status = GsonHelper.getInteger(obj,"status"); | |||||
| reason = GsonHelper.getString(obj,"auditDetail"); | |||||
| break; | |||||
| } | |||||
| } | |||||
| if (status == 1) {//通过 | |||||
| auditStatus.setAuditStatus(EnumWeappAuditStatus.SUCCESS.getCode()); | |||||
| auditStatus.setAuditErrCode(""); | |||||
| } else { | |||||
| auditStatus.setAuditStatus(EnumWeappAuditStatus.FAIL.getCode()); | |||||
| auditStatus.setAuditErrCode(reason); | |||||
| } | |||||
| auditStatus.setAuditTime(DateUtils.stringToDate(notifyMsg.getEventTime(),"yyyy-MM-dd HH:mm:ss")); | |||||
| weappAuditStatusService.updateStatus(auditStatus); | |||||
| // 发邮件 | |||||
| WxAppinfo appinfo = appinfoService.getByAppId(notifyMsg.getAppId()); | |||||
| if (appinfo != null) { | |||||
| SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 | |||||
| StringBuilder titleSB = new StringBuilder(); | |||||
| if (appinfo.getType().equals(EnumAppType.C.getCode())) { | |||||
| titleSB.append("C端小程序"); | |||||
| } else if (appinfo.getType().equals(EnumAppType.B.getCode())) { | |||||
| titleSB.append("B端小程序"); | |||||
| } else if (appinfo.getType().equals(EnumAppType.MP_S.getCode())) { | |||||
| titleSB.append("公众号-服务号"); | |||||
| } else if (appinfo.getType().equals(EnumAppType.MP_P.getCode())) { | |||||
| titleSB.append("公众号-订阅号"); | |||||
| } | |||||
| titleSB.append(appinfo.getName()); | |||||
| if (status == 1) { | |||||
| titleSB.append("审核通过"); | |||||
| } else { | |||||
| titleSB.append("审核未通过"); | |||||
| } | |||||
| StringBuilder sb = new StringBuilder(); | |||||
| sb.append(df.format(new Date())).append("\n"); | |||||
| if (status == 1) { | |||||
| sb.append("审核通过\n"); | |||||
| } else { | |||||
| sb.append("审核未通过\n").append("原因").append(reason); | |||||
| } | |||||
| String[] receivers = fmAuditEmails.split(","); | |||||
| //发送邮件 | |||||
| mailService.sendSimpleMail(receivers, titleSB.toString(), sb.toString()); | |||||
| } | |||||
| return false; | |||||
| } | |||||
| @RequestMapping(value = "/{appId}/callback") | @RequestMapping(value = "/{appId}/callback") | ||||
| @ApiOperation("消息回调") | @ApiOperation("消息回调") | ||||
| @@ -676,14 +676,11 @@ public class WxWeappInfoController extends BaseController { | |||||
| Long auditid = null; | Long auditid = null; | ||||
| String codeErrCode = ""; | String codeErrCode = ""; | ||||
| try { | try { | ||||
| WxOpenMaSubmitAuditMessage subMessage = gson.fromJson(extSet.getReleaseJson(), new TypeToken<WxOpenMaSubmitAuditMessage>() {}.getType()); | |||||
| logger.info(subMessage.toString()); | |||||
| TtOpenMaService openMaService = openService.getTtOpenComponentService().getTtMaServiceByAppid(codeStatus.getAppId()); | TtOpenMaService openMaService = openService.getTtOpenComponentService().getTtMaServiceByAppid(codeStatus.getAppId()); | ||||
| WxOpenMaSubmitAuditResult openRet = openMaService.submitAudit(subMessage); | |||||
| TtOpenResult openRet = openMaService.submitAudit(); | |||||
| logger.info(openRet.toString()); | logger.info(openRet.toString()); | ||||
| if(openRet.isSuccess()) { | if(openRet.isSuccess()) { | ||||
| submitStatus = true; | submitStatus = true; | ||||
| auditid = openRet.getAuditId(); | |||||
| } else { | } else { | ||||
| submitStatus = false; | submitStatus = false; | ||||
| } | } | ||||
| @@ -880,7 +877,7 @@ public class WxWeappInfoController extends BaseController { | |||||
| try { | try { | ||||
| TtOpenMaService openMaService = openService.getTtOpenComponentService().getTtMaServiceByAppid(auditStatus.getAppId()); | TtOpenMaService openMaService = openService.getTtOpenComponentService().getTtMaServiceByAppid(auditStatus.getAppId()); | ||||
| WxOpenResult openRet = openMaService.releaesAudited(); | |||||
| TtOpenResult openRet = openMaService.releaesAudited(); | |||||
| logger.info(openRet.toString()); | logger.info(openRet.toString()); | ||||
| boolean releaseSuccess = false; | boolean releaseSuccess = false; | ||||
| if(openRet.isSuccess()) { | if(openRet.isSuccess()) { | ||||
| @@ -889,11 +886,7 @@ public class WxWeappInfoController extends BaseController { | |||||
| if(releaseSuccess) { | if(releaseSuccess) { | ||||
| releaseStatus.setReleaseStatus(EnumWeappReleaseStatus.SUCCESS.getCode()); | releaseStatus.setReleaseStatus(EnumWeappReleaseStatus.SUCCESS.getCode()); | ||||
| } else { | } else { | ||||
| if(openRet.getErrcode().equals(OpenConstant.ERR_CODE_APP_IS_RELEASED)) { | |||||
| releaseStatus.setReleaseStatus(EnumWeappReleaseStatus.SUCCESS.getCode()); | |||||
| } else { | |||||
| releaseStatus.setReleaseStatus(EnumWeappReleaseStatus.FAIL.getCode()); | |||||
| } | |||||
| releaseStatus.setReleaseStatus(EnumWeappReleaseStatus.FAIL.getCode()); | |||||
| } | } | ||||
| releaseStatus.setReleaseErrCode(gson.toJson(openRet)); | releaseStatus.setReleaseErrCode(gson.toJson(openRet)); | ||||
| releaseStatus.setReleaseTime(new Date()); | releaseStatus.setReleaseTime(new Date()); | ||||