WapController.cs 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. using NEducation.GenKeyWs;
  2. using Microsoft.Extensions.Configuration;
  3. using NEducation.Controllers;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Configuration;
  7. using System.Linq;
  8. using System.Net.Http;
  9. using System.Threading.Tasks;
  10. using System.ServiceModel;
  11. using NEducation;
  12. using NEducation.Models;
  13. using System.Web.Mvc;
  14. using System.Web;
  15. using System.Net;
  16. using NEducation.Code;
  17. using NEducation.Content.Texts;
  18. using System.Web.SessionState;
  19. using Microsoft.EntityFrameworkCore.Metadata.Internal;
  20. using Newtonsoft.Json;
  21. using Devart.Common;
  22. namespace NEducation.Controllers
  23. {
  24. public class Data
  25. {
  26. public String key { get; set; }
  27. public String value { get; set; }
  28. public Data(String key, String value)
  29. {
  30. this.key = key;
  31. this.value = value;
  32. }
  33. }
  34. public class WapController : BaseController
  35. {
  36. static public log4net.ILog log = log4net.LogManager.GetLogger("WapController");
  37. String wsUser;
  38. String wsPass;
  39. static private String PRO = "GTS";
  40. static private String SER = "GTS_MEDU";
  41. //static private String SUB = "GTS_HappyCalling_Daily";
  42. static private String SUP_CP = "GTS";
  43. static private String CONT = null;
  44. static private String TYPE = null;
  45. GenKeyWs.WsGenKeyClient wsClient = new GenKeyWs.WsGenKeyClient();
  46. private void CreateAuthToken()
  47. {
  48. // create session authen
  49. SessionIDManager manager = new SessionIDManager();
  50. string newSessionId = manager.CreateSessionID(System.Web.HttpContext.Current);
  51. Response.Cookies["AuthToken"].Value = newSessionId;
  52. Session["AuthToken"] = newSessionId;
  53. }
  54. public async Task<ActionResult> ResponseFromWap(string DATA, string SIG)
  55. {
  56. try
  57. {
  58. //DATA = "al12Rg2wdrLixNin9i19FdMMqBF6Xe+dQzXarlvBMqGQeh/PRD5F9zBrZc0lGlN/fGoJ/NuuMh96ymeuOtyv6rlu9+KOBMGXiAH43J81zBLMJ9+aF3mQR7OT7mQnQkFe4i2gpMnYi2NRUSyJAZm1NnTeoDswqsYWVcke+jMtubSQdmBkSmm2pUTW+rLgHi4sMrPLyRlw0T5HsEuT6YUpqRKaweF97pLZDNUaJePRRPyJASHvT3yOy7VTfAIcVSC1DGrYOv3Kyj18pKhxjskCWdYUd3r4jngN/iMALnQvgAWtsBsfH50KS77rs0r6MIMpN6rv96BrtpHn0gmqqYTDGtykNa5FsRyclqyI3CLgn9hQi2TWUVMWHETqdR0E8VrdIXMNGhgaNclDgKFFyTl/V02vSH+RbeuPU05XLfUaBD/e8SKA0rTlQfGVAyJZtRvMreg76dQBZFBbda96M95Mdphhp/ZR5XrVRKt+dM1+8FxLpQefsBp21L3HFJrzgcPxkz5qQN1rdx2Umhzf0W4rQErsGk7xZoYlxVGo2/7Ouwi0BJU1ocK3/z5bSskAQTc3UWdzzm0q+KDs/gEd1ouqoA3R2n5PuMqMTZhztcpxIJODKfmSPS/pTZNPQrXSpbAMqN11FRTxzt7yjRdFrOd4zDVRPYXcQ7ExYvdY0JrXAZE=";
  59. //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";
  60. // Pre-process input data
  61. string dataGet = DATA.Replace(" ", "+");
  62. var sigGet = Uri.EscapeDataString(SIG).ToString();
  63. var data = "DATA=" + dataGet + "&SIG=" + sigGet;
  64. log.Info("data_ResponseFromWap " + data);
  65. // Load configuration settings
  66. String wsUrlRes = ConfigurationManager.AppSettings["domainRes"];
  67. String wsUrl = ConfigurationManager.AppSettings["paymentUrl"];
  68. String packageName = ConfigurationManager.AppSettings["packname"];
  69. String packNameCannel = ConfigurationManager.AppSettings["packNameCannel"];
  70. String packNameREGISTER_ToBe = ConfigurationManager.AppSettings["packNameREGISTER_ToBe"];
  71. String packNameCannel_ToBe = ConfigurationManager.AppSettings["packNameCannel_ToBe"];
  72. String DIR = ConfigurationManager.AppSettings["directoryPath"];
  73. log.Info("DIR_Wap " + DIR);
  74. if (packageName == null)
  75. {
  76. Session["register-result-message"] = "Register unsuccessful";
  77. Session["register-result-status"] = "-1";
  78. return Redirect("/Home/RegisterResult");
  79. }
  80. // Decrypt the key
  81. GenKeyWs.wsDecryptKeyResponse decrypt = await wsClient.wsDecryptKeyAsync(null, null, DIR + packageName.ToUpper() + "\\", wsUrl, data);
  82. log.Info("errorCode " + decrypt.@return.errorCode);
  83. log.Info("decrypt " + decrypt.@return.descrypt);
  84. // Log details if available
  85. if (decrypt.@return.mpsResponse != null)
  86. {
  87. log.Info("CMD " + decrypt.@return.mpsResponse.CMD);
  88. log.Info("MOBILE " + decrypt.@return.mpsResponse.MOBILE);
  89. log.Info("PRICE " + decrypt.@return.mpsResponse.PRICE);
  90. log.Info("RES " + decrypt.@return.mpsResponse.RES);
  91. log.Info("REQ " + decrypt.@return.mpsResponse.REQ);
  92. log.Info("SOURCE " + decrypt.@return.mpsResponse.SOURCE);
  93. log.Info("STATUS " + decrypt.@return.mpsResponse.STATUS);
  94. log.Info("SUB_END_DATE " + decrypt.@return.mpsResponse.SUB_END_DATE);
  95. log.Info("SUB_NEW " + decrypt.@return.mpsResponse.SUB_NEW);
  96. log.Info("SUB_SERVICE " + decrypt.@return.mpsResponse.SUB_SERVICE);
  97. log.Info("SUB_START_DATE " + decrypt.@return.mpsResponse.SUB_START_DATE);
  98. }
  99. else
  100. {
  101. log.Info("mpsResponse null ");
  102. }
  103. if (decrypt.@return.errorCode == UtilsController.WapConstant.SUCCESS)
  104. {
  105. // Handle different command cases
  106. if (decrypt.@return.mpsResponse.CMD == UtilsController.WapConstant.REGISTER)
  107. {
  108. log.Info("REGISTER MOBILE " + decrypt.@return.mpsResponse.MOBILE);
  109. if (!string.IsNullOrEmpty(decrypt.@return.mpsResponse.MOBILE))
  110. {
  111. // Validate and process phone number
  112. String phoneNumber = UtilsController.validateMsisdn(decrypt.@return.mpsResponse.MOBILE);
  113. if (!string.IsNullOrEmpty(phoneNumber))
  114. {
  115. Session["msisdn-detecting"] = phoneNumber;
  116. // Perform registration request
  117. UserRequest userRequest = new UserRequest
  118. {
  119. users = phoneNumber,
  120. msisdn = phoneNumber,
  121. subServiceCode = packNameREGISTER_ToBe + "|" + decrypt.@return.mpsResponse.PRICE,
  122. requestId = "-1",
  123. otp = decrypt.@return.mpsResponse.RES,
  124. serviceId = "3"
  125. };
  126. log.Info("MpsRequest_web: " + JsonConvert.SerializeObject(userRequest));
  127. String rs = UtilsController.SendPost(userRequest, Session.SessionID, UtilsController.WsType.MpsRequest);
  128. log.Info("MpsResult_web: " + rs);
  129. UserActionResult ress = new UserActionResult(rs);
  130. if (ress.responseCode == UtilsController.Constant.SUCCESS)
  131. {
  132. Charging charging = new Charging(rs);
  133. Session["charging"] = charging;
  134. Session["msisdn"] = decrypt.@return.mpsResponse.MOBILE;
  135. Session["package"] = packNameCannel;
  136. Session["CHARGE_ACTION"] = UtilsController.Constant.REGISTER;
  137. Session["CHARGE_DATA"] = userRequest;
  138. if (decrypt.@return.mpsResponse.RES == "0")
  139. {
  140. log.Info("decrypt.@return.mpsResponse.RES " + decrypt.@return.mpsResponse.RES);
  141. // auto login
  142. // reload user info
  143. HttpContext.Session.Remove("regInfos");
  144. Session["msisdnDetect"] = phoneNumber;
  145. // dang ky tren app
  146. Session["WHICHDEVICE"] = UtilsController.Constant.REGISTER_ON_WEB;
  147. // check user has account
  148. GetUserProfileReq req = new GetUserProfileReq();
  149. req.users = phoneNumber;
  150. String rss = UtilsController.SendPost(req, System.Web.HttpContext.Current.Session.SessionID, UtilsController.WsType.UsersGetProfile);
  151. UserProfile profile = new UserProfile(rs);
  152. if (profile.id != null)
  153. {
  154. System.Web.HttpContext.Current.Session["profile"] = profile;
  155. // create new auth
  156. CreateAuthToken();
  157. String sessionId = Session.SessionID;
  158. // login success --> store session
  159. Session["msisdn"] = phoneNumber;
  160. // get sub
  161. UtilsController.ReloadSubInfo();
  162. // all info of user was loaded from server
  163. //UserProfile profile = Session["profile"] as UserProfile;
  164. String typeLanguage = Session["typeLanguage"] as String;
  165. return Redirect("/Home/Index");
  166. }
  167. else
  168. {
  169. // Create a free account for the user
  170. UserRequest userRequests = new UserRequest
  171. {
  172. users = phoneNumber,
  173. msisdn = phoneNumber,
  174. command = "REGIST",
  175. channel = "WEB"
  176. };
  177. string rsRegister = UtilsController.SendPost(userRequest, Session.SessionID, UtilsController.WsType.UsersRegister);
  178. UserActionResult resRegister = new UserActionResult(rsRegister);
  179. Session["isSub"] = "false";
  180. if (resRegister.status == UtilsController.Constant.SUCCESS)
  181. {
  182. // Load profile
  183. GetUserProfileReq reqProfile = new GetUserProfileReq { users = phoneNumber };
  184. string rsProfile = UtilsController.SendPost(reqProfile, Session.SessionID, UtilsController.WsType.UsersGetProfile);
  185. UserProfile profileGet = new UserProfile(rsProfile);
  186. if (profileGet.id != null)
  187. {
  188. Session["profile"] = profileGet;
  189. UserInfoRequest reqStatus = new UserInfoRequest { users = phoneNumber };
  190. string rsStatus = UtilsController.SendPost(reqStatus, Session.SessionID, UtilsController.WsType.UsersCheckStatus);
  191. UserActionResult resStatus = new UserActionResult(rsStatus);
  192. if (resStatus.status == UtilsController.Constant.SUCCESS)
  193. {
  194. UserInfo userInfo = new UserInfo(rsStatus);
  195. Session["userInfo"] = userInfo;
  196. // Create new auth
  197. CreateAuthToken();
  198. Session["msisdn"] = phoneNumber;
  199. // Reload user info
  200. UtilsController.ReloadSubInfo();
  201. }
  202. }
  203. }
  204. return Redirect("/Home/Index");
  205. }
  206. }
  207. else
  208. {
  209. return Redirect("/Home/Index");
  210. }
  211. }
  212. else if (ress.status == "2")
  213. {
  214. return Json(new
  215. {
  216. error_code = ress.status,
  217. error_content = UtilsController.GetErrorCodeCharging(ress.status)
  218. });
  219. }
  220. return Json(new
  221. {
  222. error_code = ress.responseCode,
  223. error_content = UtilsController.GetErrorCodeCharging(ress.responseCode)
  224. });
  225. }
  226. else
  227. {
  228. log.Info("Cannel Can not detecting");
  229. }
  230. }
  231. Session["register-result-message"] = "Register successful";
  232. Session["register-result-status"] = "0";
  233. return Redirect("/Home/RegisterResult");
  234. }
  235. else if (decrypt.@return.mpsResponse.CMD == UtilsController.WapConstant.CANCEL)
  236. {
  237. String phoneNumber = UtilsController.validateMsisdn(decrypt.@return.mpsResponse.MOBILE);
  238. if (!string.IsNullOrEmpty(phoneNumber))
  239. {
  240. if (decrypt.@return.mpsResponse.RES == UtilsController.WapConstant.SUCCESS ||
  241. decrypt.@return.mpsResponse.RES == UtilsController.WapConstant.CANCEL_USER_IN_CHARGING_LIST)
  242. {
  243. if (!string.IsNullOrEmpty(decrypt.@return.mpsResponse.MOBILE))
  244. {
  245. String phoneNumbers = UtilsController.validateMsisdn(decrypt.@return.mpsResponse.MOBILE);
  246. if (!string.IsNullOrEmpty(phoneNumbers))
  247. {
  248. Session["msisdn-detecting"] = phoneNumber;
  249. var checkSub = UtilsController.checkAccountSub(phoneNumber, packNameCannel_ToBe);
  250. if (!checkSub)
  251. {
  252. UserRequest userRequest = new UserRequest
  253. {
  254. users = decrypt.@return.mpsResponse.MOBILE,
  255. msisdn = decrypt.@return.mpsResponse.MOBILE,
  256. subServiceCode = packNameCannel_ToBe + "|" + decrypt.@return.mpsResponse.PRICE,
  257. requestId = "-1",
  258. otp = decrypt.@return.mpsResponse.RES,
  259. serviceId = "3"
  260. };
  261. String rs = UtilsController.SendPost(userRequest, Session.SessionID, UtilsController.WsType.MpsRequest);
  262. UserActionResult ress = new UserActionResult(rs);
  263. if (ress.responseCode == UtilsController.Constant.SUCCESS)
  264. {
  265. Charging charging = new Charging(rs);
  266. Session["charging"] = charging;
  267. Session["msisdn"] = decrypt.@return.mpsResponse.MOBILE;
  268. Session["package"] = packageName;
  269. Session["CHARGE_ACTION"] = UtilsController.Constant.REGISTER;
  270. Session["CHARGE_DATA"] = userRequest;
  271. // Load profile
  272. GetUserProfileReq reqProfile = new GetUserProfileReq { users = phoneNumber };
  273. string rsProfile = UtilsController.SendPost(reqProfile, Session.SessionID, UtilsController.WsType.UsersGetProfile);
  274. UserProfile profileGet = new UserProfile(rsProfile);
  275. if (profileGet.id != null)
  276. {
  277. Session["profile"] = profileGet;
  278. UserInfoRequest reqStatus = new UserInfoRequest { users = phoneNumber };
  279. string rsStatus = UtilsController.SendPost(reqStatus, Session.SessionID, UtilsController.WsType.UsersCheckStatus);
  280. UserActionResult resStatus = new UserActionResult(rsStatus);
  281. if (resStatus.status == UtilsController.Constant.SUCCESS)
  282. {
  283. UserInfo userInfo = new UserInfo(rsStatus);
  284. Session["userInfo"] = userInfo;
  285. // Create new auth
  286. CreateAuthToken();
  287. Session["msisdn"] = phoneNumber;
  288. // Reload user info
  289. UtilsController.ReloadSubInfo();
  290. }
  291. }
  292. }
  293. else if (ress.status == "2")
  294. {
  295. return Json(new
  296. {
  297. error_code = ress.status,
  298. error_content = UtilsController.GetErrorCodeCharging(ress.status)
  299. });
  300. }
  301. return Json(new
  302. {
  303. error_code = ress.responseCode,
  304. error_content = UtilsController.GetErrorCodeCharging(ress.responseCode)
  305. });
  306. }
  307. else
  308. {
  309. return Json(new
  310. {
  311. error_code = UtilsController.Constant.USER_EXISTED,
  312. error_content = UtilsController.GetErrorCodeCharging(UtilsController.Constant.USER_EXISTED)
  313. });
  314. }
  315. }
  316. else
  317. {
  318. return Json(new
  319. {
  320. error_code = UtilsController.Constant.INVALID_MSISDN,
  321. error_content = @Lang.InvalidMsisdn,
  322. });
  323. }
  324. }
  325. }
  326. else
  327. {
  328. log.Error("CANCEL unsuccessful");
  329. Session["register-result-message"] = "Cancel unsuccessful";
  330. Session["register-result-status"] = "-1";
  331. return Redirect("/Home/RegisterResult");
  332. }
  333. Session["register-result-message"] = "Cancel successful";
  334. Session["register-result-status"] = "0";
  335. return Redirect("/Home/RegisterResult");
  336. }
  337. Session["register-result-message"] = "Cancel unsuccessful";
  338. Session["register-result-status"] = "-1";
  339. return Redirect("/Home/RegisterResult");
  340. }
  341. else if (decrypt.@return.mpsResponse.CMD == UtilsController.WapConstant.MSISDN)
  342. {
  343. if (!string.IsNullOrEmpty(decrypt.@return.mpsResponse.MOBILE) &&
  344. decrypt.@return.mpsResponse.MOBILE != "null")
  345. {
  346. // Validate and process phone number
  347. String phoneNumber = UtilsController.validateMsisdn(decrypt.@return.mpsResponse.MOBILE);
  348. if (!string.IsNullOrEmpty(phoneNumber))
  349. {
  350. // Auto login for this user
  351. Session["msisdn-detecting"] = phoneNumber;
  352. return Redirect("/Home?detecting=0");
  353. }
  354. }
  355. else
  356. {
  357. log.Info("Can not detecting");
  358. }
  359. }
  360. else
  361. {
  362. log.Info("Command: " + decrypt.@return.mpsResponse.CMD);
  363. }
  364. }
  365. else
  366. {
  367. // Handle unsuccessful registration
  368. log.Info("Error ");
  369. Session["register-result-message"] = "Register unsuccessful";
  370. Session["register-result-status"] = "-1";
  371. return Redirect("/Home/RegisterResult");
  372. }
  373. return Redirect("/Home?detecting=0");
  374. }
  375. catch (Exception ex)
  376. {
  377. log.Info("Exception: " + ex);
  378. return Redirect("/Home?detecting=0");
  379. }
  380. }
  381. // GET: Wap
  382. public static async Task<GenKeyWs.response> UserDetectingAsync(IConfiguration configuration, GenKeyWs.WsGenKeyClient wsClient, MpsParams mpsparams)
  383. {
  384. GenKeyWs.response response = new GenKeyWs.response();
  385. response.errorCode = UtilsController.WapConstant.FAILURE;
  386. //String DIR = configuration.GetSection("directoryPath").Value;
  387. //String wsUrl = configuration.GetSection("paymentUrl").Value;
  388. String DIR = configuration.GetSection("directoryPath").Value;
  389. String wsUrl = configuration.GetSection("paymentUrl").Value;
  390. GenKeyWs.wsEncryptKeyResponse makeUrl = await wsClient.wsEncryptKeyAsync(null, null, DIR, wsUrl + "mobile.html?", PRO, SER, mpsparams.SUB,
  391. mpsparams.CMD, "WAP", mpsparams.CATE, mpsparams.ITEM, SUP_CP, CONT, mpsparams.PRICE, mpsparams.MOBILE, TYPE);
  392. log.Info("UserDetecting build req: " + makeUrl.@return.enscrypt);
  393. //HttpContext.Session.SetComplexData("mps-params", mpsparams);
  394. return makeUrl.@return;
  395. }
  396. public static async Task<GenKeyWs.response> UserRegisteringAsync(GenKeyWs.WsGenKeyClient wsClient, MpsParams mpsparams)
  397. {
  398. GenKeyWs.response response = new GenKeyWs.response();
  399. response.errorCode = UtilsController.WapConstant.FAILURE;
  400. String DIR = ConfigurationManager.AppSettings["directoryPath"] + mpsparams.SUB.ToUpper() + "/";
  401. log.Info("UserRegistering build DIR: " + DIR);
  402. String wsUrl = ConfigurationManager.AppSettings["paymentUrl"];
  403. //String DIR = configuration.GetSection("directoryPath").Value + mpsparams.SUB.ToUpper() + "/";
  404. //String wsUrl = configuration.GetSection("paymentUrl").Value;
  405. log.Info("UserRegistering makeUrl:");
  406. GenKeyWs.wsEncryptKeyResponse makeUrl = await wsClient.wsEncryptKeyAsync(null, null, DIR, wsUrl + "charge.html?", PRO, SER, mpsparams.SUB,
  407. mpsparams.CMD, "WAP", mpsparams.CATE, mpsparams.ITEM, SUP_CP, CONT, mpsparams.PRICE, mpsparams.MOBILE, TYPE);
  408. log.Info("UserRegistering build req: " + makeUrl.@return.enscrypt);
  409. // save session
  410. //HttpContext.Session.SetComplexData("mps-params", mpsparams);
  411. return makeUrl.@return;
  412. }
  413. public static async Task<GenKeyWs.response> UserChargingAsync(GenKeyWs.WsGenKeyClient wsClient, MpsParams mpsparams)
  414. {
  415. GenKeyWs.response response = new GenKeyWs.response();
  416. response.errorCode = UtilsController.WapConstant.FAILURE;
  417. response.errorCode = UtilsController.WapConstant.FAILURE;
  418. String DIR = ConfigurationManager.AppSettings["directoryPath"];
  419. String wsUrl = ConfigurationManager.AppSettings["paymentUrl"];
  420. //String DIR = configuration.GetSection("directoryPath").Value;
  421. //String wsUrl = configuration.GetSection("paymentUrl").Value;
  422. GenKeyWs.wsEncryptKeyResponse makeUrl = await wsClient.wsEncryptKeyAsync(null, null, DIR, wsUrl + "charge.html?", PRO, SER, mpsparams.SUB,
  423. mpsparams.CMD, "WAP", mpsparams.CATE, mpsparams.ITEM, SUP_CP, CONT, mpsparams.PRICE, mpsparams.MOBILE, TYPE);
  424. log.Info("UserCharging build req: " + makeUrl.@return.enscrypt);
  425. //HttpContext.Session.SetComplexData("mps-params", mpsparams);
  426. return makeUrl.@return;
  427. }
  428. public static async Task<GenKeyWs.response> UserCancelingAsync(GenKeyWs.WsGenKeyClient wsClient, MpsParams mpsparams)
  429. {
  430. GenKeyWs.response response = new GenKeyWs.response();
  431. response.errorCode = UtilsController.WapConstant.FAILURE;
  432. response.errorCode = UtilsController.WapConstant.FAILURE;
  433. String DIR = ConfigurationManager.AppSettings["directoryPath"] + mpsparams.SUB.ToUpper() + "/";
  434. String wsUrl = ConfigurationManager.AppSettings["paymentUrl"];
  435. //String DIR = configuration.GetSection("directoryPath").Value + mpsparams.SUB.ToUpper() + "/";
  436. //String wsUrl = configuration.GetSection("paymentUrl").Value;
  437. GenKeyWs.wsEncryptKeyResponse makeUrl = await wsClient.wsEncryptKeyAsync(null, null, DIR, wsUrl + "charge.html?", PRO, SER, mpsparams.SUB,
  438. mpsparams.CMD, "WAP", mpsparams.CATE, mpsparams.ITEM, SUP_CP, CONT, mpsparams.PRICE, mpsparams.MOBILE, TYPE);
  439. log.Info("UserCanceling build req: " + makeUrl.@return.enscrypt);
  440. // save session
  441. //HttpContext.Session.SetComplexData("mps-params", mpsparams);
  442. return makeUrl.@return;
  443. }
  444. static public String PostData(string mpsurl)
  445. {
  446. String url = mpsurl;
  447. log.Info("Request: " + url);
  448. using (var client = new HttpClient())
  449. {
  450. var response = client.GetAsync(url).Result;
  451. if (response.IsSuccessStatusCode)
  452. {
  453. var responseContent = response.Content;
  454. // by calling .Result you are synchronously reading the result
  455. string responseString = responseContent.ReadAsStringAsync().Result;
  456. log.Info("Response: " + responseString);
  457. return responseString;
  458. }
  459. else
  460. {
  461. log.Error("Response: " + response.StatusCode.ToString());
  462. return response.StatusCode.ToString();
  463. }
  464. }
  465. }
  466. // push to webservice
  467. public async Task<bool> RegisterOtp(String package, String msisdn, String code, String action)
  468. {
  469. try
  470. {
  471. MpsReq req = new MpsReq();
  472. req.msisdn = msisdn;
  473. req.subServiceCode = package;
  474. req.otp = code; // not send to mps
  475. //NcGamesWs.subRequestPGWResponse res = await wsGGameClient.subRequestPGWAsync(wsUser, wsPass,
  476. // msisdn, UtilsController.Constant.SERVICE_ID,
  477. // package, action);
  478. //MpsRes res = new MpsRes(rs);
  479. // check success
  480. if (
  481. //res.@return == "0" &&
  482. (code == UtilsController.WapConstant.SUCCESS ||
  483. code == UtilsController.WapConstant.CANCEL_USER_IN_CHARGING_LIST))
  484. {
  485. //HttpContext.Session.SetComplexData("msisdn", msisdn);
  486. //HttpContext.Session.SetComplexData("msisdn-detecting", msisdn);
  487. return true;
  488. }
  489. return false;
  490. }
  491. catch (Exception ex)
  492. {
  493. log.Error("Exception: " + ex);
  494. return false;
  495. }
  496. }
  497. [HttpPost]
  498. [ValidateAntiForgeryToken]
  499. public ActionResult RegisterFromWap(String code, String refId, String turn, String price, String content, String msisdn, String packg, String action)
  500. {
  501. String packNameREGISTER_ToBe = ConfigurationManager.AppSettings["packNameREGISTER_ToBe"];
  502. String packNameCannel_ToBe = ConfigurationManager.AppSettings["packNameCannel_ToBe"];
  503. String packageName = ConfigurationManager.AppSettings["packname"];
  504. // khi đăng ký thành công từ camID thì gọi hàm này để gọi Be
  505. log.Info("CALLBACK: " + msisdn + ", packg: " + packg + ", code: " + code + ", content: "
  506. + content + ", turn: " + turn + ", action: " + action + ", price: " + price);
  507. if (price.Length > 9)
  508. {
  509. price = price.Substring(0, price.Length - 6);
  510. }
  511. try
  512. {
  513. //code = "0";
  514. //refId = "56f6a1e9c6714cbab5c62bb65988d128";
  515. if (code == "0")
  516. {
  517. CheckTransactionRequest checkTransactionRequest = new CheckTransactionRequest
  518. {
  519. token = "",
  520. session = Session.SessionID,
  521. wsCode = "validateMps",
  522. wsRequest = new WsRequest
  523. {
  524. msisdn = msisdn,
  525. refId = refId
  526. }
  527. };
  528. log.Info("checkTransactionRequest: " + JsonConvert.SerializeObject(checkTransactionRequest));
  529. String responseJson = UtilsController.SendPost(checkTransactionRequest, Session.SessionID, UtilsController.WsType.wsCheckTransaction);
  530. CheckTransactionResponse response = new CheckTransactionResponse(responseJson);
  531. log.Info("responseCheckTransactionRequest: " + responseJson);
  532. if (response.result != null && response.result.errorCode == "0")
  533. {
  534. string res = null;
  535. // check phone number
  536. msisdn = UtilsController.validateMsisdn(msisdn);
  537. if (msisdn != "" && msisdn == (String)Session["msisdn"])
  538. {
  539. if (action == "CANCEL")
  540. {
  541. log.Info("Cancel package: " + msisdn + ", packg: " + packg);
  542. Session["msisdn-detecting"] = msisdn;
  543. //var checkSub = UtilsController.checkAccountSub(msisdn, packNameCannel_ToBe);
  544. //if (!checkSub)
  545. //{
  546. UserRequest userRequest = new UserRequest
  547. {
  548. users = msisdn,
  549. msisdn = msisdn,
  550. subServiceCode = packNameCannel_ToBe + "|" + price,
  551. requestId = refId,
  552. otp = code,
  553. serviceId = "3"
  554. };
  555. String rs = UtilsController.SendPost(userRequest, Session.SessionID, UtilsController.WsType.MpsRequest);
  556. UserActionResult ress = new UserActionResult(rs);
  557. if (ress.responseCode == UtilsController.Constant.SUCCESS)
  558. {
  559. Charging charging = new Charging(rs);
  560. Session["charging"] = charging;
  561. Session["msisdn"] = msisdn;
  562. Session["package"] = packNameCannel_ToBe;
  563. Session["CHARGE_ACTION"] = UtilsController.Constant.REGISTER;
  564. Session["CHARGE_DATA"] = userRequest;
  565. // Load profile
  566. GetUserProfileReq reqProfile = new GetUserProfileReq { users = msisdn };
  567. string rsProfile = UtilsController.SendPost(reqProfile, Session.SessionID, UtilsController.WsType.UsersGetProfile);
  568. UserProfile profileGet = new UserProfile(rsProfile);
  569. if (profileGet.id != null)
  570. {
  571. Session["profile"] = profileGet;
  572. UserInfoRequest reqStatus = new UserInfoRequest { users = msisdn };
  573. string rsStatus = UtilsController.SendPost(reqStatus, Session.SessionID, UtilsController.WsType.UsersCheckStatus);
  574. UserActionResult resStatus = new UserActionResult(rsStatus);
  575. if (resStatus.status == UtilsController.Constant.SUCCESS)
  576. {
  577. UserInfo userInfo = new UserInfo(rsStatus);
  578. Session["userInfo"] = userInfo;
  579. Session["msisdn"] = msisdn;
  580. // Reload user info
  581. UtilsController.ReloadSubInfo();
  582. }
  583. }
  584. return Json(new
  585. {
  586. error_code = ress.responseCode,
  587. error_content = UtilsController.GetErrorCodeCharging(ress.responseCode)
  588. });
  589. }
  590. else if (ress.status == "2")
  591. {
  592. return Json(new
  593. {
  594. error_code = ress.status,
  595. error_content = UtilsController.GetErrorCodeCharging(ress.status)
  596. });
  597. }
  598. return Json(new
  599. {
  600. error_code = ress.responseCode,
  601. error_content = UtilsController.GetErrorCodeCharging(ress.responseCode)
  602. });
  603. //}
  604. //else
  605. //{
  606. // return Json(new
  607. // {
  608. // error_code = UtilsController.Constant.USER_EXISTED,
  609. // error_content = UtilsController.GetErrorCodeCharging(UtilsController.Constant.USER_EXISTED)
  610. // });
  611. //}
  612. }
  613. else
  614. {
  615. log.Info("Check package: " + msisdn + ", packg: " + packg);
  616. Session["msisdn-detecting"] = msisdn;
  617. //var checkSub = UtilsController.checkAccountSub(msisdn, packNameCannel_ToBe);
  618. //if (!checkSub)
  619. //{
  620. UserRequest userRequest = new UserRequest
  621. {
  622. users = msisdn,
  623. msisdn = msisdn,
  624. subServiceCode = packNameREGISTER_ToBe + "|" + price,
  625. requestId = refId,
  626. otp = code,
  627. serviceId = "3"
  628. };
  629. log.Info("userRequest_CAMID: " + JsonConvert.SerializeObject(userRequest));
  630. String rs = UtilsController.SendPost(userRequest, Session.SessionID, UtilsController.WsType.MpsRequest);
  631. UserActionResult ress = new UserActionResult(rs);
  632. log.Info("MpsResult: " + rs);
  633. if (ress.responseCode == UtilsController.Constant.SUCCESS)
  634. {
  635. Charging charging = new Charging(rs);
  636. Session["charging"] = charging;
  637. Session["msisdn"] = msisdn;
  638. Session["package"] = packageName;
  639. Session["CHARGE_ACTION"] = UtilsController.Constant.REGISTER;
  640. Session["CHARGE_DATA"] = userRequest;
  641. // Load profile
  642. GetUserProfileReq reqProfile = new GetUserProfileReq { users = msisdn };
  643. string rsProfile = UtilsController.SendPost(reqProfile, Session.SessionID, UtilsController.WsType.UsersGetProfile);
  644. log.Info("rsProfile: " + rsProfile);
  645. UserProfile profileGet = new UserProfile(rsProfile);
  646. if (profileGet.id != null)
  647. {
  648. Session["profile"] = profileGet;
  649. UserInfoRequest reqStatus = new UserInfoRequest { users = msisdn };
  650. string rsStatus = UtilsController.SendPost(reqStatus, Session.SessionID, UtilsController.WsType.UsersCheckStatus);
  651. UserActionResult resStatus = new UserActionResult(rsStatus);
  652. if (resStatus.status == UtilsController.Constant.SUCCESS)
  653. {
  654. UserInfo userInfo = new UserInfo(rsStatus);
  655. Session["userInfo"] = userInfo;
  656. Session["msisdn"] = msisdn;
  657. // Reload user info
  658. UtilsController.ReloadSubInfo();
  659. }
  660. }
  661. //}
  662. //else if (ress.status == "2")
  663. //{
  664. // return Json(new
  665. // {
  666. // error_code = ress.status,
  667. // error_content = UtilsController.GetErrorCodeCharging(ress.status)
  668. // });
  669. //}
  670. return Json(new
  671. {
  672. error_code = ress.responseCode,
  673. error_content = UtilsController.GetErrorCodeCharging(ress.responseCode)
  674. });
  675. }
  676. else
  677. {
  678. return Json(new
  679. {
  680. error_code = UtilsController.Constant.USER_EXISTED,
  681. error_content = UtilsController.GetErrorCodeCharging(UtilsController.Constant.USER_EXISTED)
  682. });
  683. }
  684. }
  685. //ReloadAccountInfo(msisdn);
  686. return Json(new
  687. {
  688. error = code,
  689. content = res,
  690. msisdn = msisdn.Substring(3)
  691. });
  692. }
  693. else
  694. {
  695. log.Info("REGISTER Can not detecting");
  696. }
  697. }
  698. else
  699. {
  700. // Handle error case
  701. string errorCode = response.errorCode ?? response.result?.errorCode;
  702. string errorMessage = response.errorMessage ?? response.result?.message;
  703. return Json(new
  704. {
  705. error_code = errorCode,
  706. error_content = errorMessage
  707. });
  708. }
  709. }
  710. else
  711. {
  712. log.Warn("Callback got error code: " + code + ", msisdn: " + msisdn);
  713. }
  714. // failed
  715. return Json(new
  716. {
  717. error = code,
  718. content = "failed_RegisterFromWap"
  719. });
  720. }
  721. catch (Exception ex)
  722. {
  723. log.Error("Error callback: " + code + ", msisdn: " + msisdn + ": " + ex.Message, ex);
  724. return Json(new
  725. {
  726. error = "-1",
  727. content = "failed_RegisterFromWap"
  728. });
  729. }
  730. }
  731. }
  732. }