frmActionPay.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace LYFZ.Software.MainBusiness.OAShopManagement
  10. {
  11. public partial class frmActionPay : LYFZ.Software.UI.OAShopManagement.frmActionPay
  12. {
  13. public string AppId { get; set; }
  14. public string MchId { get; set; }
  15. public string subMchId { get; set; }
  16. public string Key { get; set; }
  17. public string TypeData { get; set; }
  18. public string SerialNumber { get; set; }
  19. string OrderNumber { get; set; }
  20. public string signtype = "RSA";
  21. public frmActionPay()
  22. {
  23. InitializeComponent();
  24. }
  25. public void BindInfoData(string payType, decimal amount, string _AppId, string _MchId, string _Key, string _subMchId, string _orderNumber = "",string typeData="0")
  26. {
  27. OrderNumber = _orderNumber;
  28. AppId = _AppId;
  29. MchId = _MchId;
  30. Key = _Key;
  31. subMchId = _subMchId;
  32. TypeData = typeData;
  33. if(string.IsNullOrEmpty(_orderNumber))
  34. {
  35. OrderNumber = DateTime.Now.ToString("yyMMddHHmmssffff");
  36. }
  37. base.BindInfoData(payType, amount);
  38. }
  39. protected override void WeiXinPay(string txtCode, decimal amount)
  40. {
  41. txt_AuCode.Enabled = false;
  42. btn_Close.Enabled = false;
  43. btn_OK.Enabled = false;
  44. LYFZ.WxPayAPI.Result<LYFZ.WxPayAPI.WxPayData> resultData;
  45. if (LYFZ.BLL.BLL_SystemGlobalSetting.SysTemGlobalSetMoel.ThirdOnlinePay)
  46. {
  47. resultData = WxPayAPI.MicroPay.Run(OrderNumber, Convert.ToInt32((amount) * 100).ToString(), txtCode
  48. , AppId
  49. , MchId
  50. , Key
  51. , subMchId, LYFZ.BLL.BLL_SystemGlobalSetting.SysTemGlobalSetMoel.ThirdOnlinePay);
  52. }
  53. else
  54. {
  55. if (TypeData == "0")
  56. {
  57. resultData = WxPayAPI.MicroPay.Run(OrderNumber, Convert.ToInt32((amount) * 100).ToString(), txtCode
  58. , LYFZ.WinAPI.SDKSecurity.DESDecrypt(AppId, frmThridPayConfig.EncryptKey)
  59. , LYFZ.WinAPI.SDKSecurity.DESDecrypt(MchId, frmThridPayConfig.EncryptKey)
  60. , LYFZ.WinAPI.SDKSecurity.DESDecrypt(Key, frmThridPayConfig.EncryptKey)
  61. , subMchId, LYFZ.BLL.BLL_SystemGlobalSetting.SysTemGlobalSetMoel.ThirdOnlinePay);
  62. }
  63. else
  64. {
  65. if (string.IsNullOrEmpty(MchId))
  66. {
  67. MchId = subMchId;
  68. }
  69. subMchId = "";
  70. resultData = WxPayAPI.MicroPay.Run(OrderNumber, Convert.ToInt32((amount) * 100).ToString(), txtCode
  71. , AppId
  72. , MchId
  73. , Key
  74. , subMchId, true);
  75. }
  76. }
  77. string PayMessage = resultData.Message;
  78. if (resultData.Data!=null)
  79. {
  80. if (!resultData.Status)
  81. {
  82. try
  83. {
  84. PayMessage = resultData.Data.GetValue("err_code_des").ToString();
  85. }
  86. catch
  87. {
  88. PayMessage = resultData.Message;
  89. }
  90. }
  91. else
  92. {
  93. PayMessage = resultData.Data.ToXml();
  94. }
  95. }
  96. lab_payMsg.Text = PayMessage;
  97. base.WeiXinPay(txtCode, amount);
  98. if(resultData.Status)
  99. {
  100. SerialNumber = resultData.Data.GetValue("transaction_id").ToString();
  101. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  102. this.Close();
  103. }
  104. else
  105. {
  106. txt_AuCode.Text = "";
  107. txt_AuCode.Focus();
  108. txt_AuCode.Enabled = true;
  109. btn_Close.Enabled = true;
  110. btn_OK.Enabled = true;
  111. //this.DialogResult = System.Windows.Forms.DialogResult.No;
  112. }
  113. }
  114. protected override void AliyPay(string txtCode, decimal amount)
  115. {
  116. txt_AuCode.Enabled = false;
  117. btn_Close.Enabled = false;
  118. btn_OK.Enabled = false;
  119. LYFZ.AliF2F.Model.OrderInfo orderInfo = new AliF2F.Model.OrderInfo()
  120. {
  121. TotalSellValue = amount,
  122. PayAuthCode = txtCode,
  123. BodyInfo="付款测试",
  124. SerialNumber = OrderNumber+"_"+DateTime.Now.ToString("HHmmssffff"),
  125. Operator_id="",
  126. SellerAccount="",
  127. StoreName=""
  128. };
  129. LYFZ.AliF2F.Config.appId = this.AppId;
  130. LYFZ.AliF2F.Config.pid = this.MchId;
  131. LYFZ.AliF2F.Config.sign_type = signtype;
  132. if (LYFZ.BLL.BLL_SystemGlobalSetting.SysTemGlobalSetMoel.ThirdOnlinePay)
  133. {
  134. }
  135. else
  136. {
  137. if (TypeData == "0")
  138. {
  139. LYFZ.AliF2F.Config.servicePid = LYFZ.WinAPI.SDKSecurity.DESDecrypt(this.subMchId, frmThridPayConfig.EncryptKey);
  140. }
  141. }
  142. LYFZ.AliF2F.BarcodePayControl payControl = new LYFZ.AliF2F.BarcodePayControl();
  143. LYFZ.AliF2F.Result<LYFZ.AliF2F.Business.AlipayF2FPayResult> AliResult = payControl.AlipayDsPosOrder(orderInfo);
  144. string PayMessage = AliResult.Message;
  145. //string PayMessage = Json.JsonTool.ObjectToJson(AliResult.Data.response);
  146. if (AliResult.Data != null)
  147. {
  148. if (!AliResult.Status)
  149. {
  150. PayMessage = AliResult.Data.response.SubMsg;
  151. }
  152. else
  153. {
  154. PayMessage = LYFZ.PhotoSelectSystem.JsonTools.ObjectToJson(AliResult.Data.response);
  155. }
  156. }
  157. lab_payMsg.Text = PayMessage;
  158. if (AliResult.Status)
  159. {
  160. SerialNumber = AliResult.Data.response.TradeNo;
  161. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  162. this.Close();
  163. }
  164. else
  165. {
  166. txt_AuCode.Text = "";
  167. txt_AuCode.Focus();
  168. txt_AuCode.Enabled = true;
  169. btn_Close.Enabled = true;
  170. btn_OK.Enabled = true;
  171. //this.DialogResult = System.Windows.Forms.DialogResult.No;
  172. }
  173. base.AliyPay(txtCode, amount);
  174. }
  175. }
  176. }