using System; using System.Collections.Generic; using System.Linq; using System.Text; //---------------------------------------------------------------- //Module Name: $safeprojectname$ //Purpose: //CopyRight: Muchinfo //History: //---------------------------------------------------------------- //DateTime 2016/3/24 15:58:45 //Author //Description Create //---------------------------------------------------------------- using Muchinfo.MTPClient.Data.Model; using tas; using Muchinfo.MTPClient.Adapter.Abstract; using Muchinfo.MTPClient.Adapter.Utilities; using Muchinfo.MTPClient.Data; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model.Account; using Muchinfo.MTPClient.Data.Model.Bank; using Bank; using System.Collections.ObjectModel; namespace Muchinfo.MTPClient.Adapter.ProtoBuf { public class BankProtobufAdapter : BankAdapter { public override byte[] ToRequestQueryCity(string provinceCode) { var city = new QueryCityInfoReq(); city.Provinceid = provinceCode; city.flag = 1; return ProtoBufHelper.EntitySerialize(city); } public override ResponeEntity> ToLocalCityInfo(object obj) { var buffer = obj as byte[]; if (buffer == null) { throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); } var rspData = ProtoBufHelper.EntityDeSerialize(buffer); var resultEntity = new ResponeEntity>() { RetCode = rspData.RetCode, RetMessage = rspData.RetDesc, Entity = new List(), }; if (rspData.Rsps == null || !rspData.Rsps.Any()) { //todo:查询内容空 return resultEntity; } foreach (var cityInfo in rspData.Rsps) { var city = new City(); city.CityName = cityInfo.cityname; city.CityCode = cityInfo.cityid; city.ProvinceCoed = cityInfo.Provinceid; resultEntity.Entity.Add(city); } return resultEntity; } public override ResponeEntity> ToLocalProvinceInfo(object obj) { var buffer = obj as byte[]; if (buffer == null) { throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); } var rspData = new QueryProvinceInfoRsp(); rspData = ProtoBufHelper.EntityDeSerialize(buffer); var resultEntity = new ResponeEntity>() { RetCode = rspData.RetCode, RetMessage = rspData.RetDesc, Entity = new List(), }; if (rspData.Rsps == null || !rspData.Rsps.Any()) { //todo:查询内容空 return resultEntity; } foreach (var provinceInfo in rspData.Rsps) { var province = new Province(); province.ProvinceCode = provinceInfo.Provinceid; province.ProvinceName = provinceInfo.ProvinceName; resultEntity.Entity.Add(province); } return resultEntity; } public override byte[] ToRequestQueryProvince() { var province = new QueryProvinceInfoReq(); province.flag = 1; return ProtoBufHelper.EntitySerialize(province); } #region 银行平台密钥申请 public override byte[] ToBankCancelSignReq(SigningBank bankInfo ) { var obj = new Bank.BankCancelSignReq() { ExtOperatorID = (long)bankInfo.ExtOperatorID, AccountCode = bankInfo.AccountCode, CustomerName = bankInfo.CusBankName, BankAccountNo = bankInfo.BankAccount, BankAccountName = bankInfo.AccountName, CertType = (int)bankInfo.CredentialType, CertID = bankInfo.CredentialNumber, CusBankID = bankInfo.CusBankID+string.Empty, //ExBankName =string.IsNullOrEmpty(bankInfo.Name)?string.Empty: bankInfo.Name,//"银行名字为必填字段" ExBankName = bankInfo.Name,//"银行名字为必填字段" ExBankNo = bankInfo.BankId, OpenBankNo = bankInfo.BranchId, PaymentNo = bankInfo.PaymentNumberVisibility ? bankInfo.PaymentNumber : string.Empty, ProtocolNo = bankInfo.ProtocolNumberVisibility? bankInfo.ProtocolNumber : string.Empty, AppDateTime = bankInfo.CurrentTime.ToString(), CustomerSignId = bankInfo.CustomerSignId, Currency = bankInfo.Currency, }; return ProtoBufHelper.EntitySerialize(obj); } public override Bank.BankCancelSignRsp FromBankCancelSignRsp(object obj) { var buffer = obj as byte[]; if (buffer == null) { throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); } return ProtoBufHelper.EntityDeSerialize(buffer); } public override byte[] ToBankSignReq(tas.BankSignReq request) { return ProtoBufHelper.EntitySerialize(request); } public override tas.BankSignRsp FromBankSignRsp(object obj) { var buffer = obj as byte[]; if (buffer == null) { throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); } return ProtoBufHelper.EntityDeSerialize(buffer); } //public override byte[] ToSignUpdateReq(tas.SignUpdateReq request) //{ // return ProtoBufHelper.EntitySerialize(request); //} public override Bank.SignUpdateRsp FromSignUpdateRsp(object obj) { var buffer = obj as byte[]; if (buffer == null) { throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); } return ProtoBufHelper.EntityDeSerialize(buffer); } /// /// 银行平台密钥申请请求实体转换 /// /// ApplySecretKeyRequest对象 /// 返回ApplySecretKeyReq对象 public override byte[] ToApplySecretKeyReq(EncryptKeyRequest request) { //var req = new tas.ApplySecretKeyReq() //{ // //ExtOperatorID = request.ExtOperatorID, // CusBankId = request.CusBankId, // Currency = request.Currency, // KMCode = request.KMCode, //}; //return ProtoBufHelper.EntitySerialize(req); return new byte[1024]; } /// /// 银行平台密钥申请应答实体转换 /// /// ApplySecretKeyRsp对象 /// 返回EncryptKey对象 public override Bank.ApplySecretKeyRsp FromApplySecretKeyResponse(object obj) { var buffer = obj as byte[]; if (buffer == null) { throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); } return ProtoBufHelper.EntityDeSerialize(buffer); } public override byte[] ToSignBankPwdReq(SignBankPDW request) { var req = new Bank.SignBankPwdReq() { ExtOperatorID = request.ExtOperatorID, ExchTicket = request.ExchTicket, AccountCode = request.AccountCode, CusBankId = request.CusBankId, Currency = request.Currency, BankAccountPWD = request.BankAccountPWD, }; return ProtoBufHelper.EntitySerialize(req); } public override Bank.SignBankPwdInRsp FromSignBankPwdInRsp(object obj) { var buffer = obj as byte[]; if (buffer == null) { throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); } return ProtoBufHelper.EntityDeSerialize(buffer); } public override BankSignResult FromSignBankPwdInRspToBankSignResult(Bank.BankDepositRsp result) { return new BankSignResult() { ExchTicket = result.ExchTicket, // Status = (BankDealStatus)result.Status, Status = (BankDealStatus)result.Status, ExtOperatorID = result.ExtOperatorID, WebAddress = Encoding.UTF8.GetString(Convert.FromBase64String(result.NetAddr)), ReturnCode = result.RetCode, ReturnDesc = result.RetDesc, }; } public override BankSignResult FromBankSignRspToBankSignResult(tas.BankSignRsp result) { return null; // return new BankSignResult() // { // ExchTicket = result.ExchTicket, // // Status = (BankDealStatus)result.Status, // Status = (BankDealStatus)result.Status, // ExtOperatorID = result.ExtOperatorID, // WebAddress = Encoding.UTF8.GetString(Convert.FromBase64String(result.NetAddr)), // ReturnCode = result.RetCode, // ReturnDesc = result.RetDesc, // BankSubAccount = result.BankSubAcct, // }; } public override byte[] ToBankWithDrawReq(Bank.BankWithDrawReq request) { return ProtoBufHelper.EntitySerialize(request); } public override Bank.BankWithDrawRsp FromBankWithDrawRsp(object obj) { var buffer = obj as byte[]; if (buffer == null) { throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); } return ProtoBufHelper.EntityDeSerialize(buffer); } public override byte[] ToBankDepositReq(Bank.BankDepositReq request) { return ProtoBufHelper.EntitySerialize(request); } public override Bank.BankDepositRsp FromBankDepositRsp(object obj) { var buffer = obj as byte[]; if (buffer == null) { throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); } return ProtoBufHelper.EntityDeSerialize(buffer); } #endregion public override byte[] ToIdentifyCodeReq(IdentifyCodeReq req) { //var serverReq = new tas.BankGetIdentifyCodeReq() //{ // AccountCode = req.AccountCode, // Amount =Convert.ToDouble(req.Amount), // CusBankID = req.CusBankID, // CustomerSignId = req.CustomerSignId, // TradeType = (int)req.TradeType, // AccountType = (int)req.AccountType, // BankAccountNo = req.BankAccountNo, // BankCode =req.BankCode, // CardNum=req.CardNum, // CardType=(int)req.CardType, // Currency =req.Currency, // CustomerName=req.CustomerName, // MobilePhone=req.MobilePhone //}; //return ProtoBufHelper.EntitySerialize(serverReq); return new byte[1024]; } public override Bank.BankGetIdentifyCodeRsp FromIdentifyCodeReq(object obj) { var buffer = obj as byte[]; if (buffer == null) { throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); } return ProtoBufHelper.EntityDeSerialize(buffer); } public override byte[] ToBankSubBalanceReq(SigningBank bankInfo) { //var serverReq = new tas.QueryBankAccountInfoReq() //{ // AccountCode = bankInfo.AccountCode, // Cusbankid = bankInfo.CusBankID+string.Empty, // AccountType = 32+string.Empty, ////查询余额的账号类型是32 //}; //return ProtoBufHelper.EntitySerialize(serverReq); return new byte[1024]; } public override ResponeEntity> FromoBankSubBalanceRsp(object obj) { return new ResponeEntity>(); //var buffer = obj as byte[]; //if (buffer == null) //{ // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); //} //var bankBalanceModels = new List(); //var bankAccountRsp= ProtoBufHelper.EntityDeSerialize(buffer); //var resultEntity = new ResponeEntity>() //{ // RetCode = bankAccountRsp.RetCode, // RetMessage = bankAccountRsp.RetDesc, //}; //if ( bankAccountRsp.Rsps != null) //{ // foreach (var bankBalance in bankAccountRsp.Rsps) // { // var balance = new BankBalanceModel() // { // AccountCode = bankBalance.AccountCode, // AccountType = bankBalance.AccountType, // BankBalance = bankBalance.BankBalance, // Cusbankid = bankBalance.Cusbankid, // ExchTicket = bankBalance.ExchTicket, // PlatBalance = bankBalance.PlatBalance, // }; // bankBalanceModels.Add(balance); // } // resultEntity.Entity = bankBalanceModels; //} //return resultEntity; } public override byte[] ToBankRebindCardReq(SigningBank bankRebind) { //var Req = new tas.BankRebindCardReq() //{ // ExtOperatorID = bankRebind.ExtOperatorID, // AccountCode = bankRebind.AccountCode, // BankAccountNo = bankRebind.BankAccount, // BankAccountName = bankRebind.AccountName, // CertType = (int)bankRebind.CredentialType, // CertID = string.IsNullOrWhiteSpace(bankRebind.CredentialNumber) ? "0000" : bankRebind.CredentialNumber, // CusBankID = bankRebind.CusBankID + string.Empty, // CustomerName = bankRebind.CustomerName, // ExBankNo = bankRebind.BankId, // ExBankName = bankRebind.Name, // OpenBankNo = bankRebind.BranchId, // OpenBankName = bankRebind.BranchBankName, // PaymentNo = bankRebind.PaymentNumber, // ProtocolNo = bankRebind.ProtocolNumber, // AccountType = (int)bankRebind.AccountType, // Currency = string.IsNullOrWhiteSpace(bankRebind.Currency) ? "RMB" : bankRebind.Currency, // BankAccountPWD = string.IsNullOrEmpty(bankRebind.BankPassword) ? string.Empty : bankRebind.BankPassword, // //BankAccountPWD = bankRebind.BankPassword, // //SerialNumber = request.SerialNumber // // BankAccountPWD = request.BankAccountPWD, // IdentifyCode = bankRebind.IdentifyCode, // AgentCertID = bankRebind.AgentCID, // AgentCertType = (int)bankRebind.AgentCredentialType, // AgentName = bankRebind.AgentName, // BankAccountType = (int)bankRebind.BankAccountType, // BankCity = bankRebind.CityCode, // BankProvince = bankRebind.ProvinceCode, // MobilePhone = bankRebind.MobilePhone, // BankCardType = bankRebind.BankCardType == 0 ? 1 : (int)bankRebind.BankCardType, // RebindToNewBankCardNo = bankRebind.RebindToNewBankCardNo, // RebindToNewBankCardNoAccName = bankRebind.RebindToNewBankCardNoAccName, // RebindToNewBankNo = bankRebind.RebindToNewBankNo, //}; //return ProtoBufHelper.EntitySerialize(Req); return new byte[1024]; } public override byte[] ToBankUnBindCardReq(SigningBank bankunbind) { //var Req = new tas.BankUnbindCardReq() //{ // ExtOperatorID = bankunbind.ExtOperatorID, // AccountCode = bankunbind.AccountCode, // BankAccountNo = bankunbind.BankAccount, // BankAccountName = bankunbind.AccountName, // CusBankID = bankunbind.CusBankID + string.Empty, // ExBankNo = bankunbind.BankId, // ExBankName = bankunbind.Name, // AccountType = (int)bankunbind.AccountType, // Currency = string.IsNullOrWhiteSpace(bankunbind.Currency) ? "RMB" : bankunbind.Currency, // AppDateTime = bankunbind.AppDateTime, // ExchId = bankunbind.ExchId // //BankAccountPWD = bankRebind.BankPassword, // //SerialNumber = request.SerialNumber // // BankAccountPWD = request.BankAccountPWD, //}; //return ProtoBufHelper.EntitySerialize(Req); return new byte[1024]; } public override ResponeEntity ToBankReBindCardRsp(object obj) { return new ResponeEntity(); //var buffer = obj as byte[]; //if (buffer == null) //{ // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); //} //var rspData = ProtoBufHelper.EntityDeSerialize(buffer); //return new ResponeEntity() //{ // RetCode = rspData.RetCode, // RetMessage = rspData.RetDesc, // Entity = new BankSignResult() // { // ReturnCode = rspData.RetCode, // ReturnDesc = rspData.RetDesc, // WebAddress =string.IsNullOrEmpty(rspData.NetAddr) ?"":Encoding.UTF8.GetString(Convert.FromBase64String(rspData.NetAddr)), // ExchTicket = rspData.ExchTicket, // Status = (BankDealStatus)rspData.Status, // }, //}; } public override ResponeEntity ToBankUnBindCardRsp(object obj) { return new ResponeEntity(); // var buffer = obj as byte[]; //if (buffer == null) //{ // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!"); //} //var rspData = ProtoBufHelper.EntityDeSerialize(buffer); //return new ResponeEntity() //{ // RetCode = rspData.RetCode, // RetMessage = rspData.RetDesc, // Entity = new BankUnBindResult() // { // ReturnCode = rspData.RetCode, // ReturnDesc = rspData.RetDesc, // WebAddress = string.IsNullOrEmpty(rspData.NetAddr) ? "" : Encoding.UTF8.GetString(Convert.FromBase64String(rspData.NetAddr)), // ExchTicket = rspData.ExchTicket, // Status = (BankDealStatus)rspData.Status, // }, //}; } } }