123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532 |
- using LYFZ.Model;
- using NetDimension.NanUI;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace LYFZ.Software.MainBusiness.MicroApplet
- {
- public class frmMicroAppletAdmin : LYFZ.Software.MicroApplet.frmMicroAppletAdmin
- {
- frmAdminPage frmPage = null;
- string gotoUrl = "";
- public frmMicroAppletAdmin(string parameter = "/panel/setting/store")
- {
- if (Environment.OSVersion.Version.Major >= 6)
- {
- try
- {
- frmPage = new frmAdminPage();
- gotoUrl = parameter;
- this.UcNavigationTool.LabTitle = "微信小程序后台管理";
- this.Load += frmMicroAppletAdmin_Load;
- this.btnRefresh.Click += btnRefresh_Click;
- this.btnSetAccount.Click += BtnSetAccount_Click;
- this.frmPage.ContextMenuHandler.RunContextMenu += ContextMenuHandler_RunContextMenu;
- this.Shown += FrmMicroAppletAdmin_Shown;
- this.frmPage.LoadHandler.OnLoadEnd += LoadHandler_OnLoadEnd;
- this.frmPage.LoadHandler.OnLoadStart += LoadHandler_OnLoadStart;
- this.comAccountList.SelectedIndexChanged += ComAccountList_SelectedIndexChanged;
- }
- catch
- {
- MessageBoxCustom.Show("您的系统不支持微信小程序功能,请使用 Win7 或以上系统。");
- this.Enabled = false;
- }
- }
- else {
- MessageBoxCustom.Show("您的系统不支持微信小程序功能,请使用 Win7 或以上系统。");
- this.Enabled = false;
- }
- }
-
-
-
- bool isInitialization = false;
- private void ComAccountList_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (isInitialization)
- {
- if (this.comAccountList.SelectedItem != null)
- {
- MicroAppToken = "";
- BLL.MicroApplet.MicroAppletAccount mAccount = (BLL.MicroApplet.MicroAppletAccount)((ItemValue)this.comAccountList.SelectedItem).Value;
- CurrentMicroAppletShopID = mAccount.ShopID;
- LoadMicroAppletPage(mAccount);
- }
- }
- }
- private void BtnSetAccount_Click(object sender, EventArgs e)
- {
- frmMicroAppletAccountManager frmaccountManager = new frmMicroAppletAccountManager();
- frmaccountManager.ShowDialog();
- if (frmaccountManager.isUpdate)
- {
- if (LoadMicroConfigure())
- {
- if (String.IsNullOrEmpty(CurrentMicroAppletShopID))
- {
- CurrentMicroAppletShopID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.CurrentCompanyInfoID;
- }
- isInitialization = false;
- if (_MicroAppletAccountList.Count > 0)
- {
- BindMicroAppletAccountList(this.comAccountList, CurrentMicroAppletShopID);
- }
- LoadMicroAppletPage(GetMicroAppletAccount(CurrentMicroAppletShopID));
- }
- else
- {
- MessageBoxCustom.Show("获取小程序帐号信息失败,请确认是否正确配置相关信息");
- }
- }
- }
- static string userInfo = "";
-
- private void LoadHandler_OnLoadStart(object sender, Chromium.Event.CfxOnLoadStartEventArgs e)
- {
-
-
- {
- SetSetLocalStorage();
- }
-
- }
- private void LoadHandler_OnLoadEnd(object sender, Chromium.Event.CfxOnLoadEndEventArgs e)
- {
- SetSetLocalStorage();
- }
- void SetSetLocalStorage()
- {
-
- this.frmPage.Chromium.ExecuteJavascript("localStorage.setItem('isClient',true);");
- this.frmPage.Chromium.ExecuteJavascript(String.Format("localStorage.setItem('userInfo',JSON.stringify({0}));", userInfo));
-
- }
- public static string CurrentMicroAppletShopID = "";
- private void FrmMicroAppletAdmin_Shown(object sender, EventArgs e)
- {
- if (LoadMicroConfigure())
- {
- if (String.IsNullOrEmpty(CurrentMicroAppletShopID))
- {
- CurrentMicroAppletShopID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.CurrentCompanyInfoID;
- }
- if (_MicroAppletAccountList.Count > 0)
- {
- BindMicroAppletAccountList(this.comAccountList, CurrentMicroAppletShopID);
- }
- LoadMicroAppletPage(GetMicroAppletAccount(CurrentMicroAppletShopID));
-
- }
- else {
- MessageBoxCustom.Show("获取小程序帐号信息失败,请确认是否正确配置相关信息");
- }
- }
- void LoadMicroAppletPage(BLL.MicroApplet.MicroAppletAccount mAccount)
- {
- isInitialization = true;
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker)
- {
- try
- {
-
- backgroundWorker.ReportProgress(0, "正在验证授权...");
- if (!String.IsNullOrEmpty(mAccount.Account) && !String.IsNullOrEmpty(mAccount.Password))
- {
-
- {
- MicroAppLoginReturn loginModel = CompanyLoginReturnToken(mAccount.Account, mAccount.Password);
- if (loginModel.Code != 200)
- {
- MicroAppToken = "";
- MessageBoxCustom.Show("获取授权失败:" + loginModel.Message, backgroundWorker: backgroundWorker);
- }
- }
- }
- else
- {
- MicroAppToken = "";
- MessageBoxCustom.Show(String.Format("您还没有开通“利亚方舟影楼版微信小程序”"), backgroundWorker: backgroundWorker);
- }
-
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show(String.Format("获取授权时错误:{0}", ex.Message), backgroundWorker: backgroundWorker);
- }
- });
-
- if (this.plExMainContainer.Controls.Count <= 0)
- {
- this.frmPage.SetEmbeddedWindows(this.plExMainContainer);
- }
- if (!String.IsNullOrEmpty(MicroAppToken))
- {
- frmPage.LoadUrl(this.GetMicroAppletUrl(String.Format("{0}{1}", microAppDomainName, gotoUrl), mAccount));
-
-
-
-
-
-
- }
- else
- {
- frmPage.LoadUrl("http://www.lyfz.net/index/miniapp_desc");
- }
- }
- void frmMicroAppletAdmin_Load(object sender, EventArgs e)
- {
- this.comAccountList.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.MicroAppletManage, CustomAttributes.OperatingAuthority.MicroAppletAccountSwicth);
- this.btnSetAccount.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.MicroAppletManage, CustomAttributes.OperatingAuthority.MicroAppletAccountSet);
- }
- LYFZ.Model.Model_ErpSystemConfigure Config = new Model.Model_ErpSystemConfigure();
- LYFZ.BLL.BLL_ErpSystemConfigure bllConfig = new BLL.BLL_ErpSystemConfigure();
- public static string MicroAppToken = "";
- public static string MicroAppBindingCode = "";
- public static string microAppInterfaceDomainName = "http://wxyx.lyfz.net";
- public static string microAppDomainName = "http://ivision.lyfz.net";
- static string AuthCompanyLogin = String.Format("{0}/api.php/Auth/companyLogin", microAppInterfaceDomainName);
-
- string GetaccountAndPwdString(BLL.MicroApplet.MicroAppletAccount mAccount)
- {
- string pwdMd5 = "";
- if (!String.IsNullOrEmpty(mAccount.Password))
- {
- pwdMd5 = LYFZ.WinAPI.SDKSecurity.MD5Encrypt(mAccount.Password).ToLower();
- }
- return String.Format("account_number={0}&password={1}", mAccount.Account, pwdMd5);
- }
- string GetMicroAppletUrl(string url, BLL.MicroApplet.MicroAppletAccount mAccount)
- {
- if (url.Contains("?"))
- {
- return String.Format("{0}&{1}", url, GetaccountAndPwdString(mAccount));
- }
- else
- {
- return String.Format("{0}?{1}", url, GetaccountAndPwdString(mAccount));
- }
- }
- public static MicroAppLoginReturn CompanyLoginReturnToken(string account, string pwd)
- {
- MicroAppLoginReturn retModel = new MicroAppLoginReturn();
- try
- {
- string postData = String.Format("&phone_no={0}&password={1}&openid=&verification_code=", account, LYFZ.WinAPI.SDKSecurity.MD5Encrypt(pwd).ToLower());
- string postReturnString = LYFZ.WinAPI.CustomPublicMethod.HttpWebRequestPOST(AuthCompanyLogin, postData, Encoding.UTF8);
- if (postReturnString.IndexOf("{") == 0)
- {
- dynamic postReturnObj = Newtonsoft.Json.JsonConvert.DeserializeObject(postReturnString);
- if (Convert.ToInt32(postReturnObj["meta"]["code"]) == 200)
- {
- MicroAppToken = postReturnObj["body"]["token"];
- retModel.UserInfo = Newtonsoft.Json.JsonConvert.SerializeObject(postReturnObj["body"]);
- retModel.AppToken = MicroAppToken;
- userInfo = retModel.UserInfo;
- string getReturnString = HttpWebRequestGET(String.Format("{0}/api.php/IvisionBackstage/getBindAccount", microAppInterfaceDomainName), MicroAppToken, Encoding.UTF8);
- dynamic getReturnObj = Newtonsoft.Json.JsonConvert.DeserializeObject(getReturnString);
- if (getReturnString.IndexOf("{") == 0 && Convert.ToInt32(getReturnObj["meta"]["code"]) == 200)
- {
- retModel.Code = 200;
- retModel.Message = "OK";
- retModel.Bind_code = getReturnObj["body"]["bind_code"];
- }
- }
- else
- {
- MicroAppToken = "";
- retModel.Message = postReturnObj["meta"]["message"];
- }
- }
- else
- {
- MicroAppToken = "";
- retModel.Message = postReturnString;
- }
- }
- catch (Exception ex)
- {
- retModel.Message = ex.Message;
- }
- return retModel;
- }
- static List<LYFZ.Model.Model_ErpCompanyInfo> _CompayList = new List<Model.Model_ErpCompanyInfo>();
- public static List<BLL.MicroApplet.MicroAppletAccount> _MicroAppletAccountList = new List<BLL.MicroApplet.MicroAppletAccount>();
- public static bool LoadMicroConfigure()
- {
- bool retBl = false;
- try
- {
- _MicroAppletAccountList = new BLL.BLL_ErpSystemConfigure().GetMicroAppletAccountList();
- if (_CompayList.Count <= 0)
- {
- _CompayList = new LYFZ.BLL.BLL_ErpCompanyInfo().GetModelList("1=1");
- }
- retBl = true;
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show("加载微信小程序帐号信息时出错:" + ex.Message);
- }
- return retBl;
- }
- static LYFZ.Model.Model_ErpCompanyInfo GetCompanyInfo(string shopID)
- {
- if (_CompayList.Any(c => c.Company_DividedShop.ToLower() == shopID.ToLower()))
- {
- return _CompayList.Find(c => c.Company_DividedShop.ToLower() == shopID.ToLower());
- }
- else
- {
- return new Model.Model_ErpCompanyInfo();
- }
- }
- public static void BindMicroAppletAccountList(ComponentLibrary.ComboBoxEx comBox, string dfShopID)
- {
- comBox.Items.Clear();
- foreach (BLL.MicroApplet.MicroAppletAccount mAccount in _MicroAppletAccountList)
- {
- LYFZ.Model.Model_ErpCompanyInfo comp = GetCompanyInfo(mAccount.ShopID);
- ItemValue item = new ItemValue(mAccount, String.Format("【{0}】{1}", comp.Company_Name,mAccount.Account));
- comBox.Items.Add(item);
- if (dfShopID.Trim().Length > 0 && mAccount.ShopID.ToLower() == dfShopID.ToLower())
- {
- comBox.SelectedItem = item;
- }
- else if (dfShopID.Trim().Length <= 0 && mAccount.ShopID.ToLower() == LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.CurrentCompanyInfoID.ToLower())
- {
- comBox.SelectedItem = item;
- }
- }
- }
- public static BLL.MicroApplet.MicroAppletAccount GetMicroAppletAccount(string shopID)
- {
- if (_MicroAppletAccountList.Any(m => m.ShopID.ToLower() == shopID.ToLower()))
- {
- return _MicroAppletAccountList.Find(m => m.ShopID.ToLower() == shopID.ToLower());
- }
- else {
- return new BLL.MicroApplet.MicroAppletAccount();
- }
- }
- private void ContextMenuHandler_RunContextMenu(object sender, Chromium.Event.CfxRunContextMenuEventArgs e)
- {
- e.SetReturnValue(true);
- }
- void btnRefresh_Click(object sender, EventArgs e)
- {
-
- myRefresh(this.cbDelHuanChun.Checked);
- }
- void myRefresh(bool isDelHuanChun)
- {
- if (isDelHuanChun)
- {
- CurrentMicroAppletShopID = "";
- MicroAppToken = "";
- this.frmPage.Browser.ReloadIgnoreCache();
- if (this.comAccountList.SelectedItem != null)
- {
- BLL.MicroApplet.MicroAppletAccount mAccount = (BLL.MicroApplet.MicroAppletAccount)((ItemValue)this.comAccountList.SelectedItem).Value;
- LoadMicroAppletPage(mAccount);
- }
- }
- else
- {
- this.frmPage.Browser.Reload();
- }
- }
-
-
-
-
-
-
- public static string HttpWebRequestGET(string url, string token, Encoding _Encoding = null, bool isUrlDecode = true)
- {
- try
- {
- System.GC.Collect();
- if (_Encoding == null)
- {
- _Encoding = System.Text.Encoding.Default;
- }
- if (System.Net.ServicePointManager.DefaultConnectionLimit < 512)
- {
- System.Net.ServicePointManager.DefaultConnectionLimit = 512;
- }
- LYFZ.WinAPI.CustomPublicMethod.SetServicePointManagerSecurityProtocol(url);
- System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
- webRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/json,*/*";
- webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Zune 4.7; BOIE9;ZHCN)";
- webRequest.Method = "GET";
- webRequest.Timeout = 600000;
- webRequest.KeepAlive = false;
- webRequest.ProtocolVersion = System.Net.HttpVersion.Version10;
- webRequest.Headers.Add("token", token);
-
-
- System.Threading.Thread.Sleep(5);
- using (System.Net.WebResponse wr = webRequest.GetResponse())
- {
- System.IO.StreamReader str = new System.IO.StreamReader(wr.GetResponseStream(), _Encoding);
- string strMsg = str.ReadToEnd();
- str.Close();
- str.Dispose();
- str = null;
- webRequest.Abort();
- webRequest = null;
- if (isUrlDecode)
- {
- strMsg = System.Web.HttpUtility.UrlDecode(strMsg);
- }
- return strMsg;
-
- }
- }
- catch (Exception ex)
- {
- System.Net.ServicePointManager.Expect100Continue = false;
- return "Request failed,Exception:" + ex.Message;
- }
- }
-
-
-
-
-
-
-
-
- public static string HttpWebRequestPOST(string url, string postData, MicroAppLoginReturn appLogin, Encoding _Encoding = null, bool isUrlDecode = true)
- {
- try
- {
-
-
-
- System.GC.Collect();
- if (_Encoding == null)
- {
- _Encoding = Encoding.Default;
- }
- byte[] byteArray = _Encoding.GetBytes(postData);
- if (System.Net.ServicePointManager.DefaultConnectionLimit < 512)
- {
- System.Net.ServicePointManager.DefaultConnectionLimit = 512;
- }
-
-
- LYFZ.WinAPI.CustomPublicMethod.SetServicePointManagerSecurityProtocol(url);
-
- System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(new Uri(url));
-
-
- webRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
- webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Zune 4.7; BOIE9;ZHCN)";
- webRequest.KeepAlive = false;
- webRequest.ProtocolVersion = System.Net.HttpVersion.Version10;
- webRequest.Method = "POST";
- webRequest.Headers.Add("token", appLogin.AppToken);
- webRequest.Headers.Add("bindcode", appLogin.Bind_code);
- webRequest.ContentType = "application/x-www-form-urlencoded";
- webRequest.ContentLength = byteArray.Length;
-
- System.IO.Stream newStream = webRequest.GetRequestStream();
- newStream.Write(byteArray, 0, byteArray.Length);
- newStream.Close();
- newStream = null;
-
- webRequest.Timeout = 600000;
- System.Threading.Thread.Sleep(10);
- using (System.Net.WebResponse wr = webRequest.GetResponse())
- {
- System.IO.StreamReader str = new System.IO.StreamReader(wr.GetResponseStream(), _Encoding);
- string strMsg = str.ReadToEnd();
- str.Close();
- str.Dispose();
- str = null;
- webRequest.Abort();
- webRequest = null;
- if (isUrlDecode)
- {
- strMsg = System.Web.HttpUtility.UrlDecode(strMsg);
- }
- return strMsg;
-
- }
- }
- catch (Exception ex)
- {
- System.Net.ServicePointManager.Expect100Continue = false;
- return "Request failed,Exception:" + ex.Message;
- }
- }
- }
- }
|