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();
}
}
///
///
///
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 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 = "";
}
}
///
/// 绑定微信配置信息
///
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);
}
}
}
///
/// 绑定支付宝配置信息
///
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;
}
}
}
}
///
/// 取消操作
///
///
///
public override void btn_AliCancel_Click(object sender, EventArgs e)
{
this.Close();
base.btn_AliCancel_Click(sender, e);
}
///
///确定操作
///
///
///
public override void btn_AliOK_Click(object sender, EventArgs e)
{
SaveWXAndZFBData();
MessageBoxCustom.Show("保存成功,付款方式自动创建微信刷卡支付和支付宝条码支付");
}
///
/// 保存微信支付宝子商户信息
///
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);
//}
}
///
/// 测试支付宝条码支付
///
///
///
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);
}
///
/// 测试微信刷卡支付
///
///
///
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);
}
///
/// 更新网络上的支付宝微信的商家账号数据
///
///
///
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;
}
}
}