zoukankan      html  css  js  c++  java
  • 微信开发-获取access_token

    	public static String getAccessToken() throws ClientProtocolException,
    			IOException
    	{
    		String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential";
    		url = url + "&appid=" + 你的公众平台开发appId + "&secret=" + 你的公众平台appSecret;
    
    		DefaultHttpClient client = new DefaultHttpClient();
    		HttpGet httpGet = new HttpGet(url);
    		HttpResponse httpResponse;
    	
    		httpResponse = client.execute(httpGet);
    
    		int code = httpResponse.getStatusLine().getStatusCode();
    		String strResult = EntityUtils.toString(httpResponse.getEntity(),WxData.CharSet);
    		if (code == 200)
    		{
    			JSONObject jsonObject = JSONObject.fromObject(strResult);
    			String token = jsonObject.getString("access_token");
    			System.out.println(token);
    			
    		}
    		
    
    		return null;
    	}

    每天接口访问次数为2000次,所以要保存到全局变量中,7200s的技能持续时间;

    所需要的jar包

    commons-beanutils
    commons-collections
    commons-httpclient
    commons-lang
    commons-logging
    json-lib-2.3-jdk15


    httpcore-4.2.2
    httpmime-4.2.3
    httpclient-cache-4.2.3
    httpclient-4.2.3

  • 相关阅读:
    「APIO2017」商旅
    【CQOI2017】小Q的表格
    【HNOI2016】树
    【NOI2018模拟】Yja
    测试
    Loj #6073.「2017 山东一轮集训 Day5」距离
    「AHOI / HNOI2017」影魔
    Loj 6068. 「2017 山东一轮集训 Day4」棋盘
    【SDOI2014】向量集
    远程服务器安装nginx
  • 原文地址:https://www.cnblogs.com/MedivhQ/p/4101264.html
Copyright © 2011-2022 走看看