/// <summary> /// Lay thong tin publisher secretkey /// </summary> /// <param name="publickey"></param> /// <param name="serviceID"></param> /// <param name="serverIP"></param> /// <param name="code"></param> /// <returns></returns> public DataTable GetPublisherKey(string publickey, short serviceID, string serverIP, ref int code) { try { LogClass.SaveLog("GetPublisherKey: " + publickey + "," + serverIP); DataTable dt = new DataTable(); using (SqlConnection connection = new SqlConnection(connectString2)) { connection.Open(); using (SqlCommand cmd = new SqlCommand()) { cmd.CommandTimeout = Constants.TIMOUT_CONNECT_SQL; cmd.Connection = connection; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "sp_GetPublisherKey"; cmd.Parameters.Add("@PublicKey", SqlDbType.VarChar, 32); cmd.Parameters["@PublicKey"].Value = publickey; cmd.Parameters.Add("@ServiceID", SqlDbType.SmallInt); cmd.Parameters["@ServiceID"].Value = serviceID; cmd.Parameters.Add("@ServerIP", SqlDbType.VarChar, 200); cmd.Parameters["@ServerIP"].Value = serverIP; cmd.Parameters.Add("@Code", SqlDbType.Int); cmd.Parameters["@Code"].Direction = ParameterDirection.Output; using (SqlDataReader dr = cmd.ExecuteReader()) { dt.Load(dr); } code = int.Parse(cmd.Parameters["@Code"].Value.ToString()); } } return(dt); } catch (Exception ex) { LogClass.SaveError("ERROR GetPublisherKey: " + ex); return(null); } }
public HttpResponseMessage TransferMoneyToAgency(PayloadApi p) { LogClass.SaveCustomerLog("TransferMoneyToAgency: " + JsonConvert.SerializeObject(p)); ResultApi result = new ResultApi(); try { var publisherInfo = publisher.CheckPublickey(p, version); if (publisherInfo.status == (int)ERROR_CODDE.SUCCESS) { ManagerModel managerModel = new ManagerModel(); var data = JsonConvert.DeserializeObject <TransferMoneyToAgency>(publisherInfo.data.ToString()); string msg = ""; string otp = ""; string phone = ""; result.status = managerModel.AgencyModel.TransferMoneyToAgency(data, ref msg, ref otp, ref phone); result.msg = msg; if (result.status == 2) { //SMS.SendMessage(phone, otp + " la ma xac thuc chuyen tien cua Ban."); SMS.SendMessage(phone, "Ma OTP xac thuc GD la " + otp + ", hieu luc 3 phut.Chi tiet GD: Chuyen khoan cho dai ly so tien " + UtilClass.formatMoney((int)data.amount) + " VND."); } } else { result = publisherInfo; } } catch (Exception ex) { LogClass.SaveError("ERROR TransferMoneyToAgency: " + ex, ex, true); result.status = (int)ERROR_CODDE.ERROR_EX; result.msg = ex.Message; } return(Request.CreateResponse(result)); }
public HttpResponseMessage InputCard(PayloadApi p) { LogClass.SaveCustomerLog("InputCard: " + JsonConvert.SerializeObject(p)); ResultApi result = new ResultApi(); CardObject cardObject = new CardObject(); try { var publisherInfo = publisher.CheckPublickey(p, version); if (publisherInfo.status == (int)ERROR_CODDE.SUCCESS) { ManagerModel managerModel = new ManagerModel(); var data = JsonConvert.DeserializeObject <InputCard>(publisherInfo.data.ToString()); string msg = ""; if (data.CardType != 1 && data.CardType != 2 && data.CardType != 3) { result.msg = "CardType sai định dạng"; return(null); } int successtransaction = 0; int errortransaction = 0; int errorsavelog = 0; short debug = 0; try { string serviceCode = string.Empty; if (data.CardType == 1) { serviceCode = "VTT"; } else if (data.CardType == 2) { serviceCode = "VMS"; } else if (data.CardType == 3) { serviceCode = "VNP"; } debug = 1; for (int i = 0; i < data.Qty; i++) { debug = 2; long transactionId = DateTime.Now.Ticks; var service = new muathe24h.MechantServicesSoapClient(); string email = "*****@*****.**"; string pass = "******"; var res = service.BuyCards(new muathe24h.UserCredentials { userName = email, pass = pass } , transactionId.ToString(), serviceCode, data.Amount, 1); debug = 3; LogClass.SaveLog("muathe24h" + JsonConvert.SerializeObject(res)); string resultCode = res?.RepCode.ToString(); debug = 4; //Khoi tao ket qua ghi log mac dinh cardObject.Amount = data.Amount; cardObject.Experied = string.Empty; cardObject.CardType = data.CardType; cardObject.TelCode = serviceCode; cardObject.TradeMark = "muathe24h"; cardObject.BuyTime = DateTime.Now; cardObject.ResultCode = resultCode; debug = 5; if (res != null && res.RepCode == 0) { successtransaction++; var seri = JsonConvert.DeserializeObject <List <CardObject_Muathe24h> >(res.Data.ToString()); //Mua thanh cong ghi lai code va seri the cardObject.CardCode = seri[0].PinCode; cardObject.CardSerial = seri[0].Serial; cardObject.TransactionCode = transactionId.ToString(); cardObject.Status = true; //Mua thanh cong LogClass.SaveLog("cardObject buy success:" + JsonConvert.SerializeObject(cardObject)); result.status = managerModel.GameAcountModel.INPUT_CARD(cardObject, ref msg); if (result.status != 1) { debug = 3; errorsavelog++; cardObject.CardCode = string.Empty; cardObject.CardSerial = string.Empty; cardObject.TransactionCode = string.Empty; cardObject.Status = false; // Mua that bai LogClass.SaveLog("cardObject savelog error:" + JsonConvert.SerializeObject(cardObject)); managerModel.GameAcountModel.INPUT_CARD(cardObject, ref msg); } } else //Mua the that bai { debug = 4; errortransaction++; cardObject.CardCode = string.Empty; cardObject.CardSerial = string.Empty; cardObject.TransactionCode = string.Empty; cardObject.Status = false; // Mua that bai LogClass.SaveLog("cardObject buy card error:" + JsonConvert.SerializeObject(cardObject)); managerModel.GameAcountModel.INPUT_CARD(cardObject, ref msg); } } } catch (Exception ex) { LogClass.SaveError("Mua thẻ thất bại" + ex + "\n,cardObject:" + JsonConvert.SerializeObject(cardObject)); } string msgTotalBuyCard = "Mua thành công " + successtransaction + " thẻ"; if (errortransaction > 0) { msgTotalBuyCard += " và thất bại " + errortransaction + " thẻ"; } if (errorsavelog > 0) { msgTotalBuyCard += ". Ghi log thất bại " + errorsavelog + " thẻ"; } result.msg = msgTotalBuyCard; } else { result = publisherInfo; } } catch (Exception ex) { LogClass.SaveError("ERROR InputCard: " + ex.Message + "\n,cardObject:" + JsonConvert.SerializeObject(cardObject), ex, true); result.status = (int)ERROR_CODDE.ERROR_EX; result.msg = ex.Message; } return(Request.CreateResponse(result)); }
/// <summary> /// Cap nhat thong tin khach hang /// </summary> /// <param name="p"></param> /// <returns></returns> public int UpdateCustomer(CustomerEntity p) { try { LogClass.SaveDBLog("UpdateCustomer: " + JsonConvert.SerializeObject(p)); using (SqlConnection connection = new SqlConnection(connectString)) { connection.Open(); using (SqlCommand cmd = new SqlCommand()) { cmd.CommandTimeout = Constants.TIMOUT_CONNECT_SQL; cmd.Connection = connection; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "sp_Api_UpdateCustomer"; cmd.Parameters.Add("@CustomerID", SqlDbType.Int); cmd.Parameters["@CustomerID"].Value = p.CustomertID; cmd.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 250); cmd.Parameters["@CompanyName"].Value = p.CompanyName; cmd.Parameters.Add("@TaxCode", SqlDbType.VarChar, 15); cmd.Parameters["@TaxCode"].Value = p.TaxCode; cmd.Parameters.Add("@Address", SqlDbType.NVarChar, 150); cmd.Parameters["@Address"].Value = p.Address; cmd.Parameters.Add("@City", SqlDbType.SmallInt); cmd.Parameters["@City"].Value = p.City; cmd.Parameters.Add("@Country", SqlDbType.SmallInt); cmd.Parameters["@Country"].Value = p.Country; cmd.Parameters.Add("@Address1", SqlDbType.NVarChar, 150); cmd.Parameters["@Address1"].Value = p.Address1; cmd.Parameters.Add("@City1", SqlDbType.SmallInt); cmd.Parameters["@City1"].Value = p.City1; cmd.Parameters.Add("@Country1", SqlDbType.SmallInt); cmd.Parameters["@Country1"].Value = p.Country1; cmd.Parameters.Add("@Address2", SqlDbType.NVarChar, 150); cmd.Parameters["@Address2"].Value = p.Address2; cmd.Parameters.Add("@City2", SqlDbType.SmallInt); cmd.Parameters["@City2"].Value = p.City2; cmd.Parameters.Add("@Country2", SqlDbType.SmallInt); cmd.Parameters["@Country2"].Value = p.Country2; cmd.Parameters.Add("@Email", SqlDbType.VarChar, 80); cmd.Parameters["@Email"].Value = p.Email; cmd.Parameters.Add("@Phone", SqlDbType.VarChar, 50); cmd.Parameters["@Phone"].Value = p.Phone; cmd.Parameters.Add("@Contact", SqlDbType.NVarChar, 250); cmd.Parameters["@Contact"].Value = p.Contact; cmd.Parameters.Add("@Status", SqlDbType.TinyInt); cmd.Parameters["@Status"].Value = p.Status; cmd.Parameters.Add("@UserEdit", SqlDbType.Int); cmd.Parameters["@UserEdit"].Value = p.UserID; cmd.Parameters.Add("@UserName", SqlDbType.NVarChar, 50); cmd.Parameters["@UserName"].Value = p.UserName; cmd.Parameters.Add("@KM", SqlDbType.SmallInt); cmd.Parameters["@KM"].Value = p.KM; cmd.Parameters.Add("@KM1", SqlDbType.SmallInt); cmd.Parameters["@KM1"].Value = p.KM1; cmd.Parameters.Add("@KM2", SqlDbType.SmallInt); cmd.Parameters["@KM2"].Value = p.KM2; cmd.Parameters.Add("@LoaiDon_ID", SqlDbType.TinyInt); cmd.Parameters["@LoaiDon_ID"].Value = p.Loaidon_ID; cmd.Parameters.Add("@LoaiHinhSX_ID", SqlDbType.Int); cmd.Parameters["@LoaiHinhSX_ID"].Value = p.LoaiHinhSX_ID; cmd.Parameters.Add("@ClientIP", SqlDbType.VarChar, 40); cmd.Parameters["@ClientIP"].Value = p.ClientIP != null ? p.ClientIP : ""; cmd.Parameters.Add("@Code", SqlDbType.Int); cmd.Parameters["@Code"].Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); int code = int.Parse(cmd.Parameters["@Code"].Value.ToString()); LogClass.SaveDBLog("Result UpdateCustomer: " + code); return(code); } } } catch (Exception ex) { LogClass.SaveError("Error UpdateCustomer: " + ex.Message, ex, true); return((int)ERROR_CODDE.ERROR_EX); } }
public ResultApi CheckPublickey(PayloadApi p, string currentVersion) { ResultApi result = new ResultApi(); try { if (p == null) { result.status = (int)ERROR_CODDE.DATA_NULL; result.msg = ERROR_CODDE.DATA_NULL.ToString(); } else if (string.IsNullOrEmpty(p.data) || string.IsNullOrEmpty(p.clientIP) || string.IsNullOrEmpty(p.sign) || string.IsNullOrEmpty(p.publickey)) { result.status = (int)ERROR_CODDE.DATA_INVALID; result.msg = ERROR_CODDE.DATA_INVALID.ToString(); } else { if (p.sign == p.signServer) { string serverIP = UtilClass.GetIPAddress(); var publisherInfo = GetPublisherInfo(p.publickey, serverIP, p.serviceID); if (!string.IsNullOrEmpty(publisherInfo.publickey)) { if (publisherInfo.version == currentVersion) { string decryptData = Encryptor.DecryptString(p.data, publisherInfo.secretkey); if (decryptData != "") { result.data = decryptData; result.status = (int)ERROR_CODDE.SUCCESS; result.secreckey = publisherInfo.secretkey; } else { result.status = (int)ERROR_CODDE.DATA_ENCRYPT_INVALID; result.msg = ERROR_CODDE.DATA_ENCRYPT_INVALID.ToString(); } } else { result.status = (int)ERROR_CODDE.VERSION_INVALID; result.msg = ERROR_CODDE.VERSION_INVALID.ToString(); } } else { result.status = (int)ERROR_CODDE.PUBLICKEY_NOT_FOUND; result.msg = ERROR_CODDE.PUBLICKEY_NOT_FOUND.ToString(); } } else { result.status = (int)ERROR_CODDE.SIGN_WRONG; result.msg = ERROR_CODDE.SIGN_WRONG.ToString(); } } } catch (Exception ex) { LogClass.SaveError("ERROR CheckPublickey: " + JsonConvert.SerializeObject(p), ex, true); result.status = (int)ERROR_CODDE.ERROR_EX; result.msg = ex.Message; } return(result); }