All Downloads are FREE. Search and download functionalities are using the official Maven repository.

weixin.popular.api.TokenAPI Maven / Gradle / Ivy

Go to download

The weixin-popular is a JAVA SDK for weixin. Weixin web url is https://mp.weixin.qq.com.

There is a newer version: 2.8.43
Show newest version
package weixin.popular.api;

import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;

import weixin.popular.bean.token.Token;
import weixin.popular.client.LocalHttpClient;

/**
 * ACCESS_TOKEN API
 * @author LiYi
 *
 */
public class TokenAPI extends BaseAPI{

	/**
	 * 获取access_token
	 * @param appid appid
	 * @param secret secret
	 * @return Token
	 */
	public static Token token(String appid,String secret){
		HttpUriRequest httpUriRequest = RequestBuilder.get()
				.setUri(BASE_URI + "/cgi-bin/token")
				.addParameter("grant_type","client_credential")
				.addParameter("appid", appid)
				.addParameter("secret", secret)
				.build();
		return LocalHttpClient.executeJsonResult(httpUriRequest,Token.class);
	}
	public static Token getTokenFromProxy(String url){
		HttpUriRequest httpUriRequest = RequestBuilder.get()
				.setUri(url)
				.build();
		return LocalHttpClient.executeJsonResult(httpUriRequest,Token.class);
	}

	public static void main(String[] args) {
		Token token = TokenAPI.getTokenFromProxy("http://localhost:3000");
		System.out.println(token.getAccess_token());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy