115 lines
3.7 KiB
C#
115 lines
3.7 KiB
C#
using Mini.Common;
|
||
using Mini.Model;
|
||
using Mini.Model.Entity;
|
||
using Mini.Model.Enum;
|
||
using Mini.Services.Bas;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using ThoughtWorks.QRCode.Codec;
|
||
using ThoughtWorks.QRCode.Codec.Data;
|
||
|
||
namespace Mini.Web.WebHelper
|
||
{
|
||
/// <summary>
|
||
/// 是否显示二维码
|
||
/// </summary>
|
||
public class MangerEWM
|
||
{
|
||
private static IBasConfigService config = new BasConfigService(new EfAdminRepository<Bas_Config>(new crmContext()));
|
||
/// <summary>
|
||
/// 是否隐藏图片中的二维码
|
||
/// </summary>
|
||
/// <param name="role"></param>
|
||
/// <returns></returns>
|
||
public static string GetIsHiddenEWM(string[] role)
|
||
{
|
||
var ewmconfig = config.GetConfig(BasConfigEnums.HiddenEWM);//获取配置信息
|
||
if (ewmconfig == "1" && !role.Contains("XSTPEWM"))
|
||
return "1";
|
||
else
|
||
return "0";
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 识别图片二唯码
|
||
/// </summary>
|
||
/// <param name="filepath">图片本地存储路径</param>
|
||
/// <returns>返回为空,图片不含二唯码,不空则为二唯码图片</returns>
|
||
public static string QcodeString(string file)
|
||
{
|
||
string decoderStr = "";
|
||
try
|
||
{
|
||
QRCodeDecoder decoder = new QRCodeDecoder();
|
||
Bitmap bitmap = new Bitmap(file);
|
||
//将文件流写到byte数组中
|
||
decoderStr = decoder.decode(new QRCodeBitmapImage(bitmap));
|
||
//LogHelper.Error($"地址:{file} 二维码识别:{decoderStr}");
|
||
bitmap.Dispose();
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
//LogHelper.Error(e.ToString()+",错误地址:"+ file);
|
||
if (e.Message.ToString().IndexOf("Give up decoding") >= 0)
|
||
{
|
||
decoderStr = "unknow";
|
||
}
|
||
}
|
||
return decoderStr;
|
||
}
|
||
|
||
public static MediaResult GetNoQcodeImg(string url)
|
||
{
|
||
MediaResult result = new MediaResult();
|
||
try
|
||
{
|
||
string newurl = url.Replace("mediafile", "mediafilepath");
|
||
string wocha = Utility.GetData(newurl, "", Encoding.UTF8);//获取json数据
|
||
var mediapaths = Newtonsoft.Json.JsonConvert.DeserializeObject<mediapath>(wocha);
|
||
if (mediapaths == null)
|
||
{
|
||
result.code = 3;
|
||
}
|
||
result.local = mediapaths.local;
|
||
if (!string.IsNullOrEmpty(QcodeString(mediapaths.local)))//不为空,找到了是二维码图片
|
||
{
|
||
result.code = 2;
|
||
}
|
||
else
|
||
{
|
||
result.code = 1;//正常的图片,然后对图片url进行处理
|
||
result.returnrul = url.Replace("http://","").Substring(0, url.IndexOf("/")) + mediapaths.url;
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
result.code = 3;
|
||
LogHelper.Error("错误:" + url + "**" + e.ToString());
|
||
}
|
||
return result;
|
||
}
|
||
|
||
}
|
||
public class mediapath
|
||
{
|
||
public string local { get; set; }
|
||
public string url { get; set; }
|
||
}
|
||
public class MediaResult
|
||
{
|
||
/// <summary>
|
||
/// 1:正常
|
||
/// 2:二维码图片
|
||
/// 3:发生了错误
|
||
/// </summary>
|
||
public int code { get; set; }
|
||
public string returnrul { get; set; }
|
||
public string local { get; set; }
|
||
}
|
||
}
|