first commit
This commit is contained in:
1 parent
5b00bd10d0
commit
d15e8185bb
14 files changed
+203
-371
No files matched your search
@@ -0,0 +1,83 @@
|
||||
import base64
|
||||
import uuid
|
||||
import json
|
||||
import http.client
|
||||
import webbrowser
|
||||
|
||||
|
||||
def start_http_server():
|
||||
"""start debug"""
|
||||
webbrowser.open("ksowpscloudsvr://start=RelayHttpServer")
|
||||
|
||||
|
||||
def get_version():
|
||||
"""check http status by get version"""
|
||||
try:
|
||||
conn = http.client.HTTPConnection("127.0.0.1", 58890)
|
||||
conn.request("POST", "/version", body="{}", headers={})
|
||||
response = conn.getresponse()
|
||||
data = response.read()
|
||||
conn.close()
|
||||
return response.status == 200
|
||||
except:
|
||||
return False
|
||||
|
||||
|
||||
def invoke_wps_func(func, args):
|
||||
|
||||
# 可能触发是否允许访问
|
||||
invoke_param = {
|
||||
"Func": func,
|
||||
"Args": json.dumps(args),
|
||||
"AppType": "wps",
|
||||
}
|
||||
|
||||
req_uui = str(uuid.uuid4())
|
||||
|
||||
info = f"{json.dumps(invoke_param)});\
|
||||
var xhr = new XMLHttpRequest();\
|
||||
xhr.open('POST', 'http://127.0.0.1:58890/transferEcho/runParams');\
|
||||
xhr.send(JSON.stringify({{id: '{req_uui}', response: res}}));void(0"
|
||||
|
||||
data = {
|
||||
"name": "xbotwps",
|
||||
"function": "var res = InvokeFromXbot",
|
||||
"info": info,
|
||||
"showToFront": True,
|
||||
"jsPluginsXml": "",
|
||||
}
|
||||
|
||||
payload = {
|
||||
"id": req_uui,
|
||||
"app": "wps",
|
||||
"data": "ksowebstartupwps://"
|
||||
+ base64.b64encode(json.dumps(data).encode()).decode(),
|
||||
"mode": False,
|
||||
}
|
||||
|
||||
conn = http.client.HTTPConnection("127.0.0.1", 58890)
|
||||
payload = json.dumps(payload)
|
||||
|
||||
conn.request("POST", "/transfer/runParams", payload)
|
||||
|
||||
http_response = conn.getresponse()
|
||||
data = http_response.read()
|
||||
conn.close()
|
||||
|
||||
try:
|
||||
return json.loads(data.decode("utf-8"))
|
||||
except Exception as e:
|
||||
print(data.decode("utf-8"))
|
||||
return {"message": "failed to parse response"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
start_http_server()
|
||||
|
||||
print(get_version())
|
||||
|
||||
func = "getDocumentName"
|
||||
func = "evalCode"
|
||||
args = {"code": "wps.WpsApplication().ActiveDocument.Name"}
|
||||
res = invoke_wps_func(func, args)
|
||||
print(res)
|
||||
Reference in new issue
Block a user