调整公众号回调接口注释
This commit is contained in:
parent
76ba23188c
commit
55436c011a
|
|
@ -3,6 +3,7 @@ package com.mdd.admin.controller.channel;
|
||||||
import com.mdd.admin.service.IChannelOaCallBackService;
|
import com.mdd.admin.service.IChannelOaCallBackService;
|
||||||
import com.mdd.common.aop.NotLogin;
|
import com.mdd.common.aop.NotLogin;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
@ -13,13 +14,12 @@ import javax.annotation.Resource;
|
||||||
@Api(tags = "公众号服务器验证及消息回复")
|
@Api(tags = "公众号服务器验证及消息回复")
|
||||||
public class ChannelOaCallBackController {
|
public class ChannelOaCallBackController {
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IChannelOaCallBackService iChannelOaCallBackService;
|
private IChannelOaCallBackService iChannelOaCallBackService;
|
||||||
|
|
||||||
// 公众号服务器验证, 消息回复
|
|
||||||
@NotLogin
|
@NotLogin
|
||||||
@GetMapping(produces = "text/plain;charset=utf-8")
|
@GetMapping(produces = "text/plain;charset=utf-8")
|
||||||
|
@ApiOperation(value="公众号服务器地址验证")
|
||||||
public String authGet(@RequestParam(name = "signature", required = false) String signature,
|
public String authGet(@RequestParam(name = "signature", required = false) String signature,
|
||||||
@RequestParam(name = "timestamp", required = false) String timestamp,
|
@RequestParam(name = "timestamp", required = false) String timestamp,
|
||||||
@RequestParam(name = "nonce", required = false) String nonce,
|
@RequestParam(name = "nonce", required = false) String nonce,
|
||||||
|
|
@ -28,16 +28,15 @@ public class ChannelOaCallBackController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 消息回复
|
|
||||||
@NotLogin
|
@NotLogin
|
||||||
@PostMapping(produces = "application/xml; charset=UTF-8")
|
@PostMapping(produces = "application/xml; charset=UTF-8")
|
||||||
|
@ApiOperation(value="公众号消息回复")
|
||||||
public String post(@RequestBody String requestBody,
|
public String post(@RequestBody String requestBody,
|
||||||
@RequestParam("signature") String signature,
|
@RequestParam("signature") String signature,
|
||||||
@RequestParam("timestamp") String timestamp,
|
@RequestParam("timestamp") String timestamp,
|
||||||
@RequestParam("nonce") String nonce,
|
@RequestParam("nonce") String nonce,
|
||||||
@RequestParam(name = "encrypt_type", required = false) String encType,
|
@RequestParam(name = "encrypt_type", required = false) String encType,
|
||||||
@RequestParam(name = "msg_signature", required = false) String msgSignature) {
|
@RequestParam(name = "msg_signature", required = false) String msgSignature) {
|
||||||
|
|
||||||
return iChannelOaCallBackService.post(requestBody, signature, timestamp, nonce, encType, msgSignature);
|
return iChannelOaCallBackService.post(requestBody, signature, timestamp, nonce, encType, msgSignature);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static me.chanjar.weixin.common.api.WxConsts.EventType.SUBSCRIBE;
|
import static me.chanjar.weixin.common.api.WxConsts.EventType.SUBSCRIBE;
|
||||||
|
|
@ -29,10 +28,10 @@ public class ChannelOaCallBackServiceImpl implements IChannelOaCallBackService {
|
||||||
/**
|
/**
|
||||||
* 服务器验证
|
* 服务器验证
|
||||||
*
|
*
|
||||||
* @param signature
|
* @param signature 微信加密签名
|
||||||
* @param timestamp
|
* @param timestamp 时间戳
|
||||||
* @param nonce
|
* @param nonce 随机数
|
||||||
* @param echostr
|
* @param echostr 随机字符串
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -48,12 +47,12 @@ public class ChannelOaCallBackServiceImpl implements IChannelOaCallBackService {
|
||||||
/**
|
/**
|
||||||
* 消息回复
|
* 消息回复
|
||||||
*
|
*
|
||||||
* @param requestBody
|
* @param requestBody 请求数据
|
||||||
* @param signature
|
* @param signature 微信加密签名
|
||||||
* @param timestamp
|
* @param timestamp 时间戳
|
||||||
* @param nonce
|
* @param nonce 随机数
|
||||||
* @param encType
|
* @param encType 加密类型
|
||||||
* @param msgSignature
|
* @param msgSignature 加密签名
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -64,7 +63,7 @@ public class ChannelOaCallBackServiceImpl implements IChannelOaCallBackService {
|
||||||
throw new IllegalArgumentException("非法请求,可能属于伪造的请求!");
|
throw new IllegalArgumentException("非法请求,可能属于伪造的请求!");
|
||||||
}
|
}
|
||||||
|
|
||||||
String out = null;
|
String outMsg = null;
|
||||||
if (encType == null) {
|
if (encType == null) {
|
||||||
// 明文传输的消息
|
// 明文传输的消息
|
||||||
WxMpXmlMessage inMessage = WxMpXmlMessage.fromXml(requestBody);
|
WxMpXmlMessage inMessage = WxMpXmlMessage.fromXml(requestBody);
|
||||||
|
|
@ -72,27 +71,31 @@ public class ChannelOaCallBackServiceImpl implements IChannelOaCallBackService {
|
||||||
if (outMessage == null) {
|
if (outMessage == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
out = outMessage.toXml();
|
outMsg = outMessage.toXml();
|
||||||
|
|
||||||
} else if ("aes".equalsIgnoreCase(encType)) {
|
} else if ("aes".equalsIgnoreCase(encType)) {
|
||||||
// aes加密的消息
|
// aes加密的消息
|
||||||
WxMpXmlMessage inMessage = WxMpXmlMessage.fromEncryptedXml(requestBody, wxMpService.getWxMpConfigStorage(),
|
WxMpXmlMessage inMessage = WxMpXmlMessage.fromEncryptedXml(
|
||||||
timestamp, nonce, msgSignature);
|
requestBody,
|
||||||
|
wxMpService.getWxMpConfigStorage(),
|
||||||
|
timestamp,
|
||||||
|
nonce,
|
||||||
|
msgSignature);
|
||||||
|
|
||||||
WxMpXmlOutMessage outMessage = this.msgHandler(inMessage);
|
WxMpXmlOutMessage outMessage = this.msgHandler(inMessage);
|
||||||
if (outMessage == null) {
|
if (outMessage == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
out = outMessage.toEncryptedXml(wxMpService.getWxMpConfigStorage());
|
outMsg = outMessage.toEncryptedXml(wxMpService.getWxMpConfigStorage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return outMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息处理
|
* 消息处理
|
||||||
*
|
*
|
||||||
* @param wxMessage
|
* @param wxMessage 微信回调信息
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private WxMpXmlOutMessage msgHandler(WxMpXmlMessage wxMessage) {
|
private WxMpXmlOutMessage msgHandler(WxMpXmlMessage wxMessage) {
|
||||||
|
|
@ -112,7 +115,7 @@ public class ChannelOaCallBackServiceImpl implements IChannelOaCallBackService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new OperateException("公众号回调错误" + e.getMessage());
|
throw new OperateException("公众号消息回调错误" + e.getMessage());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -120,8 +123,8 @@ public class ChannelOaCallBackServiceImpl implements IChannelOaCallBackService {
|
||||||
/**
|
/**
|
||||||
* 返回文本消息
|
* 返回文本消息
|
||||||
*
|
*
|
||||||
* @param content
|
* @param content 文本内容
|
||||||
* @param wxMessage
|
* @param wxMessage 微信回调信息
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private WxMpXmlOutMessage textBuild(String content, WxMpXmlMessage wxMessage) {
|
private WxMpXmlOutMessage textBuild(String content, WxMpXmlMessage wxMessage) {
|
||||||
|
|
@ -133,7 +136,7 @@ public class ChannelOaCallBackServiceImpl implements IChannelOaCallBackService {
|
||||||
/**
|
/**
|
||||||
* 关键词回复
|
* 关键词回复
|
||||||
*
|
*
|
||||||
* @param wxMessage
|
* @param wxMessage 微信回调信息
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String keyMsg(WxMpXmlMessage wxMessage) {
|
private String keyMsg(WxMpXmlMessage wxMessage) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue