Prechádzať zdrojové kódy

thêm hàm đồng bộ mua lượt qua sms

student 1 mesiac pred
rodič
commit
d8f3e3c88d

+ 155 - 1
KittyFallWs/KittyFallWs/src/com/vas/webservices/KittyFallWs.java

@@ -840,7 +840,161 @@ public class KittyFallWs extends WebserviceAbstract {
     }
     
     
-    
+    @WebMethod(operationName = "contentRequest", action = "contentRequest")
+    @SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
+    @RequestWrapper(localName = "contentRequest", targetNamespace = "http://contentws/xsd")
+    public String contentRequest(
+            @WebParam(name = "username", targetNamespace = "http://contentws/xsd") String wsUser,
+            @WebParam(name = "password", targetNamespace = "http://contentws/xsd") String wsPass,
+            @WebParam(name = "serviceid", targetNamespace = "http://contentws/xsd") String serviceid,
+            @WebParam(name = "msisdn", targetNamespace = "http://contentws/xsd") String msisdn,
+            @WebParam(name = "chargetime", targetNamespace = "http://contentws/xsd") String chargetime,
+            @WebParam(name = "params", targetNamespace = "http://contentws/xsd") String params,
+            @WebParam(name = "mode", targetNamespace = "http://contentws/xsd") String mode,
+            @WebParam(name = "amount", targetNamespace = "http://contentws/xsd") String amount,
+            @WebParam(name = "transactionid", targetNamespace = "http://contentws/xsd") String transactionId) {
+
+        Response response = new Response();
+        response.setErrorCode(SUCCESS);
+        // translog
+        Timestamp reqTime = new Timestamp(System.currentTimeMillis());
+        TransactionLog transLog = new TransactionLog();
+        transLog.setTransactionId(transactionId);
+        transLog.setCommand(params);
+        transLog.setMsisdn(msisdn);
+        transLog.setRequestTime(reqTime);
+        transLog.setRequest(serviceid + "|" + msisdn + "|" + chargetime + "|" + params + "|" + mode + "|" + amount + "|" + transactionId);
+
+        try {
+            String ip = getIpClient();
+            UserInfo userInfo = null;
+            br.setLength(0);
+            br.append("contentRequest Params:").
+                    append("\nserviceid:").append(serviceid).
+                    append("\nmsisdn:").append(msisdn).
+                    append("\nchargetime:").append(chargetime).
+                    append("\namount:").append(amount).
+                    append("\nparams:").append(params).
+                    append("\nmode:").append(mode).
+                    append("\ntransactionid:").append(transactionId);
+            logger.info(br);
+
+            Request request = new Request();
+            request.setUser(msisdn);
+//            request.setPass(password);
+            if (wsUser == null || wsUser.length() == 0) {
+                logger.info("wsUser is null");
+                response.setErrorCode(PARAM_NOT_ENOUGH);
+                response.setContent("wsUser is null");
+            } else if (wsPass == null || wsPass.length() == 0) {
+                logger.info("wsPass is null");
+                response.setErrorCode(PARAM_NOT_ENOUGH);
+                response.setContent("wsPass is null");
+            } else if (msisdn == null || msisdn.length() == 0) {
+                logger.info("msisdn is null");
+                response.setErrorCode(PARAM_NOT_ENOUGH);
+                response.setContent("msisdn is null");
+            } else if (params == null || params.length() == 0) {
+                logger.info("params is null");
+                response.setErrorCode(PARAM_NOT_ENOUGH);
+                response.setContent("params is null");
+            } else if (amount == null || amount.length() == 0) {
+                logger.info("amount is null");
+                response.setErrorCode(PARAM_NOT_ENOUGH);
+                response.setContent("amount is null");
+            } else if (mode == null || mode.length() == 0) {
+                logger.info("mode is null");
+                response.setErrorCode(PARAM_NOT_ENOUGH);
+                response.setContent("mode is null");
+            }
+
+            if (!Objects.equals(mode, "REAL")) {
+                response.setErrorCode(Common.ErrorCode.SUCCESS);
+                return response.getErrorCode();
+            }
+            if (SUCCESS.equals(response.getErrorCode())) {
+                userInfo = authenticate(wsUser, wsPass, ip);
+                if (userInfo == null || userInfo.getWsUserId() <= 0) {
+                    response.setErrorCode(WRONG_PASSWORD);
+                    response.setContent("Authenticate fail!");
+                    return response.getErrorCode() + "|" + response.getContent();
+                } else {
+                    assert msisdn != null;
+                    msisdn = formatMsisdn(msisdn);
+                    ProductInfo productInfo = getProductByName(serviceid);
+                    if (productInfo == null || productInfo.getProductName() == null) {
+                        logger.info("serviceid is wrong: " + serviceid);
+                        response.setErrorCode(PARAM_NOT_VALID);
+                        response.setContent("subServiceName is wrong");
+                    } else {
+                        boolean registered = false;
+                        List<RegisterInfo> listRegInday = null;
+                        listRegInday = db.getRegisterInday(msisdn, productInfo.getProductName());
+                        if (listRegInday != null && !listRegInday.isEmpty()) {
+                            registered = true;
+                        }
+
+                        Timestamp expireTime = getExpireTime(productInfo);
+                        // check registered and write the next action to database
+                        RegisterInfo reg;
+                        if (!registered) {
+                            // insert register
+                            reg = new RegisterInfo();
+                            reg.setMsisdn(msisdn);
+                            reg.setProductName(productInfo.getProductName());
+                            reg.setExpireTime(expireTime);
+                            reg.setServiceId(Integer.parseInt("1"));
+                            reg.setChannel("MPS");
+                            reg = updateRegRenew(reg, productInfo);
+                            db.iInsertRegisterInfo(reg);
+                        } else {
+                            reg = listRegInday.get(0);
+                            db.iInsertRegisterInfo(reg);
+                        }
+
+                        //insert charge log
+                        assert amount != null;
+                        int moneyCharge = Integer.parseInt(amount);
+                        if (moneyCharge > 0) {
+                            ChargeLog chargeLog = new ChargeLog();
+                            chargeLog.setFee(moneyCharge);
+                            chargeLog.setChargeTime(new Timestamp(System.currentTimeMillis()));
+                            chargeLog.setMsisdn(msisdn);
+                            chargeLog.setDescription("Charge " + productInfo.getProductName());
+                            chargeLog.setStatus(Common.Constant.CHARGE_STATUS);
+                            db.iInsertChargeLog(chargeLog);
+                        }
+
+                        logger.info("Buy turn success success " + msisdn + ", fee " + moneyCharge);
+                        db.addTurnSpin(msisdn,productInfo.getNumberSpin());
+                        
+                        String message = MessageResponse.get(Common.Message.BUY_SPIN_SUB_SUCCESS, logger);
+                        String turnString = productInfo.getNumberSpin() > 2 ? " turns" : " turn";
+                        message = message.replace("%turn%", productInfo.getNumberSpin() + turnString);
+                        message = message.replace("%fee%", String.valueOf(productInfo.getFee()));
+
+                        response.setErrorCode(Common.ErrorCode.SUCCESS);
+                        response.setContent(message);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            logger.error("Error processing", e);
+            response.setErrorCode(EXCEPTION);
+            response.setContent("Transaction fail");
+        } finally {
+            try {
+                transLog.setErrorCode(response.getErrorCode());
+                transLog.setResponse(response.toString());
+                transLog.setResponseTime(new Timestamp(System.currentTimeMillis()));
+                db.insertTransLog1(transLog);
+            } catch (Exception ex) {
+                logger.error("Error insert log", ex);
+            } finally {
+            }
+        }
+        return response.getErrorCode();
+    }
     
     
     public void processAfterCharge(String msisdn, int fee) {