Search in sources :

Example 6 with Charge

use of com.code.server.db.model.Charge 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";
}
Also used : User(com.code.server.db.model.User) UserBean(com.code.server.constant.game.UserBean) HashMap(java.util.HashMap) Charge(com.code.server.db.model.Charge) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ResponseVo(com.code.server.constant.response.ResponseVo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with Charge

use of com.code.server.db.model.Charge 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;
}
Also used : User(com.code.server.db.model.User) Element(org.dom4j.Element) Charge(com.code.server.db.model.Charge) IOException(java.io.IOException) ResponseVo(com.code.server.constant.response.ResponseVo) UserBean(com.code.server.constant.game.UserBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with Charge

use of com.code.server.db.model.Charge in project summer by foxsugar.

the class UnifiedOrder method charge.

/**
 * 微信统一下单
 *
 * @param userId
 * @param spIp
 * @param origin
 * @param money
 * @return
 */
@RequestMapping(value = "/charge", method = RequestMethod.POST)
public Map<String, Object> charge(String userId, String spIp, int origin, int money) {
    Map<String, Object> result = new HashMap<>();
    int code = 0;
    // }
    if (code != 0) {
        result.put("code", code);
        return result;
    }
    SortedMap<String, String> packageParams = new TreeMap<>();
    // 微信
    int money100 = money * 100;
    String body = "龙七棋牌-充值";
    String bodyUTF8 = null;
    try {
        bodyUTF8 = new String(body.getBytes(), "UTF-8");
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
    }
    String orderId = PayUtil.getOrderIdByUUId();
    // appID       应用id
    packageParams.put("appid", serverConfig.getAppId());
    // appID       商户号
    packageParams.put("mch_id", serverConfig.getMchId());
    // 32位随机数
    packageParams.put("nonce_str", PayUtil.getRandomStringByLength(32));
    // 商品描述
    packageParams.put("body", bodyUTF8);
    packageParams.put("out_trade_no", orderId);
    // 充值金额
    packageParams.put("total_fee", "" + money100);
    // 终端IP
    packageParams.put("spbill_create_ip", spIp);
    // 支付类型
    packageParams.put("trade_type", "APP");
    // 通知地址
    packageParams.put("notify_url", serverConfig.getNotifyUrl());
    String rtn = postCharge(packageParams);
    // 解析xmlString
    Element root = PayUtil.ParsingXML(rtn);
    SortedMap<String, String> secondParams = new TreeMap<>();
    // 业务成功
    if ("SUCCESS".equals(root.elementText("result_code"))) {
        secondParams.put("appid", serverConfig.getAppId());
        secondParams.put("partnerid", serverConfig.getMchId());
        secondParams.put("prepayid", root.elementText("prepay_id"));
        secondParams.put("noncestr", root.elementText("nonce_str"));
        secondParams.put("timestamp", String.valueOf(System.currentTimeMillis() / 1000));
        secondParams.put("package", "Sign=WXPay");
        String paySign = PayUtil.createSign("UTF-8", serverConfig.getKey(), secondParams);
        secondParams.put("sign", paySign);
        Charge charge = new Charge();
        charge.setOrderId(orderId);
        charge.setUserid(Long.valueOf(userId));
        charge.setMoney(money);
        charge.setMoney_point(money * 10);
        charge.setOrigin(origin);
        charge.setStatus(0);
        charge.setSign(paySign);
        charge.setSp_ip(spIp);
        charge.setRecharge_source("1");
        charge.setCreatetime(new Date());
        chargeService.save(charge);
    } else {
        // 余额不足
        if ("NOTENOUGH".equals(root.elementText("err_code"))) {
            secondParams.put("err_code", root.elementText("err_code"));
            secondParams.put("err_code_des", root.elementText("err_code_des"));
            result.put("code", 10000);
            return result;
        // 订单已支付
        } else if ("ORDERPAID".equals(root.elementText("err_code"))) {
            secondParams.put("err_code", root.elementText("err_code"));
            secondParams.put("err_code_des", root.elementText("err_code_des"));
            result.put("code", 11111);
            return result;
        // 订单已关闭
        } else if ("ORDERCLOSED".equals(root.elementText("err_code"))) {
            secondParams.put("err_code", root.elementText("err_code"));
            secondParams.put("err_code_des", root.elementText("err_code_des"));
            result.put("code", 10001);
            return result;
        }
    }
    // }
    result.put("params", secondParams);
    result.put("code", 0);
    return result;
}
Also used : Element(org.dom4j.Element) Charge(com.code.server.db.model.Charge) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with Charge

use of com.code.server.db.model.Charge in project summer by foxsugar.

the class GameRpcHandler method charge.

@Override
public void charge(Order order, AsyncMethodCallback<Integer> resultHandler) throws TException {
    long userId = order.getUserId();
    UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
    UserService userService = SpringUtil.getBean(UserService.class);
    User user = userService.getUserByUserId(userId);
    String name = "";
    if (userBean == null) {
        if (user != null) {
            if (order.getType() == ChargeType.money.getValue()) {
                user.setMoney(user.getMoney() + order.getNum());
            } else if (order.getType() == ChargeType.gold.getValue()) {
                user.setGold(user.getGold() + order.getNum());
            }
            userService.save(user);
            name = user.getUsername();
        } else {
            resultHandler.onComplete(RPCError.NO_USER.getValue());
            return;
        }
    } else {
        // 在redis里
        name = userBean.getUsername();
        if (order.getType() == ChargeType.money.getValue()) {
            double nowMoney = RedisManager.getUserRedisService().addUserMoney(userId, order.getNum());
            user.setMoney(nowMoney);
            userService.save(user);
        } else if (order.getType() == ChargeType.gold.getValue()) {
            RedisManager.addGold(userId, order.getNum());
        }
    }
    // 充值记录
    if (order.getAgentId() != 0 && order.getType() == ChargeType.money.getValue()) {
        Charge charge = new Charge();
        charge.setOrderId("" + IdWorker.getDefaultInstance().nextId());
        charge.setUserid(order.getUserId());
        charge.setUsername(name);
        charge.setCreatetime(new Date());
        charge.setCallbacktime(new Date());
        charge.setOrigin(order.getAgentId());
        charge.setMoney(order.getNum());
        charge.setMoney_point(order.getNum());
        charge.setRecharge_source("" + IChargeType.AGENT);
        charge.setStatus(1);
        SpringUtil.getBean(ChargeService.class).save(charge);
    }
    resultHandler.onComplete(0);
}
Also used : User(com.code.server.db.model.User) UserBean(com.code.server.constant.game.UserBean) UserService(com.code.server.db.Service.UserService) Charge(com.code.server.db.model.Charge) ChargeService(com.code.server.db.Service.ChargeService) Date(java.util.Date)

Example 10 with Charge

use of com.code.server.db.model.Charge in project summer by foxsugar.

the class PayServiceImpl method create.

@Override
public Charge create(Integer money) {
    Charge aCharge = new Charge();
    aCharge.setCreatetime(new Date());
    aCharge.setMoney(money);
    aCharge.setSign("0");
    Charge charge = dao.save(aCharge);
    return charge;
}
Also used : Charge(com.code.server.db.model.Charge) Date(java.util.Date)

Aggregations

Charge (com.code.server.db.model.Charge)10 UserBean (com.code.server.constant.game.UserBean)5 ResponseVo (com.code.server.constant.response.ResponseVo)5 User (com.code.server.db.model.User)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Date (java.util.Date)3 ChargeService (com.code.server.db.Service.ChargeService)2 UserService (com.code.server.db.Service.UserService)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 HashMap (java.util.HashMap)2 Element (org.dom4j.Element)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1