using NEducation.GenKeyWs; using Microsoft.Extensions.Configuration; using NEducation.Controllers; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Net.Http; using System.Threading.Tasks; using System.ServiceModel; using NEducation; using NEducation.Models; using System.Web.Mvc; using System.Web; using System.Net; using NEducation.Code; using NEducation.Content.Texts; using System.Web.SessionState; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Newtonsoft.Json; using Devart.Common; namespace NEducation.Controllers { public class Data { public String key { get; set; } public String value { get; set; } public Data(String key, String value) { this.key = key; this.value = value; } } public class WapController : BaseController { static public log4net.ILog log = log4net.LogManager.GetLogger("WapController"); String wsUser; String wsPass; static private String PRO = "GTS"; static private String SER = "GTS_MEDU"; //static private String SUB = "GTS_HappyCalling_Daily"; static private String SUP_CP = "GTS"; static private String CONT = null; static private String TYPE = null; GenKeyWs.WsGenKeyClient wsClient = new GenKeyWs.WsGenKeyClient(); private void CreateAuthToken() { // create session authen SessionIDManager manager = new SessionIDManager(); string newSessionId = manager.CreateSessionID(System.Web.HttpContext.Current); Response.Cookies["AuthToken"].Value = newSessionId; Session["AuthToken"] = newSessionId; } public async Task ResponseFromWap(string DATA, string SIG) { try { //DATA = "al12Rg2wdrLixNin9i19FdMMqBF6Xe+dQzXarlvBMqGQeh/PRD5F9zBrZc0lGlN/fGoJ/NuuMh96ymeuOtyv6rlu9+KOBMGXiAH43J81zBLMJ9+aF3mQR7OT7mQnQkFe4i2gpMnYi2NRUSyJAZm1NnTeoDswqsYWVcke+jMtubSQdmBkSmm2pUTW+rLgHi4sMrPLyRlw0T5HsEuT6YUpqRKaweF97pLZDNUaJePRRPyJASHvT3yOy7VTfAIcVSC1DGrYOv3Kyj18pKhxjskCWdYUd3r4jngN/iMALnQvgAWtsBsfH50KS77rs0r6MIMpN6rv96BrtpHn0gmqqYTDGtykNa5FsRyclqyI3CLgn9hQi2TWUVMWHETqdR0E8VrdIXMNGhgaNclDgKFFyTl/V02vSH+RbeuPU05XLfUaBD/e8SKA0rTlQfGVAyJZtRvMreg76dQBZFBbda96M95Mdphhp/ZR5XrVRKt+dM1+8FxLpQefsBp21L3HFJrzgcPxkz5qQN1rdx2Umhzf0W4rQErsGk7xZoYlxVGo2/7Ouwi0BJU1ocK3/z5bSskAQTc3UWdzzm0q+KDs/gEd1ouqoA3R2n5PuMqMTZhztcpxIJODKfmSPS/pTZNPQrXSpbAMqN11FRTxzt7yjRdFrOd4zDVRPYXcQ7ExYvdY0JrXAZE="; //SIG = "Bwdr1erav2UsFY7OpAGFNN%2BZPQ90cLDhqniE6Ta2kaD3kEtrKIprsfIz6BAL%2BIY8KhC1Xx0N7cSZyU1uAfEHRG%2BCJ5hbM5s%2B7kzMv4ZE7CFHqF9LuZrQQqz8IHzkPRHBgyWDy7RtESE1y%2BMRC1X9sAAdNFKxEL0NSCQigepfFD6YTnNFJix1OPAYwy1KfRTVAU10%2F%2BlkNuGegk651SH%2FgZ8yptwpnoIYdlUPQh3D404vm58EpFz7%2BtetzcolF6ajvJFGov%2BOvAOataD7%2BQDrJpqQ%2B7pf8A3fdAPAqRTmpUjCYtL0gRL8TILkPrF%2BmpaWCyWFzYug7CGvr%2F2qQForFhPH0xQj2SFI1tfBfYQOg4V7oCnOI9Jq0haiQ2mCCA5o1cQ0dEAK43NdRP2dfmwh%2BgVK%2BVeZpWxqOLhegeU%2B9bFA0iUmjXCxLNcSbsHqA7j7IvmPb4Ms2zhv4B9ALQ94YZft9Ut5ZRzvO8LYrmhmWqvK8mFQwIGwQNTKMd9UCCoSiTV8an7MFG2uzweS9Q65wwNbbaEstD8mOvD9Jkwv2x71WGI%2FFwkGPrbxzrfATD5DgQ7IFIpDD0Rr%2BPG4S5WlJlSYTPks%2FRgLNyHgQ%2BX3UGPINNKzj3xaC25RCN2iKoN7TY%2F4FEB8Day0gfd3aMfvFCpOXF5h6uGOpAp7ETsOgP0%3D"; // Pre-process input data string dataGet = DATA.Replace(" ", "+"); var sigGet = Uri.EscapeDataString(SIG).ToString(); var data = "DATA=" + dataGet + "&SIG=" + sigGet; log.Info("data_ResponseFromWap " + data); // Load configuration settings String wsUrlRes = ConfigurationManager.AppSettings["domainRes"]; String wsUrl = ConfigurationManager.AppSettings["paymentUrl"]; String packageName = ConfigurationManager.AppSettings["packname"]; String packNameCannel = ConfigurationManager.AppSettings["packNameCannel"]; String packNameREGISTER_ToBe = ConfigurationManager.AppSettings["packNameREGISTER_ToBe"]; String packNameCannel_ToBe = ConfigurationManager.AppSettings["packNameCannel_ToBe"]; String DIR = ConfigurationManager.AppSettings["directoryPath"]; log.Info("DIR_Wap " + DIR); if (packageName == null) { Session["register-result-message"] = "Register unsuccessful"; Session["register-result-status"] = "-1"; return Redirect("/Home/RegisterResult"); } // Decrypt the key GenKeyWs.wsDecryptKeyResponse decrypt = await wsClient.wsDecryptKeyAsync(null, null, DIR + packageName.ToUpper() + "\\", wsUrl, data); log.Info("errorCode " + decrypt.@return.errorCode); log.Info("decrypt " + decrypt.@return.descrypt); // Log details if available if (decrypt.@return.mpsResponse != null) { log.Info("CMD " + decrypt.@return.mpsResponse.CMD); log.Info("MOBILE " + decrypt.@return.mpsResponse.MOBILE); log.Info("PRICE " + decrypt.@return.mpsResponse.PRICE); log.Info("RES " + decrypt.@return.mpsResponse.RES); log.Info("REQ " + decrypt.@return.mpsResponse.REQ); log.Info("SOURCE " + decrypt.@return.mpsResponse.SOURCE); log.Info("STATUS " + decrypt.@return.mpsResponse.STATUS); log.Info("SUB_END_DATE " + decrypt.@return.mpsResponse.SUB_END_DATE); log.Info("SUB_NEW " + decrypt.@return.mpsResponse.SUB_NEW); log.Info("SUB_SERVICE " + decrypt.@return.mpsResponse.SUB_SERVICE); log.Info("SUB_START_DATE " + decrypt.@return.mpsResponse.SUB_START_DATE); } else { log.Info("mpsResponse null "); } if (decrypt.@return.errorCode == UtilsController.WapConstant.SUCCESS) { // Handle different command cases if (decrypt.@return.mpsResponse.CMD == UtilsController.WapConstant.REGISTER) { log.Info("REGISTER MOBILE " + decrypt.@return.mpsResponse.MOBILE); if (!string.IsNullOrEmpty(decrypt.@return.mpsResponse.MOBILE)) { // Validate and process phone number String phoneNumber = UtilsController.validateMsisdn(decrypt.@return.mpsResponse.MOBILE); if (!string.IsNullOrEmpty(phoneNumber)) { Session["msisdn-detecting"] = phoneNumber; // Perform registration request UserRequest userRequest = new UserRequest { users = phoneNumber, msisdn = phoneNumber, subServiceCode = packNameREGISTER_ToBe + "|" + decrypt.@return.mpsResponse.PRICE, requestId = "-1", otp = decrypt.@return.mpsResponse.RES, serviceId = "3" }; log.Info("MpsRequest_web: " + JsonConvert.SerializeObject(userRequest)); String rs = UtilsController.SendPost(userRequest, Session.SessionID, UtilsController.WsType.MpsRequest); log.Info("MpsResult_web: " + rs); UserActionResult ress = new UserActionResult(rs); if (ress.responseCode == UtilsController.Constant.SUCCESS) { Charging charging = new Charging(rs); Session["charging"] = charging; Session["msisdn"] = decrypt.@return.mpsResponse.MOBILE; Session["package"] = packNameCannel; Session["CHARGE_ACTION"] = UtilsController.Constant.REGISTER; Session["CHARGE_DATA"] = userRequest; if (decrypt.@return.mpsResponse.RES == "0") { log.Info("decrypt.@return.mpsResponse.RES " + decrypt.@return.mpsResponse.RES); // auto login // reload user info HttpContext.Session.Remove("regInfos"); Session["msisdnDetect"] = phoneNumber; // dang ky tren app Session["WHICHDEVICE"] = UtilsController.Constant.REGISTER_ON_WEB; // check user has account GetUserProfileReq req = new GetUserProfileReq(); req.users = phoneNumber; String rss = UtilsController.SendPost(req, System.Web.HttpContext.Current.Session.SessionID, UtilsController.WsType.UsersGetProfile); UserProfile profile = new UserProfile(rs); if (profile.id != null) { System.Web.HttpContext.Current.Session["profile"] = profile; // create new auth CreateAuthToken(); String sessionId = Session.SessionID; // login success --> store session Session["msisdn"] = phoneNumber; // get sub UtilsController.ReloadSubInfo(); // all info of user was loaded from server //UserProfile profile = Session["profile"] as UserProfile; String typeLanguage = Session["typeLanguage"] as String; return Redirect("/Home/Index"); } else { // Create a free account for the user UserRequest userRequests = new UserRequest { users = phoneNumber, msisdn = phoneNumber, command = "REGIST", channel = "WEB" }; string rsRegister = UtilsController.SendPost(userRequest, Session.SessionID, UtilsController.WsType.UsersRegister); UserActionResult resRegister = new UserActionResult(rsRegister); Session["isSub"] = "false"; if (resRegister.status == UtilsController.Constant.SUCCESS) { // Load profile GetUserProfileReq reqProfile = new GetUserProfileReq { users = phoneNumber }; string rsProfile = UtilsController.SendPost(reqProfile, Session.SessionID, UtilsController.WsType.UsersGetProfile); UserProfile profileGet = new UserProfile(rsProfile); if (profileGet.id != null) { Session["profile"] = profileGet; UserInfoRequest reqStatus = new UserInfoRequest { users = phoneNumber }; string rsStatus = UtilsController.SendPost(reqStatus, Session.SessionID, UtilsController.WsType.UsersCheckStatus); UserActionResult resStatus = new UserActionResult(rsStatus); if (resStatus.status == UtilsController.Constant.SUCCESS) { UserInfo userInfo = new UserInfo(rsStatus); Session["userInfo"] = userInfo; // Create new auth CreateAuthToken(); Session["msisdn"] = phoneNumber; // Reload user info UtilsController.ReloadSubInfo(); } } } return Redirect("/Home/Index"); } } else { return Redirect("/Home/Index"); } } else if (ress.status == "2") { return Json(new { error_code = ress.status, error_content = UtilsController.GetErrorCodeCharging(ress.status) }); } return Json(new { error_code = ress.responseCode, error_content = UtilsController.GetErrorCodeCharging(ress.responseCode) }); } else { log.Info("Cannel Can not detecting"); } } Session["register-result-message"] = "Register successful"; Session["register-result-status"] = "0"; return Redirect("/Home/RegisterResult"); } else if (decrypt.@return.mpsResponse.CMD == UtilsController.WapConstant.CANCEL) { String phoneNumber = UtilsController.validateMsisdn(decrypt.@return.mpsResponse.MOBILE); if (!string.IsNullOrEmpty(phoneNumber)) { if (decrypt.@return.mpsResponse.RES == UtilsController.WapConstant.SUCCESS || decrypt.@return.mpsResponse.RES == UtilsController.WapConstant.CANCEL_USER_IN_CHARGING_LIST) { if (!string.IsNullOrEmpty(decrypt.@return.mpsResponse.MOBILE)) { String phoneNumbers = UtilsController.validateMsisdn(decrypt.@return.mpsResponse.MOBILE); if (!string.IsNullOrEmpty(phoneNumbers)) { Session["msisdn-detecting"] = phoneNumber; var checkSub = UtilsController.checkAccountSub(phoneNumber, packNameCannel_ToBe); if (!checkSub) { UserRequest userRequest = new UserRequest { users = decrypt.@return.mpsResponse.MOBILE, msisdn = decrypt.@return.mpsResponse.MOBILE, subServiceCode = packNameCannel_ToBe + "|" + decrypt.@return.mpsResponse.PRICE, requestId = "-1", otp = decrypt.@return.mpsResponse.RES, serviceId = "3" }; String rs = UtilsController.SendPost(userRequest, Session.SessionID, UtilsController.WsType.MpsRequest); UserActionResult ress = new UserActionResult(rs); if (ress.responseCode == UtilsController.Constant.SUCCESS) { Charging charging = new Charging(rs); Session["charging"] = charging; Session["msisdn"] = decrypt.@return.mpsResponse.MOBILE; Session["package"] = packageName; Session["CHARGE_ACTION"] = UtilsController.Constant.REGISTER; Session["CHARGE_DATA"] = userRequest; // Load profile GetUserProfileReq reqProfile = new GetUserProfileReq { users = phoneNumber }; string rsProfile = UtilsController.SendPost(reqProfile, Session.SessionID, UtilsController.WsType.UsersGetProfile); UserProfile profileGet = new UserProfile(rsProfile); if (profileGet.id != null) { Session["profile"] = profileGet; UserInfoRequest reqStatus = new UserInfoRequest { users = phoneNumber }; string rsStatus = UtilsController.SendPost(reqStatus, Session.SessionID, UtilsController.WsType.UsersCheckStatus); UserActionResult resStatus = new UserActionResult(rsStatus); if (resStatus.status == UtilsController.Constant.SUCCESS) { UserInfo userInfo = new UserInfo(rsStatus); Session["userInfo"] = userInfo; // Create new auth CreateAuthToken(); Session["msisdn"] = phoneNumber; // Reload user info UtilsController.ReloadSubInfo(); } } } else if (ress.status == "2") { return Json(new { error_code = ress.status, error_content = UtilsController.GetErrorCodeCharging(ress.status) }); } return Json(new { error_code = ress.responseCode, error_content = UtilsController.GetErrorCodeCharging(ress.responseCode) }); } else { return Json(new { error_code = UtilsController.Constant.USER_EXISTED, error_content = UtilsController.GetErrorCodeCharging(UtilsController.Constant.USER_EXISTED) }); } } else { return Json(new { error_code = UtilsController.Constant.INVALID_MSISDN, error_content = @Lang.InvalidMsisdn, }); } } } else { log.Error("CANCEL unsuccessful"); Session["register-result-message"] = "Cancel unsuccessful"; Session["register-result-status"] = "-1"; return Redirect("/Home/RegisterResult"); } Session["register-result-message"] = "Cancel successful"; Session["register-result-status"] = "0"; return Redirect("/Home/RegisterResult"); } Session["register-result-message"] = "Cancel unsuccessful"; Session["register-result-status"] = "-1"; return Redirect("/Home/RegisterResult"); } else if (decrypt.@return.mpsResponse.CMD == UtilsController.WapConstant.MSISDN) { if (!string.IsNullOrEmpty(decrypt.@return.mpsResponse.MOBILE) && decrypt.@return.mpsResponse.MOBILE != "null") { // Validate and process phone number String phoneNumber = UtilsController.validateMsisdn(decrypt.@return.mpsResponse.MOBILE); if (!string.IsNullOrEmpty(phoneNumber)) { // Auto login for this user Session["msisdn-detecting"] = phoneNumber; return Redirect("/Home?detecting=0"); } } else { log.Info("Can not detecting"); } } else { log.Info("Command: " + decrypt.@return.mpsResponse.CMD); } } else { // Handle unsuccessful registration log.Info("Error "); Session["register-result-message"] = "Register unsuccessful"; Session["register-result-status"] = "-1"; return Redirect("/Home/RegisterResult"); } return Redirect("/Home?detecting=0"); } catch (Exception ex) { log.Info("Exception: " + ex); return Redirect("/Home?detecting=0"); } } // GET: Wap public static async Task UserDetectingAsync(IConfiguration configuration, GenKeyWs.WsGenKeyClient wsClient, MpsParams mpsparams) { GenKeyWs.response response = new GenKeyWs.response(); response.errorCode = UtilsController.WapConstant.FAILURE; //String DIR = configuration.GetSection("directoryPath").Value; //String wsUrl = configuration.GetSection("paymentUrl").Value; String DIR = configuration.GetSection("directoryPath").Value; String wsUrl = configuration.GetSection("paymentUrl").Value; GenKeyWs.wsEncryptKeyResponse makeUrl = await wsClient.wsEncryptKeyAsync(null, null, DIR, wsUrl + "mobile.html?", PRO, SER, mpsparams.SUB, mpsparams.CMD, "WAP", mpsparams.CATE, mpsparams.ITEM, SUP_CP, CONT, mpsparams.PRICE, mpsparams.MOBILE, TYPE); log.Info("UserDetecting build req: " + makeUrl.@return.enscrypt); //HttpContext.Session.SetComplexData("mps-params", mpsparams); return makeUrl.@return; } public static async Task UserRegisteringAsync(GenKeyWs.WsGenKeyClient wsClient, MpsParams mpsparams) { GenKeyWs.response response = new GenKeyWs.response(); response.errorCode = UtilsController.WapConstant.FAILURE; String DIR = ConfigurationManager.AppSettings["directoryPath"] + mpsparams.SUB.ToUpper() + "/"; log.Info("UserRegistering build DIR: " + DIR); String wsUrl = ConfigurationManager.AppSettings["paymentUrl"]; //String DIR = configuration.GetSection("directoryPath").Value + mpsparams.SUB.ToUpper() + "/"; //String wsUrl = configuration.GetSection("paymentUrl").Value; log.Info("UserRegistering makeUrl:"); GenKeyWs.wsEncryptKeyResponse makeUrl = await wsClient.wsEncryptKeyAsync(null, null, DIR, wsUrl + "charge.html?", PRO, SER, mpsparams.SUB, mpsparams.CMD, "WAP", mpsparams.CATE, mpsparams.ITEM, SUP_CP, CONT, mpsparams.PRICE, mpsparams.MOBILE, TYPE); log.Info("UserRegistering build req: " + makeUrl.@return.enscrypt); // save session //HttpContext.Session.SetComplexData("mps-params", mpsparams); return makeUrl.@return; } public static async Task UserChargingAsync(GenKeyWs.WsGenKeyClient wsClient, MpsParams mpsparams) { GenKeyWs.response response = new GenKeyWs.response(); response.errorCode = UtilsController.WapConstant.FAILURE; response.errorCode = UtilsController.WapConstant.FAILURE; String DIR = ConfigurationManager.AppSettings["directoryPath"]; String wsUrl = ConfigurationManager.AppSettings["paymentUrl"]; //String DIR = configuration.GetSection("directoryPath").Value; //String wsUrl = configuration.GetSection("paymentUrl").Value; GenKeyWs.wsEncryptKeyResponse makeUrl = await wsClient.wsEncryptKeyAsync(null, null, DIR, wsUrl + "charge.html?", PRO, SER, mpsparams.SUB, mpsparams.CMD, "WAP", mpsparams.CATE, mpsparams.ITEM, SUP_CP, CONT, mpsparams.PRICE, mpsparams.MOBILE, TYPE); log.Info("UserCharging build req: " + makeUrl.@return.enscrypt); //HttpContext.Session.SetComplexData("mps-params", mpsparams); return makeUrl.@return; } public static async Task UserCancelingAsync(GenKeyWs.WsGenKeyClient wsClient, MpsParams mpsparams) { GenKeyWs.response response = new GenKeyWs.response(); response.errorCode = UtilsController.WapConstant.FAILURE; response.errorCode = UtilsController.WapConstant.FAILURE; String DIR = ConfigurationManager.AppSettings["directoryPath"] + mpsparams.SUB.ToUpper() + "/"; String wsUrl = ConfigurationManager.AppSettings["paymentUrl"]; //String DIR = configuration.GetSection("directoryPath").Value + mpsparams.SUB.ToUpper() + "/"; //String wsUrl = configuration.GetSection("paymentUrl").Value; GenKeyWs.wsEncryptKeyResponse makeUrl = await wsClient.wsEncryptKeyAsync(null, null, DIR, wsUrl + "charge.html?", PRO, SER, mpsparams.SUB, mpsparams.CMD, "WAP", mpsparams.CATE, mpsparams.ITEM, SUP_CP, CONT, mpsparams.PRICE, mpsparams.MOBILE, TYPE); log.Info("UserCanceling build req: " + makeUrl.@return.enscrypt); // save session //HttpContext.Session.SetComplexData("mps-params", mpsparams); return makeUrl.@return; } static public String PostData(string mpsurl) { String url = mpsurl; log.Info("Request: " + url); using (var client = new HttpClient()) { var response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { var responseContent = response.Content; // by calling .Result you are synchronously reading the result string responseString = responseContent.ReadAsStringAsync().Result; log.Info("Response: " + responseString); return responseString; } else { log.Error("Response: " + response.StatusCode.ToString()); return response.StatusCode.ToString(); } } } // push to webservice public async Task RegisterOtp(String package, String msisdn, String code, String action) { try { MpsReq req = new MpsReq(); req.msisdn = msisdn; req.subServiceCode = package; req.otp = code; // not send to mps //NcGamesWs.subRequestPGWResponse res = await wsGGameClient.subRequestPGWAsync(wsUser, wsPass, // msisdn, UtilsController.Constant.SERVICE_ID, // package, action); //MpsRes res = new MpsRes(rs); // check success if ( //res.@return == "0" && (code == UtilsController.WapConstant.SUCCESS || code == UtilsController.WapConstant.CANCEL_USER_IN_CHARGING_LIST)) { //HttpContext.Session.SetComplexData("msisdn", msisdn); //HttpContext.Session.SetComplexData("msisdn-detecting", msisdn); return true; } return false; } catch (Exception ex) { log.Error("Exception: " + ex); return false; } } [HttpPost] [ValidateAntiForgeryToken] public ActionResult RegisterFromWap(String code, String refId, String turn, String price, String content, String msisdn, String packg, String action) { String packNameREGISTER_ToBe = ConfigurationManager.AppSettings["packNameREGISTER_ToBe"]; String packNameCannel_ToBe = ConfigurationManager.AppSettings["packNameCannel_ToBe"]; String packageName = ConfigurationManager.AppSettings["packname"]; // khi đăng ký thành công từ camID thì gọi hàm này để gọi Be log.Info("CALLBACK: " + msisdn + ", packg: " + packg + ", code: " + code + ", content: " + content + ", turn: " + turn + ", action: " + action + ", price: " + price); if (price.Length > 9) { price = price.Substring(0, price.Length - 6); } try { //code = "0"; //refId = "56f6a1e9c6714cbab5c62bb65988d128"; if (code == "0") { CheckTransactionRequest checkTransactionRequest = new CheckTransactionRequest { token = "", session = Session.SessionID, wsCode = "validateMps", wsRequest = new WsRequest { msisdn = msisdn, refId = refId } }; log.Info("checkTransactionRequest: " + JsonConvert.SerializeObject(checkTransactionRequest)); String responseJson = UtilsController.SendPost(checkTransactionRequest, Session.SessionID, UtilsController.WsType.wsCheckTransaction); CheckTransactionResponse response = new CheckTransactionResponse(responseJson); log.Info("responseCheckTransactionRequest: " + responseJson); if (response.result != null && response.result.errorCode == "0") { string res = null; // check phone number msisdn = UtilsController.validateMsisdn(msisdn); if (msisdn != "" && msisdn == (String)Session["msisdn"]) { if (action == "CANCEL") { log.Info("Cancel package: " + msisdn + ", packg: " + packg); Session["msisdn-detecting"] = msisdn; //var checkSub = UtilsController.checkAccountSub(msisdn, packNameCannel_ToBe); //if (!checkSub) //{ UserRequest userRequest = new UserRequest { users = msisdn, msisdn = msisdn, subServiceCode = packNameCannel_ToBe + "|" + price, requestId = refId, otp = code, serviceId = "3" }; String rs = UtilsController.SendPost(userRequest, Session.SessionID, UtilsController.WsType.MpsRequest); UserActionResult ress = new UserActionResult(rs); if (ress.responseCode == UtilsController.Constant.SUCCESS) { Charging charging = new Charging(rs); Session["charging"] = charging; Session["msisdn"] = msisdn; Session["package"] = packNameCannel_ToBe; Session["CHARGE_ACTION"] = UtilsController.Constant.REGISTER; Session["CHARGE_DATA"] = userRequest; // Load profile GetUserProfileReq reqProfile = new GetUserProfileReq { users = msisdn }; string rsProfile = UtilsController.SendPost(reqProfile, Session.SessionID, UtilsController.WsType.UsersGetProfile); UserProfile profileGet = new UserProfile(rsProfile); if (profileGet.id != null) { Session["profile"] = profileGet; UserInfoRequest reqStatus = new UserInfoRequest { users = msisdn }; string rsStatus = UtilsController.SendPost(reqStatus, Session.SessionID, UtilsController.WsType.UsersCheckStatus); UserActionResult resStatus = new UserActionResult(rsStatus); if (resStatus.status == UtilsController.Constant.SUCCESS) { UserInfo userInfo = new UserInfo(rsStatus); Session["userInfo"] = userInfo; Session["msisdn"] = msisdn; // Reload user info UtilsController.ReloadSubInfo(); } } return Json(new { error_code = ress.responseCode, error_content = UtilsController.GetErrorCodeCharging(ress.responseCode) }); } else if (ress.status == "2") { return Json(new { error_code = ress.status, error_content = UtilsController.GetErrorCodeCharging(ress.status) }); } return Json(new { error_code = ress.responseCode, error_content = UtilsController.GetErrorCodeCharging(ress.responseCode) }); //} //else //{ // return Json(new // { // error_code = UtilsController.Constant.USER_EXISTED, // error_content = UtilsController.GetErrorCodeCharging(UtilsController.Constant.USER_EXISTED) // }); //} } else { log.Info("Check package: " + msisdn + ", packg: " + packg); Session["msisdn-detecting"] = msisdn; //var checkSub = UtilsController.checkAccountSub(msisdn, packNameCannel_ToBe); //if (!checkSub) //{ UserRequest userRequest = new UserRequest { users = msisdn, msisdn = msisdn, subServiceCode = packNameREGISTER_ToBe + "|" + price, requestId = refId, otp = code, serviceId = "3" }; log.Info("userRequest_CAMID: " + JsonConvert.SerializeObject(userRequest)); String rs = UtilsController.SendPost(userRequest, Session.SessionID, UtilsController.WsType.MpsRequest); UserActionResult ress = new UserActionResult(rs); log.Info("MpsResult: " + rs); if (ress.responseCode == UtilsController.Constant.SUCCESS) { Charging charging = new Charging(rs); Session["charging"] = charging; Session["msisdn"] = msisdn; Session["package"] = packageName; Session["CHARGE_ACTION"] = UtilsController.Constant.REGISTER; Session["CHARGE_DATA"] = userRequest; // Load profile GetUserProfileReq reqProfile = new GetUserProfileReq { users = msisdn }; string rsProfile = UtilsController.SendPost(reqProfile, Session.SessionID, UtilsController.WsType.UsersGetProfile); log.Info("rsProfile: " + rsProfile); UserProfile profileGet = new UserProfile(rsProfile); if (profileGet.id != null) { Session["profile"] = profileGet; UserInfoRequest reqStatus = new UserInfoRequest { users = msisdn }; string rsStatus = UtilsController.SendPost(reqStatus, Session.SessionID, UtilsController.WsType.UsersCheckStatus); UserActionResult resStatus = new UserActionResult(rsStatus); if (resStatus.status == UtilsController.Constant.SUCCESS) { UserInfo userInfo = new UserInfo(rsStatus); Session["userInfo"] = userInfo; Session["msisdn"] = msisdn; // Reload user info UtilsController.ReloadSubInfo(); } } //} //else if (ress.status == "2") //{ // return Json(new // { // error_code = ress.status, // error_content = UtilsController.GetErrorCodeCharging(ress.status) // }); //} return Json(new { error_code = ress.responseCode, error_content = UtilsController.GetErrorCodeCharging(ress.responseCode) }); } else { return Json(new { error_code = UtilsController.Constant.USER_EXISTED, error_content = UtilsController.GetErrorCodeCharging(UtilsController.Constant.USER_EXISTED) }); } } //ReloadAccountInfo(msisdn); return Json(new { error = code, content = res, msisdn = msisdn.Substring(3) }); } else { log.Info("REGISTER Can not detecting"); } } else { // Handle error case string errorCode = response.errorCode ?? response.result?.errorCode; string errorMessage = response.errorMessage ?? response.result?.message; return Json(new { error_code = errorCode, error_content = errorMessage }); } } else { log.Warn("Callback got error code: " + code + ", msisdn: " + msisdn); } // failed return Json(new { error = code, content = "failed_RegisterFromWap" }); } catch (Exception ex) { log.Error("Error callback: " + code + ", msisdn: " + msisdn + ": " + ex.Message, ex); return Json(new { error = "-1", content = "failed_RegisterFromWap" }); } } } }