/// <summary> /// 获取个人小程序码图片 /// </summary> /// <param name="path">小程序码跳转的路径</param> /// <param name="session">用户session</param> /// <returns></returns> public string GetUserQRCode(string path, string session) { HF.Cloud.BLL.Common.Logger.Error("GetUserQRCode方法,参数path:" + path + "------session:" + session); string imgPath = ""; //判断数据库中是否有值 SB_UserEL userEL = GetUserELBySession(session); //如果QRCode有值,则返回数据库中QRCode的值 if (!string.IsNullOrEmpty(userEL.QRCode) && userEL.QRCode != "") { //获取图片名称 string qrCodeImageName = userEL.QRCode; //获取图片路径 string qrCodeImagePath = System.Configuration.ConfigurationManager.AppSettings["QRCodeGet_User"]; imgPath = qrCodeImagePath + qrCodeImageName; } //数据库中QRCode没有数据,则需要获取小程序码图片保存图片,并把图片名称保存到数据库中 else { //获取token WX_TokenBLL tokenBLL = new WX_TokenBLL(); string token = tokenBLL.GetToken(); //获取小程序码接口 string url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + token; Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("path", path); JavaScriptSerializer js = new JavaScriptSerializer(); js.MaxJsonLength = int.MaxValue; string json = js.Serialize(dic); HF.Cloud.BLL.Common.Logger.Error("GetUserQRCode方法,获取小程序码的json:" + json); HF.Cloud.BLL.Common.Logger.Error("GetUserQRCode方法,url:" + url + "-----Path:" + path); //post返回的小程序码流 Stream QRCodeStream = WeChatAppDecrypt.Post(url, json); //将图片流转换成图片 Bitmap tp = new Bitmap(QRCodeStream); string QRCodeSave_User = System.Configuration.ConfigurationManager.AppSettings["QRCodeSave_User"]; string image_userName = Guid.NewGuid().ToString(); string qrCodeImageName = image_userName + ".jpg"; HF.Cloud.BLL.Common.Logger.Error("GetUserQRCode方法,保存小程序图片路径名称:" + QRCodeSave_User + qrCodeImageName); tp.Save(QRCodeSave_User + qrCodeImageName); //把小程序码图片名称保存到数据库中 userEL.QRCode = qrCodeImageName; int ra; long returnValue = userEL.ExecNonQuery(27, out ra); HF.Cloud.BLL.Common.Logger.Error("GetUserQRCode方法,保存小程序图片名称结果:" + ra); if (ra > 0) { string QRCodeGet_User = System.Configuration.ConfigurationManager.AppSettings["QRCodeGet_User"]; imgPath = QRCodeGet_User + qrCodeImageName; } else { imgPath = "error"; } } HF.Cloud.BLL.Common.Logger.Error("GetUserQRCode方法,返回的结果:" + imgPath); return(imgPath); }
/// <summary> /// 获取群组小程序码图片路径 /// </summary> /// <param name="path">小程序码跳转路径</param> /// <param name="groupID">群组ID</param> /// <returns></returns> public string GetQRCode_Group(string path, string groupID) { HF.Cloud.BLL.Common.Logger.Error("GetQRCode_Group方法,获取的参数path:" + path + "------groupID:" + groupID); string imgPath = ""; //判断数据库中是否有值 GroupEL groupEL = new GroupEL(); groupEL.ID = long.Parse(groupID); DataTable dt = groupEL.ExecDT(3); HF.Cloud.BLL.Common.Logger.Error("GetQRCode_Group方法,查找群组记录:" + dt.Rows.Count); if (dt != null && dt.Rows.Count > 0) { //如果数据库中"QRCode"有值,则从数据库中取值 if (!string.IsNullOrEmpty(dt.Rows[0]["QRCode"].ToString()) && dt.Rows[0]["QRCode"].ToString() != "") { //获取图片名称 string qrCodeImageName = dt.Rows[0]["QRCode"].ToString(); //获取图片路径 string qrCodeImagePath = System.Configuration.ConfigurationManager.AppSettings["QRCodeGet_Group"]; imgPath = qrCodeImagePath + qrCodeImageName; } //如果没有值则请求小程序服务器获取小程序码图片,并把图片名称保存到数据库中 else { //获取token WX_TokenBLL tokenBLL = new WX_TokenBLL(); string token = tokenBLL.GetToken(); //获取小程序码接口 string url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + token; Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("path", path); JavaScriptSerializer js = new JavaScriptSerializer(); js.MaxJsonLength = int.MaxValue; string json = js.Serialize(dic); HF.Cloud.BLL.Common.Logger.Error("GetQRCode_Group方法,url:" + url + "-----Path:" + path); //post返回的小程序码流 Stream QRCodeStream = WeChatAppDecrypt.Post(url, json); //将图片流转换成图片 Bitmap tp = new Bitmap(QRCodeStream); string QRCodeSave_Group = System.Configuration.ConfigurationManager.AppSettings["QRCodeSave_Group"]; string image_userName = Guid.NewGuid().ToString(); string qrCodeImageName = image_userName + ".jpg"; tp.Save(QRCodeSave_Group + qrCodeImageName); //把小程序码图片名称保存到数据库中 groupEL.QRCode = qrCodeImageName; int ra; long returnValue = groupEL.ExecNonQuery(21, out ra); HF.Cloud.BLL.Common.Logger.Error("GetQRCode_Group方法,保存小程序图片名称结果:" + ra); if (ra > 0) { string QRCodeGet_Group = System.Configuration.ConfigurationManager.AppSettings["QRCodeGet_Group"]; imgPath = QRCodeGet_Group + qrCodeImageName; } else { imgPath = "error"; } } } else { imgPath = "error"; } HF.Cloud.BLL.Common.Logger.Error("GetQRCode_Group方法,小程序码图片路径:" + imgPath); return(imgPath); }