Пример #1
0
 /**
  * 获取登录类型
  *
  * @param request
  * @return
  */
 public static int getLoginType(HttpServletRequest request) {
   Map<String, Object> userMap = CommonUtil.getSessionUser(request);
   Object oLoginType = userMap.get(Constant.SESSION_UER_LOGIN_TYPE);
   int loginType =
       CommonUtil.notEmptyString(oLoginType) ? Integer.valueOf(oLoginType.toString()) : -1;
   return loginType;
 }
Пример #2
0
  public static Map<String, String> getParam(
      String appId, String appSecret, String requestUrl, String queryString) {
    if (token == null) {
      token = CommonUtil.getToken(appId, appSecret);
      jsapi_ticket = CommonUtil.getJsApiTicket(token.getAccessToken());
      time = getTime();
    } else {
      if (!time.substring(0, 13).equals(getTime().substring(0, 13))) {
        token = null;
        token = CommonUtil.getToken(appId, appSecret);
        jsapi_ticket = CommonUtil.getJsApiTicket(token.getAccessToken());
        time = getTime();
      }
    }
    String url = getUrl(requestUrl, queryString);
    Map<String, String> params = sign(jsapi_ticket, url);
    params.put("appid", appId);
    JSONObject jsonObject = JSONObject.fromObject(params);
    String jsonStr = jsonObject.toString();
    Map<String, String> map = new HashMap<>();
    map.put("timestamp", jsonObject.getString("timestamp"));
    map.put("appid", jsonObject.getString("appid"));
    map.put("nonceStr", jsonObject.getString("nonceStr"));
    map.put("jsapi_ticket", jsonObject.getString("jsapi_ticket"));
    map.put("signature", jsonObject.getString("signature"));
    System.out.println(jsonStr);

    return map;
  }
Пример #3
0
 public String GetCftPackage() throws SDKRuntimeException {
   if ("" == PartnerKey) {
     throw new SDKRuntimeException("��Կ����Ϊ�գ�");
   }
   String unSignParaString = CommonUtil.FormatBizQueryParaMap(parameters, false);
   String paraString = CommonUtil.FormatBizQueryParaMap(parameters, true);
   return paraString + "&sign=" + MD5SignUtil.Sign(unSignParaString, PartnerKey);
 }
Пример #4
0
 /*
  * <xml> <AppId><![CDATA[wwwwb4f85f3a797777]]></AppId>
  * <Package><![CDATA[a=1&url=http%3A%2F%2Fwww.qq.com]]></Package>
  * <TimeStamp> 1369745073</TimeStamp>
  * <NonceStr><![CDATA[iuytxA0cH6PyTAVISB28]]></NonceStr>
  * <RetCode>0</RetCode> <RetErrMsg><![CDATA[ok]]></ RetErrMsg>
  * <AppSignature><![CDATA[53cca9d47b883bd4a5c85a9300df3da0cb48565c]]>
  * </AppSignature> <SignMethod><![CDATA[sha1]]></ SignMethod > </xml>
  */
 public String CreateNativePackage(String retcode, String reterrmsg) throws SDKRuntimeException {
   HashMap<String, String> nativeObj = new HashMap<String, String>();
   if (CheckCftParameters() == false && retcode == "0") {
     throw new SDKRuntimeException("���package����ȱʧ��");
   }
   nativeObj.put("AppId", AppId);
   nativeObj.put("Package", GetCftPackage());
   nativeObj.put("TimeStamp", Long.toString(new Date().getTime() / 1000));
   nativeObj.put("RetCode", retcode);
   nativeObj.put("RetErrMsg", reterrmsg);
   nativeObj.put("NonceStr", CommonUtil.CreateNoncestr());
   nativeObj.put("AppSignature", GetBizSign(nativeObj));
   nativeObj.put("SignMethod", SignType);
   return CommonUtil.ArrayToXml(nativeObj);
 }
