123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604 |
- using LYFZ.BLL;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace LYFZ.Software.MainBusiness.OAShopManagement
- {
- public partial class frmThridPayConfig : LYFZ.Software.UI.OAShopManagement.frmThridPayConfig
- {
- LYFZ.BLL.BLL_ErpSystemConfigure config = new BLL.BLL_ErpSystemConfigure();
- BLL.BLL_ErpSystemCategory categoryBll = new BLL.BLL_ErpSystemCategory();
- LYFZ.Model.Model_ErpSystemConfigure wxModConfig;
- LYFZ.Model.Model_ErpSystemConfigure alModConfig;
- string wxMchid = "";
- string aliMchid = "";
- public static string EncryptKey = "Ivz0IC3k";
- public frmThridPayConfig()
- {
- InitializeComponent();
- this.Shown += frmThridPayConfig_Shown;
- BindWXData();
- BindAliData();
- CheckPay();
- if(LYFZ.BLL.BLL_SystemGlobalSetting.SysTemGlobalSetMoel.ThirdOnlinePay)
- {
- rdo_WXAgentBtn.Visible = false;
- rdo_WXAutonomyBtn.Visible = false;
- rdo_ZFBAgentBtn.Visible = false;
- rdo_ZFBAutonomyBtn.Visible = false;
- }
- }
- void frmThridPayConfig_Shown(object sender, EventArgs e)
- {
- bool b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.UIFunctionVersion(
- VersionControl.VersionFunctionEnum.App和微信公众号扫码支付);
- if (!b)
- {
- this.Close();
- }
- }
- /// <summary>
- ///
- /// </summary>
- void CheckPay()
- {
- if(LYFZ.BLL.BLL_SystemGlobalSetting.SysTemGlobalSetMoel.ThirdOnlinePay)
- {
- cb_MySaltCompanyPay.Visible = true;
- txt_MchId.Visible = false;
- txt_AliAppid.Enabled = false;
- txt_AliMchId.Enabled = false;
- txt_AliKey.Enabled = false;
- txt_AliPublicKey.Enabled = false;
- string PayData = "";
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
- {
- PayData = LYFZ.WinAPI.HttpClientHelper.GetResponse("http://webapi.lyfz.net/mapi.aspx?cname=CompanyPay");
- //Newtonsoft.Json.Linq.JArray payList = new Newtonsoft.Json.Linq.JArray(PayData);
- object tempJObj = Newtonsoft.Json.JsonConvert.DeserializeObject(PayData);
- Newtonsoft.Json.Linq.JArray payList = (Newtonsoft.Json.Linq.JArray)tempJObj;
- for(int i=0;i<payList.Count;i++)
- {
- string type =((Newtonsoft.Json.Linq.JObject) payList[i]).GetValue("Type").ToString();
- string name=((Newtonsoft.Json.Linq.JObject) payList[i]).GetValue("Name").ToString();
- string MchId = ((Newtonsoft.Json.Linq.JObject)payList[i]).GetValue("MchId").ToString();
- if(type.Equals("WeiXin"))
- {
- PayItemData payItemData = new PayItemData()
- {
- Type = type,
- Name = name,
- jObject = ((Newtonsoft.Json.Linq.JObject)payList[i])
- };
- cb_MySaltCompanyPay.Items.Add(payItemData);
- wxMchid = "";
- if (txt_MchId.Text == MchId)
- {
- cb_MySaltCompanyPay.SelectedIndex = cb_MySaltCompanyPay.Items.Count - 1;
- }
- }
- else
- {
- PayItemData payItemData = new PayItemData()
- {
- Type = type,
- Name = name,
- jObject = ((Newtonsoft.Json.Linq.JObject)payList[i])
- };
- cb_AliPayAccount.Items.Add(payItemData);
- aliMchid = "";
- if (txt_AliMchId.Text == MchId)
- {
- cb_AliPayAccount.SelectedIndex = cb_AliPayAccount.Items.Count - 1;
- }
- }
- }
- });
- if (cb_MySaltCompanyPay.Items.Count > 0 && cb_MySaltCompanyPay.SelectedIndex==-1)
- {
- //cb_MySaltCompanyPay.SelectedIndex = 0;
- txt_AppId.Text = "";
- txt_Key.Text = "";
- txt_MchId.Text = "";
- }
- if (cb_AliPayAccount.Items.Count > 0 && cb_AliPayAccount.SelectedIndex == -1)
- {
- //cb_AliPayAccount.SelectedIndex = 0;
- txt_AliAppid.Text = "";
- txt_AliMchId.Text = "";
- txt_AliKey.Text = "";
- txt_AliPublicKey.Text = "";
- }
- cb_AliPayAccount.SelectedIndexChanged += cb_AliPayAccount_SelectedIndexChanged;
- cb_MySaltCompanyPay.SelectedIndexChanged += cb_MySaltCompanyPay_SelectedIndexChanged;
- }
- else
- {
- cb_MySaltCompanyPay.Visible = false;
- txt_MchId.Visible = true;
- txt_AliAppid.Enabled = true;
- txt_AliMchId.Enabled = true;
- txt_AliKey.Enabled = true;
- txt_AliPublicKey.Enabled = true;
- }
- }
- void cb_MySaltCompanyPay_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (((PayItemData)cb_MySaltCompanyPay.SelectedItem) != null)
- {
- txt_AppId.Text = ((PayItemData)cb_MySaltCompanyPay.SelectedItem).jObject.GetValue("AppId").ToString();
- txt_Key.Text = ((PayItemData)cb_MySaltCompanyPay.SelectedItem).jObject.GetValue("Key").ToString();
- txt_MchId.Text = ((PayItemData)cb_MySaltCompanyPay.SelectedItem).jObject.GetValue("MchId").ToString();
- }
- else
- {
- txt_AppId.Text = "";
- txt_Key.Text = "";
- txt_MchId.Text = "";
- }
- }
- void cb_AliPayAccount_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (((PayItemData)cb_AliPayAccount.SelectedItem)!=null)
- {
- txt_AliAppid.Text = ((PayItemData)cb_AliPayAccount.SelectedItem).jObject.GetValue("AppId").ToString();
- txt_AliMchId.Text = ((PayItemData)cb_AliPayAccount.SelectedItem).jObject.GetValue("MchId").ToString();
- txt_AliPublicKey.Text = ((PayItemData)cb_AliPayAccount.SelectedItem).jObject.GetValue("PublicKey").ToString();
- txt_AliKey.Text = ((PayItemData)cb_AliPayAccount.SelectedItem).jObject.GetValue("PrivateKey").ToString();
- }
- else
- {
- txt_AliAppid.Text = "";
- txt_AliMchId.Text = "";
- txt_AliPublicKey.Text = "";
- txt_AliKey.Text = "";
- }
- }
- /// <summary>
- /// 绑定微信配置信息
- /// </summary>
- void BindWXData()
- {
- DataSet ds = config.GetSystemConfigure("*", "WeiXinPayConfig");
- if (ds.Tables[0].Rows.Count == 0)
- {
- WXConfigData wxData = new WXConfigData()
- {
- AppId = LYFZ.WinAPI.SDKSecurity.DESEncrypt("wxe30d2c612847beeb", frmThridPayConfig.EncryptKey),
- MCHID = LYFZ.WinAPI.SDKSecurity.DESEncrypt("1454966002", frmThridPayConfig.EncryptKey),
- Key = LYFZ.WinAPI.SDKSecurity.DESEncrypt("VIst5wdcsILt3kgMImwa21z9XPIvz0IC", frmThridPayConfig.EncryptKey),
- SubMchId = "",
- Open = false
- };
- wxModConfig = new Model.Model_ErpSystemConfigure()
- {
- Sconfig_Code = "WeiXinPayConfig",
- Sconfig_Name = "微信支付账户",
- Sconfig_Value = Json.JsonTool.ObjectToJson(wxData)
- };
- config.Add(wxModConfig);
- txt_AppId.Text = wxData.AppId.Trim();
- txt_Key.Text = wxData.Key.Trim();
- txt_MchId.Text = wxData.SubMchId;
- wxMchid = wxData.MCHID.Trim();
- cb_Open.Checked = wxData.Open;
- }
- else
- {
- wxModConfig = config.DataRowToModel(ds.Tables[0].Rows[0]);
- WXConfigData data = new WXConfigData();
- data = (WXConfigData)Json.JsonTool.JsonToObject(wxModConfig.Sconfig_Value, data);
- txt_AppId.Text = data.AppId.Trim();
- txt_Key.Text = data.Key.Trim();
- txt_MchId.Text = data.SubMchId;
- wxMchid = data.MCHID.Trim();
- cb_Open.Checked = data.Open;
- if (!LYFZ.BLL.BLL_SystemGlobalSetting.SysTemGlobalSetMoel.ThirdOnlinePay)
- {
- if(data.TypeData==0)
- {
- rdo_WXAgentBtn.Checked=true;
-
- }
- else
- {
- rdo_WXAutonomyBtn.Checked = true;
- }
- rdo_WXAgentBtn_Click(null, null);
- }
- }
-
- }
- /// <summary>
- /// 绑定支付宝配置信息
- /// </summary>
- void BindAliData()
- {
- DataSet ds = config.GetSystemConfigure("*", "AliPayConfig");
- if (ds.Tables[0].Rows.Count == 0)
- {
- AliConfigData aliData = new AliConfigData()
- {
- AppId = "",
- Key = "",
- MCHID = "",
- publicKey = "",
- SubMchId = LYFZ.WinAPI.SDKSecurity.DESEncrypt("2088621649564405", frmThridPayConfig.EncryptKey),
- Open = false,
- SignType =rdo_RSA.Checked?"RSA":"RSA2"
- };
- alModConfig = new Model.Model_ErpSystemConfigure()
- {
- Sconfig_Code = "AliPayConfig",
- Sconfig_Name = "支付宝账户",
- Sconfig_Value = Json.JsonTool.ObjectToJson(aliData)
- };
- config.Add(alModConfig);
- cb_AliOpen.Checked = aliData.Open;
- txt_AliAppid.Text = aliData.AppId.Trim();
- txt_AliMchId.Text = aliData.MCHID.Trim();
- aliMchid = aliData.SubMchId;
- txt_AliKey.Text = aliData.Key;
- txt_AliPublicKey.Text = aliData.publicKey;
- }
- else
- {
- alModConfig = config.DataRowToModel(ds.Tables[0].Rows[0]);
- AliConfigData data = new AliConfigData();
- data = (AliConfigData)Json.JsonTool.JsonToObject(alModConfig.Sconfig_Value, data);
- cb_AliOpen.Checked = data.Open;
- txt_AliAppid.Text = data.AppId.Trim();
- txt_AliMchId.Text = data.MCHID.Trim();
- aliMchid = data.SubMchId;
- if(string.IsNullOrEmpty(aliMchid))
- {
- aliMchid = LYFZ.WinAPI.SDKSecurity.DESEncrypt("2088621649564405", frmThridPayConfig.EncryptKey);
- }
- txt_AliKey.Text = data.Key;
- txt_AliPublicKey.Text = data.publicKey;
- if(string.IsNullOrEmpty(data.SignType)|| data.SignType.Equals("RSA"))
- {
- rdo_RSA.Checked = true;
- }
- else if(data.SignType.Equals("RSA2"))
- {
- rdo_RSA2.Checked = true;
- }
- if (!LYFZ.BLL.BLL_SystemGlobalSetting.SysTemGlobalSetMoel.ThirdOnlinePay)
- {
- if (data.TypeData == 0)
- {
- rdo_ZFBAgentBtn.Checked = true;
- }
- else
- {
- rdo_ZFBAutonomyBtn.Checked = true;
- }
- }
- }
- }
- /// <summary>
- /// 取消操作
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public override void btn_AliCancel_Click(object sender, EventArgs e)
- {
- this.Close();
- base.btn_AliCancel_Click(sender, e);
- }
- /// <summary>
- ///确定操作
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public override void btn_AliOK_Click(object sender, EventArgs e)
- {
- SaveWXAndZFBData();
- MessageBoxCustom.Show("保存成功,付款方式自动创建微信刷卡支付和支付宝条码支付");
- }
- /// <summary>
- /// 保存微信支付宝子商户信息
- /// </summary>
- void SaveWXAndZFBData()
- {
- WXConfigData data = new WXConfigData()
- {
- AppId = txt_AppId.Text.Trim(),
- Key = txt_Key.Text.Trim(),
- MCHID = wxMchid.Trim(),
- SubMchId = txt_MchId.Text.Trim(),
- Open = cb_Open.Checked
- };
- if(rdo_WXAgentBtn.Checked)
- {
- data.TypeData = 0;
- }
- else if (rdo_WXAutonomyBtn.Checked)
- {
- data.TypeData = 1;
- data.MCHID = txt_MchId.Text.Trim();
- }
- string strJson = Json.JsonTool.ObjectToJson(data);
- wxModConfig.Sconfig_Value = strJson;
- config.Update((object)wxModConfig, " Sconfig_Code='WeiXinPayConfig' ", "ID");
- AliConfigData alData = new AliConfigData()
- {
- AppId = txt_AliAppid.Text.Trim(),
- MCHID = txt_AliMchId.Text.Trim(),
- Key = txt_AliKey.Text,
- publicKey = txt_AliPublicKey.Text,
- Open = cb_AliOpen.Checked,
- SubMchId = aliMchid == null ? "" : aliMchid.Trim(),
- SignType = rdo_RSA.Checked ? "RSA" : rdo_RSA2.Checked ? "RSA2" : ""
- };
- if (rdo_ZFBAgentBtn.Checked)
- {
- data.TypeData = 0;
- }
- else if (rdo_ZFBAutonomyBtn.Checked)
- {
- data.TypeData = 1;
- }
- strJson = Json.JsonTool.ObjectToJson(alData);
- alModConfig.Sconfig_Value = strJson;
- config.Update((object)alModConfig, " Sconfig_Code='AliPayConfig' ", "ID");
- LYFZ.Software.MainBusiness.MultipleFileImport.FileUtil.WriteFileByASCII(Application.StartupPath + "\\RSA\\alipay_rsa_public_key.pem", txt_AliPublicKey.Text);
- LYFZ.Software.MainBusiness.MultipleFileImport.FileUtil.WriteFileByASCII(Application.StartupPath + "\\RSA\\rsa_public_key.pem", txt_AliPublicKey.Text);
- LYFZ.Software.MainBusiness.MultipleFileImport.FileUtil.WriteFileByASCII(Application.StartupPath + "\\RSA\\rsa_private_key.pem", txt_AliKey.Text);
- //base.btn_AliOK_Click(sender, e);
- DataSet ds = categoryBll.GetList("Sc_ClassCode='WXSKZF' or Sc_ClassCode='ZFBTMZF' ");
- bool bWx = false;
- bool bZfb = false;
- for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
- {
- if (ds.Tables[0].Rows[i]["Sc_ClassCode"].ToString() == "WXSKZF")
- {
- bWx = true;
- }
- if (ds.Tables[0].Rows[i]["Sc_ClassCode"].ToString() == "ZFBTMZF")
- {
- bZfb = true;
- }
- }
- if (!bWx)
- {
- LYFZ.Model.Model_ErpSystemCategory category = new Model.Model_ErpSystemCategory()
- {
- Sc_ClassCode = "WXSKZF",
- Sc_ClassName = "微信刷卡支付",
- Sc_ClassParentID = 81,
- Sc_IsDisable = false,
- Sc_ClassRemark = "接口自动生成",
- Sc_IsReadOnly = true,
- Sc_URL = "",
- Sc_IsDelete = false,
- Sc_CreateDatetime = DateTime.Now,
- Sc_CreateName = "",
- Sc_IsEnabledURL = false,
- Sc_UpdateDatetime = DateTime.Now
- };
- categoryBll.Add(category);
- }
- if (!bZfb)
- {
- LYFZ.Model.Model_ErpSystemCategory category = new Model.Model_ErpSystemCategory()
- {
- Sc_ClassCode = "ZFBTMZF",
- Sc_ClassName = "支付宝条码支付",
- Sc_ClassParentID = 81,
- Sc_IsDisable = false,
- Sc_ClassRemark = "接口自动生成",
- Sc_IsReadOnly = true,
- Sc_URL = "",
- Sc_IsDelete = false,
- Sc_CreateDatetime = DateTime.Now,
- Sc_CreateName = "",
- Sc_IsEnabledURL = false,
- Sc_UpdateDatetime = DateTime.Now
- };
- categoryBll.Add(category);
- }
- string wxid = "";
- string zfbid = "";
- ds = categoryBll.GetList("Sc_ClassCode='WXSKZF' or Sc_ClassCode='ZFBTMZF' ");
- for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
- {
- if (ds.Tables[0].Rows[i]["Sc_ClassCode"].ToString() == "WXSKZF")
- {
- wxid = ds.Tables[0].Rows[i]["ID"].ToString();
- }
- if (ds.Tables[0].Rows[i]["Sc_ClassCode"].ToString() == "ZFBTMZF")
- {
- zfbid = ds.Tables[0].Rows[i]["ID"].ToString();
- }
- }
- //string strIDs = "";
- //if (!cb_Open.Checked)
- //{
- // strIDs = wxid;
- //}
- //if (!cb_AliOpen.Checked)
- //{
- // if (!string.IsNullOrEmpty(strIDs))
- // {
- // strIDs += ",";
- // }
- // strIDs += zfbid;
- //}
- //if (!string.IsNullOrEmpty(strIDs))
- //{
- // categoryBll.DeleteList(strIDs);
- //}
- }
- /// <summary>
- /// 测试支付宝条码支付
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public override void btn_AliCheck_Click(object sender, EventArgs e)
- {
- LYFZ.Software.MainBusiness.MultipleFileImport.FileUtil.WriteFileByASCII(Application.StartupPath + "\\RSA\\alipay_rsa_public_key.pem", txt_AliPublicKey.Text);
- LYFZ.Software.MainBusiness.MultipleFileImport.FileUtil.WriteFileByASCII(Application.StartupPath + "\\RSA\\rsa_public_key.pem", txt_AliPublicKey.Text);
- LYFZ.Software.MainBusiness.MultipleFileImport.FileUtil.WriteFileByASCII(Application.StartupPath + "\\RSA\\rsa_private_key.pem", txt_AliKey.Text);
- frmActionPay frmPay = new frmActionPay();
- frmPay.signtype = rdo_RSA.Checked ? "RSA" : rdo_RSA2.Checked ? "RSA2" : "";
- frmPay.BindInfoData("支付宝条码支付", 0.01m, txt_AliAppid.Text.Trim(), txt_AliMchId.Text.Trim(), "", aliMchid, "", rdo_ZFBAgentBtn.Checked?"0":"1");
- frmPay.ShowDialog();
- base.btn_AliCheck_Click(sender, e);
- }
- /// <summary>
- /// 测试微信刷卡支付
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public override void btn_Check_Click(object sender, EventArgs e)
- {
- frmActionPay frmPay = new frmActionPay();
- if(LYFZ.BLL.BLL_SystemGlobalSetting.SysTemGlobalSetMoel.ThirdOnlinePay)
- {
- frmPay.BindInfoData("微信刷卡支付", 0.01m, txt_AppId.Text.Trim(), txt_MchId.Text.Trim(), txt_Key.Text.Trim(), "");
- }
- else{
- if(rdo_WXAgentBtn.Checked)
- {
- frmPay.BindInfoData("微信刷卡支付", 0.01m, txt_AppId.Text.Trim(), wxMchid, txt_Key.Text.Trim(), txt_MchId.Text.Trim(), "");
- }
- else
- {
- frmPay.BindInfoData("微信刷卡支付", 0.01m, txt_AppId.Text.Trim(), txt_MchId.Text.Trim(), txt_Key.Text.Trim(), "", "","1");
- }
-
- }
-
- frmPay.ShowDialog();
- base.btn_Check_Click(sender, e);
- }
- /// <summary>
- /// 更新网络上的支付宝微信的商家账号数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public override void btn_Update_Click(object sender, EventArgs e)
- {
- if (!LYFZ.BLL.BLL_SystemGlobalSetting.SysTemGlobalSetMoel.ThirdOnlinePay)
- {
- //base.btn_Update_Click(sender, e);
- string wxData = "";
- string zfbData = "";
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
- {
- wxData = LYFZ.WinAPI.HttpClientHelper.GetResponse("http://wx.lyfz.net/PaymentService/PaymentService.aspx?type=wx");
- zfbData = LYFZ.WinAPI.HttpClientHelper.GetResponse("http://wx.lyfz.net/PaymentService/PaymentService.aspx?type=zfb");
- });
- dynamic wxjsonDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject(wxData);
- dynamic zfbjsonDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject(zfbData);
- bool bwx = false;
- if (wxjsonDataObj["msg"] == "成功")
- {
- if (rdo_WXAgentBtn.Checked)
- {
- bwx = true;
- txt_AppId.Text = wxjsonDataObj["data"]["appid"];
- txt_Key.Text = wxjsonDataObj["data"]["key"];
- wxMchid = wxjsonDataObj["data"]["businessNumber"];
- }
- }
- bool bzfb = false;
- if (zfbjsonDataObj["msg"] == "成功")
- {
- if (rdo_ZFBAgentBtn.Checked)
- {
- bzfb = true;
- aliMchid = zfbjsonDataObj["data"]["CompanyPid"];
- }
- }
- if (bwx && bzfb)
- {
- MessageBoxCustom.Show("更新成功!!", "提示");
- }
- else if (!bwx && !bzfb)
- {
- MessageBoxCustom.Show("微信和支付宝更新失败", "提示");
- }
- else if (!bwx)
- {
- MessageBoxCustom.Show("微信更新失败", "提示");
- }
- else if (!bzfb)
- {
- MessageBoxCustom.Show("支付宝更新失败", "提示");
- }
- //btn_AliOK_Click(null, null);
- SaveWXAndZFBData();
- BindWXData();
- BindAliData();
- }
- }
- }
- public class PayItemData
- {
- public string Name { get; set; }
- public string Type { get; set; }
- public Newtonsoft.Json.Linq.JObject jObject { get; set; }
- public override string ToString()
- {
- return Name;
- }
- }
- }
|