IA300ClientJavascript.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /*******************************************************
  2. *
  3. * 使用此JS脚本之前请先仔细阅读IA300帮助文档!
  4. *
  5. * @author Fuly
  6. * @version 3.0
  7. * @date 2012/6/28
  8. * @explanation IA300 v3.0版用户存储区和安全存储区扩大至2K,增加
  9. * 相应的扩展函数操作这两个区域同时保留之前操作存储区的函数
  10. *
  11. **********************************************************/
  12. var _IA300Client;
  13. var _TimerErrorMessage;
  14. var _ExpireUrl;
  15. function IA300_GetInstance()
  16. {
  17. if(_IA300Client == null)
  18. {
  19. _IA300Client = document.getElementById("IA300Client");
  20. }
  21. _IA300Client.Model = 0;
  22. return _IA300Client;
  23. }
  24. /*******************************************************
  25. *
  26. * 函数名称:IA300_CheckPassword()
  27. * 功 能:打开 USB Key
  28. * 输 入:password:页面传递进来的密码,是USB Key的用户密码
  29. * 返 回 值:返回值为0即成功,1为失败,用户密码不正确
  30. * 说 明:此方法未打开方法,也是第判断USB Key是否合法的USB Key
  31. *
  32. **********************************************************/
  33. function IA300_CheckPassword(password)
  34. {
  35. return IA300_GetInstance().IA300Open(password);
  36. }
  37. /*******************************************************
  38. *
  39. * 函数名称:IA300_LogOut()
  40. * 功 能:登出IA300USB Key
  41. * 返 回 值:返回0则表示登出成功,否则为失败
  42. * 说 明:和IA300Open成对使用,有打开则必须有登出USB Key
  43. *
  44. **********************************************************/
  45. function IA300_LogOut() {
  46. return IA300_GetInstance().IA300Close();
  47. }
  48. /*******************************************************
  49. *
  50. * 函数名称:IA300_GetLastError()
  51. * 功 能:获取IA300函数执行失败的错误码
  52. * 返 回 值:返回值为错误代号
  53. * 说 明:获取USB Key最后一次执行失败的错误信息,可结合帮
  54. * 助文档或设号工具查询错误信息
  55. *
  56. **********************************************************/
  57. function IA300_GetLastError()
  58. {
  59. return IA300_GetInstance().IA300GetLastError();
  60. }
  61. /*******************************************************
  62. *
  63. * 函数名称:IA300_GetHardwareId()
  64. * 功 能:获取USB Key的硬件ID
  65. * 返 回 值:返回值为该USB Key的硬件ID,返回NULL为失败
  66. * 说 明:获取IA300USB Key唯一硬件ID,若未获取到,可使用
  67. * IA300_GetLastError()方法来获取错误吗,然后查明
  68. * 错误原因
  69. *
  70. **********************************************************/
  71. function IA300_GetHardwareId()
  72. {
  73. return IA300_GetInstance().IA300GetUID();
  74. }
  75. /*******************************************************
  76. *
  77. * 函数名称:IA300_RequestEnabled()
  78. * 功 能:检查USB Key远程申请注册功能是否打开
  79. * 返 回 值:返回值为0即禁止,1为打开
  80. * 说 明:远程申请时请查找Key后调用此方法
  81. *
  82. **********************************************************/
  83. function IA300_RequestEnabled()
  84. {
  85. return IA300_GetInstance().RequestEnabled;
  86. }
  87. /*******************************************************
  88. *
  89. * 函数名称:IA300_SHA1WithSeedEx()
  90. * 功 能:
  91. * 返 回 值:
  92. * 说 明:检测到Key后调用此方法
  93. *
  94. **********************************************************/
  95. function IA300_SHA1WithSeedEx(RanDoms)
  96. {
  97. return IA300_GetInstance().IA300SHA1WithSeedEx(RanDoms);
  98. }
  99. /*******************************************************
  100. *
  101. * 函数名称:IA300_GetMachineCode()
  102. * 功 能:可以获取本地以太网MAC(MD5后值),服务端计算SHA1时,在随机数后连接 IA300GetMachineCode()此值即可。
  103. * 返 回 值:返回值为MD5后的MAC地址,否则失败
  104. * 说 明:检测到Key后调用此方法
  105. *
  106. **********************************************************/
  107. function IA300_GetMachineCode()
  108. {
  109. return IA300_GetInstance().IA300GetMachineCode();
  110. }
  111. /*******************************************************
  112. *
  113. * 函数名称:IA300_CalculateClientHash()
  114. * 功 能:进行硬件SHA1运算
  115. * 输 入:randomMessageFromServer:32个字符的随机数
  116. * 返 回 值:返回值为0即成功,1为失败,可用IA300_GetLastErr
  117. * or()获取USB Key错误信息
  118. * 说 明:IA300Key生成客户端摘要值(SHA1算法)需要传入32位
  119. * 字符随机数与Key中种子码计算生成
  120. *
  121. **********************************************************/
  122. function IA300_CalculateClientHash(randomMessageFromServer)
  123. {
  124. return IA300_GetInstance().IA300SHA1WithSeed(randomMessageFromServer);
  125. }
  126. /*******************************************************
  127. *
  128. * 函数名称:IA300_CheckExist()
  129. * 功 能:检查USB Key是否存在
  130. * 说 明:此方法结合IA300_StartCheckTimer方法可用来定时
  131. * 检测USB Key是否存在,不存在即返回到指定页面(
  132. * _ExpireUrl)
  133. *
  134. **********************************************************/
  135. function IA300_CheckExist()
  136. {
  137. var rtn =IA300_GetInstance().IA300CheckExist();
  138. if(rtn < 1)
  139. {
  140. IA300_LogOut();
  141. if(_TimerErrorMessage != null)
  142. {
  143. alert(_TimerErrorMessage + " Error Code: " +IA300Client.IA300GetLastError());
  144. }
  145. if(_ExpireUrl != null)
  146. {
  147. window.location = _ExpireUrl;
  148. }
  149. }
  150. return rtn;
  151. }
  152. /*******************************************************
  153. *
  154. * 函数名称:IA300_StartCheckTimer()
  155. * 功 能:定时操作方法
  156. * 输 入:interval:时间1000/秒;errMsg:输出的错误信息
  157. * logonUrl:跳转地址
  158. * 说 明:此方法结合IA300_CheckExist方法可用来定时检测加
  159. * 密Key是否存在,不存在即返回到指定页面(_ExpireUrl)
  160. *
  161. **********************************************************/
  162. function IA300_StartCheckTimer(interval, errMsg, logonUrl)
  163. {
  164. _TimerErrorMessage = errMsg;
  165. _ExpireUrl = logonUrl;
  166. //定时检测
  167. window.setInterval(IA300_CheckExist, interval);
  168. }
  169. /*******************************************************
  170. *
  171. * 函数名称:IA300_ChangePassword()
  172. * 功 能:修改密码
  173. * 输 入:oldPassword:原始密码;newPassword:新密码
  174. * newPasswordConfirm:新密码确认
  175. * 返 回 值:返回值1即原始密码为空,2即新密码确认失败,返回3
  176. * 为修改失败,可用IA300_GetLastError()获取USB Key
  177. * 错误信息
  178. * 说 明:修改IA300Key密码,IA300打开后才能调用此方法,需
  179. * 验证原密码,通过原有密码才能修改为新的密码
  180. *
  181. **********************************************************/
  182. function IA300_ChangePassword(oldPassword, newPassword, newPasswordConfirm)
  183. {
  184. if(oldPassword == "")
  185. {
  186. return 1;
  187. }
  188. if(newPassword != newPasswordConfirm)
  189. {
  190. return 2;
  191. }
  192. if( 0 != IA300_GetInstance().IA300ChangePassword(oldPassword,newPassword))
  193. {
  194. return 3;
  195. }
  196. return 0;
  197. }
  198. /*******************************************************
  199. *
  200. * 函数名称:IA300_ResetPasswordRequest()
  201. * 功 能:修改密码
  202. * 返 回 值:成功即返回生成的请求重置信息;失败可用
  203. * IA300_GetLastError()获取USB Key错误信息
  204. * 说 明:生成IA300USB Key密码重置信息,每调用一次此方法,
  205. * 生成的密码请求都是不同的,以最后一次调用生成的
  206. * 信息发送到服务端,请求密码重置,由服务端进行处
  207. * 理后生成一个经过密码重置的新密码
  208. *
  209. **********************************************************/
  210. function IA300_ResetPasswordRequest()
  211. {
  212. return IA300_GetInstance().IA300GenResetPwdRequest();
  213. }
  214. /*******************************************************
  215. *
  216. * 函数名称:IA300_ResetPassword()
  217. * 功 能:修改密码
  218. * 输 入:serverResponse:服务端密码重置新密码的信息
  219. * 返 回 值:返回值为0即成功,1为失败,可用IA300_GetLastErr
  220. * or()获取USB Key错误信息
  221. * 说 明:IA300USB Key密码重置,接受服务器端重置用户密码
  222. * 信息,若返回值为0,密码被重置为服务器端定义的
  223. * 新密码
  224. *
  225. **********************************************************/
  226. function IA300_ResetPassword(serverResponse)
  227. {
  228. return IA300_GetInstance().IA300ResetPassword(serverResponse);
  229. }
  230. /*******************************************************
  231. *
  232. * 函数名称:IA300WriteUserStorage()
  233. * 功 能:用户数据区写入
  234. * 输 入:UserStorage:IA300用户自定义数据
  235. * 说 明:写入用户数据区的自定义数据(为明文,客户端写入)
  236. *
  237. **********************************************************/
  238. function IA300_WriteUserStorage(UserStorage) {
  239. return IA300_GetInstance().IA300WriteUserStorage(UserStorage);
  240. }
  241. /*******************************************************
  242. *
  243. * 函数名称: IA300ReadUserStorage()
  244. * 功 能:用户数据区读取
  245. * 输 入:_length:IA300用户自定义数据 读取长度
  246. * 说 明:读取用户数据区的自定义数据(为明文,客户端读取)
  247. *
  248. **********************************************************/
  249. function IA300_ReadUserStorage(length) {
  250. return IA300_GetInstance().IA300ReadUserStorage(length);
  251. }
  252. /*******************************************************
  253. *
  254. * 函数名称:IA300_WriteStorage()
  255. * 功 能:USB Key安全存储区写入
  256. * 输 入:storage:IA300用户自定义写入存储区数据
  257. * 返 回 值:返回0,写入存储区数据成功
  258. * 说 明:写入存储区用户自定义的数据(为密文,由服务端确定
  259. * 并加密写入的数据)
  260. *
  261. **********************************************************/
  262. function IA300_WriteStorage(storage) {
  263. return IA300_GetInstance().IA300SecureWriteStorage(storage);
  264. }
  265. /*******************************************************
  266. *
  267. * 函数名称:IA300_ReadStorage()
  268. * 功 能:USB Key安全存储区读取
  269. * 输 入:storage:IA300用户自定义读取数据长度
  270. * 返 回 值:返回长度内的数据
  271. * 说 明:读取存储区用户自定义数据(为密文,需要服务端解读)
  272. *
  273. **********************************************************/
  274. function IA300_ReadStorage(storage) {
  275. return IA300_GetInstance().IA300SecureReadStorage(storage);
  276. }
  277. /*******************************************************
  278. *
  279. * 函数名称: IA300_WriteUserStorageEx()
  280. * 功 能:用户数据区写入
  281. * 输 入:UserStorage:IA300用户自定义数据
  282. * 说 明:扩展的用户数据区写入函数, 支持读取新版本2K大小数据区
  283. *
  284. **********************************************************/
  285. function IA300_WriteUserStorageEx(nStartAddr, pBuffer) {
  286. return IA300_GetInstance().IA300WriteUserStorageEx(nStartAddr, pBuffer);
  287. }
  288. /*******************************************************
  289. *
  290. * 函数名称: IA300_ReadUserStorageEx()
  291. * 功 能:用户数据区读取
  292. * 输 入:_length:IA300用户自定义数据 读取长度
  293. * 说 明:扩展的用户数据区读取函数, 支持读取新版本2K大小数据区
  294. *
  295. **********************************************************/
  296. function IA300_ReadUserStorageEx(nStartAddr, nDataLen) {
  297. return IA300_GetInstance().IA300ReadUserStorageEx(nStartAddr, nDataLen);
  298. }
  299. /*******************************************************
  300. *
  301. * 函数名称: IA300_SecureWriteStorageEx()
  302. * 功 能:USB Key安全存储区写入
  303. * 输 入:storage:IA300用户自定义写入存储区数据
  304. * 返 回 值:返回0,写入存储区数据成功
  305. * 说 明:扩展的安全数据区写入函数, 支持读取新版本2K大小数据区
  306. *
  307. **********************************************************/
  308. function IA300_SecureWriteStorageEx(nStartAddr, pBuffer) {
  309. return IA300_GetInstance().IA300SecureWriteStorageEx(nStartAddr, pBuffer);
  310. }
  311. /*******************************************************
  312. *
  313. * 函数名称:IA300_SecureReadStorageEx()
  314. * 功 能:USB Key安全存储区读取
  315. * 输 入:nStartAddr:数据读取地址; nDataLen:读取数据长度
  316. * 返 回 值:返回长度内的数据
  317. * 说 明:扩展的用户数据区读取函数, 支持读取新版本2K大小数据区
  318. *
  319. **********************************************************/
  320. function IA300_SecureReadStorageEx(nStartAddr, nDataLen) {
  321. return IA300_GetInstance().IA300SecureReadStorageEx(nStartAddr, nDataLen);
  322. }
  323. /*******************************************************
  324. *
  325. * 函数名称:IA300_DataEncrypt()
  326. * 功 能:客户端3des加密
  327. * 返 回 值:返回加密后的数据为成功,空为失败
  328. *
  329. **********************************************************/
  330. function IA300_DataEncrypt(pBuffer)
  331. {
  332. return IA300_GetInstance().IA300DataEncrypt(pBuffer);
  333. }
  334. /*******************************************************
  335. *
  336. * 函数名称:IA300_RemoteChangeRequest()
  337. * 功 能:申请远程注册
  338. * 输 入:strRandom:随机数
  339. * 返 回 值:返回USB Key相关参数,此参数作为服务端生成Response的重要参数
  340. * 说 明:
  341. *
  342. **********************************************************/
  343. function IA300_RemoteChangeRequest(strRandom)
  344. {
  345. var rtn = IA300_GetInstance().IA300CheckExist();
  346. if(rtn == 0)
  347. {
  348. alert("请插入USB Key进行注册申请!");
  349. return;
  350. }
  351. return IA300_GetInstance().IA300RemoteChangeRequest(strRandom);
  352. }
  353. /*******************************************************
  354. *
  355. * 函数名称:IA300_RemoteChange()
  356. * 功 能:远程注册
  357. * 输 入:strResponse:服务端返回的注册参数;strRandom:服务端传递过来的随机数,是申请的时候参与请求的随机数
  358. * 返 回 值:返回0,表示注册成功,返回1,表示注册失败。
  359. * 说 明:
  360. *
  361. **********************************************************/
  362. function IA300_RemoteChange(strResponse,strRandom)
  363. {
  364. var rtn = IA300_GetInstance().IA300CheckExist();
  365. if(rtn == 0)
  366. {
  367. alert("请插入USB Key完成注册!");
  368. return;
  369. }
  370. return IA300_GetInstance().IA300RemoteChange(strResponse,strRandom);
  371. }
  372. /*******************************************************
  373. *
  374. * 函数名称:IA300GetName()
  375. * 功 能:获取USB Key中设置的USB Key别名
  376. * 返 回 值:返回Key中设置的USB Key别名
  377. *
  378. **********************************************************/
  379. function IA300_GetName()
  380. {
  381. return IA300_GetInstance().Name;
  382. }
  383. /*******************************************************
  384. *
  385. * 函数名称:IA300GetDescription()
  386. * 功 能:获取USB Key中设置的公司名称信息
  387. * 返 回 值:返回Key中设置的公司名称
  388. *
  389. **********************************************************/
  390. function IA300_GetDescription()
  391. {
  392. return IA300_GetInstance().Description;
  393. }
  394. /*******************************************************
  395. *
  396. * 函数名称:IA300GetUrl()
  397. * 功 能:获取USB Key中设置的网址
  398. * 返 回 值:返回Key中设置的网址信息
  399. * 说 明:此网址为插Key自动弹出网页的地址
  400. *
  401. **********************************************************/
  402. function IA300_GetUrl()
  403. {
  404. return IA300_GetInstance().Url;
  405. }
  406. /*******************************************************
  407. *
  408. * 函数名称:IA300GetOther()
  409. * 功 能:获取USB Key中设置的其他信息,例如联系电话等
  410. * 返 回 值:返回Key中设置的其他信息
  411. *
  412. **********************************************************/
  413. function IA300_GetOther()
  414. {
  415. return IA300_GetInstance().Other;
  416. }
  417. /*******************************************************
  418. *
  419. * 函数名称:createElementIA300()
  420. * 功 能:自动判断操作系统是X64或X32并自动添加相应的插件
  421. * 说 明:自动判断操作系统是X64或X32并自动添加相应的插件_CLSID为IA300ClinetID
  422. *
  423. **********************************************************/
  424. //已完成判断系统,自动添加插件;
  425. //未完成相应系统不同插件的添加,现皆为x32插件
  426. function createElementIA300()
  427. {
  428. var ia300client;
  429. var browser = DetectBrowser();
  430. if(browser == "IE") {
  431. if (IsIE9Above() == true) {
  432. ia300client = document.createElement('object');
  433. if (ia300client != null) {
  434. ia300client.setAttribute("id", "IA300Client");
  435. ia300client.setAttribute("CLASSID", "clsid:6AAEEBD3-838D-4A35-9571-26EFC79882ED");
  436. ia300client.setAttribute("width", "0");
  437. ia300client.setAttribute("height", "0");
  438. }
  439. }
  440. else //IE6,7
  441. {
  442. ia300client = document.createElement("<object id=\"IA300Client\" CLASSID=\"clsid:6AAEEBD3-838D-4A35-9571-26EFC79882ED\" style=\"left:0px; top:0px; width:0; height:0; \" ></object>");
  443. }
  444. document.body.appendChild(ia300client);
  445. }
  446. else {
  447. ia300client = document.createElement('embed');
  448. if (ia300client != null) {
  449. ia300client.setAttribute("id", "IA300Client");
  450. ia300client.setAttribute("width", "0");
  451. ia300client.setAttribute("height", "0");
  452. ia300client.setAttribute("type", "application/IA300Plugin");
  453. document.body.appendChild(ia300client);
  454. }
  455. }
  456. }
  457. /*******************************************************
  458. *
  459. * 函数名称:DetectIA300Plugin()()
  460. * 功 能:自动判断是否注册客户端插件
  461. * 说 明:IA300ACTIVEX.IA300ActiveXCtrl.1为IA300Clinet插件注册后的NAME
  462. *
  463. **********************************************************/
  464. function DetectIA300Plugin() {
  465. var browser = DetectBrowser();
  466. if(browser == "IE")
  467. {
  468. try
  469. {
  470. var comActiveX = new ActiveXObject("IA300ACTIVEX.IA300ActiveXCtrl.1");
  471. }
  472. catch(e)
  473. {
  474. return false;
  475. }
  476. return true;
  477. }
  478. else
  479. {
  480. var ia300Plugin = navigator.plugins["IA300 Plugin"];
  481. if (ia300Plugin != null)
  482. {
  483. return true;
  484. }
  485. return false;
  486. }
  487. }
  488. /*******************************************************
  489. *
  490. * 函数名称:DetectBrowser()()
  491. * 功 能:自动判断当前使用浏览器
  492. * 说 明:自动判断浏览器引擎,返回结果为当前浏览器名称
  493. *
  494. **********************************************************/
  495. function DetectBrowser()
  496. {
  497. var Sys = {};
  498. var ua = navigator.userAgent.toLowerCase();
  499. var s;
  500. (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
  501. (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
  502. (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
  503. (s = ua.match(/rv:([\d.]+)/)) ? Sys.ie = s[1] :
  504. (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1]:
  505. (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
  506. var browser="Unknown";
  507. if (Sys.ie){browser="IE";}
  508. if (Sys.firefox) {browser="Firefox";}
  509. if (Sys.chrome) {browser="Chrome";}
  510. if (Sys.opera) {browser="Opera";}
  511. if (Sys.safari) { browser = "Safari"; }
  512. return browser;
  513. }
  514. function IsIE9Above() {
  515. if (navigator.userAgent.indexOf("Gecko") >= 0) {
  516. return true;
  517. }
  518. else {
  519. var ua = navigator.userAgent.toLowerCase().match(/msie ([\d.]+)/)[1];
  520. if (parseInt(ua, 10) >= 9)
  521. return true;
  522. else
  523. return false;
  524. }
  525. }