using AllBase; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using TemuKJD.BaseForms; using Work; using Work.BLL.Tools; namespace TemuKJD.WXForms.AdminForms { public partial class WXAdminSetTopUpQrCodeForm : Form { public WXAdminSetTopUpQrCodeForm() { InitializeComponent(); } private void btnUploadImg_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Multiselect = false; // 设置过滤条件,只显示文本文件 openFileDialog.Filter = "图片文件 (*.jpeg;*.jpg;*.png)|*.jpeg;*.jpg;*.png|All files (*.*)|*.*"; // 显示对话框并获取结果 if (openFileDialog.ShowDialog() == DialogResult.OK) { try { string filePath = openFileDialog.FileName; Image image = Image.FromFile(filePath); string imgBase64 = ""; using (MemoryStream memoryStream = new MemoryStream()) { image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] imageBytes = memoryStream.ToArray(); imgBase64 = Convert.ToBase64String(imageBytes); } var url = BaseClass.BuildWXObjString("user/update_top_up_qrcode"); var data = UserLogin.GetSignaturex(); data += "&qrcode_base64=" + imgBase64; var html = GetHtml.PostUtf8(url, data); if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) { var msg = BaseRegex.GetStringJson(ref html, "msg"); } refreshQrcode(); } catch (Exception ex) { BaseMsgForm.ShowError("打开二维码图片失败 " + ex.Message); return; } } } private void WXAdminSetTopUpQrCodeForm_Load(object sender, EventArgs e) { refreshQrcode(); } public void refreshQrcode() { var url = BaseClass.BuildWXObjString("user/get_top_up_qrcode"); var data = UserLogin.GetSignaturex(); var html = GetHtml.PostUtf8(url, data); if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) { var msg = BaseRegex.GetStringJson(ref html, "msg"); BaseMsgForm.ShowError(msg); } else { var base64Str = BaseRegex.GetStringJson(ref html, "qrcode_base64"); if (!string.IsNullOrEmpty(base64Str)) pictureBox1.Image = Base64ChangeImgUrl.Base64ToImage(base64Str); } } private void btnRefresh_Click(object sender, EventArgs e) { refreshQrcode(); } } }