|
|
|
@@ -6,7 +6,6 @@ import com.iformall.common.Result; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.po.*; |
|
|
|
import com.iformall.enums.*; |
|
|
|
import com.iformall.mp.manager.WxMpManager; |
|
|
|
import com.iformall.service.*; |
|
|
|
import com.iformall.service.wechat.FmOpenService; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
@@ -15,7 +14,6 @@ import me.chanjar.weixin.common.error.WxErrorException; |
|
|
|
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; |
|
|
|
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; |
|
|
|
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; |
|
|
|
import me.chanjar.weixin.mp.bean.result.WxMpUser; |
|
|
|
import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; |
|
|
|
import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult; |
|
|
|
import me.chanjar.weixin.open.bean.result.WxOpenPlatformResult; |
|
|
|
@@ -35,7 +33,6 @@ import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.PrintWriter; |
|
|
|
import java.nio.charset.Charset; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
@Controller |
|
|
|
@@ -44,9 +41,6 @@ import java.util.Date; |
|
|
|
public class WechatCalllbackController extends BaseController { |
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass()); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private String fmAuditEmails; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected FmOpenService openService; |
|
|
|
|
|
|
|
@@ -56,21 +50,6 @@ public class WechatCalllbackController extends BaseController { |
|
|
|
@Autowired |
|
|
|
private WxAuthorizerInfoService authorizerInfoService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxWeappAuditStatusService weappAuditStatusService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxAppinfoService appinfoService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxCUserService userService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private MailService mailService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxMpManager mpManager; |
|
|
|
|
|
|
|
@PostMapping(value = "/notify") |
|
|
|
@ApiOperation("接收ticket回调") |
|
|
|
@ResponseBody |
|
|
|
@@ -229,156 +208,12 @@ public class WechatCalllbackController extends BaseController { |
|
|
|
wechatWriteSuccess(printWriter); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 实际回调消息处理 |
|
|
|
* @param appId |
|
|
|
* @param response |
|
|
|
* @param inMessage |
|
|
|
* @throws IOException |
|
|
|
*/ |
|
|
|
private void handleCallbackMessage(String appId, |
|
|
|
HttpServletResponse response, |
|
|
|
WxMpXmlMessage inMessage) throws IOException { |
|
|
|
WxAuthorizerInfo authorizerInfo = authorizerInfoService.getByAppId(appId); |
|
|
|
|
|
|
|
PrintWriter printWriter = response.getWriter(); |
|
|
|
|
|
|
|
// 小程序 消息 处理 |
|
|
|
if(authorizerInfo != null && (authorizerInfo.getType() <= EnumAppType.C.getCode())) { |
|
|
|
/**判断消息类型,调用对应的方法*/ |
|
|
|
handleWeappCallbackMessage(appId, inMessage); |
|
|
|
wechatWriteSuccess(printWriter); |
|
|
|
return; |
|
|
|
} else { |
|
|
|
handleMPCallbackMessage(appId, inMessage, authorizerInfo); |
|
|
|
wechatWriteSuccess(printWriter); |
|
|
|
return; |
|
|
|
/* |
|
|
|
// 公众号 |
|
|
|
try { |
|
|
|
WxMpXmlOutMessage outMessage = mpManager.getRouter(appId).route(inMessage); |
|
|
|
getThreadCount( 1 ); |
|
|
|
if (outMessage == null) { |
|
|
|
this.logger.info("2 return: success"); |
|
|
|
wechatWriteSuccess(printWriter); |
|
|
|
return; |
|
|
|
} |
|
|
|
// logger.info("组装回复" + outMessage.toXml()); |
|
|
|
// out = outMessage.toEncryptedXml(mpService.getWxMpConfigStorage()); |
|
|
|
// logger.info("组装回复消息-->"+out); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("路由消息时出现异常!", e); |
|
|
|
} |
|
|
|
*/ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 处理小程序回调消息 |
|
|
|
* @param appId |
|
|
|
* @param inMessage |
|
|
|
*/ |
|
|
|
private void handleWeappCallbackMessage(String appId, WxMpXmlMessage inMessage) { |
|
|
|
switch (inMessage.getMsgType()) { |
|
|
|
case "event": { |
|
|
|
switch (inMessage.getEvent()) { |
|
|
|
case "weapp_audit_success": { // 审核成功 |
|
|
|
updateAuditStatus(appId, true, ""); |
|
|
|
break; |
|
|
|
} |
|
|
|
case "weapp_audit_fail": { // 审核失败 |
|
|
|
updateAuditStatus(appId, false, inMessage.getReason()); |
|
|
|
break; |
|
|
|
} |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
default: |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 处理公众号回调消息 |
|
|
|
* @param appId |
|
|
|
* @param inMessage |
|
|
|
* @param authorizerInfo |
|
|
|
*/ |
|
|
|
private void handleMPCallbackMessage(String appId, WxMpXmlMessage inMessage, WxAuthorizerInfo authorizerInfo) { |
|
|
|
switch (inMessage.getMsgType()) { |
|
|
|
case "event": { |
|
|
|
switch (inMessage.getEvent()) { |
|
|
|
case "subscribe": { // 关注 |
|
|
|
handleEventSubscribe(appId, inMessage, authorizerInfo); |
|
|
|
break; |
|
|
|
} |
|
|
|
case "unsubscribe": { // 取消关注 |
|
|
|
handleEventUnsubscribe(appId, inMessage, authorizerInfo); |
|
|
|
break; |
|
|
|
} |
|
|
|
default: { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
default: { |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void wechatWriteSuccess(PrintWriter printWriter) { |
|
|
|
printWriter.print("success"); |
|
|
|
printWriter.flush(); |
|
|
|
printWriter.close(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 新关注消息处理 |
|
|
|
* @param appId |
|
|
|
* @param inMessage |
|
|
|
* @param authorizerInfo |
|
|
|
*/ |
|
|
|
private void handleEventSubscribe(String appId, WxMpXmlMessage inMessage, WxAuthorizerInfo authorizerInfo) { |
|
|
|
this.logger.info("新关注用户 OPENID: " + inMessage.getFromUser() + ", AppId: " + appId); |
|
|
|
|
|
|
|
// 获取微信用户基本信息 |
|
|
|
try { |
|
|
|
WxMpUser userWxInfo = openService.getWxOpenComponentService().getWxMpServiceByAppid(appId).getUserService() |
|
|
|
.userInfo(inMessage.getFromUser()); |
|
|
|
if (userWxInfo != null) { |
|
|
|
this.logger.info(userWxInfo.toString()); |
|
|
|
userService.saveOrUpdateMpUser(userWxInfo, authorizerInfo); |
|
|
|
} |
|
|
|
} catch (WxErrorException e) { |
|
|
|
if (e.getError().getErrorCode() == 48001) { |
|
|
|
this.logger.info("该公众号没有获取用户信息权限!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 取消关注消息处理 |
|
|
|
* @param appId |
|
|
|
* @param inMessage |
|
|
|
* @param authorizerInfo |
|
|
|
*/ |
|
|
|
private void handleEventUnsubscribe(String appId, WxMpXmlMessage inMessage, WxAuthorizerInfo authorizerInfo) { |
|
|
|
String openId = inMessage.getFromUser(); |
|
|
|
this.logger.info("取消关注用户 OPENID: " + openId + ", AppId: " + appId); |
|
|
|
|
|
|
|
WxMpUser mpUser = new WxMpUser(); |
|
|
|
mpUser.setOpenId(inMessage.getFromUser()); |
|
|
|
mpUser.setSubscribe(false); |
|
|
|
mpUser.setSubscribeTime(inMessage.getCreateTime()); |
|
|
|
|
|
|
|
userService.saveOrUpdateMpUser(mpUser, authorizerInfo); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 测试账号特殊处理 |
|
|
|
* @param appId |
|
|
|
@@ -443,56 +278,6 @@ public class WechatCalllbackController extends BaseController { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void updateAuditStatus(String appId, boolean success, String reason) { |
|
|
|
WxWeappAuditStatus auditStatus = weappAuditStatusService.getByAppId(appId); |
|
|
|
if (auditStatus != null) { |
|
|
|
if (success) { |
|
|
|
auditStatus.setAuditStatus(EnumWeappAuditStatus.SUCCESS.getCode()); |
|
|
|
auditStatus.setAuditErrCode(""); |
|
|
|
} else { |
|
|
|
auditStatus.setAuditStatus(EnumWeappAuditStatus.FAIL.getCode()); |
|
|
|
auditStatus.setAuditErrCode(reason); |
|
|
|
} |
|
|
|
auditStatus.setAuditTime(new Date()); |
|
|
|
weappAuditStatusService.updateStatus(auditStatus); |
|
|
|
} |
|
|
|
|
|
|
|
// 发邮件 |
|
|
|
WxAppinfo appinfo = appinfoService.getByAppId(appId); |
|
|
|
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 (success) { |
|
|
|
titleSB.append("审核通过"); |
|
|
|
} else { |
|
|
|
titleSB.append("审核未通过"); |
|
|
|
} |
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
sb.append(df.format(new Date())).append("\n"); |
|
|
|
if (success) { |
|
|
|
sb.append("审核通过\n"); |
|
|
|
} else { |
|
|
|
sb.append("审核未通过\n").append("原因").append(reason); |
|
|
|
} |
|
|
|
|
|
|
|
String[] receivers = fmAuditEmails.split(","); |
|
|
|
|
|
|
|
//发送邮件 |
|
|
|
mailService.sendSimpleMail(receivers, titleSB.toString(), sb.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@GetMapping(value = "/createOpenPlatform") |
|
|
|
@ApiOperation("创建微信开放平台") |
|
|
|
|