Java版本微信企业号的开发--02

来源:互联网 发布:英剧推荐 知乎 编辑:程序博客网 时间:2024/06/05 14:21

最近很忙所以也没空更新文章。上一篇文章,已经完成了,微信号的申请,下面就是具体的接入。


首先介绍一下,进入企业微信号的后台以后我们需要添加自己的应用,当然你也可以使用第三方的。

应用分为以下两大类:


主页型应用比较简单,简单地说就是配一个链接地址,然后打开应用跳到你的url里面去。

消息型应用就和公众号差不多了,这里可以添加多个,可以发消息,实现通信。下面就是需要填写的页面,还可以选择可见范围。


填写完了,应用就建好了,但是现在还不能开发因为这个应用需要地址回调,也就是测试你的地址是否正确。


首先设置可信域名,这个不用我多少,然后开启回调模式。


然后保存的时候微信会发起一个get请求的验证,到了这里我们只需要在我们代码中得到响应的参数,然后返回一个字符串就好了。

@RequestMapping(value = { "/coreJoin" }, method = RequestMethod.GET)public void coreJoinGet(HttpServletRequest request, HttpServletResponse response) throws IOException {// 微信加密签名String msg_signature = request.getParameter("msg_signature");// 时间戳String timestamp = request.getParameter("timestamp");// 随机数String nonce = request.getParameter("nonce");// 随机字符串String echostr = request.getParameter("echostr");System.out.println("request=" + request.getRequestURL());PrintWriter out = response.getWriter();// 通过检验signature对请求进行校验,若校验成功则原样返回echostr,表示接入成功,否则接入失败String result = null;try {WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(ParamesAPI.token, ParamesAPI.encodingAESKey, ParamesAPI.corpId);result = wxcpt.VerifyURL(msg_signature, timestamp, nonce, echostr);} catch (AesException e) {e.printStackTrace();}if (result == null) {result = ParamesAPI.token;}out.print(result);out.close();out = null;}
运行我们程序,然后在微信上点击保存,验证通过,回调成功。







4 0