/** * 创建更新激活码 * * @param model * 激活码 * @return 激活码编号 */ public int createUpdate(wh.game.model.ActiveCode model) throws Exception{ Map<String, Object> inParameters = new HashMap<String, Object>(); inParameters.put("ActiveCodeId", model.getActiveCodeId()); inParameters.put("GameId", model.getGameId()); inParameters.put("ServerId", model.getServerId()); inParameters.put("Name", model.getName()); inParameters.put("Code", model.getCode()); inParameters.put("ActiveCodeType", model.getActiveCodeType()); inParameters.put("CreateDate", Utility.getSqlDate(model.getCreateDate())); inParameters.put("ModifyDate", Utility.getSqlDate(model.getModifyDate())); inParameters.put("Status", model.getStatus()); inParameters.put("UsedType", model.getUsedType()); OutParameters outParameters = new OutParameters(); outParameters.putOutParmType("ErrNo", java.sql.Types.INTEGER); outParameters.putOutParmType("ErrMsg", java.sql.Types.NVARCHAR); int parasCount = inParameters.size() + outParameters.getOutParmTypes().size(); StringBuilder sbBuilder = new StringBuilder(); for (int i = 0; i < parasCount; i++) { if (0 == i) { sbBuilder.append("?"); } else { sbBuilder.append(",?"); } } int retValue = SQLHelper.runProcedureNonQuery(Config.CONNECTION_STRING_ULD, "{? = call WH_Game_ActiveCode_CreateUpdate(" + sbBuilder.toString() + ")}", inParameters, outParameters); int errNo = Integer.valueOf(outParameters.getOutParmValue("ErrNo").toString()); String errMsg = outParameters.getOutParmValue("ErrMsg").toString(); MyErr.checkErr(errNo, errMsg); return retValue; }
@SuppressWarnings("unchecked") public MessageReturn checkSid(String sid, int gameIdp, int serverIdp, int channelIdp, int channelSubIdp, int mobiledeviceIdp, int statisticAnalysisIdp) { MessageReturn messageReturn = new MessageReturn(); final int gameId = gameIdp; final int serverId = serverIdp; final int channelId = channelIdp; final int channelSubId = channelSubIdp; final int mobiledeviceId = mobiledeviceIdp; final int statisticAnalysisId = statisticAnalysisIdp; LogHelper.log("UserUc->checkSid gameId:" + String.valueOf(gameId)); LogHelper.log("UserUc->checkSid serverId:" + String.valueOf(serverId)); String checkSidUrl = "http://payunite.ulaoda.com/UCCheckSid.ashx?sid=" + sid + "&gameId=" + gameId; LogHelper.log("UserUc->checkSid url:" + checkSidUrl); Map<String, String> retMap = null; try { String retValue = Utility.getWebContent(checkSidUrl); if (!Utility.isEmpty(retValue)) { retMap = (Map<String, String>) JSONObject.parseObject(retValue, Map.class); } else { LogHelper.log("UserUc->checkSid retMap is empty:" + checkSidUrl); } } catch (IOException e) { e.printStackTrace(); LogHelper.log("UserUc->checkSid exception:" + e.getMessage()); } if (retMap != null) { int errNo = Utility.getInt(retMap.get("ErrNo")); if (errNo < 0) { messageReturn.setErr(errNo, retMap.get("ErrMsg")); } else { Map<String, String> tempMap = new HashMap<String, String>(); String ucid = retMap.get("ucid"); tempMap.put("UserId", retMap.get("ucid")); tempMap.put("UserName", retMap.get("nickName")); final String channelUserId = tempMap.get("UserId"); // 模拟登录 new Thread() { public void run() { LogHelper.log("UserUc->checkSid thread begin" + String.valueOf(serverId)); UserUnite.getInstance().login(gameId, serverId, channelId, channelSubId, channelUserId, mobiledeviceId, statisticAnalysisId); LogHelper.log("UserUc->checkSid thread end" + String.valueOf(serverId)); } }.start(); // 针对于傲剑游戏提供的时间签名 setTimeSignForAojian(messageReturn, gameId, tempMap, channelId, ucid); } } return messageReturn; }
/** * 获取游戏接口参数列表 * * @param queryModel * 查询用户实体 * @param totalCount * 返回总数量 * @param isAll * 是否获取所有数据,false、否;true、是; * @param pageIndex * 页码,从1开始(>=1) * @param pageSize * 每页显示数量 * @param fldSort * 排序字段,默认""则按照主键编号排序 * @param sortType * 排序方法,0为升序,1为降序 * @return 游戏接口参数列表 */ public List<wh.game.model.GameInterfaceParams> getList(wh.game.model.GameInterfaceParams queryModel, RefObject<Integer> totalCount, boolean isAll, int pageIndex, int pageSize, String fldSort, int sortType) throws Exception { List<wh.game.model.GameInterfaceParams> list = new ArrayList<wh.game.model.GameInterfaceParams>(); if (Utility.isEmpty(fldSort)) { fldSort = ""; } Map<String, Object> inParameters = new HashMap<String, Object>(); inParameters.put("IsAll", isAll); inParameters.put("PageIndex", pageIndex); inParameters.put("PageSize", pageSize); inParameters.put("FldSort", fldSort); inParameters.put("SortType", sortType); inParameters.put("GameInterfaceParamsId", queryModel.getGameInterfaceParamsId()); inParameters.put("GameInterfaceId", queryModel.getGameInterfaceId()); inParameters.put("GameId", queryModel.getGameId()); inParameters.put("ParamName", queryModel.getParamName()); inParameters.put("ParamValue", queryModel.getParamValue()); inParameters.put("ParamExplain", queryModel.getParamExplain()); inParameters.put("SignType", queryModel.getSignType()); inParameters.put("SignIndex", queryModel.getSignIndex()); inParameters.put("ParamType", queryModel.getParamType()); inParameters.put("ParamInType", queryModel.getParamInType()); inParameters.put("ParamOutType", queryModel.getParamOutType()); inParameters.put("SignFormatValue", queryModel.getSignFormatValue()); Map<String, Integer> outParameters = new HashMap<String, Integer>(); outParameters.put("ErrNo", java.sql.Types.INTEGER); outParameters.put("ErrMsg", java.sql.Types.NVARCHAR); outParameters.put("TotalCount", java.sql.Types.INTEGER); int parasCount = inParameters.size() + outParameters.size(); StringBuilder sbBuilder = new StringBuilder(); for (int i = 0; i < parasCount; i++) { if (0 == i) { sbBuilder.append("?"); } else { sbBuilder.append(",?"); } } ResultSet rs = null; CallableStatement cstmt = null; int errNo = 0; String errMsg = ""; try { rs = SQLHelper.runProcedure(Config.CONNECTION_STRING_ULD, "{call WH_Game_GameInterfaceParams_GetList(" + sbBuilder.toString() + ")}", inParameters, outParameters); if (rs != null) { while (rs.next()) { list.add(getModel(rs)); } cstmt = (CallableStatement)rs.getStatement(); errNo = cstmt.getInt("ErrNo"); errMsg = cstmt.getString("ErrMsg"); totalCount.argvalue = cstmt.getInt("TotalCount"); } } catch (Exception e) { throw new Exception(e.getMessage(), e); } finally { SQLHelper.closeAll(cstmt); } MyErr.checkErr(errNo, errMsg); return list; }
/** * 在我们平台创建订单 * * @param playerId * 角色编号,供订单充值成功后调用游戏服务器,传给游戏方 * @param channelUserId * 渠道用户编号 * @param channleId * 我们定义的渠道编号 * @param channelSubId * 我们定义的渠道子编号 * @param gameId * 我们定义的游戏编号 * @param serverId * 我们定义的服务器编号 * @param orderId * 渠道方的订单编号 * @param amount * 渠道方的订单金额 * @param payWay * 渠道方的充值方式 * @param payWayName * 渠道方的充值方式名称 * @return */ public MessageReturn checkOrder(String playerId, String channelUserId, int channelId, int channelSubId, int gameId, int serverId, String orderId, float amount, int payWay, String payWayName) { MessageReturn messageReturn = new MessageReturn(); LogHelper.log("channelUserId:" + channelUserId); LogHelper.log("channelId:" + channelId); LogHelper.log("channelSubId:" + channelSubId); LogHelper.log("gameId:" + gameId); LogHelper.log("orderId:" + orderId); LogHelper.log("amount:" + amount); // 创建一下订单,不需要告知游戏方,因为会在客户端通知游戏方,订单提交成功 // 对于订单处理成功,渠道方会调用我们的一个地址,在那里需要通知游戏方订单处理成功 String userName = UserUnite.getUserNameByChannelUserId(channelId, channelSubId, channelUserId); LogHelper.log("userName:"******"", 1, refMyErr); int userId = 0; if (user != null) { userId = user.getUserId(); LogHelper.log("user is not null userId:" + userId); } LogHelper.log("userId:" + userId); wh.order.model.Order order = null; // 需要先判断一下UC的这个订单是否回调web 充值端已经创建,如果已经创建则不再创建 wh.order.model.Order queryModel = new wh.order.model.Order(); queryModel.setTel(channelUserId + "_UCUSERIDORDERID_" + orderId); queryModel.setStatus((byte) 1); RefObject<Integer> totalCount = new RefObject<Integer>(0); java.util.List<wh.order.model.Order> list = wh.order.bll.Order.getInstance().getList(queryModel, totalCount, true, 1, 1, "", 0, refMyErr); if (list.size() > 0) { order = list.get(0); messageReturn.setRetObject(order.getOrderId());//统一传游老大订单编号 } // 如果web服务端并没有创建orderBean,那就根据Uc传过来的参数创建OrderBean // 谁创建orderBean谁创建orderChannelBean if (order == null) { order = new wh.order.model.Order(); order.setGameId(gameId); order.setServerId(serverId); order.setUserId(userId); order.setChargedUserId(userId); order.setChargedUserName(userName); order.setPaySourceType(OrderEnum.PaySourceType.Android客户端.getValue()); order.setOrderType(OrderEnum.OrderType.已提交.getValue()); order.setAccountType(OrderEnum.AccountType.D币.getValue()); order.setChargeType(OrderEnum.ChargeType.充值游戏.getValue()); order.setCreateDate(new Date()); order.setModifyDate(new Date()); order.setTel(channelUserId + "_UCUSERIDORDERID_" + orderId); order.setPayAccount(BigDecimal.valueOf((amount))); order.setRealPayAccount(BigDecimal.valueOf(amount)); // 75为其他渠道充值 order.setPayType((byte) 75); order.setStatus((byte) 1); // 注:因从客户端传过来的ServerId实际为SequenceNumber,所以在此要转化一下 order.setServerId(ServerTools.getServerIdBySequenceNumber(order.getGameId(), order.getServerId(), "UserUC-checkOrder")); messageReturn = wh.order.bll.Order.getInstance().createUpdate(order); // 将数据写入OrderChannel表中 // OrderChannel 需要的参数 // localOrderId 本地订单编号ok // regChannelId 注册渠道编号---user.getChannelId() // ocChannelId 实际渠道编号---channel.txt // gameChannelId 游戏方渠道编号--->大渠道实际,小渠道7 // status=1 wh.order.model.OrderChannel orderChannelModel = new OrderChannel(); orderChannelModel.setLocalOrderId(Utility.getInt(messageReturn.getRetObject())); orderChannelModel.setRegChannelId(user.getChannelId()); orderChannelModel.setOcChannelId(channelId); orderChannelModel.setGameChannelId(channelId); orderChannelModel.setStatus((byte) 1); wh.order.bll.OrderChannel.getInstance().createUpdate(orderChannelModel); wh.order.model.OrderLog orderLog = new wh.order.model.OrderLog(); orderLog.setCreateDate(new Date()); orderLog.setLogName("playerid"); orderLog.setDescription(playerId); orderLog.setOrderId(Utility.getInt(messageReturn.getRetObject())); orderLog.setStatus((byte) 1); orderLog.setUserId(userId); wh.order.bll.OrderLog.getInstance().createUpdate(orderLog); } return messageReturn; }
// 针对于傲剑游戏提供的时间签名,RSA签名之后将值返回给客户端 private void setTimeSignForAojian(MessageReturn messageReturn, final int gameId, Map<String, String> tempMap, int channelId, String ucid) { if (gameId == 8) { RefObject<MyErr> refMyErr = new RefObject<MyErr>(null); ; // 其中 // timesign = RSA({"time": // "2013-11-11 15:26:32","addValue":"1","channelid":"13","userid":"uld123456","MD5":"8C5EABE5012EA60BEF37742D54E9C607"}) // MD5 = MD5(time + addValue + channelid + userid); String time = Utility.getFormatDate(); int addValue = wh.member.bll.HBUser.getInstance().getMaxHbUserId(refMyErr); String channelid = String.valueOf(channelId); String userid = ucid; String md5String = Utility.encodeMD5(time + addValue + channelId + userid); TimeSignObject tso = new TimeSignObject(); tso.setTime(time); tso.setAddvalue(String.valueOf(addValue)); tso.setChannelid(channelid); tso.setUserid(userid); tso.setMd5(md5String); String timeString = JSON.toJSONString(tso); // 处理截取的字符串存入cutVector中,再将cutVector中的字符串依次加密 int timeStringLength = timeString.getBytes().length; int cutLength = 100; Vector<String> cutVector = new Vector<String>(); for (int i = 0; i < timeStringLength; i += cutLength) { if (i < timeStringLength && timeStringLength / (cutLength + i) != 0) { cutVector.add(timeString.substring(i, i + cutLength)); } else { cutVector.add(timeString.substring(i, timeStringLength)); } } // 签名准备 String timeSign = ""; RSAEncrypt rsaEncrypt = new RSAEncrypt(); try { rsaEncrypt.loadPublicKey(Config.getConfig("GAME_TIMESIGN_RSA_PUBLIC_KEY_" + gameId)); rsaEncrypt.loadPrivateKey(Config.getConfig("GAME_TIMESIGN_RSA_PRIVATE_KEY_" + gameId)); Vector<String> signStrings = new Vector<String>(); for (int i = 0; i < cutVector.size(); i++) { byte[] encodeBytes = rsaEncrypt.encrypt(rsaEncrypt.getPublicKey(), cutVector.get(i).getBytes("UTF-8")); signStrings.add(Base64.encode(encodeBytes)); } Iterator<String> iterator2 = signStrings.iterator(); while (iterator2.hasNext()) { timeSign += iterator2.next(); } } catch (Exception e) { e.printStackTrace(); } tempMap.put("TimeSign", timeSign); } messageReturn.setRetObject(tempMap); }