|
@@ -32,11 +32,10 @@ import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
@RestController
|
|
|
-@RequestMapping("/wx/cp/addcontact")
|
|
|
+@RequestMapping("/wx/cp/addcontact/{corpId}/{agentId}")
|
|
|
public class WxaAddContactController {
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
- private static Integer agentId=1000004;
|
|
|
- final WxCpService wxCpService = WxCpConfiguration.getCpService(agentId);
|
|
|
+// private static Integer agentId=1000004;
|
|
|
@Autowired
|
|
|
private ExternalUserService externalUserService;
|
|
|
@Autowired
|
|
@@ -47,12 +46,16 @@ public class WxaAddContactController {
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping("/authWx")
|
|
|
- public String authGet(@RequestParam(name = "msg_signature", required = false) String signature,
|
|
|
+ public String authGet(@PathVariable String corpId,
|
|
|
+ @PathVariable Integer agentId,
|
|
|
+ @RequestParam(name = "msg_signature", required = false) String signature,
|
|
|
@RequestParam(name = "timestamp", required = false) String timestamp,
|
|
|
@RequestParam(name = "nonce", required = false) String nonce,
|
|
|
@RequestParam(name = "echostr", required = false) String echostr) {
|
|
|
this.logger.info("\n1接收到来自微信服务器的认证消息:signature = [{}], timestamp = [{}], nonce = [{}], echostr = [{}]"+signature+timestamp+nonce+echostr);
|
|
|
|
|
|
+ final WxCpService wxCpService = WxCpConfiguration.getCpService(corpId,agentId);
|
|
|
+
|
|
|
if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) {
|
|
|
throw new IllegalArgumentException("请求参数非法,请核实!");
|
|
|
}
|
|
@@ -77,13 +80,16 @@ public class WxaAddContactController {
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping(value = "/authWx")
|
|
|
- public String authPost(@RequestBody String requestBody,
|
|
|
+ public String authPost(@PathVariable String corpId,
|
|
|
+ @PathVariable Integer agentId,
|
|
|
+ @RequestBody String requestBody,
|
|
|
@RequestParam(name = "msg_signature", required = false) String signature,
|
|
|
@RequestParam(name = "timestamp", required = false) String timestamp,
|
|
|
@RequestParam(name = "nonce", required = false) String nonce,
|
|
|
@RequestParam(name = "echostr", required = false) String echostr) {
|
|
|
this.logger.info("\n1接收到来自微信服务器的认证消息:"+signature+"--"+timestamp+"--"+nonce+"--"+echostr);
|
|
|
|
|
|
+ final WxCpService wxCpService = WxCpConfiguration.getCpService(corpId,agentId);
|
|
|
|
|
|
//获取Token
|
|
|
try {
|
|
@@ -91,7 +97,7 @@ public class WxaAddContactController {
|
|
|
WxCpXmlMessage inMessage = WxCpXmlMessage.fromEncryptedXml(requestBody, wxCpService.getWxCpConfigStorage(),
|
|
|
timestamp, nonce, signature);
|
|
|
this.logger.info("\n消息解密后内容为:\n{} "+JsonUtils.toJson(inMessage));
|
|
|
- WxCpXmlOutMessage outMessage = this.route(agentId, inMessage);
|
|
|
+ WxCpXmlOutMessage outMessage = this.route(corpId,agentId, inMessage);
|
|
|
if (outMessage == null) {
|
|
|
return "";
|
|
|
}
|
|
@@ -213,9 +219,14 @@ public class WxaAddContactController {
|
|
|
* @param res
|
|
|
*/
|
|
|
@GetMapping(value = "/authWxInfo")
|
|
|
- public void authWxInfoPost(@RequestParam(name = "code", required = false) String code,
|
|
|
+ public void authWxInfoPost(@PathVariable String corpId,
|
|
|
+ @PathVariable Integer agentId,
|
|
|
+ @RequestParam(name = "code", required = false) String code,
|
|
|
@RequestParam(name = "state", required = false) String state, HttpServletResponse res) {
|
|
|
this.logger.info("接收到来自微信服务器的用户授权消息:"+code+"--"+state);
|
|
|
+
|
|
|
+ final WxCpService wxCpService = WxCpConfiguration.getCpService(corpId,agentId);
|
|
|
+
|
|
|
try {
|
|
|
String url="http://coop.360lj.com:7000/client/index.html";
|
|
|
//获取用户信息
|
|
@@ -233,12 +244,16 @@ public class WxaAddContactController {
|
|
|
|
|
|
|
|
|
@GetMapping("/authUsers")
|
|
|
- public String authUsersGet(@RequestParam(name = "msg_signature", required = false) String signature,
|
|
|
+ public String authUsersGet(@PathVariable String corpId,
|
|
|
+ @PathVariable Integer agentId,
|
|
|
+ @RequestParam(name = "msg_signature", required = false) String signature,
|
|
|
@RequestParam(name = "timestamp", required = false) String timestamp,
|
|
|
@RequestParam(name = "nonce", required = false) String nonce,
|
|
|
@RequestParam(name = "echostr", required = false) String echostr) {
|
|
|
this.logger.info("\n1接收到来自微信服务器的认证消息:signature = [{}], timestamp = [{}], nonce = [{}], echostr = [{}]"+signature+timestamp+nonce+echostr+agentId);
|
|
|
|
|
|
+ final WxCpService wxCpService = WxCpConfiguration.getCpService(corpId,agentId);
|
|
|
+
|
|
|
if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) {
|
|
|
throw new IllegalArgumentException("请求参数非法,请核实!");
|
|
|
}
|
|
@@ -254,20 +269,24 @@ public class WxaAddContactController {
|
|
|
}
|
|
|
|
|
|
@PostMapping(value = "/authUsers")
|
|
|
- public String authUsersPost(@RequestBody String requestBody,
|
|
|
+ public String authUsersPost(@PathVariable String corpId,
|
|
|
+ @PathVariable Integer agentId,
|
|
|
+ @RequestBody String requestBody,
|
|
|
@RequestParam(name = "msg_signature", required = false) String signature,
|
|
|
@RequestParam(name = "timestamp", required = false) String timestamp,
|
|
|
@RequestParam(name = "nonce", required = false) String nonce,
|
|
|
@RequestParam(name = "echostr", required = false) String echostr) {
|
|
|
this.logger.info("\n1接收到来自微信服务器的企业用户变更信息:"+signature+"--"+timestamp+"--"+nonce+"--"+echostr);
|
|
|
|
|
|
+ final WxCpService wxCpService = WxCpConfiguration.getCpService(corpId,agentId);
|
|
|
+
|
|
|
//获取Token
|
|
|
try {
|
|
|
Date date = new Date();
|
|
|
WxCpXmlMessage inMessage = WxCpXmlMessage.fromEncryptedXml(requestBody, wxCpService.getWxCpConfigStorage(),
|
|
|
timestamp, nonce, signature);
|
|
|
this.logger.info("\n消息解密后内容为:\n{} "+JsonUtils.toJson(inMessage));
|
|
|
- WxCpXmlOutMessage outMessage = this.route(agentId, inMessage);
|
|
|
+ WxCpXmlOutMessage outMessage = this.route(corpId,agentId, inMessage);
|
|
|
if (outMessage == null) {
|
|
|
return "";
|
|
|
}
|
|
@@ -338,9 +357,9 @@ public class WxaAddContactController {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private WxCpXmlOutMessage route(Integer agentId, WxCpXmlMessage message) {
|
|
|
+ private WxCpXmlOutMessage route(String corpId,Integer agentId, WxCpXmlMessage message) {
|
|
|
try {
|
|
|
- return WxCpConfiguration.getRouters().get(agentId).route(message);
|
|
|
+ return WxCpConfiguration.getRouters().get(corpId).get(agentId).route(message);
|
|
|
} catch (Exception e) {
|
|
|
this.logger.error(e.getMessage(), e);
|
|
|
}
|