123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 |
- 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 frmMicroLetterPlatformInterface : LYFZ.Software.UI.OAShopManagement.frmMicroLetterPlatformInterface
- {
- BLL.BLL_ErpMicroInterface bllInterface = new BLL.BLL_ErpMicroInterface();
- string _PrimitiveID = "";
- /// <summary>
- /// 门店ID 每个门店只能添加一个公众号
- /// </summary>
- public string PrimitiveID
- {
- get { return _PrimitiveID; }
- set { _PrimitiveID = value; }
- }
- public string MenuData = "";
- public frmMicroLetterPlatformInterface()
- {
- this.btnAuthorizationAndBind.Click += btnAuthorizationAndBind_Click;
- this.btnClose.Click += btnClose_Click;
- this.Load += frmMicroLetterPlatformInterface_Load;
- this.btnDetected.Click += btnDetected_Click;
- this.btnCustommenuManager.Click += btnCustommenuManager_Click;
-
- this.btnAutoReply.Click += btnAutoReply_Click;
- }
- LYFZ.BLL.BLL_ErpSystemConfigure config = new BLL.BLL_ErpSystemConfigure();
- LYFZ.Model.ModelAPPInterface AppModel = new Model.ModelAPPInterface();
-
- void btnAuthorizationAndBind_Click(object sender, EventArgs e)
- {
- try
- {
- string myDomainName = AppModel.AppEnId+modFace.AppID;
- System.Diagnostics.Process.Start(BLL.BLL_MicroInterface.GetAuthorizationAndBindUrl(modFace.AppID, myDomainName));
- }
- catch { }
- }
-
- void btnAutoReply_Click(object sender, EventArgs e)
- {
- frmMicroLetterAutoReply frmAutorly = new frmMicroLetterAutoReply();
- frmAutorly.Show();
- }
- void btnCustommenuManager_Click(object sender, EventArgs e)
- {
- frmCustommenuManager frmcmanager = new frmCustommenuManager();
- frmcmanager.ID = modFace.ID;
- frmcmanager.ShowDialog();
- MenuData = frmcmanager.MenuData;
- }
- List<LYFZ.Model.Model_ErpCompanyInfo> compayList = new List<Model.Model_ErpCompanyInfo>();
- public List<LYFZ.Model.Model_ErpCompanyInfo> CompayList
- {
- get { return compayList; }
- set { compayList = value; }
- }
- private delegate void UpdateControl();
- /// <summary>
- /// 保存接口信息
- /// </summary>
- void Save_MicroInterface()
- {
- try
- {
- /* modelMIF.MicroName = this.txtPublicNumberName.Text.Trim();
- modelMIF.MicroNumber = this.txtMicroSignal.Text.Trim();
- modelMIF.PrimitiveID = "";// this.txtPrimitiveID.Text.Trim();
- modelMIF.APPEnterpriseID = this.txtAPPEnterpriseID.Text.Trim();
- modelMIF.AppID = this.txtAppID.Text.Trim();
- modelMIF.AppSecret = "";//this.txtAppSecret.Text.Trim();
- modelMIF.Token = this.txtToken.Text.Trim();
- modelMIF.EncodingAESKey = "";//this.txtEncodingAESKey.Text.Trim();
- //modelMIF.InterfaceUrl = LYFZ.BLL.BLL_MicroInterface.GetMicroServerAddressUrl(LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.SoftwareInfo.SDomainName).Trim();
- //if (LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.SoftwareInfo.IsBranchStore)
- //{
- // modelMIF.InterfaceUrl = LYFZ.BLL.BLL_MicroInterface.GetMicroServerAddressUrl(LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.SoftwareInfo.MainStoreDomainName).Trim(); ;
- //}
- // modelMIF.VisitDomainName = this.txtVisitDomainName.Text.Trim().ToLower().Replace("http://", "");
- modelMIF.IsThirdPartyPlatformURL = false;//this.cbxIsThirdPartyPlatformURL.Checked;
- modelMIF.ThirdPartyPlatformURL = "";//this.txtThirdPartyPlatformURL.Text.Trim();*/
- /* if (this.cbxIsThirdPartyPlatformURL.Checked)
- {
- if (modelMIF.ThirdPartyPlatformURL.Trim().Length <= 0 || !modelMIF.ThirdPartyPlatformURL.Trim().ToLower().Contains("http://"))
- {
- MessageBoxCustom.Show("请输入正确的第三方平台接口URL地址!"); return;
- }
- }*/
-
- string cCompanyID = "";
- if (this.comboBoxMdian.SelectedItem == null)
- {
- MessageBoxCustom.Show("请选择所属门店");
- return;
- }
- LYFZ.Model.Model_ErpCompanyInfo selectCom = (LYFZ.Model.Model_ErpCompanyInfo)((ItemValue)this.comboBoxMdian.SelectedItem).Value;
- cCompanyID = selectCom.Company_DividedShop;
-
- modFace.AppID = this.txtAppID.Text.Trim();
- modFace.MicroName = this.txtPublicNumberName.Text.Trim();
- modFace.MicroNumber = this.txtMicroSignal.Text.Trim();
- modFace.PrimitiveID = cCompanyID;
- if (String.IsNullOrEmpty(AppModel.AppUrlPath.Trim()) || String.IsNullOrEmpty(AppModel.AppEnId.Trim()))
- {
- MessageBoxCustom.Show("APP接口还未注册授权");
- return;
- }
- if (modFace.AppID.Trim().Length < 1)
- {
- MessageBoxCustom.Show("请输入公众号的 APPID 可在公众号后查看");
- }
- else if (AppModel.AppUrlPath.IndexOf('.') <= 0 && AppModel.AppUrlPath.Length > 0)
- {
- MessageBoxCustom.Show("APP接口地址名格式不正确");
- }
- else
- {
- bool modFaceOK = false;
- if (modFace.ID > 0)
- {
- modFaceOK = bllInterface.Update(modFace);
- }
- else {
- if (bllInterface.Exists("PrimitiveID", cCompanyID))
- {
- MessageBoxCustom.Show("选择门店“" + selectCom.Company_Name + "”已经添加了公众号,每个门店只为绑定一个公众号");
- return;
- }
- modFaceOK = bllInterface.Add(modFace);
- }
- if (modFaceOK)
- {
- // MessageBoxCustom.Show("保存成功");
- modFace = (LYFZ.Model.Model_ErpMicroInterface)bllInterface.GetModelObject("PrimitiveID", cCompanyID);
-
- Detecting();
- }
- else
- {
- MessageBoxCustom.Show("保存失败请重试");
- }
- }
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show("保存出错:" + ex.Message);
- }
- }
- /// <summary>
- /// 是否正在检测
- /// </summary>
- static bool isDetecting = false;
- void btnDetected_Click(object sender, EventArgs e)
- {
- Save_MicroInterface();
-
- }
- void showDetectedInfo(string info, Color color)
- {
- try
- {
- if (this.InvokeRequired)
- {
- this.Invoke(new UpdateControl(delegate()
- {
- this.labDetectedInfo.ForeColor = color;
- this.labDetectedInfo.Text = info;
- }));
- }
- else {
- this.labDetectedInfo.ForeColor = color;
- this.labDetectedInfo.Text = info;
- }
- }
- catch { }
- isDetecting = false;
- }
- LYFZ.BLL.BLL_ErpCompanyInfo comInfoDal = new BLL.BLL_ErpCompanyInfo();
- /// <summary>
- /// 检测接口状态
- /// </summary>
- void Detecting()
- {
- if (!isDetecting)
- {
- this.btnAuthorizationAndBind.Enabled = false;
-
- System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
- {
- showDetectedInfo("保存成功,正在检测请稍等...", Color.DarkOrange);
- isDetecting = true;
-
- string url = LYFZ.BLL.BLL_MicroInterface.GetPostInfoUrl();
- LYFZ.Model.Model_ErpCompanyInfo compModel = comInfoDal.GetModel("Company_DividedShop",modFace.PrimitiveID);
- if (compModel.ID <= 0)
- {
- showDetectedInfo("获取本店信息失败...", Color.Red);
- return;
- }
- // int PortNumber = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.SoftwareInfo.WebServerPort;
- string CompanyName = "未知客户";
- if (compModel.ID > 0)
- {
- //店名
- CompanyName = compModel.Company_Name + "_" + compModel.Company_Manager + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.SoftwareInfo.GetSoftwareVersionDescription();
- }
- string JMGDomainName =AppModel.AppEnId+modFace.AppID;
- string ShellDomainName = AppModel.AppUrlPath.Trim();
-
-
- string AppID = modFace.AppID.Trim();
- string MicroNumber = modFace.MicroNumber;
- string postData = LYFZ.BLL.BLL_MicroInterface.GetPostServerAddressData(JMGDomainName, ShellDomainName, System.Web.HttpUtility.UrlEncode(CompanyName), AppModel.AppEnId, AppID, MicroNumber, System.Web.HttpUtility.UrlEncode(modFace.MicroName));
- string retMsg = LYFZ.WinAPI.CustomPublicMethod.HttpWebRequestPOST(url, postData);
-
- if (!retMsg.Trim().ToLower().Contains("Success".ToLower()))
- {
- showDetectedInfo("连接微信服务器平台失败,请检查网络是否正常后重试...", Color.Red);
- LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(EnumPublic.SystemLogsType.系统日志,
- retMsg+" 提交数据:"+ postData,
- "system",
- "system");
- // LYFZ.BLL.BLL_FileLogs.WriteMainLogs("连接微信服务器平台失败:" + retMsg);
- // LYFZ.BLL.BLL_FileLogs.WriteMainLogs("向微信服务器平台提交的数据:" + postData);
- return;
- }
- string getTestMsg = LYFZ.WinAPI.CustomPublicMethod.HttpWebRequestGET(AppModel.AppUrlPath + "/Default.aspx",Encoding.UTF8);
- if (!getTestMsg.ToLower().Contains("WEBAPI".ToLower()))
- {
- showDetectedInfo("检测到APP接口服务器没有正常工作...", Color.Red);
- return;
- }
- showDetectedInfo("手机APP和微信接口服务已正常工作...", Color.Green);
- this.Invoke(new UpdateControl(delegate()
- {
- this.btnAuthorizationAndBind.Enabled = true;
- }));
- }));
- t.Start();
- }
- else
- {
- MessageBoxCustom.Show("正在检测,请耐心等待!");
- }
- }
- LYFZ.BLL.BLL_MicroInterface bllMIF = new BLL.BLL_MicroInterface();
- LYFZ.Model.Model_ErpMicroInterface modFace=new Model.Model_ErpMicroInterface();
- void frmMicroLetterPlatformInterface_Load(object sender, EventArgs e)
- {
- // LYFZ.WindowsServiceHandling.MessageService.WeixinConfigRegister();
- // mConfig = new LYFZ.BLL.BLL_Config().GetModel_SysConfig();
- /* string WebMobileUrl =LYFZ.BLL.BLL_MicroInterface.GetWebAPPGoToUrl(LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.SoftwareInfo.SDomainName.ToString());
- if (LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.SoftwareInfo.IsBranchStore)
- {
- WebMobileUrl = LYFZ.BLL.BLL_MicroInterface.GetWebAPPGoToUrl(LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.SoftwareInfo.MainStoreDomainName.ToString());
- }
- this.picQrCodeImage.Image = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.CreateCode_Choose(WebMobileUrl, "Byte", "M", 8, 4);*/
- if (!String.IsNullOrEmpty(PrimitiveID))
- {
- modFace = bllInterface.GetModelMicroInterface(PrimitiveID);
- //(LYFZ.Model.Model_ErpMicroInterface)bllInterface.GetModelObject("PrimitiveID", PrimitiveID);
- MenuData = modFace.MenuData;
- this.txtPublicNumberName.Text = modFace.MicroName.Trim();
- this.txtMicroSignal.Text = modFace.MicroNumber.Trim();
- this.txtAppID.Text = modFace.AppID.Trim();
- }
- BindMenDianList();
-
- AppModel = config.GetModelAPPInterface();
- showDetectedInfo("请点击“检测APP和微信接口”按钮检测接口服务是否正常", Color.DarkOrange);
- }
- void BindMenDianList()
- {
- this.comboBoxMdian.Items.Clear();
- foreach (LYFZ.Model.Model_ErpCompanyInfo com in compayList)
- {
- ItemValue item = new ItemValue(com, com.Company_Name);
- this.comboBoxMdian.Items.Add(item);
- if (PrimitiveID.Trim().Length > 0 && com.Company_DividedShop.ToLower() == PrimitiveID.ToLower())
- {
- this.comboBoxMdian.SelectedItem = item;
- }
- else if (PrimitiveID.Trim().Length <= 0 && com.Company_DividedShop.ToLower() == LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.CurrentCompanyInfoID.ToLower())
- {
- this.comboBoxMdian.SelectedItem = item;
- }
-
- }
-
- }
- void btnClose_Click(object sender, EventArgs e)
- {
- /*
- //测试代码
- try
- {
- LYFZ.BLL.BLL_SMSTemplates smsTemplates = new BLL.BLL_SMSTemplates();
- dynamic tMParameters = new System.Dynamic.ExpandoObject();
- tMParameters.XXX = "小小";
- tMParameters.XXXNO = "201505081446052981";
- tMParameters.MemberNo = "1360001";
- tMParameters.ConsumptionAmount = "100.00元";
- tMParameters.Time = SDateTime.Now;
- tMParameters.PointsIncrease = 0;
- tMParameters.ConsumptionType = "订购";
- tMParameters.ConsumptionStore = "门站";
- smsTemplates.GenerateEventTemplateMessage(EnumPublic.MicroSendEvent.现金卡消费后X分钟发提醒消息, tMParameters);
- }
- catch
- { }*/
- this.Close();
- }
- /// <summary>
- /// 上传文件到服务器
- /// </summary>
- /// <param name="SubPath"></param>
- /// <param name="fullFilePath"></param>
- /// <returns></returns>
- private bool UploadFileToServer(string yuname, string fullFilePath)
- {
- try
- {
- Random random = new Random();
- Bitmap bmp= LYFZ.BLL.SelectPhotoHandling.GeneratePreviewBitmap(fullFilePath, 800, 600);
- string newfilename = yuname + System.IO.Path.GetExtension(fullFilePath);
- if (LYFZ.BLL.SelectPhotoHandling.SaveIamge(bmp, System.IO.Path.GetDirectoryName(fullFilePath) + newfilename))
- {
- string url = "http://wx.lyfz.net:8086/WeiXinAPP/UploadPhoto.aspx?yuname=" + yuname + "&filename=" + newfilename + "&t=" + random.Next();
- System.Net.WebClient myWebClient = new System.Net.WebClient();
- myWebClient.Credentials = System.Net.CredentialCache.DefaultCredentials;
- byte[] by = myWebClient.UploadFile(url, "POST", fullFilePath);
- string content = System.Text.Encoding.UTF8.GetString(by);
- if (content == "Success")
- {
- myWebClient.Dispose();
- myWebClient = null;
- try
- {
- System.IO.File.Delete(newfilename);
- }
- catch { }
- return true;
- }
- else
- {
- return false;
- }
- }
- else {
- return false;
- }
- }
- catch
- {
- return false;
- }
- }
-
- }
- }
|