Micro-enterprise development to prepare the letter

1. Enterprise micro-channel official website

https://work.weixin.qq.com/

2. Admin address (direct access)

https://work.weixin.qq.com/wework_admin/frame

3. Reference letter micro enterprise API

Please look at the document when the basic concept of the reference server Description:

I use java development, we introduce the following basic ways to call java enterprise micro-letter

First of all: the interface micro-channel business is information Httpget and httppost transmission.

Httpclient need to add the jar package

Called

public static String getJSApiTicketSs() {
    // 获取token
    String acess_token = WorkWeixinUtil.getAccessTokenSs();
    String urlStr = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=" + acess_token;
    String backData = WorkWeixinUtil.sendGet(urlStr);
    String ticket = (String) JSONObject.fromObject(backData).get("ticket");
    return ticket;
}

util Methods

public static String sendGet(String url) {
        String result = null;
        HttpGet httpRequst = new HttpGet(url);
        try {
            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(30000).setConnectTimeout(30000).build();// 设置请求和传输超时时间
            httpRequst.setConfig(requestConfig);
            HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequst);// 其中HttpGet是
            if (httpResponse.getStatusLine().getStatusCode() == 200) {
                HttpEntity httpEntity = httpResponse.getEntity();
                result = EntityUtils.toString(httpEntity);// 取出应答字符串
                // 一般来说都要删除多余的字符
                result.replaceAll("\r", "");// 去掉返回结果中的"\r"字符,否则会在结果字符串后面显示一个小方格
            } else if (httpResponse.getStatusLine().getStatusCode() == 500) {
                httpRequst.abort();
                HttpGet httpRequstReload = new HttpGet(url);
                RequestConfig requestConfigReload = RequestConfig.custom().setSocketTimeout(30000).setConnectTimeout(30000).build();// 设置请求和传输超时时间
                httpRequstReload.setConfig(requestConfigReload);
                HttpResponse httpResponseReload = new DefaultHttpClient().execute(httpRequstReload);// 其中HttpGet是
                if (httpResponseReload.getStatusLine().getStatusCode() == 200) {
                    HttpEntity httpEntityReload = httpResponseReload.getEntity();
                    result = EntityUtils.toString(httpEntityReload);// 取出应答字符串
                    // 一般来说都要删除多余的字符
                    result.replaceAll("\r", "");// 去掉返回结果中的"\r"字符,否则会在结果字符串后面显示一个小方格
                } else {
                    httpRequstReload.abort();
                }
            } else {
                httpRequst.abort();
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
            result = e.getMessage().toString();
        } catch (IOException e) {
            e.printStackTrace();
            result = e.getMessage().toString();
        }
        return result;
    }

    public static String getAccessTokenSs() {
        String corpid = "";
        String corpsecret = "";
        corpid = "123456";//按实际填写
        corpsecret = "corpsecret";//按实际填写
        String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid="+corpid+"&corpsecret="+corpsecret;
        String backData = WorkWeixinUtil.sendGet(url);
        String accessToken = (String) JSONObject.fromObject(backData).get("access_token");
        return accessToken;
    }

This can be a pleasant call interface.

 

OAuth2 Profile

Micro-enterprise authorization letter provided login OAuth, allowing web pages opened from micro-enterprise communication terminal to obtain identity information of the members, eliminating login link.
URL link enterprise applications (including custom menus or link in the message), can be used to obtain information on the identity of the members of UserId by OAuth2.0 verification interface.

 

Published 45 original articles · won praise 11 · views 10000 +

Guess you like

Origin blog.csdn.net/zyc050707/article/details/102486677