use of com.code.server.constant.game.UserBean in project summer by foxsugar.
the class GameRpcNewHandler method getUserInfo.
@Override
public void getUserInfo(long userId, AsyncMethodCallback<com.code.server.rpc.idl.User> resultHandler) throws TException {
com.code.server.rpc.idl.User userRep = new com.code.server.rpc.idl.User();
UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
if (userBean == null) {
UserService userService = SpringUtil.getBean(UserService.class);
User user = userService.getUserByUserId(userId);
if (user != null) {
userRep.setId(userId);
userRep.setGold(user.getGold());
userRep.setMoney(user.getMoney());
userRep.setUsername(user.getUsername());
}
} else {
userRep.setId(userBean.getId());
userRep.setGold(userBean.getGold());
userRep.setMoney(userBean.getMoney());
userRep.setUsername(userBean.getUsername());
}
resultHandler.onComplete(userRep);
}
use of com.code.server.constant.game.UserBean in project summer by foxsugar.
the class LoginAction method checkOpenId.
@RequestMapping("/checkOpenId")
public Map<String, Object> checkOpenId(String openId, String username, String image, int sex, String token_user) {
int code = 0;
Map<String, Object> params = new HashMap<>();
String userId = userRedisService.getUserIdByOpenId(openId);
if (userId == null) {
code = login4sqlByOpenId(openId, username, image, sex, params);
userId = (String) params.get("userId");
} else {
// 刷新redis数据
UserBean userBean = userRedisService.getUserBean(Long.valueOf(userId));
if (userBean != null) {
userBean.setUsername(username);
userBean.setImage(image);
userBean.setSex(sex);
userBean.setLastLoginDate(new Date());
userRedisService.updateUserBean(Long.valueOf(userId), userBean);
}
String redisToken = getToken(Long.valueOf(userId));
userRedisService.setToken(Long.valueOf(userId), redisToken);
params.put("token", redisToken);
params.put("userId", userId);
}
// 黑名单
boolean isInBlackList = ServerManager.constant.getBlackList() != null && ServerManager.constant.getBlackList().contains(userId);
if (isInBlackList) {
code = ErrorCode.BLACK_LIST;
} else {
setHostAndPort(userId, params, code == 0);
}
return getParams("checkOpenId", params, code);
}
use of com.code.server.constant.game.UserBean in project summer by foxsugar.
the class LoginAction method saveUser2Redis.
public static void saveUser2Redis(User user, String token) {
UserBean userBean = GameUserService.user2userBean(user);
// userId-userbean
RedisManager.getUserRedisService().setUserBean(userBean);
// userId-money
RedisManager.getUserRedisService().setUserMoney(user.getId(), user.getMoney());
RedisManager.getUserRedisService().setUserGold(user.getId(), user.getGold());
// userId-token
RedisManager.getUserRedisService().setToken(user.getId(), token);
// account-userId
RedisManager.getUserRedisService().setAccountUserId(user.getAccount(), user.getId());
// userId-account
RedisManager.getUserRedisService().setUserIdAccount(user.getId(), user.getAccount());
// openid-userId
RedisManager.getUserRedisService().setOpenIdUserId(user.getOpenId(), user.getId());
// userId-openid
RedisManager.getUserRedisService().setUserIdOpenId(user.getId(), user.getOpenId());
}
use of com.code.server.constant.game.UserBean in project summer by foxsugar.
the class TestAction method callback.
@RequestMapping("/Pay/callback")
public String callback(HttpServletRequest request) {
String memberid = request.getParameter("memberid");
String orderid = request.getParameter("orderid");
String amount = request.getParameter("amount");
String datetime = request.getParameter("datetime");
String returncode = request.getParameter("returncode");
String sign = request.getParameter("sign");
String transaction_id = request.getParameter("transaction_id");
logger.info("{}", transaction_id);
String SignTemp = "amount=" + amount + "&datetime=" + datetime + "&memberid=" + memberid + "&orderid=" + orderid + "&transaction_id=" + transaction_id + "&returncode=" + returncode + "&key=" + keyValue + "";
String md5sign = null;
try {
md5sign = md5(SignTemp);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
logger.info("-------------------------------");
logger.info("memberid{}, orderid{}, amount{}, datetime{}, requestcode{}, returncode{}, reserved1{}, reserverd2{}, sign{}, tempSign{}", memberid, orderid, amount, datetime, returncode, sign, SignTemp);
logger.info("-------------------------------");
logger.info("-local sign:{}", md5sign);
logger.info("-sign:{}", sign);
if (true) {
if (returncode.equals("00")) {
Charge charge = chargeService.getChargeByOrderid(orderid);
if (charge.getStatus() == 1) {
return "success";
}
charge.setStatus(1);
chargeService.save(charge);
logger.info("支付成功!");
UserBean UserBeanRedis = userRedisService.getUserBean(charge.getUserid());
double addMoney = charge.getMoney();
if (UserBeanRedis != null) {
userRedisService.addUserMoney(charge.getUserid(), addMoney);
} else {
User user = userService.getUserByUserId(charge.getUserid());
System.out.println("修改玩家豆豆");
user.setMoney(user.getMoney() + addMoney);
userService.save(user);
}
System.out.println("通知客户端刷新充值");
Map<String, String> rs = new HashMap<>();
MsgSender.sendMsg2Player(new ResponseVo("userService", "refresh", rs), charge.getUserid());
} else {
logger.info("支付失败");
return "failed";
}
} else {
logger.info("支付失败");
return "failed";
}
return "success";
}
use of com.code.server.constant.game.UserBean in project summer by foxsugar.
the class PayCallback method callback.
/**
* 接受微信回调
*
* @param
*/
@RequestMapping(value = "/callback")
public String callback(HttpServletRequest request, HttpServletResponse response) {
System.out.println("接受回调参数");
// 获取微信返回结果
String parameterstr = PayUtil.ObtainParameterString(request);
System.out.println("parameterstr:" + parameterstr);
// 解析xmlString
Element element = PayUtil.ParsingXML(parameterstr);
SortedMap<String, String> secondParams = new TreeMap<>();
secondParams.put("appid", element.elementText("appid"));
secondParams.put("bank_type", element.elementText("bank_type"));
secondParams.put("cash_fee", element.elementText("cash_fee"));
secondParams.put("fee_type", element.elementText("fee_type"));
secondParams.put("is_subscribe", element.elementText("is_subscribe"));
secondParams.put("mch_id", element.elementText("mch_id"));
secondParams.put("nonce_str", element.elementText("nonce_str"));
secondParams.put("openid", element.elementText("openid"));
secondParams.put("out_trade_no", element.elementText("out_trade_no"));
secondParams.put("result_code", element.elementText("result_code"));
secondParams.put("return_code", element.elementText("return_code"));
secondParams.put("time_end", element.elementText("time_end"));
secondParams.put("total_fee", element.elementText("total_fee"));
secondParams.put("trade_type", element.elementText("trade_type"));
secondParams.put("transaction_id", element.elementText("transaction_id"));
String paySign = PayUtil.createSign("UTF-8", serverConfig.getKey(), secondParams);
System.out.println(paySign);
// 解析返回结果
String returnXML = null;
System.out.println("回调成功");
// 业务返回成功
Charge charge = chargeService.getChargeByOrderid(element.elementText("out_trade_no"));
if ("SUCCESS".equals(element.elementText("result_code"))) {
String transaction_id = element.elementText("transaction_id");
charge.setTransaction_id(transaction_id);
System.out.println("业务成功");
System.out.println(charge.getMoney());
System.out.println(element.elementText("cash_fee"));
System.out.println(paySign);
System.out.println(element.elementText("sign"));
int money_total = Integer.valueOf(element.elementText("total_fee")) / 100;
if (paySign.equals(element.elementText("sign")) && charge.getMoney() == money_total) {
if (0 == charge.getStatus()) {
System.out.println("修改订单状态");
// 修改支付订单状态 已支付
charge.setStatus(1);
charge.setCallbacktime(new Date());
chargeService.save(charge);
UserBean UserBeanRedis = userRedisService.getUserBean(charge.getUserid());
int addMoney = Integer.valueOf(element.elementText("total_fee")) / 10;
// 龙七分档
if (chargeMoney.containsKey(money_total)) {
addMoney = chargeMoney.get(money_total);
}
if (UserBeanRedis != null) {
// userRedisService.setUserMoney(charge.getUserid(),UserBeanRedis.getMoney() + Double.valueOf(element.elementText("total_fee")) / 10);
userRedisService.addUserMoney(charge.getUserid(), addMoney);
} else {
// 查询玩家
User user = userService.getUserByUserId(charge.getUserid());
System.out.println("修改玩家豆豆");
// 修改玩家豆豆
user.setMoney(user.getMoney() + addMoney);
userService.save(user);
}
System.out.println("通知客户端刷新充值");
Map<String, String> rs = new HashMap<>();
MsgSender.sendMsg2Player(new ResponseVo("userService", "refresh", rs), charge.getUserid());
} else {
Map<String, String> rs = new HashMap<>();
rs.put("err_code", element.elementText("err_code"));
rs.put("err_code_des", element.elementText("err_code_des"));
ResponseVo vo = new ResponseVo("userService", "refresh", rs);
vo.setCode(ErrorCode.ORDER_WAS_PAID);
MsgSender.sendMsg2Player(vo, charge.getUserid());
}
/*returnXML = "<xml>";
returnXML += "<return_code>![CDATA[SUCCESS]]</return_code>";
returnXML += "<return_msg>![CDATA[OK]]</return_msg>";
returnXML += "</xml>";*/
returnXML = "SUCCESS";
} else {
Map<String, String> rs = new HashMap<>();
rs.put("err_code", element.elementText("err_code"));
rs.put("err_code_des", element.elementText("err_code_des"));
ResponseVo vo = new ResponseVo("userService", "refresh", rs);
vo.setCode(ErrorCode.PARAMETER_SIGN_MONEY_ERROR);
MsgSender.sendMsg2Player(vo, charge.getUserid());
returnXML = "SUCCESS";
}
} else {
// 余额不足
if ("NOTENOUGH".equals(element.elementText("err_code"))) {
Map<String, String> rs = new HashMap<>();
rs.put("err_code", element.elementText("err_code"));
rs.put("err_code_des", element.elementText("err_code_des"));
ResponseVo vo = new ResponseVo("userService", "refresh", rs);
vo.setCode(ErrorCode.BALANCE_INSUFFICIENT);
MsgSender.sendMsg2Player(vo, charge.getUserid());
// 订单已支付
} else if ("ORDERPAID".equals(element.elementText("err_code"))) {
Map<String, String> rs = new HashMap<>();
rs.put("err_code", element.elementText("err_code"));
rs.put("err_code_des", element.elementText("err_code_des"));
ResponseVo vo = new ResponseVo("userService", "refresh", rs);
vo.setCode(ErrorCode.ORDER_WAS_PAID);
MsgSender.sendMsg2Player(vo, charge.getUserid());
// 订单已关闭
} else if ("ORDERCLOSED".equals(element.elementText("err_code"))) {
Map<String, String> rs = new HashMap<>();
rs.put("err_code", element.elementText("err_code"));
rs.put("err_code_des", element.elementText("err_code_des"));
ResponseVo vo = new ResponseVo("userService", "refresh", rs);
vo.setCode(ErrorCode.ORDER_WAS_CLOSED);
MsgSender.sendMsg2Player(vo, charge.getUserid());
}
returnXML = "SUCCESS";
}
System.out.println("回调结束,返回微信成功信息");
System.out.println(returnXML);
try {
response.getWriter().write(returnXML);
response.getWriter().flush();
} catch (IOException e) {
e.printStackTrace();
}
return returnXML;
}
Aggregations