微信公众号开发之删除公众号的菜单按钮

main函数:

public class DeleteMenu {
	public static void main(String[] args) {
		//地址
		String url = " https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN";
		url = url.replace("ACCESS_TOKEN",WxService.getAccessToken());
		Util util = new Util();
		String result = util.get(url);
		System.out.println("删除菜单的结果:"+result);
	}
}

WxService.getAccessToken所在部分的函数:(获取AccessToken)

private static final String Token = "ouyang";
	private static final String Get_Token_Url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
	private static final String appID = "你的appid";
	private static final String appsecret = "你的appsecret";
	private static AccessToken at;
	private static void getToken() {
		String url = Get_Token_Url.replace("APPID",appID).replace("APPSECRET",appsecret);
		String tokenStr = Util.get(url);
		System.out.println(tokenStr);
		JSONObject jsonObj = JSONObject.parseObject(tokenStr);
		String token = jsonObj.getString("access_token");
		String expireIn = jsonObj.getString("expires_in");
		at = new AccessToken(token,expireIn);
	}
	
	public static String getAccessToken() {
		if(at == null || at.isExpired()) {
			getToken();
		}
		return at.getAccessToken();
	}

AccessToken类:

public class AccessToken {
	private String accessToken;
	private long expireTime;
	
	public AccessToken(String accessToken,String expireIn) {
		super();
		this.accessToken = accessToken;
		expireTime = System.currentTimeMillis()+Integer.parseInt(expireIn)*1000;
	}
	/* Token是否过期 */
			
	public boolean isExpired() {
		return System.currentTimeMillis()>expireTime;
	}
	
	public String getAccessToken() {
		return accessToken;
	}
	public void setAccessToken(String accessToken) {
		this.accessToken = accessToken;
	}
	public long getExpireTime() {
		return expireTime;
	}
	public void setExpireTime(long expireTime) {
		this.expireTime = expireTime;
	}
	 
}

如有不对,欢迎斧正。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值