forked from chanjarster/weixin-java-tools
-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
CP_如何支持多个企业号应用或企业号
Daniel Qian edited this page Feb 26, 2015
·
1 revision
如果你的项目里需要支持一个企业号的多个应用,有两种办法:
- 所有应用的token,AESEncodingKey和url都设置成一样,然后在代码里根据agentId来路由消息。
- 每个应用的token,AESEncodingKey和url全部都不一样,然后针对每个应用构造一套WxCpConfigStorage和WxCpServiceImpl。
第一种方法比较方便,但是存在极大的安全隐患。按照公众号的设计思路,企业号里的各个应用之间应该是互相独立的(token,AESEncodingKey和url都不一样)。 所以推荐第二种方法。
企业号之间相互独立性和前面讲过同一企业号的各个应用之间应该是互相独立性实际上是一样的。 也就是说应该采用前面讲的第二种方法来实现在一个项目里对多个企业号的支持。
String encType = request.getParameter("encrypt_type");
String nonce = request.getParameter("nonce");
String timestamp = request.getParameter("timestamp");
String msgSignature = request.getParameter("msg_signature");
String signature = request.getParameter("signature");
String openid = request.getParameter("openid");
log.info("接收微信请求:[openid=[{}], [openid=[{}],[signature=[{}], encType=[{}], msgSignature=[{}],"
+ " timestamp=[{}], nonce=[{}], requestBody=[{}] ",
appid, openid, signature, encType, msgSignature, timestamp, nonce, requestBody);
if (!this.wxMpService.switchover(appid)) {
throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid));
}
if (!wxMpService.checkSignature(timestamp, nonce, signature)) {
throw new IllegalArgumentException("非法请求,可能属于伪造的请求!");
}
return ResponseEntity.ok("");