|
|
|
@@ -1,15 +1,22 @@ |
|
|
|
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.domain.po.WxAppinfo; |
|
|
|
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.api.bean.TtOpenNotifyMsg; |
|
|
|
import com.iformall.utils.DateUtils; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import me.chanjar.weixin.common.error.WxErrorException; |
|
|
|
import me.chanjar.weixin.common.util.json.GsonHelper; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
@@ -21,6 +28,7 @@ import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.PrintWriter; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@@ -39,6 +47,18 @@ public class TtCalllbackController extends BaseController { |
|
|
|
@Autowired |
|
|
|
private WxAuthorizerInfoService authorizerInfoService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxWeappAuditStatusService weappAuditStatusService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxAppinfoService appinfoService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private MailService mailService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private String fmAuditEmails; |
|
|
|
|
|
|
|
@PostMapping(value = "/notify") |
|
|
|
@ApiOperation("接收ticket回调") |
|
|
|
@ResponseBody |
|
|
|
@@ -93,45 +113,87 @@ public class TtCalllbackController extends BaseController { |
|
|
|
}else if(StringUtils.isNotBlank(ticket.getEvent()) && StringUtils.equalsIgnoreCase(ticket.getEvent(), "UPDATE_AUTHORIZED")){ |
|
|
|
logger.info("------------找回授权码通知"); |
|
|
|
|
|
|
|
}else if(StringUtils.isNotBlank(ticket.getEvent()) && StringUtils.equalsIgnoreCase(ticket.getEvent(), "PACKAGE_AUDIT")){ |
|
|
|
logger.info("------------审核结果通知"); |
|
|
|
handleWeappAuditedMessage(ticket); |
|
|
|
}else{ |
|
|
|
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") |
|
|
|
@ApiOperation("消息回调") |
|
|
|
|