コード例 #1
0
 @Override
 protected void doExecute() throws Exception {
   if (S.isInvalidValue(shopFavoritedIn)) {
     throw new IncorrectInputParameterException("is_user_shop_favorited_in is null or empty");
   }
   long beginTime = System.currentTimeMillis();
   JSONObject content = new JSONObject(shopFavoritedIn);
   final String userId = content.optString(ShopFavoriteKey.OWN_USER_KEY, null);
   if (S.isInvalidValue(userId)) {
     throw new IncorrectInputParameterException("User id is null or empty");
   }
   List<String> ownerList = shopFavoriteDAOR.getAllShopIdsByUserId(userId);
   List<String> sourceList = new ArrayList<String>();
   JSONArray idArray = content.getJSONArray(ShopFavoriteKey.OWN_ID_SET_KEY);
   for (int i = 0; i < idArray.length(); i++) {
     JSONObject singleObject = idArray.getJSONObject(i);
     final String shopId = singleObject.optString(ShopFavoriteKey.OWN_ID_KEY, null);
     if (S.isInvalidValue(shopId)) {
       continue;
     }
     sourceList.add(shopId);
   }
   result = getOwnResult(S.SUCCESS_CODE, S.EMPTY_STR, sourceList, ownerList);
   long endTime = System.currentTimeMillis();
   long costTime = endTime - beginTime;
   LOGGER.info("isUserShopFavorited cost>>>" + costTime);
 }
コード例 #2
0
ファイル: TaobaoApiUtil.java プロジェクト: kkme/udc
 public static String refreshToken(
     String refreshTokenUrl, String appKey, String appSecret, String refreshToken)
     throws IOException, IncorrectInputParameterException, JSONException {
   Map<String, String> parameters = new HashMap<String, String>();
   parameters.put(UserTaobaoInfoKey.API_GRANT_TYPE, UserTaobaoInfoKey.API_REFRESH_TOKEN);
   parameters.put(UserTaobaoInfoKey.API_REFRESH_TOKEN, refreshToken);
   parameters.put(UserTaobaoInfoKey.API_CLIENT_ID, appKey);
   parameters.put(UserTaobaoInfoKey.API_CLIENT_SECRET, appSecret);
   parameters.put(UserTaobaoInfoKey.API_SCOPE, UserTaobaoInfoKey.API_SCOPE_VALUE);
   parameters.put(UserTaobaoInfoKey.API_VIEW, UserTaobaoInfoKey.API_VIEW_VALUE);
   String reponseStr =
       WebUtils.doPost(refreshTokenUrl, parameters, S.FIVE_SECONDS, S.FIVE_SECONDS);
   if (S.isInvalidValue(reponseStr)) {
     throw new IncorrectInputParameterException("Refresh token response return is null");
   }
   JSONObject responseObject = new JSONObject(reponseStr);
   String token = responseObject.getString(UserTaobaoInfoKey.API_ACCESS_TOKEN);
   if (token == null) {
     throw new IncorrectInputParameterException("Token return after refreshing is null");
   }
   return token;
 }
コード例 #3
0
 @Override
 protected JSONObject getOwnResult(
     int code, String reason, List<String> sourceList, List<String> ownerList) {
   try {
     JSONObject statusObject = new JSONObject();
     statusObject.put("status_code", code);
     statusObject.put("status_reason", reason);
     JSONArray idArray = new JSONArray();
     for (String shopId : sourceList) {
       JSONObject singleObject = new JSONObject();
       singleObject.put("shopID", shopId);
       singleObject.put("isfavorited", N.booleanToInt(ownerList.contains(shopId)));
       idArray.put(singleObject);
     }
     JSONObject result = new JSONObject();
     result.put("status", statusObject);
     result.put("isfavorited", idArray);
     return result;
   } catch (JSONException e) {
     LOGGER.error(e);
     return null;
   }
 }