Пример #5
0
  public String GetBizSign(HashMap<String, String> bizObj) throws SDKRuntimeException {
    HashMap<String, String> bizParameters = new HashMap<String, String>();

    List<Map.Entry<String, String>> infoIds =
        new ArrayList<Map.Entry<String, String>>(bizObj.entrySet());

    Collections.sort(
        infoIds,
        new Comparator<Map.Entry<String, String>>() {
          public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) {
            return (o1.getKey()).toString().compareTo(o2.getKey());
          }
        });

    for (int i = 0; i < infoIds.size(); i++) {
      Map.Entry<String, String> item = infoIds.get(i);
      if (item.getKey() != "") {
        bizParameters.put(item.getKey().toLowerCase(), item.getValue());
      }
    }

    if (AppKey == "") {
      throw new SDKRuntimeException("APPKEYΪ�գ�");
    }
    bizParameters.put("appkey", AppKey);
    String bizString = CommonUtil.FormatBizQueryParaMap(bizParameters, false);
    // System.out.println(bizString);

    return SHA1Util.Sha1(bizString);
  }
Пример #6
0
  /*
   * weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXXX&productid=XXXXXX&timestamp
   * =XXXXXX&noncestr=XXXXXX
   */
  public String CreateNativeUrl(String productid) throws SDKRuntimeException {
    String bizString = "";
    try {
      HashMap<String, String> nativeObj = new HashMap<String, String>();
      nativeObj.put("appid", AppId);
      nativeObj.put("productid", URLEncoder.encode(productid, "utf-8"));
      nativeObj.put("timestamp", Long.toString(new Date().getTime() / 1000));
      nativeObj.put("noncestr", CommonUtil.CreateNoncestr());
      nativeObj.put("sign", GetBizSign(nativeObj));
      bizString = CommonUtil.FormatBizQueryParaMap(nativeObj, false);

    } catch (Exception e) {
      throw new SDKRuntimeException(e.getMessage());
    }
    return "weixin://wxpay/bizpayurl?" + bizString;
  }
Пример #7
0
  /**
   * 如果第二个字符串为空则返回第一个字符串,否则取两个字符串的交集
   *
   * @return "34,777"
   */
  public static String justInFirstString(String str1, String str2) {
    if (CommonUtil.isEmptyString(str2)) {
      return str1;
    }
    String[] str1Arr = str1.split(",");
    String[] str2Arr = str2.split(",");
    Set<String> set1 = new HashSet<String>();
    Set<String> set2 = new HashSet<String>();
    for (String str : str1Arr) {
      set1.add(str);
    }
    for (String str : str2Arr) {
      set2.add(str);
    }
    Set<String> retainSet = new HashSet<String>();
    retainSet.addAll(set1);
    retainSet.retainAll(set2);

    StringBuffer strB = new StringBuffer();
    for (String str : retainSet) {
      strB.append(str).append(",");
    }
    String resultStr = strB.toString();
    if (resultStr.endsWith(",")) {
      return resultStr.substring(0, resultStr.length() - 1);
    }
    return resultStr;
  }
Пример #8
0
 /**
  * 设置部门领导和用户登录后数据权限
  *
  * @param request
  * @param conditions
  */
 public static void setLeadersOrgans(HttpServletRequest request, Map<String, Object> conditions) {
   Map<String, Object> userMap = CommonUtil.getSessionUser(request);
   Object oLoginType = userMap.get(Constant.SESSION_UER_LOGIN_TYPE);
   int loginType =
       CommonUtil.notEmptyString(oLoginType) ? Integer.valueOf(oLoginType.toString()) : -2;
   if (loginType == 2) {
     String leadersOrganId = userMap.get(Constant.SESSION_UER_LOGIN_ORGANS).toString();
     String searchOrgId =
         conditions.get("organ_id") == null ? "" : conditions.get("organ_id").toString();
     String organ_id = CommonUtil.justInFirstString(leadersOrganId, searchOrgId);
     organ_id = CommonUtil.isEmptyString(organ_id) ? "-1" : organ_id;
     conditions.put("organ_id", organ_id);
   } else if (loginType == 3) {
     CommonUtil.setUserId2ParamsMap(conditions, request);
   }
 }
Пример #9
0
 /**
  * @return common Path folder in WEB-INF
  * @author phanthanhson create a directory
  */
 public static String getCommonPath(HttpServletRequest request) {
   String baseDir = CommonUtil.getBaseFolder();
   ServletContext context = request.getSession().getServletContext();
   String realBaseDir = context.getRealPath(baseDir);
   File baseFile = new File(realBaseDir);
   if (!baseFile.exists()) {
     baseFile.mkdir();
   }
   // Get commonPath in String form
   String commonPath = getBaseFolder() + getCommonFolderName();
   return commonPath;
 }
