Python插件 - 保存/审核/提交 【WebSocket】请求传输

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

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...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息