星火微课系统客户端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

DAL_TmatrixCode.cs 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. using Common.system;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Collections.Specialized;
  5. using System.Threading;
  6. using XHWK.Model;
  7. namespace XHWK.WKTool.DAL
  8. {
  9. /// <summary>
  10. /// TQL在线铺码服务-改为SDK 暂无用
  11. /// </summary>
  12. public class DAL_TmatrixCode
  13. {
  14. /// <summary>
  15. /// TQL铺码地址
  16. /// </summary>
  17. private string TmatrixCodeURL = APP.TmatrixCodeURL;
  18. /// <summary>
  19. /// TQL用户名
  20. /// </summary>
  21. string TQLUserName = "test122";
  22. /// <summary>
  23. /// TQL密码
  24. /// </summary>
  25. string TQLPassword = "123456";
  26. /// <summary>
  27. /// 用户登陆后的用户ID
  28. /// </summary>
  29. string UserID;
  30. /// <summary>
  31. /// 分配的铺码 ID
  32. /// </summary>
  33. string pageserial;
  34. //1000 操作成功
  35. //1001 打开数据库失败
  36. //1002 用户名或密码错误
  37. //1003 Key 信息错误(过期或已使用完)
  38. //1004 上传 Pdf 文档无法打开
  39. //1005 铺码初始化失败
  40. //1006 铺码错误
  41. //1007 Json 数据错误
  42. //1008 接口错误
  43. //1009 UserID 错误
  44. //1010 未查到该历史数据
  45. /// <summary>
  46. /// TQL登陆
  47. /// </summary>
  48. /// <param name="Message"></param>
  49. /// <returns></returns>
  50. public bool TQLUserLogin(out string Message)
  51. {
  52. Exception ex = null;
  53. Message = "";//请求重试5次 共5秒
  54. for (int num = 0; num < 5; num++)
  55. {
  56. try
  57. {
  58. JObject jo = HttpHelper.PostFunction(TmatrixCodeURL + @"/TmatrixCode/User/UserLogin", @"application/x-www-form-urlencoded", @"userName=" + TQLUserName + "&password=" + TQLPassword, "");
  59. if (jo == null)
  60. {
  61. Message = "无法访问铺码服务器,请检查网络或铺码服务器地址。";
  62. return false;
  63. }
  64. //"state":"1000",
  65. //"message":"File upload was succeed!",
  66. //" userID ":"1"
  67. //1000 操作成功
  68. if (jo["state"].ToString() == "1000")
  69. {
  70. Message = "";
  71. //登陆成功后用户ID
  72. UserID = jo["userID"].ToString();
  73. return true;
  74. }
  75. else
  76. {
  77. Message = jo["message"].ToString();
  78. return false;
  79. }
  80. }
  81. catch (Exception e)
  82. {
  83. Message = "无法访问铺码服务器:" + e.Message;
  84. ex = e;
  85. Thread.Sleep(1000);
  86. }
  87. }
  88. string ErrMessage = "【TQL登陆】(TQLUserLogin):请求失败。" + Message;
  89. LogHelper.WriteErrLog(ErrMessage, ex);
  90. return false;
  91. }
  92. /// <summary>
  93. /// TQL上传文件
  94. /// </summary>
  95. /// <param name="filePath">文件路径</param>
  96. /// <param name="fileName">文件名</param>
  97. /// <param name="Message"></param>
  98. /// <returns></returns>
  99. public bool TQLStartTmatrix(string filePath, string fileName, out string Message)
  100. {
  101. Exception ex = null;
  102. Message = "";//请求重试5次 共5秒
  103. if (string.IsNullOrWhiteSpace(UserID))
  104. {
  105. if (!TQLUserLogin(out Message))
  106. {
  107. return false;
  108. }
  109. }
  110. for (int num = 0; num < 5; num++)
  111. {
  112. try
  113. {
  114. //byte[] byteArray = FileToolsCommon.ReadBigFileSpecifyLength(VideoInfo.VideoPath, len, (int)VideoInfo.SliceLen);
  115. //userID Y 字符 登录之后分配的 ID
  116. //callBack Y 回调 API 该 API 由应用方提供,为 post 请求
  117. //createimage Y 字符 是否生成 png 图片(若生 成则会进行文件打包成 zip)0,不生成,1 生 成。
  118. //fileName Y 字符 文件名称数组
  119. //tmatrixType Y 字符 铺码类型(0.600DPI 打 印、1.1200DPI 打印、 2.印刷
  120. //fileData
  121. //参数
  122. NameValueCollection formFields = new NameValueCollection
  123. {
  124. { "userID", UserID },
  125. { "callBack", ""},
  126. { "createimage", "0" },
  127. { "fileName", fileName },
  128. { "tmatrixType", "1" }
  129. };
  130. string[] PathList = new string[] { filePath };
  131. JObject jo = HttpHelper.UploadFilesToRemoteUrl(TmatrixCodeURL + @"/TmatrixCode/User/startTmatrix", PathList, "", formFields);
  132. if (jo == null)
  133. {
  134. Message = "无法访问铺码服务器,请检查网络或铺码服务器地址。";
  135. return false;
  136. }
  137. Model_TmatrixCode resultObj = JsonHelper.JsonToObj<Model_TmatrixCode>(jo.ToString());
  138. //1000 操作成功
  139. if (resultObj.state == "1000")
  140. {
  141. Message = "";
  142. pageserial = resultObj.pageserial;
  143. return true;
  144. }
  145. else
  146. {
  147. Message = resultObj.message;
  148. return false;
  149. }
  150. }
  151. catch (Exception e)
  152. {
  153. Message = "无法访问铺码服务器:" + e.Message;
  154. ex = e;
  155. Thread.Sleep(1000);
  156. }
  157. }
  158. string ErrMessage = "【TQL上传】(TQLStartTmatrix):请求失败。" + Message;
  159. LogHelper.WriteErrLog(ErrMessage, ex);
  160. return false;
  161. }
  162. /// <summary>
  163. /// 查询进度
  164. /// </summary>
  165. /// <param name="Message"></param>
  166. /// <returns>-1失败 0:未铺码 1:正在铺码 2:铺码完成,3:未查到。</returns>
  167. public int TQLSchedulequery(out string Message)
  168. {
  169. Exception ex = null;
  170. Message = "";//请求重试5次 共5秒
  171. for (int num = 0; num < 5; num++)
  172. {
  173. try
  174. {
  175. string[] pageserialList = new string[] { pageserial };
  176. JObject jo = HttpHelper.PostFunction(TmatrixCodeURL + @"/TmatrixCode/User/schedulequery", @"application/x-www-form-urlencoded", @"userID=" + UserID + "&pageserialList=" + pageserialList, "");
  177. if (jo == null)
  178. {
  179. Message = "无法访问铺码服务器,请检查网络或铺码服务器地址。";
  180. return -1;
  181. }
  182. Model_ScheduleQuery resultObj = JsonHelper.JsonToObj<Model_ScheduleQuery>(jo.ToString());
  183. //1000 操作成功
  184. if (resultObj.state == "1000")
  185. {
  186. //state Y 字符 返回标志
  187. //message Y 字符 返回标志说明
  188. //list Y 字符 进度数组
  189. //schedule Y 字符 返回铺码进度:0 - 100
  190. //pageserial 铺码 ID 字符 铺码 ID
  191. //state Y 数字 0:未铺码 1:正在铺码 2:铺码完成,3:未查到。
  192. Message = "";
  193. return int.Parse(resultObj.list.Find(x => x.pageserial == pageserial).state);
  194. }
  195. else
  196. {
  197. Message = resultObj.message;
  198. return -1;
  199. }
  200. }
  201. catch (Exception e)
  202. {
  203. Message = "无法访问铺码服务器:" + e.Message;
  204. ex = e;
  205. Thread.Sleep(1000);
  206. }
  207. }
  208. string ErrMessage = "【TQL查询进度】(TQLSchedulequery):请求失败。" + Message;
  209. LogHelper.WriteErrLog(ErrMessage, ex);
  210. return -1;
  211. }
  212. /// <summary>
  213. /// TQL历史查询
  214. /// </summary>
  215. /// <param name="Message"></param>
  216. /// <returns></returns>
  217. public string TQLHistoryQuery(string fileName, string startPage, string maxPage, out string Message)
  218. {
  219. Exception ex = null;
  220. Message = "";//请求重试5次 共5秒
  221. for (int num = 0; num < 5; num++)
  222. {
  223. try
  224. {
  225. //userID Y 字符 登录之后分配的 ID
  226. //fileName N 字符 查询文件名称
  227. //pageserial N 字符 铺码 ID(铺码 ID 或文件名必须设置一个)
  228. //startPage Y int 开始查询页码,从 1 开 始
  229. //maxPage Y int 最大页码数
  230. JObject jo = HttpHelper.PostFunction(TmatrixCodeURL + @"/TmatrixCode/User/HistoryQuery", @"application/x-www-form-urlencoded", @"userID=" + UserID + "&fileName=" + fileName + "&pageserial=" + pageserial + "&startPage=" + startPage + "&maxPage=" + maxPage, "");
  231. if (jo == null)
  232. {
  233. Message = "无法访问铺码服务器,请检查网络或铺码服务器地址。";
  234. return "";
  235. }
  236. Model_HistoryQuery resultObj = JsonHelper.JsonToObj<Model_HistoryQuery>(jo.ToString());
  237. //1000 操作成功
  238. if (resultObj.state == "1000")
  239. {
  240. Message = "";
  241. Model_HistoryPageList model_HistoryPageList = resultObj.pageList[0];
  242. Model_HistoryListItem model_HistoryListItem = model_HistoryPageList.list.Find(x => x.pageserial == pageserial);
  243. return model_HistoryListItem.url;
  244. }
  245. else
  246. {
  247. Message = resultObj.message;
  248. return "";
  249. }
  250. }
  251. catch (Exception e)
  252. {
  253. Message = "无法访问铺码服务器:" + e.Message;
  254. ex = e;
  255. Thread.Sleep(1000);
  256. }
  257. }
  258. string ErrMessage = "【TQL查询历史记录】(TQLHistoryQuery):请求失败。" + Message;
  259. LogHelper.WriteErrLog(ErrMessage, ex);
  260. return "";
  261. }
  262. }
  263. }