Пример #10
0
 /*
  * "appId" : "wxf8b4f85f3a794e77", //���ں���ƣ����̻����� "timeStamp" : "189026618",
  * //ʱ�����������ʹ����һ��ֵ "nonceStr" : "adssdasssd13d", //��� "package" :
  * "bank_type=WX&body=XXX&fee_type=1&input_charset=GBK&notify_url=http%3a%2f
  * %2fwww.qq.com&out_trade_no=16642817866003386000&partner=1900000109&
  * spbill_create_i
  * p=127.0.0.1&total_fee=1&sign=BEEF37AD19575D92E191C1E4B1474CA9",
  * //��չ�ֶΣ����̻����� "signType" : "SHA1", //΢��ǩ��ʽ:sha1 "paySign" :
  * "7717231c335a05165b1874658306fa431fe9a0de" //΢��ǩ��
  */
 public String CreateBizPackage() throws SDKRuntimeException {
   HashMap<String, String> nativeObj = new HashMap<String, String>();
   if (CheckCftParameters() == false) {
     throw new SDKRuntimeException("���package����ȱʧ��");
   }
   nativeObj.put("appId", AppId);
   nativeObj.put("package", GetCftPackage());
   nativeObj.put("timestamp", Long.toString(new Date().getTime() / 1000));
   nativeObj.put("noncestr", CommonUtil.CreateNoncestr());
   nativeObj.put("paySign", GetBizSign(nativeObj));
   nativeObj.put("signType", SignType);
   return null; // TODO JSONObject.fromObject(nativeObj).toString();
 }
Пример #11
0
 /**
  * 将jsonArray字符串转换成Map对象
  *
  * @param params
  * @return
  * @throws Exception
  */
 public static List<Map<String, Object>> convertJsonArrayStringA2Map(String params)
     throws Exception {
   List<Map<String, Object>> paramsList = new ArrayList<Map<String, Object>>();
   if (CommonUtil.notEmptyString(params)) {
     JSONArray jsonArray = new JSONArray(params);
     int len = jsonArray.length();
     for (int i = 0; i < len; i++) {
       Map<String, Object> map = convertJsonString2Map(jsonArray.getJSONObject(i).toString());
       paramsList.add(map);
     }
   }
   return paramsList;
 }
Пример #12
0
 /**
  * 获取session中的用户企业ID
  *
  * @param request
  * @return
  */
 public static String getSessionUserTenantId(HttpServletRequest request) {
   Map<String, Object> userMap = getSessionUser(request);
   String tenantId = null;
   if (CommonUtil.notEmptyCollections(userMap)) {
     String sessionUserType = userMap.get(Constant.SESSION_USER_TYPE).toString();
     if (sessionUserType.equals(Constant.SESSION_USER_TYPE_USER)) {
       tenantId = userMap.get("tenant_id").toString();
     } else if (sessionUserType.equals(Constant.SESSION_USER_TYPE_TENANT)) {
       tenantId = userMap.get("id").toString();
     }
   }
   return tenantId;
 }
Пример #13
0
 /*
  * { "appid":"wwwwb4f85f3a797777", "traceid":"crestxu",
  * "noncestr":"111112222233333", "package":
  * "bank_type=WX&body=XXX&fee_type=1&input_charset=GBK&notify_url=http%3a%2f%2f
  * www
  * .qq.com&out_trade_no=16642817866003386000&partner=1900000109&spbill_create_ip
  * =127.0.0.1&total_fee=1&sign=BEEF37AD19575D92E191C1E4B1474CA9",
  * "timestamp":1381405298,
  * "app_signature":"53cca9d47b883bd4a5c85a9300df3da0cb48565c",
  * "sign_method":"sha1" }
  */
 public String CreateAppPackage(String traceid) throws SDKRuntimeException {
   HashMap<String, String> nativeObj = new HashMap<String, String>();
   if (CheckCftParameters() == false) {
     throw new SDKRuntimeException("生成package参数缺失!");
   }
   nativeObj.put("appid", AppId);
   nativeObj.put("package", GetCftPackage());
   nativeObj.put("timestamp", Long.toString(new Date().getTime() / 1000));
   nativeObj.put("traceid", traceid);
   nativeObj.put("noncestr", CommonUtil.CreateNoncestr());
   nativeObj.put("app_signature", GetBizSign(nativeObj));
   nativeObj.put("sign_method", SignType);
   return JSONObject.fromObject(nativeObj).toString();
 }
