明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2924|回复: 18

[提问] LISP如何实现限制使用时间(网络时间)?到期后不能使用。

[复制链接]
发表于 2022-5-30 17:06 | 显示全部楼层 |阅读模式
LISP如何实现限制使用时间(网络时间)?到期后不能使用。
发表于 2022-5-31 15:27 | 显示全部楼层
  1. ;;---------------------=={ Internet Time }==------------------;;
  2. ;;                                                            ;;
  3. ;;  Returns the date and/or UTC time as a string in the       ;;
  4. ;;  format specified. Data is sourced from a NIST server.     ;;
  5. ;;------------------------------------------------------------;;
  6. ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
  7. ;;------------------------------------------------------------;;
  8. ;;  Arguments:                                                ;;
  9. ;;  format - string specifying format of returned information ;;
  10. ;;           using the following identifiers to represent     ;;
  11. ;;           date & time quantities:                          ;;
  12. ;;           YY = Year, MO = Month,   DD = Day                ;;
  13. ;;           HH = Hour, MM = Minutes, SS = Seconds            ;;
  14. ;;------------------------------------------------------------;;
  15. ;;  Returns:  String containing formatted date/time data      ;;
  16. ;;------------------------------------------------------------;;

  17. (defun LM:InternetTime ( format / result rgx server xml )
  18.     (setq server "http://time.nist.gov:13")
  19.     (setq result
  20.         (vl-catch-all-apply
  21.             (function
  22.                 (lambda ( / str )
  23.                     (setq xml (vlax-create-object "MSXML2.XMLHTTP.3.0"))
  24.                     (setq rgx (vlax-create-object "VBScript.RegExp"))
  25.                     (vlax-invoke-method xml 'open "POST" server :vlax-false)
  26.                     (vlax-invoke-method xml 'send)
  27.                     (if (setq str (vlax-get-property xml 'responsetext))
  28.                         (progn
  29.                             (vlax-put-property rgx 'global     actrue)
  30.                             (vlax-put-property rgx 'ignorecase actrue)
  31.                             (vlax-put-property rgx 'multiline  actrue)
  32.                             (mapcar
  33.                                 (function
  34.                                     (lambda ( a b )
  35.                                         (vlax-put-property rgx 'pattern a)
  36.                                         (setq format (vlax-invoke rgx 'replace format b))
  37.                                     )
  38.                                 )
  39.                                '("YY" "MO" "DD" "HH" "MM" "SS")
  40.                                '("$1" "$2" "$3" "$4" "$5" "$6")
  41.                             )
  42.                             (vlax-put-property rgx 'pattern
  43.                                 (strcat
  44.                                     "(?:[^\\d]+[\\d]+[^\\d]+)"
  45.                                     "([\\d]+)(?:[^\\d]+)([\\d]+)(?:[^\\d]+)([\\d]+)(?:[^\\d]+)"
  46.                                     "([\\d]+)(?:[^\\d]+)([\\d]+)(?:[^\\d]+)([\\d]+)(?:.+)\\n"
  47.                                 )
  48.                             )
  49.                             (vlax-invoke-method rgx 'replace str format)
  50.                         )
  51.                     )
  52.                 )
  53.             )
  54.         )
  55.     )
  56.     (if xml  (vlax-release-object xml))
  57.     (if rgx  (vlax-release-object rgx))
  58.     (if (not (vl-catch-all-error-p result))
  59.         result
  60.     )
  61. )


The 'format' parameter

This parameter is a string specifying the format for the returned data. It is used in a similar way to the 'picture' parameter for the edtime DIESEL function, using the following identifiers to represent date & time quantities:

Code: [Select]
YY  =  Year
MO  =  Month
DD  =  Day
HH  =  Hours
MM  =  Minutes
SS  =  Seconds

Examples

Code: [Select]
_$ (LM:InternetTime "DD/MO/YY, HH:MM:SS")
"17/09/11, 19:37:07"

Code: [Select]
_$ (LM:InternetTime "MO.DD.YY")
"09.17.11"

Code: [Select]
_$ (LM:InternetTime "HH:MM")
"19:37"
回复 支持 2 反对 2

使用道具 举报

发表于 2022-6-1 17:49 | 显示全部楼层
本帖最后由 xshrimp 于 2022-6-2 09:24 编辑

;;;xshrimp 2022.06.01
(defun xzj-InternetTime( / fs timeStr tmpFile true ts wscript)
  (setq tmpFile (vl-filename-mktemp nil nil ".txt"))
  (setq wscript (vlax-create-object "wscript.shell"))
  (setq fs     (vlax-create-object "scripting.filesystemobject"))
  (vlax-invoke wscript 'run (strcat "cmd.exe /c curl  https://www.beijing-time.org/t/time.asp>\"" tmpFile "\"")  0 1)  
  (setq ts (vlax-invoke fs 'opentextfile tmpFile  1 -1));true -1
  (setq timeStr (vlax-invoke ts 'readall))
  (vlax-invoke ts 'Close)  
  (vlax-invoke fs 'DeleteFile tmpFile)
  (alert timeStr)
)
(xzj-InternetTime)

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2022-5-31 06:50 | 显示全部楼层
没有网络如何处理?还是用系统时间控制比较容易些。
发表于 2022-5-31 07:58 | 显示全部楼层
获取初次试用时间,保存
以后每次用的时候取当前时间,和保存的时间比较,看看用了多少天了,过期就不运行
发表于 2022-5-31 09:14 | 显示全部楼层
要么联网获取真实时间,同时承担没网络不能运行的后果。要么获取本地时间,同时承担用户修改时间跳过的后果。根据需要选择合适的验证方式。
发表于 2022-5-31 22:42 | 显示全部楼层
xshrimp 发表于 2022-5-31 15:27
The 'format' parameter

This parameter is a string specifying the format for the returned data ...

老哥没用,放回nil
发表于 2022-6-2 07:49 | 显示全部楼层
xshrimp 发表于 2022-6-1 17:49
;;;xshrimp 2022.06.01
(defun xzj-InternetTime( / fs timeStr tmpFile true ts wscript)
  (setq tmpFi ...

如果tmpFile空,则(setq timeStr (vlax-invoke ts 'ReadAll))失败,为什么会空呢?
发表于 2022-6-2 09:01 | 显示全部楼层
本帖最后由 xshrimp 于 2022-6-2 09:21 编辑
自贡黄明儒 发表于 2022-6-2 07:49
如果tmpFile空,则(setq timeStr (vlax-invoke ts 'ReadAll))失败,为什么会空呢?

执行太快,文件还没有写入数据,就读.文件为空.
或者没有读就删了?
已经修改了.你再试下呢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-20 13:24 , Processed in 0.505311 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表