示例#1
0
 @Override
 public <T> T getObject(String key, Class<T> clazz) {
   if (StringTools.isEmpty(key) || clazz == null || !enable) {
     return null;
   }
   String jsonValue = get(key);
   return StringTools.isEmpty(jsonValue) ? null : (T) JsonTools.fromJson(jsonValue, clazz);
 }
示例#2
0
 @Override
 public void set(String key, String value) {
   if (StringTools.isEmpty(key) || !enable) {
     return;
   }
   client.set(buildKey(key), 0, value);
 }
示例#3
0
 @Override
 public void del(String key) {
   if (StringTools.isEmpty(key) || !enable) {
     return;
   }
   client.delete(buildKey(key));
 }
示例#4
0
 @Override
 public void setObject(String key, Object value, int exprieSecond) {
   if (StringTools.isEmpty(key) || value == null || exprieSecond < 0 || !enable) {
     return;
   }
   set(key, JsonTools.toJson(value), exprieSecond);
 }
示例#5
0
 @Override
 public void setObject(String key, Object value) {
   if (StringTools.isEmpty(key) || value == null || !enable) {
     return;
   }
   set(key, JsonTools.toJson(value));
 }
示例#6
0
 @Override
 public void set(String key, String value, int exprieSecond) {
   if (StringTools.isEmpty(key) || !enable) {
     return;
   }
   if (exprieSecond < 0) {
     exprieSecond = 0;
   }
   client.set(buildKey(key), exprieSecond, value);
 }
示例#7
0
 @Override
 public boolean add(String key, String value, int exprieSecond) {
   if (StringTools.isEmpty(key) || !enable) {
     return false;
   }
   if (exprieSecond < 0) {
     exprieSecond = 0;
   }
   return client.add(buildKey(key), exprieSecond, value).getStatus().isSuccess();
 }
示例#8
0
 @Override
 public String get(String key) {
   if (StringTools.isEmpty(key) || !enable) {
     return "";
   }
   GetFuture<Object> result = client.asyncGet(buildKey(key));
   if (result != null) {
     try {
       return (String) result.get(3, TimeUnit.SECONDS);
     } catch (InterruptedException e) {
       logger.error("Memcached asyncGet InterruptedException:", e);
     } catch (ExecutionException e) {
       logger.error("Memcached asyncGet ExecutionException:", e);
     } catch (TimeoutException e) {
       logger.error("Memcached asyncGet TimeoutException:", e);
     }
   }
   return "";
 }
示例#9
0
  public Result<WxPayResponse> execute(
      @Param(name = "cash", defaultValue = "0") Integer cash,
      @Param(name = "type", defaultValue = "0") Integer type,
      @Param("data1") Integer data1) {
    String domain = super.getDomain(request);

    UserDO userDO = super.getUserDO(request);
    ShoppingLevelEnum level = super.getLevel(request);

    if (userDO == null || userDO.getId() == null || StringTools.isEmpty(userDO.getOpenId())) {
      return Result.newInstance(null, "用户不存在", false);
    }

    TopupTypeEnum topupType = TopupTypeEnum.getByCode(type);
    if (topupType == null) {
      return Result.newInstance(null, "业务类型不存在", false);
    }
    cash = getPrice(userDO, level, topupType, data1, cash);
    if (cash < 0) {
      return Result.newInstance(null, "交易金额不能为负数", false);
    }

    if (super.getWxVersion(request) < 5) {
      return Result.newInstance(null, "您的微信版本低于5.0无法使用微信支付", false);
    }

    TopupDO topupDO = new TopupDO();
    topupDO.setUserId(userDO.getId());
    topupDO.setOpenId(userDO.getOpenId());
    topupDO.setAmount(cash);
    topupDO.setStatus(TopupStatusEnum.待支付.getCode());
    topupDO.setType(type);
    topupDO.setDescription(topupType.getDesc());
    if (data1 != null) {
      topupDO.setData1(data1 + "");
    }
    transactionManager.createTopup(topupDO);

    WxPayRequest wxPayRequest = new WxPayRequest();
    wxPayRequest.setOpenId(topupDO.getOpenId());
    wxPayRequest.setDescription(topupType.getDesc());
    wxPayRequest.setNotifyUrl("http://wxt.wetuan.com/wxCallback.htm");
    wxPayRequest.setTradeNo(topupDO.getUuid());
    if (systemConfigCache.getSwitch(SystemConfigKeyEnum.DEBUG_MODE.getCode())) {
      // 测试模式下, 只交易1分钱
      wxPayRequest.setTotalFee(new BigDecimal(1));
    } else {
      // 转化成分
      BigDecimal totalFee = new BigDecimal(topupDO.getAmount() * 100);
      wxPayRequest.setTotalFee(totalFee);
    }

    WxPayResponse wxPay = weixinManager.getUnifiedorder(domain, wxPayRequest);

    topupDO.setWeixinPrepayResult(wxPay.getResultCode());
    transactionManager.updateTopup(topupDO);

    SortedMap<String, String> parameters = new TreeMap<String, String>();
    parameters.put("appId", wxPay.getAppId());
    parameters.put("timeStamp", wxPay.getTimestamp());
    parameters.put("nonceStr", wxPay.getNonceStr());
    parameters.put("package", wxPay.getPackageValue());
    parameters.put("signType", "MD5");
    String paySign = weixinManager.createSignMD5(domain, parameters);
    wxPay.setPaySign(paySign);
    return Result.newInstance(wxPay, "交易成功", true);
  }