Пример #1
0
 /**
  * 获取当前用户店铺信息
  *
  * @return
  * @throws ApiException
  */
 public Shop getShop(String nick) throws ApiException {
   ShopGetRequest req = new ShopGetRequest();
   req.setFields("sid,cid,title,nick,desc,bulletin,pic_path,created,modified");
   req.setNick(nick);
   ShopGetResponse resp = client.execute(req);
   throwIfError(resp);
   return resp.getShop();
 }
Пример #2
0
 public static String getShopId(String apiUrl, String appKey, String appSecret, String userId)
     throws ApiException, IncorrectInputParameterException {
   final String nick = userId.replace(S.PREFIX_TAOBAO, S.EMPTY_STR);
   TaobaoClient client =
       new DefaultTaobaoClient(
           apiUrl, appKey, appSecret, Constants.FORMAT_JSON, S.FIVE_SECONDS, S.FIVE_SECONDS);
   ShopGetRequest request = new ShopGetRequest();
   request.setFields(UserTaobaoInfoKey.API_SID);
   request.setNick(nick);
   ShopGetResponse response = client.execute(request);
   if (response == null) {
     throw new IncorrectInputParameterException("ShopGetResponse return is null");
   }
   if (response.isSuccess()) {
     Long sid = response.getShop().getSid();
     return String.valueOf(sid);
   }
   throw new IncorrectInputParameterException(
       "User < "
           + userId
           + " > request seller shop id failed with error code and message < "
           + response.getErrorCode()
           + ","
           + response.getMsg()
           + " > and sub code and message < "
           + response.getSubCode()
           + ","
           + response.getSubMsg()
           + " >");
 }
Пример #3
0
  /**
   * 动态获取评分
   *
   * @param id
   * @return
   */
  public ShopVo dynamicGetScore(Integer id) throws Exception {
    if (logger.isInfoEnabled()) {
      logger.info("动态获取评分:id = " + id);
    }
    // 获取店铺信息与店铺授权信息
    ShopVo shopVo = getShopVo(id);

    if (logger.isInfoEnabled()) {
      logger.info("从外部平台动态获取评分信息:id = " + id);
    }

    // 判断来自哪个平台
    if (StringUtils.equals(shopVo.getOutPlatformType(), PlatformType.TAO_BAO.getName())
        || StringUtils.equals(shopVo.getOutPlatformType(), PlatformType.TAO_BAO_2.getName())) {
      // 来自淘宝平台
      Map<String, Object> argsMap = new HashMap<String, Object>();
      // 设置返回字段(必须)
      argsMap.put(
          ConstantTaoBao.FIELDS,
          "sid,cid,nick,title,desc,bulletin,pic_path,created,modified,shop_score");
      // 设置卖家昵称(必须)
      argsMap.put(ConstantTaoBao.NICK, shopVo.getNick());

      if (logger.isInfoEnabled()) {
        logger.info("查询淘宝店铺信息,参数argsMap = " + argsMap);
      }

      // 创建淘宝shopApi
      TbShopApi shopApi = new TbShopApi(shopVo.getSessionKey());
      // 获取淘宝店铺信息
      ShopGetResponse response = shopApi.shopGet(argsMap);
      if (StringUtils.isNotBlank(response.getErrorCode())) {
        throw new TaoBaoApiException(
            "调用淘宝 shopApi.getShop(" + argsMap + ")出现异常," + response.getBody());
      }
      com.taobao.api.domain.Shop shop = response.getShop();
      // 设置商品描述评分
      shopVo.setItemScore(shop.getShopScore().getItemScore());
      // 设置服务态度评分
      shopVo.setServiceScore(shop.getShopScore().getServiceScore());
      // 设置发货速度评分
      shopVo.setDeliveryScore(shop.getShopScore().getDeliveryScore());

    } else if (StringUtils.equals(shopVo.getOutPlatformType(), PlatformType.JING_DONG.getName())) {
      // todo:来自京东平台
    }

    // 获取评分信息的同时将评分信息更新到本地
    Shop shop = getById(id);

    if (shop == null) {
      shop = new Shop();
    }

    shop.setBulletin(shopVo.getBulletin());
    shop.setDescription(shopVo.getDescription());
    // 设置商品描述评分
    shop.setItemScore(shopVo.getItemScore());
    // 设置服务态度评分
    shop.setServiceScore(shopVo.getServiceScore());
    // 设置发货速度评分
    shop.setDeliveryScore(shopVo.getDeliveryScore());

    if (logger.isInfoEnabled()) {
      logger.info("店铺:更新评分信息至本地," + shop);
    }
    // 将评分信息更新到本地
    generalDAO.saveOrUpdate(shop);
    return shopVo;
  }