Python插件 - 保存/审核/提交 【WebSocket】请求传输
# 对接第三方系统常用方式
# 代码
``` python
#项目: 服务插件 - socket对接
#作者: 老李头(Dean)
import clr
clr.AddReference("System")
clr.AddReference("System.Core")
clr.AddReference("Kingdee.BOS")
clr.AddReference("Kingdee.BOS.App")
clr.AddReference("Kingdee.BOS.Core")
clr.AddReference("Kingdee.BOS.DataEntity")
clr.AddReference("Newtonsoft.Json")
from Kingdee.BOS.Util import *
from Kingdee.BOS.Core.DynamicForm import *
from Kingdee.BOS.Core.DynamicForm.PlugIn import *
from Kingdee.BOS.Core.DynamicForm.PlugIn.Args import *
from Kingdee.BOS.Core.Metadata.FormElement import *
from System import *
from System.ComponentModel import *
from System.Net import *
from System.Net.Sockets import *
from System.IO import *
from System.Linq import *
from System.Text import *
from Newtonsoft.Json import *
from Newtonsoft.Json.Linq import *
def AfterExecuteOperationTransaction(e):
billid="";
Billno = "";
this.OperationResult.IsShowMessage = True; #弹出操作结果
server = "127.0.0.1"; #IP地址
ServerPort = 9000; #端口
#保存之后 Operation_Save
#提交之后 Operation_Submit
#审核之后 Operation_Audit
if this.FormOperation.OperationId == FormOperation.Operation_Save:
obj = e.DataEntitys;
for item in obj:
billid = item["Id"].ToString(); #单据内码
Billno = item["BillNo"].ToString(); #单据编号
#发送数据
SendResult = SocketSend(server, ServerPort, JsonConvert.SerializeObject(obj));
result = OperateResult();
result.PKValue = billid;
result.Number = Billno;
result.SuccessStatus = SendResult;
result.Message = "socket发送成功" if SendResult == True else "socket发送失败";
#加个弹窗提示
this.OperationResult.OperateResult.Add(result);
"""socket连接"""
def ConnectSocket(server,port):
s = None;
AddressList = Dns.GetHostAddresses(server);
for address in AddressList:
ipe = IPEndPoint(address, port);
tempSocket = Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
tempSocket.Connect(ipe);
if tempSocket.Connected == True:
s = tempSocket;
break;
else:
continue;
return s;
"""socket发送"""
def SocketSend( server, port, dataJson):
bytesSent = Encoding.UTF8.GetBytes(dataJson);
#连接Socket
s = ConnectSocket(server, port);
if s ==None: #连接失败
return False;
#发送消息
s.Send(bytesSent, bytesSent.Length, 0);
#发送完关闭
s.Close();
return True;
```
# 部署
![image.webp](/download/0100956cb5f599c2405792e5beb4d1ef04ec.webp)
![image.webp](/download/0100ea36f97feaac43fcb13072ba4e0869a2.webp)
Python插件 - 保存/审核/提交 【WebSocket】请求传输
# 对接第三方系统常用方式# 代码``` python#项目: 服务插件 - socket对接#作者: 老李头(Dean)import clrclr.AddReference("Sys...
点击下载文档
上一篇:WebAPI查询记录清单列表下一篇:让我看看
本文2024-09-16 17:13:53发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-14373.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章