本帖最后由 jun353835273 于 2024-6-22 09:30 编辑
接口是吾爱的https://www.52pojie.cn/thread-1903090-1-1.html,能用多久也不知道,只是一种获取翻译的方法,部分字符偶尔会拦截
就是返回速度比较感人,只能拿来玩玩,希望抛砖引玉,有好接口的lisper贴码分享。
百度翻译接口也行,不过水平有限通过纯lisp获取成功率太低,估计是我方法不对。通过其他语言倒是直接成功了的。
百度接口地址:https://fanyi-api.baidu.com/api/trans/vip/translate
源码奉上
- (defun getxml (url / xml http)
- (setq http (vlax-create-object "WinHTTP.WinHTTPRequest.5.1"))
- (vlax-invoke-method http "open" "get" url 0)
- (vlax-invoke-method http "send")
- (setq xml (vlax-get-property http "responsetext"))
- (vlax-release-object http)
- xml
- )
- (defun c:TTR (/ n ss e dt txt)
- (setvar "cmdecho" 0)
- (if (setq ss (ssget '((0 . "TEXT")))
- n 0
- )
- (progn
- (repeat (sslength ss)
- (setq e (ssname ss n)
- n (1+ n)
- )
- (setq dt (entget e))
- (setq txt (cons (cdr (assoc 1 dt)) txt))
- (setq txt (fy (car txt)))
- (entmod (subst (cons 1 txt) (assoc 1 dt) dt))
- )
- )
- )
- (princ)
- )
(defun fy(word / url4 gettxt s str e str2 )
(setq url4 (strcat "https://findmyip.net/api/translate.php?text=" word ));"&source_lang=zh&target_lang=en"
(setq gettxt (getxml url4))
(setq s(vl-string-search "translate_result" gettxt ))
(setq str(substr gettxt (+ s 20) ))
(setq e(vl-string-search "processTime" str ))
(setq str2(substr str 1 (- e 4) ))
)
|