BankProtobufAdapter.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. //----------------------------------------------------------------
  6. //Module Name: $safeprojectname$
  7. //Purpose:
  8. //CopyRight: Muchinfo
  9. //History:
  10. //----------------------------------------------------------------
  11. //DateTime 2016/3/24 15:58:45
  12. //Author
  13. //Description Create
  14. //----------------------------------------------------------------
  15. using Muchinfo.MTPClient.Data.Model;
  16. using tas;
  17. using Muchinfo.MTPClient.Adapter.Abstract;
  18. using Muchinfo.MTPClient.Adapter.Utilities;
  19. using Muchinfo.MTPClient.Data;
  20. using Muchinfo.MTPClient.Data.Enums;
  21. using Muchinfo.MTPClient.Data.Model.Account;
  22. using Muchinfo.MTPClient.Data.Model.Bank;
  23. using Bank;
  24. using System.Collections.ObjectModel;
  25. namespace Muchinfo.MTPClient.Adapter.ProtoBuf
  26. {
  27. public class BankProtobufAdapter : BankAdapter
  28. {
  29. public override byte[] ToRequestQueryCity(string provinceCode)
  30. {
  31. var city = new QueryCityInfoReq();
  32. city.Provinceid = provinceCode;
  33. city.flag = 1;
  34. return ProtoBufHelper.EntitySerialize(city);
  35. }
  36. public override ResponeEntity<List<City>> ToLocalCityInfo(object obj)
  37. {
  38. var buffer = obj as byte[];
  39. if (buffer == null)
  40. {
  41. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  42. }
  43. var rspData = ProtoBufHelper.EntityDeSerialize<QueryCityInfoRsp>(buffer);
  44. var resultEntity = new ResponeEntity<List<City>>()
  45. {
  46. RetCode = rspData.RetCode,
  47. RetMessage = rspData.RetDesc,
  48. Entity = new List<City>(),
  49. };
  50. if (rspData.Rsps == null || !rspData.Rsps.Any())
  51. {
  52. //todo:查询内容空
  53. return resultEntity;
  54. }
  55. foreach (var cityInfo in rspData.Rsps)
  56. {
  57. var city = new City();
  58. city.CityName = cityInfo.cityname;
  59. city.CityCode = cityInfo.cityid;
  60. city.ProvinceCoed = cityInfo.Provinceid;
  61. resultEntity.Entity.Add(city);
  62. }
  63. return resultEntity;
  64. }
  65. public override ResponeEntity<List<Province>> ToLocalProvinceInfo(object obj)
  66. {
  67. var buffer = obj as byte[];
  68. if (buffer == null)
  69. {
  70. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  71. }
  72. var rspData = new QueryProvinceInfoRsp();
  73. rspData = ProtoBufHelper.EntityDeSerialize<QueryProvinceInfoRsp>(buffer);
  74. var resultEntity = new ResponeEntity<List<Province>>()
  75. {
  76. RetCode = rspData.RetCode,
  77. RetMessage = rspData.RetDesc,
  78. Entity = new List<Province>(),
  79. };
  80. if (rspData.Rsps == null || !rspData.Rsps.Any())
  81. {
  82. //todo:查询内容空
  83. return resultEntity;
  84. }
  85. foreach (var provinceInfo in rspData.Rsps)
  86. {
  87. var province = new Province();
  88. province.ProvinceCode = provinceInfo.Provinceid;
  89. province.ProvinceName = provinceInfo.ProvinceName;
  90. resultEntity.Entity.Add(province);
  91. }
  92. return resultEntity;
  93. }
  94. public override byte[] ToRequestQueryProvince()
  95. {
  96. var province = new QueryProvinceInfoReq();
  97. province.flag = 1;
  98. return ProtoBufHelper.EntitySerialize(province);
  99. }
  100. #region 银行平台密钥申请
  101. public override byte[] ToBankCancelSignReq(SigningBank bankInfo )
  102. {
  103. var obj = new Bank.BankCancelSignReq()
  104. {
  105. ExtOperatorID = (long)bankInfo.ExtOperatorID,
  106. AccountCode = bankInfo.AccountCode,
  107. CustomerName = bankInfo.CusBankName,
  108. BankAccountNo = bankInfo.BankAccount,
  109. BankAccountName = bankInfo.AccountName,
  110. CertType = (int)bankInfo.CredentialType,
  111. CertID = bankInfo.CredentialNumber,
  112. CusBankID = bankInfo.CusBankID+string.Empty,
  113. //ExBankName =string.IsNullOrEmpty(bankInfo.Name)?string.Empty: bankInfo.Name,//"银行名字为必填字段"
  114. ExBankName = bankInfo.Name,//"银行名字为必填字段"
  115. ExBankNo = bankInfo.BankId,
  116. OpenBankNo = bankInfo.BranchId,
  117. PaymentNo = bankInfo.PaymentNumberVisibility ? bankInfo.PaymentNumber : string.Empty,
  118. ProtocolNo = bankInfo.ProtocolNumberVisibility? bankInfo.ProtocolNumber : string.Empty,
  119. AppDateTime = bankInfo.CurrentTime.ToString(),
  120. CustomerSignId = bankInfo.CustomerSignId,
  121. Currency = bankInfo.Currency,
  122. };
  123. return ProtoBufHelper.EntitySerialize(obj);
  124. }
  125. public override Bank.BankCancelSignRsp FromBankCancelSignRsp(object obj)
  126. {
  127. var buffer = obj as byte[];
  128. if (buffer == null)
  129. {
  130. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  131. }
  132. return ProtoBufHelper.EntityDeSerialize<Bank.BankCancelSignRsp>(buffer);
  133. }
  134. public override byte[] ToBankSignReq(tas.BankSignReq request)
  135. {
  136. return ProtoBufHelper.EntitySerialize(request);
  137. }
  138. public override tas.BankSignRsp FromBankSignRsp(object obj)
  139. {
  140. var buffer = obj as byte[];
  141. if (buffer == null)
  142. {
  143. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  144. }
  145. return ProtoBufHelper.EntityDeSerialize<tas.BankSignRsp>(buffer);
  146. }
  147. //public override byte[] ToSignUpdateReq(tas.SignUpdateReq request)
  148. //{
  149. // return ProtoBufHelper.EntitySerialize(request);
  150. //}
  151. public override Bank.SignUpdateRsp FromSignUpdateRsp(object obj)
  152. {
  153. var buffer = obj as byte[];
  154. if (buffer == null)
  155. {
  156. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  157. }
  158. return ProtoBufHelper.EntityDeSerialize<Bank.SignUpdateRsp>(buffer);
  159. }
  160. /// <summary>
  161. /// 银行平台密钥申请请求实体转换
  162. /// </summary>
  163. /// <param name="request">ApplySecretKeyRequest对象</param>
  164. /// <returns>返回ApplySecretKeyReq对象</returns>
  165. public override byte[] ToApplySecretKeyReq(EncryptKeyRequest request)
  166. {
  167. //var req = new tas.ApplySecretKeyReq()
  168. //{
  169. // //ExtOperatorID = request.ExtOperatorID,
  170. // CusBankId = request.CusBankId,
  171. // Currency = request.Currency,
  172. // KMCode = request.KMCode,
  173. //};
  174. //return ProtoBufHelper.EntitySerialize(req);
  175. return new byte[1024];
  176. }
  177. /// <summary>
  178. /// 银行平台密钥申请应答实体转换
  179. /// </summary>
  180. /// <param name="rsp">ApplySecretKeyRsp对象</param>
  181. /// <returns>返回EncryptKey对象</returns>
  182. public override Bank.ApplySecretKeyRsp FromApplySecretKeyResponse(object obj)
  183. {
  184. var buffer = obj as byte[];
  185. if (buffer == null)
  186. {
  187. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  188. }
  189. return ProtoBufHelper.EntityDeSerialize<Bank.ApplySecretKeyRsp>(buffer);
  190. }
  191. public override byte[] ToSignBankPwdReq(SignBankPDW request)
  192. {
  193. var req = new Bank.SignBankPwdReq()
  194. {
  195. ExtOperatorID = request.ExtOperatorID,
  196. ExchTicket = request.ExchTicket,
  197. AccountCode = request.AccountCode,
  198. CusBankId = request.CusBankId,
  199. Currency = request.Currency,
  200. BankAccountPWD = request.BankAccountPWD,
  201. };
  202. return ProtoBufHelper.EntitySerialize(req);
  203. }
  204. public override Bank.SignBankPwdInRsp FromSignBankPwdInRsp(object obj)
  205. {
  206. var buffer = obj as byte[];
  207. if (buffer == null)
  208. {
  209. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  210. }
  211. return ProtoBufHelper.EntityDeSerialize<Bank.SignBankPwdInRsp>(buffer);
  212. }
  213. public override BankSignResult FromSignBankPwdInRspToBankSignResult(Bank.BankDepositRsp result)
  214. {
  215. return new BankSignResult()
  216. {
  217. ExchTicket = result.ExchTicket,
  218. // Status = (BankDealStatus)result.Status,
  219. Status = (BankDealStatus)result.Status,
  220. ExtOperatorID = result.ExtOperatorID,
  221. WebAddress = Encoding.UTF8.GetString(Convert.FromBase64String(result.NetAddr)),
  222. ReturnCode = result.RetCode,
  223. ReturnDesc = result.RetDesc,
  224. };
  225. }
  226. public override BankSignResult FromBankSignRspToBankSignResult(tas.BankSignRsp result)
  227. {
  228. return null;
  229. // return new BankSignResult()
  230. // {
  231. // ExchTicket = result.ExchTicket,
  232. // // Status = (BankDealStatus)result.Status,
  233. // Status = (BankDealStatus)result.Status,
  234. // ExtOperatorID = result.ExtOperatorID,
  235. // WebAddress = Encoding.UTF8.GetString(Convert.FromBase64String(result.NetAddr)),
  236. // ReturnCode = result.RetCode,
  237. // ReturnDesc = result.RetDesc,
  238. // BankSubAccount = result.BankSubAcct,
  239. // };
  240. }
  241. public override byte[] ToBankWithDrawReq(Bank.BankWithDrawReq request)
  242. {
  243. return ProtoBufHelper.EntitySerialize(request);
  244. }
  245. public override Bank.BankWithDrawRsp FromBankWithDrawRsp(object obj)
  246. {
  247. var buffer = obj as byte[];
  248. if (buffer == null)
  249. {
  250. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  251. }
  252. return ProtoBufHelper.EntityDeSerialize<Bank.BankWithDrawRsp>(buffer);
  253. }
  254. public override byte[] ToBankDepositReq(Bank.BankDepositReq request)
  255. {
  256. return ProtoBufHelper.EntitySerialize(request);
  257. }
  258. public override Bank.BankDepositRsp FromBankDepositRsp(object obj)
  259. {
  260. var buffer = obj as byte[];
  261. if (buffer == null)
  262. {
  263. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  264. }
  265. return ProtoBufHelper.EntityDeSerialize<Bank.BankDepositRsp>(buffer);
  266. }
  267. #endregion
  268. public override byte[] ToIdentifyCodeReq(IdentifyCodeReq req)
  269. {
  270. //var serverReq = new tas.BankGetIdentifyCodeReq()
  271. //{
  272. // AccountCode = req.AccountCode,
  273. // Amount =Convert.ToDouble(req.Amount),
  274. // CusBankID = req.CusBankID,
  275. // CustomerSignId = req.CustomerSignId,
  276. // TradeType = (int)req.TradeType,
  277. // AccountType = (int)req.AccountType,
  278. // BankAccountNo = req.BankAccountNo,
  279. // BankCode =req.BankCode,
  280. // CardNum=req.CardNum,
  281. // CardType=(int)req.CardType,
  282. // Currency =req.Currency,
  283. // CustomerName=req.CustomerName,
  284. // MobilePhone=req.MobilePhone
  285. //};
  286. //return ProtoBufHelper.EntitySerialize(serverReq);
  287. return new byte[1024];
  288. }
  289. public override Bank.BankGetIdentifyCodeRsp FromIdentifyCodeReq(object obj)
  290. {
  291. var buffer = obj as byte[];
  292. if (buffer == null)
  293. {
  294. throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  295. }
  296. return ProtoBufHelper.EntityDeSerialize<Bank.BankGetIdentifyCodeRsp>(buffer);
  297. }
  298. public override byte[] ToBankSubBalanceReq(SigningBank bankInfo)
  299. {
  300. //var serverReq = new tas.QueryBankAccountInfoReq()
  301. //{
  302. // AccountCode = bankInfo.AccountCode,
  303. // Cusbankid = bankInfo.CusBankID+string.Empty,
  304. // AccountType = 32+string.Empty, ////查询余额的账号类型是32
  305. //};
  306. //return ProtoBufHelper.EntitySerialize(serverReq);
  307. return new byte[1024];
  308. }
  309. public override ResponeEntity<List<BankBalanceModel>> FromoBankSubBalanceRsp(object obj)
  310. {
  311. return new ResponeEntity<List<BankBalanceModel>>();
  312. //var buffer = obj as byte[];
  313. //if (buffer == null)
  314. //{
  315. // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  316. //}
  317. //var bankBalanceModels = new List<BankBalanceModel>();
  318. //var bankAccountRsp= ProtoBufHelper.EntityDeSerialize<tas.QueryBankAccountInfoRsp>(buffer);
  319. //var resultEntity = new ResponeEntity<List<BankBalanceModel>>()
  320. //{
  321. // RetCode = bankAccountRsp.RetCode,
  322. // RetMessage = bankAccountRsp.RetDesc,
  323. //};
  324. //if ( bankAccountRsp.Rsps != null)
  325. //{
  326. // foreach (var bankBalance in bankAccountRsp.Rsps)
  327. // {
  328. // var balance = new BankBalanceModel()
  329. // {
  330. // AccountCode = bankBalance.AccountCode,
  331. // AccountType = bankBalance.AccountType,
  332. // BankBalance = bankBalance.BankBalance,
  333. // Cusbankid = bankBalance.Cusbankid,
  334. // ExchTicket = bankBalance.ExchTicket,
  335. // PlatBalance = bankBalance.PlatBalance,
  336. // };
  337. // bankBalanceModels.Add(balance);
  338. // }
  339. // resultEntity.Entity = bankBalanceModels;
  340. //}
  341. //return resultEntity;
  342. }
  343. public override byte[] ToBankRebindCardReq(SigningBank bankRebind)
  344. {
  345. //var Req = new tas.BankRebindCardReq()
  346. //{
  347. // ExtOperatorID = bankRebind.ExtOperatorID,
  348. // AccountCode = bankRebind.AccountCode,
  349. // BankAccountNo = bankRebind.BankAccount,
  350. // BankAccountName = bankRebind.AccountName,
  351. // CertType = (int)bankRebind.CredentialType,
  352. // CertID = string.IsNullOrWhiteSpace(bankRebind.CredentialNumber) ? "0000" : bankRebind.CredentialNumber,
  353. // CusBankID = bankRebind.CusBankID + string.Empty,
  354. // CustomerName = bankRebind.CustomerName,
  355. // ExBankNo = bankRebind.BankId,
  356. // ExBankName = bankRebind.Name,
  357. // OpenBankNo = bankRebind.BranchId,
  358. // OpenBankName = bankRebind.BranchBankName,
  359. // PaymentNo = bankRebind.PaymentNumber,
  360. // ProtocolNo = bankRebind.ProtocolNumber,
  361. // AccountType = (int)bankRebind.AccountType,
  362. // Currency = string.IsNullOrWhiteSpace(bankRebind.Currency) ? "RMB" : bankRebind.Currency,
  363. // BankAccountPWD = string.IsNullOrEmpty(bankRebind.BankPassword) ? string.Empty : bankRebind.BankPassword,
  364. // //BankAccountPWD = bankRebind.BankPassword,
  365. // //SerialNumber = request.SerialNumber
  366. // // BankAccountPWD = request.BankAccountPWD,
  367. // IdentifyCode = bankRebind.IdentifyCode,
  368. // AgentCertID = bankRebind.AgentCID,
  369. // AgentCertType = (int)bankRebind.AgentCredentialType,
  370. // AgentName = bankRebind.AgentName,
  371. // BankAccountType = (int)bankRebind.BankAccountType,
  372. // BankCity = bankRebind.CityCode,
  373. // BankProvince = bankRebind.ProvinceCode,
  374. // MobilePhone = bankRebind.MobilePhone,
  375. // BankCardType = bankRebind.BankCardType == 0 ? 1 : (int)bankRebind.BankCardType,
  376. // RebindToNewBankCardNo = bankRebind.RebindToNewBankCardNo,
  377. // RebindToNewBankCardNoAccName = bankRebind.RebindToNewBankCardNoAccName,
  378. // RebindToNewBankNo = bankRebind.RebindToNewBankNo,
  379. //};
  380. //return ProtoBufHelper.EntitySerialize(Req);
  381. return new byte[1024];
  382. }
  383. public override byte[] ToBankUnBindCardReq(SigningBank bankunbind)
  384. {
  385. //var Req = new tas.BankUnbindCardReq()
  386. //{
  387. // ExtOperatorID = bankunbind.ExtOperatorID,
  388. // AccountCode = bankunbind.AccountCode,
  389. // BankAccountNo = bankunbind.BankAccount,
  390. // BankAccountName = bankunbind.AccountName,
  391. // CusBankID = bankunbind.CusBankID + string.Empty,
  392. // ExBankNo = bankunbind.BankId,
  393. // ExBankName = bankunbind.Name,
  394. // AccountType = (int)bankunbind.AccountType,
  395. // Currency = string.IsNullOrWhiteSpace(bankunbind.Currency) ? "RMB" : bankunbind.Currency,
  396. // AppDateTime = bankunbind.AppDateTime,
  397. // ExchId = bankunbind.ExchId
  398. // //BankAccountPWD = bankRebind.BankPassword,
  399. // //SerialNumber = request.SerialNumber
  400. // // BankAccountPWD = request.BankAccountPWD,
  401. //};
  402. //return ProtoBufHelper.EntitySerialize(Req);
  403. return new byte[1024];
  404. }
  405. public override ResponeEntity<BankSignResult> ToBankReBindCardRsp(object obj)
  406. {
  407. return new ResponeEntity<BankSignResult>();
  408. //var buffer = obj as byte[];
  409. //if (buffer == null)
  410. //{
  411. // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  412. //}
  413. //var rspData = ProtoBufHelper.EntityDeSerialize<BankUnbindCardRsp>(buffer);
  414. //return new ResponeEntity<BankSignResult>()
  415. //{
  416. // RetCode = rspData.RetCode,
  417. // RetMessage = rspData.RetDesc,
  418. // Entity = new BankSignResult()
  419. // {
  420. // ReturnCode = rspData.RetCode,
  421. // ReturnDesc = rspData.RetDesc,
  422. // WebAddress =string.IsNullOrEmpty(rspData.NetAddr) ?"":Encoding.UTF8.GetString(Convert.FromBase64String(rspData.NetAddr)),
  423. // ExchTicket = rspData.ExchTicket,
  424. // Status = (BankDealStatus)rspData.Status,
  425. // },
  426. //};
  427. }
  428. public override ResponeEntity<BankUnBindResult> ToBankUnBindCardRsp(object obj)
  429. {
  430. return new ResponeEntity<BankUnBindResult>();
  431. // var buffer = obj as byte[];
  432. //if (buffer == null)
  433. //{
  434. // throw new Exception(System.Reflection.MethodBase.GetCurrentMethod().Name + "进行反序列化对象内容为空!");
  435. //}
  436. //var rspData = ProtoBufHelper.EntityDeSerialize<BankUnbindCardRsp>(buffer);
  437. //return new ResponeEntity<BankUnBindResult>()
  438. //{
  439. // RetCode = rspData.RetCode,
  440. // RetMessage = rspData.RetDesc,
  441. // Entity = new BankUnBindResult()
  442. // {
  443. // ReturnCode = rspData.RetCode,
  444. // ReturnDesc = rspData.RetDesc,
  445. // WebAddress = string.IsNullOrEmpty(rspData.NetAddr) ? "" : Encoding.UTF8.GetString(Convert.FromBase64String(rspData.NetAddr)),
  446. // ExchTicket = rspData.ExchTicket,
  447. // Status = (BankDealStatus)rspData.Status,
  448. // },
  449. //};
  450. }
  451. }
  452. }