1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249 |
- using Aliyun.OSS;
- using LYFZ.ComponentLibrary;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Windows.Forms;
- namespace LYFZ.Software.MainBusiness.MicroShare
- {
- public partial class FrmMicroShare : LYFZ.Software.UI.MicroShare.FrmMicroShare
- {
- private delegate void UpdateControl();
- public FrmMicroShare()
- {
- this.buttonExit.Click += buttonExit_Click;
- // this.rdo_yxb1.CheckedChanged += rdo_photo_type_CheckedChanged;
- // this.rdo_yxb_kb.CheckedChanged += rdo_photo_type_CheckedChanged;
- // this.rdo_yxb_la_1.CheckedChanged += rdo_photo_type_CheckedChanged;
- this.likSelect.Click += likSelect_Click;
- this.cbxTemplates.SelectedIndexChanged += cbxTemplates_SelectedIndexChanged;
- this.btnWebMp3.Click += btnWebMp3_Click;
- // testOSS();
- }
- /// <summary>
- /// 测试
- /// </summary>
- void testOSS()
- {
- var client = new OssClient("oss-cn-shanghai.aliyuncs.com", "LTAI4AxacSz3Y3tt", "xCDW8AtaqmYqZMNzszFEHChfIp26E0");
- try
- {
- string photoFile = @"D:\Original_IMG_9961.jpg";
- string imgMd5 = LYFZ.WinAPI.SDKSecurity.GetMD5HashFromFile(photoFile);
- //customer-photos/<date>
- string key = imgMd5;
- bool retBl = client.DoesObjectExist("lyfz-enterprise-photocache", key);
- // client.DeleteObject("lyfz-enterprise-photocache", key);
- if (!retBl)
- {
- PutObjectResult ret = client.PutObject("lyfz-enterprise-photocache", key, photoFile);
- }
- string imgurl = "https://lyfz-enterprise-photocache.oss-cn-shanghai.aliyuncs.com/" + key;
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show("上传相片时失败,原因:" + ex.Message);
- }
-
- }
- string webMP3Path = "";
- bool isWebMP3 = false;
- void btnWebMp3_Click(object sender, EventArgs e)
- {
- frmWebMp3 webMP3 = new frmWebMp3();
- if (webMP3.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- webMP3Path = webMP3.WebMP3Path;
- this.txtMusieUpload.Text = "网络MP3:"+webMP3.Mp3Name;
- isWebMP3 = true;
- }
- }
- void cbxTemplates_SelectedIndexChanged(object sender, EventArgs e)
- {
- try
- {
- if (this.cbxTemplates.SelectedItem != null)
- {
- ItemValue item = (ItemValue)this.cbxTemplates.SelectedItem;
- LYFZ.Model.MicroShareTemplate msTemplate = (LYFZ.Model.MicroShareTemplate)item.Value;
- this._photo_type = msTemplate.TemplateCode.Trim();
- }
- }
- catch {
- this._photo_type = "yxb_kb";
- }
- }
- void likSelect_Click(object sender, EventArgs e)
- {
- LYFZ.Software.MainBusiness.SMSManagement.frmSelectSmsInfo selectInfo = new LYFZ.Software.MainBusiness.SMSManagement.frmSelectSmsInfo();
- if (selectInfo.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- if (selectInfo.SmsModel.ID > 0)
- {
- this.txtGreetings.Text = selectInfo.SmsModel.ST_SMSContent;
- }
- }
- }
- static string accessKeyId = "0";
- static string accessKeySecret = "0";
- static string endpoint = "https://oss-cn-shenzhen.aliyuncs.com";//Config.Endpoint;
- static string securityToken = "0";
- static string bucketName = "lyfz-yxb";
- /// <summary>
- /// 获取阿里云服务器上文件地址
- /// </summary>
- /// <param name="key"></param>
- /// <returns></returns>
- static string GetAliyunOSSServerPath(string key)
- {
- //https://lyfz-yxb.oss-cn-shenzhen.aliyuncs.com/customer-musics/JSB
- return endpoint.ToLower().Replace("https://", "https://" + bucketName + ".")
- .Replace("http://", "http://" + bucketName + ".").Trim('/')+"/"+key;
- }
- /// <summary>
- /// 获取阿里云
- /// </summary>
- void GetAliyunOSSAccessKey()
- {
- try
- {
- try
- {
- string retEndpoint = LYFZ.WinAPI.CustomPublicMethod.HttpWebRequestGET(domainName + "/api/alioss/get.php", Encoding.UTF8, myCookieContainer, isUrlDecode: false);
- dynamic EndpointJson = Newtonsoft.Json.JsonConvert.DeserializeObject(retEndpoint);
- endpoint = EndpointJson.endpoint;
- bucketName = EndpointJson.bucketname;
- }
- catch { }
- string retAccessKey = LYFZ.WinAPI.CustomPublicMethod.HttpWebRequestGET(domainName + "/api/alioss/getSTSaccess.php", Encoding.UTF8, myCookieContainer, isUrlDecode: false);
- dynamic AccessKeyJson = Newtonsoft.Json.JsonConvert.DeserializeObject(retAccessKey);
- accessKeyId = AccessKeyJson.Credentials.AccessKeyId.ToString().Trim();
- accessKeySecret = AccessKeyJson.Credentials.AccessKeySecret.ToString().Trim();
- securityToken = AccessKeyJson.Credentials.SecurityToken.ToString().Trim();
-
- }
- catch {
-
- }
- }
- LYFZ.Model.MicroShareTemplates microTemplate = new Model.MicroShareTemplates();
- void LoadMicroShareTemplates()
- {
- try
- {
- string retTemplates = LYFZ.WinAPI.CustomPublicMethod.HttpWebRequestGET(domainName+"/index.php?m=Photo&a=template", Encoding.UTF8);
- dynamic TemplatesJson = Newtonsoft.Json.JsonConvert.DeserializeObject(retTemplates);
- if (TemplatesJson.status.ToString() == "200")
- {
- string defaultTemplate = TemplatesJson.data.defaults.ToString();
- foreach (dynamic Template in TemplatesJson.data.templates)
- {
- LYFZ.Model.MicroShareTemplate msTemplate = new Model.MicroShareTemplate();
- if (Template.value.ToString() == defaultTemplate)
- {
- msTemplate.IsDefault = true;
- microTemplate.DefaultTemplate = msTemplate;
- }
- msTemplate.TemplateName = Template.text.ToString();
- msTemplate.TemplateCode = Template.value.ToString();
- microTemplate.MicroShareTemplateList.Add(msTemplate);
- }
- }
- else {
- MessageBoxCustom.Show("获取相册模板失败:" + TemplatesJson.info.ToString());
- }
-
-
- }
- catch (Exception ex){
- MessageBoxCustom.Show("获取相册模板失败:"+ex.Message);
- }
- }
- public static string domainName = "http://yxb.lyfz.net";//"yxb.lyfz.net"ayafafa.com;
- string _photo_type = "yxb_kb";
- /// <summary>
- /// 相册类型
- /// </summary>
- public string Photo_type
- {
- get { return _photo_type; }
- set { _photo_type = value; }
- }
- /* void rdo_photo_type_CheckedChanged(object sender, EventArgs e)
- {
- try
- {
- this._photo_type = ((RadioButtonEx)sender).Tag.ToString();
- }
- catch {
- this._photo_type = "yxb_kb";
- }
- }*/
- void buttonExit_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 像片集合
- /// </summary>
- public List<string> SPhotoList = new List<string>();
- /// <summary>
- /// 客户姓名
- /// </summary>
- public string F_CusName;
- private string _F_Attractions;
- /// <summary>
- /// 拍摄景点
- /// </summary>
- public string F_Attractions
- {
- get { return _F_Attractions; }
- set { _F_Attractions = value; }
- }
- /// <summary>
- /// 化妆师
- /// </summary>
- public string F_MakeupArtist;
- /// <summary>
- /// 订单号
- /// </summary>
- public string F_Number;
- #region 显示图片与数据
- protected override void FrmMicroShare_Shown(object sender, EventArgs e)
- {
- try
- {
- ImageList ImageList1 = new ImageList();
- List<string> listName = new List<string>();
- List<string> listPath = new List<string>();
- ImageList1.ColorDepth = ColorDepth.Depth32Bit;
- ImageList1.ImageSize = new Size(95, 100);
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
- {
- backgroundWorker.ReportProgress(0, "正在获取模板...");
- LoadMicroShareTemplates();
- backgroundWorker.ReportProgress(0, "正在加载相片...");
- // this.Invoke(new UpdateControl(delegate()
- // {
- for (int i = 0; i < SPhotoList.Count; i++)
- {
- string PhotoPath = SPhotoList[i].Trim();
- string aa = LYFZ.BLL.SelectPhotoHandling.SmallPathToOriginalPath(PhotoPath);
- string bb = LYFZ.BLL.SelectPhotoHandling.ServerFileNameToOriginalName(BLL.SelectPhotoHandling.PhotoType.Preview, System.IO.Path.GetFileName(aa));
- string PhotoName = System.IO.Path.GetFileNameWithoutExtension(PhotoPath);
- using (System.IO.FileStream fs = new System.IO.FileStream(PhotoPath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
- {
- Image image = System.Drawing.Image.FromStream(fs);
- ImageList1.Images.Add(PhotoPath, image);
- listName.Add(LYFZ.BLL.SelectPhotoHandling.SmallNameToOriginalName(PhotoName));
- listPath.Add(PhotoPath);
- fs.Close();
- }
- }
- // }));
- });
- #region 显示图片
- this.lstPic.LargeImageList = ImageList1;
- this.lstPic.View = View.LargeIcon;
- for (int i = 0; i < ImageList1.Images.Count; i++)
- {
- ListViewItem lvi = new ListViewItem();
- lvi.ImageIndex = i;
- lvi.Text = listName[i];
- lvi.Tag = listPath[i];
- lvi.ToolTipText = listName[i];
- this.lstPic.Items.Add(lvi);
- }
- #endregion
- #region 显示内容
- txtCustomerName.Text = F_CusName;
- txtShootingAttractions.Text = F_Attractions;
- txtMakeupArtist.Text = F_MakeupArtist;
- #endregion
- txtCount.Text = "0";
- foreach (LYFZ.Model.MicroShareTemplate msTemplate in this.microTemplate.MicroShareTemplateList)
- {
- ItemValue item=new ItemValue(msTemplate, msTemplate.TemplateName);
- this.cbxTemplates.Items.Add(item);
- if (msTemplate.IsDefault)
- {
- this.cbxTemplates.SelectedItem = item;
- }
- }
- if (this.cbxTemplates.Items.Count>0&&this.cbxTemplates.SelectedItem == null)
- {
- this.cbxTemplates.SelectedIndex = 0;
- }
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show(ex.Message);
- }
- }
- #endregion
- #region 上传
- protected override void btnUpload_Click(object sender, EventArgs e)
- {
- try
- {
- #region 判断
- if (lstPic.CheckedItems.Count == 0)
- {
- MessageBoxCustom.Show("请勾选你要分享的图片!");
- return;
- }
- int ZhangSum = Convert.ToInt32(txtCount.Text);
- if (ZhangSum >20)
- {
- MessageBoxCustom.Show("请分享的图片超过最大张数!");
- return;
- }
- if (string.IsNullOrEmpty(txtAlbumTitle.Text))
- {
- MessageBoxCustom.Show("相册标题不能为空!");
- return;
- }
- if (string.IsNullOrEmpty(txtCustomerName.Text))
- {
- MessageBoxCustom.Show("客户姓名不能为空!");
- return;
- }
- if (txtAlbumTitle.Text.Trim().Length>10)
- {
- MessageBoxCustom.Show("相册标题不能大于10个字符!");
- return;
- }
- if (txtAlbumItroduction.Text.Trim().Length > 150)
- {
- MessageBoxCustom.Show("相册介绍不能大于150个字符!");
- return;
- }
- if (txtGreetings.Text.Trim().Length > 100)
- {
- MessageBoxCustom.Show("祝福语不能大于100个字符!");
- return;
- }
- #endregion
- #region 获取赢销宝接口
- //检查赢销宝登录
- if (CheckYxbLogin())
- {
- //创建图片 并上传
- CreatePic();
- }
- #endregion
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show(ex.Message);
- }
- }
- #endregion
- #region 选中项改变事件
- protected override void lstPic_ItemChecked(object sender, ItemCheckedEventArgs e)
- {
- try
- {
- if (lstPic.CheckedItems.Count > 0)
- {
- txtCount.Text = lstPic.CheckedItems.Count.ToString();
- }
- else { txtCount.Text = "0"; }
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show(ex.Message);
- }
-
- }
- #endregion
- #region 全选
- protected override void btnAll_Click(object sender, EventArgs e)
- {
- try
- {
- for (int i = 0; i < lstPic.Items.Count; i++)
- {
- lstPic.Items[i].Checked = true;
- }
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show(ex.Message);
- }
- }
- #endregion
- #region 取消
- protected override void btnCancel_Click(object sender, EventArgs e)
- {
- try
- {
- for (int i = 0; i < lstPic.Items.Count; i++)
- {
- lstPic.Items[i].Checked = false;
- }
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show(ex.Message);
- }
- }
- #endregion
- #region 右键菜单事件
- /// <summary>
- /// 取消
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void toolCancel_Click(object sender, EventArgs e)
- {
- if (lstPic.SelectedItems.Count > 0)
- {
- for (int i = 0; i < lstPic.SelectedItems.Count; i++)
- {
- lstPic.SelectedItems[i].Checked = false;
- }
- }
- }
- /// <summary>
- /// 选中
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected override void toolSelected_Click(object sender, EventArgs e)
- {
- if (lstPic.SelectedItems.Count > 0)
- {
- for (int i = 0; i < lstPic.SelectedItems.Count; i++)
- {
- lstPic.SelectedItems[i].Checked = true;
- }
- }
- }
- #endregion
- #region 浏览上传背景音乐
- string PhotoFilePath = "";
- string MiuseUpLoadName = "";
- protected override void btnBrowse_Click(object sender, EventArgs e)
- {
- #region 判断
- /* if (lstPic.CheckedItems.Count == 0)
- {
- MessageBoxCustom.Show("请打勾你要分享的图片!");
- return;
- }
- int ZhangSum = Convert.ToInt32(txtCount.Text);
- if (ZhangSum > 20)
- {
- MessageBoxCustom.Show("请分享的图片超过最大张数!");
- return;
- }
- if (string.IsNullOrEmpty(txtAlbumTitle.Text))
- {
- MessageBoxCustom.Show("相册标题不能为空!");
- return;
- }
- if (string.IsNullOrEmpty(txtCustomerName.Text))
- {
- MessageBoxCustom.Show("客户姓名不能为空!");
- return;
- }*/
- #endregion
- openFileDialog1.Filter = "mp3文件(*.mp3)|*.mp3";
- openFileDialog1.FileName = "";
- if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- PhotoFilePath = openFileDialog1.FileName;
- txtMusieUpload.Text = PhotoFilePath;
- isWebMP3 = false;
- //判断文件大小
- FileInfo fileInfo = new FileInfo(PhotoFilePath);
- int ShowFileSize = Convert.ToInt32(fileInfo.Length) / Convert.ToInt32(1024);//文件大小
- if (ShowFileSize > 2048)
- {
- MessageBoxCustom.Show("由于文件过大将影响相册打开速度和浪费客户流量,所以不能超过2MB,建意上传小于1MB以下的MP3!");
- txtMusieUpload.Text = "";
- }
- /* else
- {
- //WaitForm wf = new WaitForm();
- //wf.ShowForm(this);
-
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
- {
- CheckYxbLogin();
- // this.Invoke(new UpdateControl(delegate()
- // {
- backgroundWorker.ReportProgress(0, "正在上传音乐请稍等...");
- string ResponseHtmlUpLoad = null;
- string FormUrl = null;
- #region 获取上传文件音频路径
- FormUrl = "http://yxb.lyfz.net/index.php?m=Photo&a=upload_file";
- Hashtable hastable = new Hashtable();
- string file = PhotoFilePath;
- hastable["file1"] = file;
- ResponseHtmlUpLoad = SendHttpRequestPost(FormUrl, null, hastable, Encoding.UTF8).Replace("\"", "").Replace("\\", "").Replace(",info", "|").Replace("{data:[", "").Replace("]", "");
- MiuseUpLoadName = ResponseHtmlUpLoad.Split('|')[0];
-
- //wf.CloseForm();
- //wf = null;
- #endregion
- // MessageBoxCustom.Show(MiuseUpLoadName);
- // }));
- });
- if (MiuseUpLoadName.Trim().Length > 0)
- {
- }
- else { }
- }*/
-
-
- }
- }
- #endregion
- bool uploadMP3(string mp3Path)
- {
- if (mp3Path.Length <= 0) { return false; }
- if (isWebMP3)
- {
- MiuseUpLoadName = this.webMP3Path;
- return true;
- }
- else
- {
- var client = new OssClient(endpoint, accessKeyId, accessKeySecret, securityToken);
- try
- {
- string fileToUpload = mp3Path;//@"C:\Users\Administrator\Downloads\记事本.mp3";
- string mp3Md5 = LYFZ.WinAPI.SDKSecurity.GetMD5HashFromFile(fileToUpload);
- string key = "customer-musics/" + mp3Md5;
- bool retBl = client.DoesObjectExist(bucketName, key);
- if (!retBl)
- {
- PutObjectResult ret = client.PutObject(bucketName, key, fileToUpload);
- }
- MiuseUpLoadName = GetAliyunOSSServerPath(key);
- return true;
- }
- catch
- {
- return false;
- }
- }
- //旧版上传接口
- //string ResponseHtmlUpLoad = null;
- // string FormUrl = null;
- #region 获取上传文件音频路径
- // FormUrl = domainName + "/index.php?m=Photo&a=upload_file";
- // Hashtable hastable = new Hashtable();
- //string file = PhotoFilePath;
- //hastable["file1"] = file;
-
- /* ResponseHtmlUpLoad = SendHttpRequestPost(FormUrl, null, hastable, Encoding.UTF8).Replace("\"", "").Replace("\\", "").Replace(",info", "|").Replace("{data:[", "").Replace("]", "");
- MiuseUpLoadName = ResponseHtmlUpLoad.Split('|')[0];
- if (MiuseUpLoadName.Trim().Length > 0)
- {
- return true;
- }
- else {
- return false;
- }*/
- #endregion
- }
- #region 赢销宝接口
- #region 检查赢销宝登录
- /// <summary>
- /// 检查赢销宝登录
- /// </summary>
- public bool CheckYxbLogin()
- {
- try
- {
- LYFZ.BLL.BaseBLL.BaseBLL_ErpCompanyInfo CompanyInfoBll = new BLL.BaseBLL.BaseBLL_ErpCompanyInfo();
- DataTable dt = CompanyInfoBll.GetList("Company_DividedShop='" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID() + "'").Tables[0];
- string password = "";
- string uid = "";
- if (dt.Rows.Count > 0)
- {
- uid = dt.Rows[0]["Company_MicroShareAccount"].ToString();
- password = dt.Rows[0]["Company_MicroSharePassword"].ToString();
- }
- string FormData = null;
- string FormUrl = null;
- FormData = string.Format("username={0}&password={1}", uid, password); // 要发放的数据
- FormUrl = domainName + "/index.php?m=Photo&a=login";
- string ResponseHtml = HttpPost(FormUrl, FormData);
- if (ResponseHtml == "2")
- {
- MessageBoxCustom.Show("登陆失败!请在本店信息设置账户与密码是否正确!");
- return false;
-
- }
- if (ResponseHtml == "3")
- {
- MessageBoxCustom.Show("账号未开通权限!");
- return false;
- }
- return true;
- //创建图片
- // CreatePic();
- //switch (ResponseHtml)
- //{
- // //case "1":
- // // MessageBoxCustom.Show("登录成功!");
- // // break;
- // case "2":
- // MessageBoxCustom.Show("登陆失败!");
- // break;
-
- // case "3":
- // MessageBoxCustom.Show("账号未开通权限!");
- // break;
- //}
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show("赢销宝帐号登录失败:" + ex.Message);
- return false;
- }
- }
- #endregion
- #region 创建图片
- /// <summary>
- /// 创建图片
- /// </summary>
- public void CreatePic()
- {
- try
- {
- // string ResponseHtmlUpLoad = "";
- /*if (myCookieContainer == null)
- {
- CheckYxbLogin();
- }*/
- string FormData = "";
- string FormUrl = domainName+"/index.php?m=Photo&a=upload_file";
- string UpLoadName = "";
- #region 获取上传图片文件音频路径
- Hashtable hastable = new Hashtable();
- // int fileSum = 0;
- //获取选中图片上传
- try
- {
- string MP3Path = txtMusieUpload.Text.Trim();
- int FolderImageCount = this.lstPic.CheckedItems.Count;
- List<string> uploadphotoList = new List<string>();
- for (int i = 0; i < FolderImageCount; i++)
- {
- ListViewItem lv = lstPic.CheckedItems[i];
- if (lv != null)
- {
- string file = LYFZ.BLL.SelectPhotoHandling.SmallPathToPreviewPath(lv.Tag.ToString());
- uploadphotoList.Add(file);
- }
- }
- LYFZ.ComponentLibrary.FrmLoadHandling.ExecutionDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
- {
- backgroundWorker.ReportProgress(0, "正在验证上传请求...");
- GetAliyunOSSAccessKey();
- backgroundWorker.ReportProgress(0, "准备上传文件...");
- if (MP3Path.Trim().Length > 0)
- {
- backgroundWorker.ReportProgress(60, "正在上传音乐,需要时间较长...");
- if (uploadMP3(MP3Path))
- {
- backgroundWorker.ReportProgress(100, "音乐上传成功...");
- }
- else
- {
- // MessageBoxCustom.Show("音乐上传失败",backgroundWorker:backgroundWorker);
- throw new Exception("上传背景音乐文件时失败");
- }
- }
- int ForCount = 0;
- backgroundWorker.ReportProgress(10, "正在上传相片,请稍等...");
- var client = new OssClient(endpoint, accessKeyId, accessKeySecret, securityToken);
- try
- {
- foreach (string photoPath in uploadphotoList)
- {
-
- string photoFile = photoPath;
- string imgMd5 = LYFZ.WinAPI.SDKSecurity.GetMD5HashFromFile(photoFile);
- //customer-photos/<date>
- string key = "customer-photos/" + SDateTime.Now.ToString("yyyyMM") + "/" + imgMd5;
- bool retBl = client.DoesObjectExist(bucketName, key);
- if (!retBl)
- {
- if (".jpg,.png.jpge".Contains(System.IO.Path.GetExtension(photoPath).ToLower().Trim()))
- {
- Bitmap bmp = LYFZ.BLL.SelectPhotoHandling.GeneratePreviewBitmap(photoPath, 640, 960);
- photoFile = LYFZ.ImageFunction.ThumbImgae.SaveTemporaryCompressionImage(bmp, System.IO.Path.GetFileName(photoPath));
- }
- PutObjectResult ret = client.PutObject(bucketName, key, photoFile);
- if (".jpg,.png.jpge".Contains(System.IO.Path.GetExtension(photoFile).ToLower().Trim()))
- {
- LYFZ.ImageFunction.ThumbImgae.DeleteTemporaryCompressionImage(photoFile);
- }
- }
- UpLoadName += GetAliyunOSSServerPath(key) + "|";
- try
- { backgroundWorker.ReportProgress(Convert.ToInt32(1000 / FolderImageCount * (ForCount + 1))); ForCount++; }
- catch { }
- }
-
-
- }
- catch(Exception ex)
- {
- MessageBoxCustom.Show("上传相片时失败,原因1:" + ex.Message,backgroundWorker:backgroundWorker);
- }
- }, width: 500);
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show("上传相片时失败,原因2:" + ex.Message);
- return;
- }
-
- #endregion
- #region 截取封面图片,创建图片
- string[] strUpLoadName = UpLoadName.Split('|');
- FormUrl = domainName + "/index.php?m=Photo&a=add";
- //获取参数数据
- string title = txtAlbumTitle.Text.Trim().Replace("&", "&");
- string customer_name = txtCustomerName.Text.Trim().Replace("&", "&").Replace("/", "&");
- string location = txtShootingAttractions.Text.Trim().Replace("&", "&");
- string picurl = strUpLoadName[0].ToString().Replace("{data:[", "").Replace("}", "").Replace("]", "").Split(',')[0];
- string info = txtAlbumItroduction.Text.Trim().Replace("&", "&");
- string dresser = txtMakeupArtist.Text.Trim().Replace("&", "&");
- string bg_audio_url = MiuseUpLoadName;// MuiseUpLoad.Split(',')[0].ToString().Replace("{data:[", "").Replace("}", "").Replace("]", "");
- string comment_text1 = txtGreetings.Text.Trim().Replace("&", "&");
- FormData = string.Format("title={0}&customer_name={1}&location={2}&picurl={3}&info={4}&dresser={5}&bg_audio_url={6}&photo_type={7}&comment_text1={8}", title, customer_name, location, picurl, info, dresser, bg_audio_url, Photo_type, comment_text1); // 要发放的数据
- string ResponseHtml = HttpPost(FormUrl, FormData);
- try
- {
- dynamic AccessKeyJson = Newtonsoft.Json.JsonConvert.DeserializeObject(ResponseHtml);
- if (AccessKeyJson.status != 200)
- {
- MessageBoxCustom.Show("添加相册时失败:" + AccessKeyJson.info);
- return;
- }
- }
- catch (Exception ex){
- MessageBoxCustom.Show("添加相册时出错:"+ex.Message);
- return;
- }
- // 插入数据与获取返回状态
- string[] str = ResponseHtml.Split(',');
- if (str.Length >= 3 && ResponseHtml.Contains("\"data\":"))
- {
- string str_data = str[0].ToString().Replace("{\"data\":", "");
- string str_info = str[1].ToString().Replace("info\":\"", "").Replace("\"", "");
- string str_status = str[2].ToString().Replace("\"status\":", "").Replace("}", "");
- switch (str_status)
- {
- //case "200":
- // MessageBoxCustom.Show("创建成功!");
- // break;
- case "201":
- MessageBoxCustom.Show("创建失败!");
- break;
- case "202":
- MessageBoxCustom.Show("时间超长,请关闭后在打开窗体!");
- break;
- case "203":
- MessageBoxCustom.Show("出现异常,可能是参数不正确");
- break;
- }
- #endregion
- #region 创建成功后上传图片获取二维码
- if (str_status == "200")
- {
- try
- {
- #region 上传图片
- FormUrl = domainName + "/index.php?m=Photo&a=upload";
- //string[] strUpload = ResponseHtmlUpLoad.Split(',');
- string pid = str_data;
- string strAdd = "pid=" + pid + "";
- for (int t = 0; t < strUpLoadName.Length - 1; t++)
- {
- int u = t + 1;
- string str_dataUpdate = strUpLoadName[t]; //strUpload[t].ToString().Replace("{data:[", "").Replace("}", "").Replace("]", "");
- // str_dataUpdate = str_dataUpdate.Split(',')[0].ToString().Replace("info\":\"", "").Replace("\"", "");
- string url = str_dataUpdate;
- string description = "";
- strAdd += "&photoid[]=" + Convert.ToInt32(u) + "&url[]=" + url + "&description=" + description + "";
- }
- ResponseHtml = HttpPost(FormUrl, strAdd);
-
- #endregion
- #region 获取二维码
- Random rad = new Random();
- FormUrl = domainName + "/index.php?m=Photo&a=getQrcode";
- pid = str_data;
- FormData = string.Format("pid={0}", pid); // 要发放的数据
- // string FileName = GetQrcodePath() + "\\" + F_Number + "(" + rad.Next(1000, 10000) + ")" + ".png";
- try
- {
- Bitmap retBmp = SavePhotoFromUrl(FormUrl, FormData);
- if (retBmp != null)
- {
- picTwoDimensionalCode.Image = retBmp;
- }
- else
- {
- MessageBoxCustom.Show("获取二维码失败");
- }
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show("显示二维码时出错:" + ex.Message);
- }
- #endregion
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show("提交相片信息时出错:"+ex.Message);
- }
- }
- }
- else
- {
- MessageBoxCustom.Show("上传出错:" + ResponseHtml);
- }
- #endregion
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show("上传失败,原因:" + ex.Message);
- }
- }
- #endregion
- #endregion
- #region post提交方法
- #region URL请求数据
- CookieContainer myCookieContainer = new CookieContainer();
- #region URL请求数据
- /// <summary>
- /// HTTP POST方式请求数据
- /// </summary>
- /// <param name="url">URL.</param>
- /// <param name="param">POST的数据</param>
- /// <returns></returns>
- public string HttpPost(string url, string param)
- {
- HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
- request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*";
- request.Method = "POST";
- request.ContentType = "application/x-www-form-urlencoded";
- request.Accept = "*/*";
- request.Timeout = 15000;
- request.AllowAutoRedirect = false;
- StreamWriter requestStream = null;
- WebResponse response = null;
- string responseStr = "";
- request.CookieContainer = myCookieContainer;
- try
- {
- requestStream = new StreamWriter(request.GetRequestStream());
- requestStream.Write(param);
- requestStream.Close();
- response = request.GetResponse();
- if (response != null)
- {
- StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
- responseStr = reader.ReadToEnd();
- reader.Close();
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- finally
- {
- request = null;
- requestStream = null;
- response = null;
- }
- return responseStr;
- }
- #endregion
- #endregion
- #region 向指定的URL地址发起一个POST请求,同时可以上传一些数据项以及上传文件。
- /// <summary>
- /// 向指定的URL地址发起一个POST请求,同时可以上传一些数据项以及上传文件。
- /// </summary>
- /// <param name="url">要请求的URL地址</param>
- /// <param name="keyvalues">要上传的数据项</param>
- /// <param name="fileList">要上传的文件列表</param>
- /// <param name="encoding">发送数据项,接收的字符编码方式</param>
- /// <returns>服务器的返回结果</returns>
- public string SendHttpRequestPost(string url, Hashtable keyvalues, Hashtable fileList, Encoding encoding)
- {
- //if (fileList == null)
- // return SendHttpRequestPost(url, keyvalues, encoding);
- if (string.IsNullOrEmpty(url))
- throw new ArgumentNullException("url");
- if (encoding == null)
- encoding = Encoding.UTF8;
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
- request.Method = "POST"; // 要上传文件,一定要是POST方法
- // 数据块的分隔标记,用于设置请求头,注意:这个地方最好不要使用汉字。
- string boundary = "---------------------------" + Guid.NewGuid().ToString("N");
- // 数据块的分隔标记,用于写入请求体。
- // 注意:前面多了一段: "--" ,而且它们将独占一行。
- byte[] boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
- // 设置请求头。指示是一个上传表单,以及各数据块的分隔标记。
- request.ContentType = "multipart/form-data; boundary=" + boundary;
- request.CookieContainer = myCookieContainer;
- // 先得到请求流,准备写入数据。
- Stream stream = request.GetRequestStream();
- //if (keyvalues != null && keyvalues.Count > 0)
- //{
- // // 写入非文件的keyvalues部分
- // //foreach (KeyValuePair<string, string> kvp in keyvalues)
- // foreach (DictionaryEntry kvp in keyvalues)
- // {
- // // 写入数据块的分隔标记
- // stream.Write(boundaryBytes, 0, boundaryBytes.Length);
- // // 写入数据项描述,这里的Value部分可以不用URL编码
- // string str = string.Format(
- // "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}",
- // kvp.Key, kvp.Value);
- // byte[] data = encoding.GetBytes(str);
- // stream.Write(data, 0, data.Length);
- // }
- //}
- // 写入要上传的文件
- foreach (DictionaryEntry kvp in fileList)//KeyValuePair<string, string> kvp
- {
- // 写入数据块的分隔标记
- stream.Write(boundaryBytes, 0, boundaryBytes.Length);
- string photoFile = kvp.Value.ToString();
- if (".jpg,.png.jpge".Contains(System.IO.Path.GetExtension(photoFile).ToLower().Trim()))
- {
- Bitmap bmp = LYFZ.BLL.SelectPhotoHandling.GeneratePreviewBitmap(photoFile, 640, 960);
- photoFile = LYFZ.ImageFunction.ThumbImgae.SaveTemporaryCompressionImage(bmp, System.IO.Path.GetFileName(photoFile));
- }
- // 写入文件描述,这里设置一个通用的类型描述:application/octet-stream,具体的描述在注册表里有。
- string description = string.Format(
- "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" +
- "Content-Type: application/octet-stream\r\n\r\n",
- kvp.Key, Path.GetFileName(photoFile.Trim()));
- // 注意:这里如果不使用UTF-8,对于汉字会有乱码。
- byte[] header = Encoding.UTF8.GetBytes(description);
- stream.Write(header, 0, header.Length);
- // 写入文件内容
- byte[] body = File.ReadAllBytes(photoFile.Trim());
- stream.Write(body, 0, body.Length);
- if (".jpg,.png.jpge".Contains(System.IO.Path.GetExtension(photoFile).ToLower().Trim()))
- {
- LYFZ.ImageFunction.ThumbImgae.DeleteTemporaryCompressionImage(photoFile);
- }
- }
- // 写入结束标记
- boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
- stream.Write(boundaryBytes, 0, boundaryBytes.Length);
- stream.Close();
- try
- {
-
- // 开始发起请求,并获取服务器返回的结果。
- using (WebResponse response = request.GetResponse())
- {
- request.Timeout = 300000;
- using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
- {
- return reader.ReadToEnd();
- }
- }
- }
- catch { return ""; }
- }
- #endregion
- #region 获取二维码方法
- #region 获取二维码方法Post
- /// <summary>
- /// 获取二维码方法
- /// </summary>
- /// <param name="ToLocalPath">图片本地磁盘地址</param>
- /// <param name="Url">图片网址</param>
- /// <returns></returns>
- public Bitmap SavePhotoFromUrl(string Url, string param)
- {
- Bitmap Value = null;
- WebResponse response = null;
- // Stream stream = null;
- try
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
- request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*";
- request.Method = "POST";
- request.ContentType = "application/x-www-form-urlencoded";
- request.Accept = "*/*";
- request.Timeout = 15000;
- request.AllowAutoRedirect = false;
- request.CookieContainer = myCookieContainer;
- StreamWriter requestStream = null;
- requestStream = new StreamWriter(request.GetRequestStream());
- requestStream.Write(param);
- requestStream.Close();
- response = request.GetResponse();
- // stream = response.GetResponseStream();
- if (!response.ContentType.ToLower().StartsWith("text/"))
- {
- //Value = SaveBinaryFile(response, FileName);
- MemoryStream ImageMS = GetBinaryFileMemoryStream(response);
- if (ImageMS != null)
- {
- Bitmap tempBmp = new Bitmap(ImageMS);
- Value = new Bitmap(tempBmp);
- tempBmp.Dispose();
- ImageMS.Close();
- ImageMS.Dispose();
- }
- response.Close();
-
- }
- }
- catch
- {
- }
- return Value;
- }
- private static MemoryStream GetBinaryFileMemoryStream(WebResponse response)
- {
- byte[] buffer = new byte[1024];
- MemoryStream ImageMS = new MemoryStream();
- try
- {
- Stream inStream = response.GetResponseStream();
- int l;
- do
- {
- l = inStream.Read(buffer, 0, buffer.Length);
- if (l > 0)
- ImageMS.Write(buffer, 0, l);
- }
- while (l > 0);
- inStream.Close();
- }
- catch
- {
- ImageMS = null;
- }
- return ImageMS;
- }
- #endregion
- #region 获取二维码方法Post
- /// <summary>
- /// 获取二维码方法
- /// </summary>
- /// <param name="ToLocalPath">图片本地磁盘地址</param>
- /// <param name="Url">图片网址</param>
- /// <returns></returns>
- public bool SavePhotoFromUrl(string FileName, string Url, string param)
- {
- bool Value = false;
- WebResponse response = null;
- Stream stream = null;
- try
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
- request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*";
- request.Method = "POST";
- request.ContentType = "application/x-www-form-urlencoded";
- request.Accept = "*/*";
- request.Timeout = 15000;
- request.AllowAutoRedirect = false;
- request.CookieContainer = myCookieContainer;
- StreamWriter requestStream = null;
- requestStream = new StreamWriter(request.GetRequestStream());
- requestStream.Write(param);
- requestStream.Close();
- response = request.GetResponse();
- stream = response.GetResponseStream();
- if (!response.ContentType.ToLower().StartsWith("text/"))
- {
- Value = SaveBinaryFile(response, FileName);
- }
- }
- catch (Exception err)
- {
- string aa = err.ToString();
- }
- return Value;
- }
- #endregion
- #region 将二进制文件保存到磁盘
- private static bool SaveBinaryFile(WebResponse response, string FileName)
- {
- bool Value = true;
- byte[] buffer = new byte[1024];
- try
- {
- if (File.Exists(FileName))
- File.Delete(FileName);
- Stream outStream = System.IO.File.Create(FileName);
- Stream inStream = response.GetResponseStream();
- int l;
- do
- {
- l = inStream.Read(buffer, 0, buffer.Length);
- if (l > 0)
- outStream.Write(buffer, 0, l);
- }
- while (l > 0);
- outStream.Close();
- inStream.Close();
- }
- catch
- {
- Value = false;
- }
- return Value;
- }
- #endregion
- #endregion
- #endregion
- #region 获取二维码目录
- /// <summary>
- /// 获取二维码目录
- /// </summary>
- public string GetQrcodePath()
- {
- LYFZ.Model.Model_Config mConfig = new LYFZ.BLL.BLL_Config().GetModel_SysConfig();
- string tempPath = "\\\\" + mConfig.ServerHostOrIP + "\\ShareDirectory$\\Qrcode\\" + F_Number;
- if (!System.IO.Directory.Exists(tempPath))
- {
- System.IO.Directory.CreateDirectory(tempPath);
- }
- return tempPath;
- }
- #endregion
- }
- }
|