package com.yunniu.farming.util;

import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;


@Component
public class WXApiUtil {

	private static Logger log = LoggerFactory.getLogger(WXApiUtil.class);


	/**
	 * @功能:获取access_token
	 */
	public static String getAccessToken(String appId, String appSecret){
		String access_token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
		String url = access_token_url.replace("APPID", appId).replace("APPSECRET", appSecret);
		String res = HttpRequest.sendGet(url);
		JSONObject json = JSONObject.parseObject(res);
		if(json==null || json.get("errcode")!=null) return "";
		return json.getString("access_token");
	}





}








