public static String getWXJSSignature(String ticket, Map<String, Object> toSignData) { Map toSignMap = new TreeMap<String, Object>(); toSignMap.putAll(toSignData); toSignMap.put("jsapi_ticket", ticket); String waitSign = JOYWXJSServiceImpl.getWaitSignStr(toSignMap); String result = DigestUtil.encode("SHA1", waitSign); return result; }
public String getWXJSCrendentail(int data_type, String json_key) throws Exception { JOYWXJSData dataRequirement = new JOYWXJSData(); dataRequirement.type = data_type; // dataRequirement.expireTime = new Date(System.currentTimeMillis()); HashMap<String, Object> paraMap = new HashMap<String, Object>(); JOYWXJSData jsDataFilter = new JOYWXJSData(); jsDataFilter.type = data_type; paraMap.put("filter", jsDataFilter); paraMap.put("minExpireTime", new Date(System.currentTimeMillis())); List<Map<String, Object>> mapList = joywxjsDataDao.getPagedRecordList(paraMap); // List<JOYWXJSData> dataList if (mapList.size() == 0) { JSONObject getFromWX = null; if (data_type == JOYWXJSData.type_access_token) { getFromWX = JOYWXJSServiceImpl.getAccessTokenFromWX(); } else if (data_type == JOYWXJSData.type_jsapi_ticket) { String accessToken_pre = this.getWXJSCrendentail(JOYWXJSData.type_access_token, "access_token"); if (accessToken_pre != null) getFromWX = JOYWXJSServiceImpl.getJSAPITicketFromWX(accessToken_pre); } if (getFromWX != null) { JOYWXJSData toSaveToken = new JOYWXJSData(); toSaveToken.type = data_type; toSaveToken.expireTime = new Date( System.currentTimeMillis() + Long.parseLong(String.valueOf(getFromWX.get("expires_in"))) * 1000); toSaveToken.detailData = getFromWX.toJSONString(); joywxjsDataDao.insertRecord(toSaveToken); return String.valueOf(getFromWX.get(json_key)); } } else { JOYWXJSData tokenJson = new JOYWXJSData(); tokenJson.fromMap(mapList.get(0)); JSONParser parser = new JSONParser(); JSONObject tokenJobj = (JSONObject) parser.parse(tokenJson.detailData); return String.valueOf(tokenJobj.get(json_key)); } return null; }
public String getSignature(Map map) throws Exception { return JOYWXJSServiceImpl.getWXJSSignature( this.getWXJSCrendentail(JOYWXJSData.type_jsapi_ticket, "ticket"), map); }