登录 注册

Eos中调用企业微信的消息推送

发布时间:Jun 12, 2019 10:20:26 AM 发布人:管理员


归属栏目: EOS开发


外部链接: 


关键字: 


归属栏目: EOS开发


文章来源: 


摘要: 

Eos中调用企业微信的消息推送

本文介绍EOS应用如何与企业微信进行集成,如何获取企业微信提供的API完成微信消息推送,可是实现指定用户消息推送,可以实现批量消息推送。

1.eos运算逻辑中编写主要方法

/**发推送消息

       * @param CORPID

       * @param CORPSECRET

       * @param agentid 企业应用的id

       * @param users 要推送的用户id,多用户以|隔开

       * @param content 要推送的内容

       * @throws JSONException

       * @throws IOException

       */

      @Bizlet("")

      public static void send(String CORPID, String CORPSECRET,int agentid,String users,String content) throws JSONException, IOException {

            String urlStr = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid="+ CORPID + "&corpsecret=" + CORPSECRET;

            JSONObject json = processUrl(urlStr);

            if (null != json && null != json.getString("access_token")) {

                  String sendUrl="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="+json.getString("access_token");

                String data ="{\"touser\" : \""+users+"\",\"toparty\" : \"\",\"totag\" : \"\",\"msgtype\" : \"text\",\"agentid\" : "+agentid+",\"text\" : {\"content\" : \""+content+"\"},\"safe\":0}";

                PostMethod postmethod = new PostMethod(sendUrl);

            byte[] b = data.getBytes("UTF-8");

            InputStream is = new ByteArrayInputStream(b, 0, b.length);

            RequestEntity re = new InputStreamRequestEntity(is, b.length, "application/xop+xml; charset=UTF-8; type=\"text/xml\"");

            postmethod.setRequestEntity(re);

            HttpClient httpClient = new HttpClient();

            int statusCode = httpClient.executeMethod(postmethod);

            System.err.println("statuscode = " + statusCode);

            String soapResponseData = postmethod.getResponseBodyAsString();

            System.out.println(soapResponseData);

            }

      }

 }

2.底层调用(也可以封成逻辑流供前端调用)

 send("wxaf9ee15633cf3594","d5WsHUPZK4zT5qffXc-BdJNIFXGYz9QLKfMOTMy7sl4",1000011,"sysadmin|chenguanghua","您今日有xxx条通知待查看<a href='http://omptest.jinke.com:9090/default/mobile/mobileindex.jsp?ssotype=notice'>立即查看</a>");

 

 


相关文章

返回