Пример #14
0
 /**
  * 将企业ID加入到参数中
  *
  * @param paramsMap
  * @param request
  */
 public static void setUserId2ParamsMap(
     Map<String, Object> paramsMap, HttpServletRequest request) {
   Map<String, Object> userMap = getSessionUser(request);
   String userId = null;
   if (CommonUtil.notEmptyCollections(userMap)) {
     String sessionUserType = userMap.get(Constant.SESSION_USER_TYPE).toString();
     if (sessionUserType.equals(Constant.SESSION_USER_TYPE_USER)) {
       userId = userMap.get("id").toString();
     } else if (sessionUserType.equals(Constant.SESSION_USER_TYPE_TENANT)) {
       userId = userMap.get("id").toString(); // 企业ID
     }
   }
   paramsMap.put("user_id", userId);
 }
Пример #15
0
 /**
  * 将json字符串转换成Map对象
  *
  * @param params
  * @return
  * @throws Exception
  */
 public static HashMap<String, Object> convertJsonString2Map(String params) throws Exception {
   HashMap<String, Object> paramsMap = new HashMap<String, Object>();
   if (CommonUtil.notEmptyString(params)) {
     JSONObject jsonObject = new JSONObject(params);
     Iterator it = jsonObject.keys();
     while (it.hasNext()) {
       String key = (String) it.next();
       String value = jsonObject.getString(key);
       if (notEmptyString(value)) {
         paramsMap.put(key, value);
       }
     }
   }
   return paramsMap;
 }
Пример #16
0
 /**
  * 获取登录类型
  *
  * @param request
  * @return -1、异常状态; 0、客户端登录; 1、企业管理员登录; 2、部门领导登录; 3、企业用户个人登录
  */
 public static int loginTypeCode(HttpServletRequest request) {
   String userFromSource = getSessionUserSource(request);
   if (Constant.SESSION_USER_SOURCE_MOBILE.equals(userFromSource)) {
     return Constant.SESSION_UER_LOGIN_TYPE_CLIENT;
   }
   if (userFromSource.equals(Constant.SESSION_USER_SOURCE_WEB)) {
     Map<String, Object> userMap = getSessionUser(request);
     String sessionUserType = userMap.get(Constant.SESSION_USER_TYPE).toString();
     if (sessionUserType.equals(Constant.SESSION_USER_TYPE_TENANT)) {
       return Constant.SESSION_UER_LOGIN_TYPE_ADMIN;
     } else if (sessionUserType.equals(Constant.SESSION_USER_TYPE_USER)) {
       Object oIsLeader = userMap.get("isLeader");
       if (CommonUtil.notEmptyString(oIsLeader) && Boolean.valueOf(oIsLeader.toString())) {
         return Constant.SESSION_UER_LOGIN_TYPE_ORGAN;
       } else {
         return Constant.SESSION_UER_LOGIN_TYPE_USER;
       }
     }
   }
   return Constant.SESSION_UER_LOGIN_TYPE_ERROR;
 }
Пример #17
0
 /**
  * 获取session中的用户来源
  *
  * @param request
  * @return
  */
 public static String getSessionUserSource(HttpServletRequest request) {
   Object userFromSource = request.getSession().getAttribute(Constant.SESSION_USER_SOURCE);
   return CommonUtil.isEmptyString(userFromSource) ? null : userFromSource.toString();
 }
Пример #18
0
 /**
  * 参数为空
  *
  * @param params
  * @return
  */
 public static ModelAndView getNullParamsResult(String params) {
   ModelMap model = new ModelMap();
   CommonUtil.setFailureMessage(model, "01", "参数为空");
   return new ModelAndView("/page", model);
 }