Python插件 - 保存/审核/提交 【POST】请求传输至第三方系统

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

Python插件 - 保存/审核/提交 【POST】请求传输至第三方系统

# 对接第三方系统常用方式 ``` python import clr clr.AddReference("System") clr.AddReference("System.Core") clr.AddReference("Kingdee.BOS") 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.Net import * from System.IO import * from System.Linq import * from System.Text import * from Newtonsoft.Json import * from Newtonsoft.Json.Linq import * class dog: tenantId=0 relationshipId="12621517591749" id="" key="" def AfterExecuteOperationTransaction(e): billid=""; Billno = ""; this.OperationResult.IsShowMessage = True; #保存之后 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(); SendData(billid,Billno); #发送到第三方服务器 def post(url,postdata): encode = "UTF-8"; webRequest = HttpWebRequest.Create(url); webRequest.Method = "POST"; webRequest.ContentType = "application/json"; paraUrlCoded = postdata; payload = Encoding.GetEncoding(encode.ToUpper()).GetBytes(paraUrlCoded); webRequest.ContentLength = payload.Length; writer = webRequest.GetRequestStream(); writer.Write(payload, 0, payload.Length); writer.Close(); response = webRequest.GetResponse(); sr = StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encode)); res = sr.ReadToEnd(); return res; def SendData(billid, Billno): url = "http://127.0.0.1:8052/SendData"; dog.id = billid; result_str = post(url,JsonConvert.SerializeObject(dog)); postresult = JObject.Parse(result_str); result = OperateResult(); if postresult != None: if postresult["code"].ToString() == "200": #注意解析返回格式:接口返回格式 {"code":"200","msg":"success"} #TojObjectresult = JObject.Parse(postresult["result"].ToString()); result.SuccessStatus = True; result.PKValue = billid; result.Number = Billno; result.Message = postresult["msg"].ToString(); #"【{0}】- 同步成功【主键值:{1}】【消息:{2}】!".format(Billno,TojObjectresult["pkid"],TojObjectresult["msg"]); this.OperationResult.OperateResult.Add(result); return; else: result.SuccessStatus = False; result.PKValue = billid; result.Number = Billno; result.Message = "【{0}】- 同步失败 !".format(Billno); this.OperationResult.OperateResult.Add(result); return; ``` # 简单的python开发集合 ### [记录一下python简单的插件开发- beforef7select&基础资料组织 列表只显示用户拥有的组织权限](https://wenku.my7c.com/article/432506265244103680?productLineId=1) ### [记录一下python简单的插件开发- 单元格格式化事件&物料收发汇总格式化仓位编码](https://wenku.my7c.com/article/432502474717361152?productLineId=1) ### [记录一下python简单的插件开发- 菜单按钮事件(表体菜单按钮事件)执行SQL语句](https://wenku.my7c.com/article/433286928398603520) ### [python插件 - 动态 简单账表 通过SQL存储过程输出列实现动态展示](https://wenku.my7c.com/article/433709738048508160?productLineId=1):triangular_flag_on_post: ### [Python插件 - 将生产订单二开字段携带至下级订单上](https://wenku.my7c.com/article/434474741080938240?productLineId=1) :new: ### [Python插件 - 单据转换插件-WebApi下推单据 自定义入参插件](https://wenku.my7c.com/article/445155491019305984?fromAction=POST_ARTICLE&productLineId=1) :pushpin: ### [简单Python插件 - 点击菜单弹窗动态表单录入数据返回父窗体](https://wenku.my7c.com/article/449987803519330560?productLineId=1) :pushpin: ### [Python插件 - 【服务插件】取文本字段值赋值基础资料字段](https://wenku.my7c.com/article/453951446166029312?productLineId=1) ### [Python插件 - 保存、审核、提交 发送请求传输至第三方系统](https://wenku.my7c.com/article/452432069977609216?productLineId=1)

这个是要写在 操作 里的服务插件吗?


如果参数中包含中文字符也可以使用吗

JsonConvert.SerializeObject(dog)这个转换会出现

"__doc__":null,"__module__":"<module>"

请问怎么解决,谢谢


image.webp这个报错是什么意思


Python插件 - 保存/审核/提交 【POST】请求传输至第三方系统

# 对接第三方系统常用方式``` pythonimport clrclr.AddReference("System")clr.AddReference("System.Core")clr.AddReference("Kingdee....
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息