Пример #1
0
 /** 获取TOKEN,一天最多获取200次,需要所有用户共享值 */
 public String GetToken() {
   String requestUrl =
       tokenUrl + "?grant_type=client_credential&appid=" + appid + "&secret=" + appsecret;
   TenpayHttpClient httpClient = new TenpayHttpClient();
   httpClient.setReqContent(requestUrl);
   if (httpClient.call()) {
     String res = httpClient.getResContent();
     Gson gson = new Gson();
     TreeMap map = gson.fromJson(res, TreeMap.class);
     // 在有效期内直接返回access_token
     if (map.containsKey("access_token")) {
       String s = map.get("access_token").toString();
     }
     // 如果请求成功
     if (null != map) {
       try {
         if (map.containsKey("access_token")) {
           Token = map.get("access_token").toString();
           return this.Token;
         }
       } catch (Exception e) {
         // 获取token失败
         System.out.println("失败:" + map.get("errmsg"));
       }
     }
   }
   return "";
 }