|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- using Common.system;
-
- using Newtonsoft.Json.Linq;
-
- using System;
- using System.Collections.Specialized;
- using System.Threading;
-
- using XHWK.Model;
-
- namespace XHWK.WKTool.DAL
- {
- /// <summary>
- /// TQL在线铺码服务-改为SDK 暂无用
- /// </summary>
- public class DAL_TmatrixCode
- {
- /// <summary>
- /// TQL铺码地址
- /// </summary>
- private string TmatrixCodeURL = APP.TmatrixCodeURL;
- /// <summary>
- /// TQL用户名
- /// </summary>
- string TQLUserName = "test122";
- /// <summary>
- /// TQL密码
- /// </summary>
- string TQLPassword = "123456";
- /// <summary>
- /// 用户登陆后的用户ID
- /// </summary>
- string UserID;
- /// <summary>
- /// 分配的铺码 ID
- /// </summary>
- string pageserial;
- //1000 操作成功
- //1001 打开数据库失败
- //1002 用户名或密码错误
- //1003 Key 信息错误(过期或已使用完)
- //1004 上传 Pdf 文档无法打开
- //1005 铺码初始化失败
- //1006 铺码错误
- //1007 Json 数据错误
- //1008 接口错误
- //1009 UserID 错误
- //1010 未查到该历史数据
- /// <summary>
- /// TQL登陆
- /// </summary>
- /// <param name="Message"></param>
- /// <returns></returns>
- public bool TQLUserLogin(out string Message)
- {
- Exception ex = null;
- Message = "";//请求重试5次 共5秒
- for (int num = 0; num < 5; num++)
- {
- try
- {
- JObject jo = HttpHelper.PostFunction(TmatrixCodeURL + @"/TmatrixCode/User/UserLogin", @"application/x-www-form-urlencoded", @"userName=" + TQLUserName + "&password=" + TQLPassword, "");
- if (jo == null)
- {
- Message = "无法访问铺码服务器,请检查网络或铺码服务器地址。";
- return false;
- }
- //"state":"1000",
- //"message":"File upload was succeed!",
- //" userID ":"1"
- //1000 操作成功
- if (jo["state"].ToString() == "1000")
- {
- Message = "";
- //登陆成功后用户ID
- UserID = jo["userID"].ToString();
- return true;
- }
- else
- {
- Message = jo["message"].ToString();
- return false;
- }
- }
- catch (Exception e)
- {
- Message = "无法访问铺码服务器:" + e.Message;
- ex = e;
- Thread.Sleep(1000);
- }
- }
- string ErrMessage = "【TQL登陆】(TQLUserLogin):请求失败。" + Message;
- LogHelper.WriteErrLog(ErrMessage, ex);
- return false;
- }
-
- /// <summary>
- /// TQL上传文件
- /// </summary>
- /// <param name="filePath">文件路径</param>
- /// <param name="fileName">文件名</param>
- /// <param name="Message"></param>
- /// <returns></returns>
- public bool TQLStartTmatrix(string filePath, string fileName, out string Message)
- {
- Exception ex = null;
- Message = "";//请求重试5次 共5秒
- if (string.IsNullOrWhiteSpace(UserID))
- {
- if (!TQLUserLogin(out Message))
- {
- return false;
- }
- }
- for (int num = 0; num < 5; num++)
- {
- try
- {
- //byte[] byteArray = FileToolsCommon.ReadBigFileSpecifyLength(VideoInfo.VideoPath, len, (int)VideoInfo.SliceLen);
- //userID Y 字符 登录之后分配的 ID
- //callBack Y 回调 API 该 API 由应用方提供,为 post 请求
- //createimage Y 字符 是否生成 png 图片(若生 成则会进行文件打包成 zip)0,不生成,1 生 成。
- //fileName Y 字符 文件名称数组
- //tmatrixType Y 字符 铺码类型(0.600DPI 打 印、1.1200DPI 打印、 2.印刷
- //fileData
- //参数
- NameValueCollection formFields = new NameValueCollection
- {
- { "userID", UserID },
- { "callBack", ""},
- { "createimage", "0" },
- { "fileName", fileName },
- { "tmatrixType", "1" }
- };
- string[] PathList = new string[] { filePath };
- JObject jo = HttpHelper.UploadFilesToRemoteUrl(TmatrixCodeURL + @"/TmatrixCode/User/startTmatrix", PathList, "", formFields);
- if (jo == null)
- {
- Message = "无法访问铺码服务器,请检查网络或铺码服务器地址。";
- return false;
- }
- Model_TmatrixCode resultObj = JsonHelper.JsonToObj<Model_TmatrixCode>(jo.ToString());
-
- //1000 操作成功
- if (resultObj.state == "1000")
- {
- Message = "";
- pageserial = resultObj.pageserial;
- return true;
- }
- else
- {
- Message = resultObj.message;
- return false;
- }
- }
- catch (Exception e)
- {
- Message = "无法访问铺码服务器:" + e.Message;
- ex = e;
- Thread.Sleep(1000);
- }
- }
- string ErrMessage = "【TQL上传】(TQLStartTmatrix):请求失败。" + Message;
- LogHelper.WriteErrLog(ErrMessage, ex);
- return false;
- }
-
- /// <summary>
- /// 查询进度
- /// </summary>
- /// <param name="Message"></param>
- /// <returns>-1失败 0:未铺码 1:正在铺码 2:铺码完成,3:未查到。</returns>
- public int TQLSchedulequery(out string Message)
- {
- Exception ex = null;
- Message = "";//请求重试5次 共5秒
- for (int num = 0; num < 5; num++)
- {
- try
- {
- string[] pageserialList = new string[] { pageserial };
- JObject jo = HttpHelper.PostFunction(TmatrixCodeURL + @"/TmatrixCode/User/schedulequery", @"application/x-www-form-urlencoded", @"userID=" + UserID + "&pageserialList=" + pageserialList, "");
- if (jo == null)
- {
- Message = "无法访问铺码服务器,请检查网络或铺码服务器地址。";
- return -1;
- }
- Model_ScheduleQuery resultObj = JsonHelper.JsonToObj<Model_ScheduleQuery>(jo.ToString());
-
- //1000 操作成功
- if (resultObj.state == "1000")
- {
- //state Y 字符 返回标志
- //message Y 字符 返回标志说明
- //list Y 字符 进度数组
- //schedule Y 字符 返回铺码进度:0 - 100
- //pageserial 铺码 ID 字符 铺码 ID
- //state Y 数字 0:未铺码 1:正在铺码 2:铺码完成,3:未查到。
- Message = "";
- return int.Parse(resultObj.list.Find(x => x.pageserial == pageserial).state);
- }
- else
- {
- Message = resultObj.message;
- return -1;
- }
- }
- catch (Exception e)
- {
- Message = "无法访问铺码服务器:" + e.Message;
- ex = e;
- Thread.Sleep(1000);
- }
- }
- string ErrMessage = "【TQL查询进度】(TQLSchedulequery):请求失败。" + Message;
- LogHelper.WriteErrLog(ErrMessage, ex);
- return -1;
- }
-
- /// <summary>
- /// TQL历史查询
- /// </summary>
- /// <param name="Message"></param>
- /// <returns></returns>
- public string TQLHistoryQuery(string fileName, string startPage, string maxPage, out string Message)
- {
- Exception ex = null;
- Message = "";//请求重试5次 共5秒
- for (int num = 0; num < 5; num++)
- {
- try
- {
- //userID Y 字符 登录之后分配的 ID
- //fileName N 字符 查询文件名称
- //pageserial N 字符 铺码 ID(铺码 ID 或文件名必须设置一个)
- //startPage Y int 开始查询页码,从 1 开 始
- //maxPage Y int 最大页码数
- JObject jo = HttpHelper.PostFunction(TmatrixCodeURL + @"/TmatrixCode/User/HistoryQuery", @"application/x-www-form-urlencoded", @"userID=" + UserID + "&fileName=" + fileName + "&pageserial=" + pageserial + "&startPage=" + startPage + "&maxPage=" + maxPage, "");
- if (jo == null)
- {
- Message = "无法访问铺码服务器,请检查网络或铺码服务器地址。";
- return "";
- }
-
- Model_HistoryQuery resultObj = JsonHelper.JsonToObj<Model_HistoryQuery>(jo.ToString());
- //1000 操作成功
- if (resultObj.state == "1000")
- {
- Message = "";
- Model_HistoryPageList model_HistoryPageList = resultObj.pageList[0];
- Model_HistoryListItem model_HistoryListItem = model_HistoryPageList.list.Find(x => x.pageserial == pageserial);
-
- return model_HistoryListItem.url;
- }
- else
- {
- Message = resultObj.message;
- return "";
- }
- }
- catch (Exception e)
- {
- Message = "无法访问铺码服务器:" + e.Message;
- ex = e;
- Thread.Sleep(1000);
- }
- }
- string ErrMessage = "【TQL查询历史记录】(TQLHistoryQuery):请求失败。" + Message;
- LogHelper.WriteErrLog(ErrMessage, ex);
- return "";
- }
- }
- }
|