【学习笔记】-运用python调用云之家的群组机器人
1.创建云之家群组,添加通知型机器人。复制该机器人的webhook地址。
2.简单添加基础资料。
3.注册表单python插件,其中posturl为第一步中复制的webhook地址
import clr
#添加对cloud插件开发的常用组件的引用
clr.AddReference('System')
clr.AddReference('System.Data')
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.DataEntity')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('Kingdee.BOS.App')
clr.AddReference('Kingdee.BOS.App.Core')
#导入cloud基础库中的常用实体对象(分命名空间导入,不会递归导入)
#import sys
from Kingdee.BOS import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Core.DependencyRules import *
from Kingdee.BOS.Core.Bill import *
from Kingdee.BOS.Core.DynamicForm.PlugIn import *
from Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel import *
from System import *
from System.Data import *
from System.Net import *
from System.Text import *
from System.IO import *
from Kingdee.BOS.App.Data import *
from System.Collections.Generic import List
from Kingdee.BOS.Core.DynamicForm import *
from Kingdee.BOS.Core.Metadata.EntityElement import *
from Kingdee.BOS.Core.Metadata.FieldElement import *
from Kingdee.BOS.Orm.DataEntity import *
def ButtonClick(e):
key=e.Key.ToUpperInvariant();
if(key=="FSUBMIT"):
posturl='https://www.yunzhijia.com/gateway/robot/webhook/send?yzjtype=0&yzjtoken=XXXXXX'
body='{"content":"'+this.Model.GetValue("FCONTENT").ToString()+'"}'
msg=ToPost(posturl,body);
this.View.ShowMessage(msg)
def ToPost(posturl,postdata):
result="";
try:
webRequest=HttpWebRequest.Create(posturl)
webRequest.Method="POST"
webRequest.ContentType="application/json"
data=Encoding.UTF8.GetBytes(postdata)
webRequest.ContentLength=data.Length
webRequest.GetRequestStream().Write(data,0,data.Length)
webRequest.GetRequestStream().Flush()
webRequest.GetRequestStream().Close()
webResponse=webRequest.GetResponse()
streamReader=StreamReader(webResponse.GetResponseStream(),Encoding.GetEncoding("utf-8"))
result=streamReader.ReadToEnd()
#return result
except Exception as e:
result=str(e)+postdata
finally:
return result
4点击提交,机器人即可发送消息
其他说明:①一个群组可添加多个机器人 ②发送消息除了文本类型,可以带链接或图片地址。③除了通知型机器人,也可以创建对话型机器人,需要建一个网站用来接收和处理回复消息。
【学习笔记】-运用python调用云之家的群组机器人
本文2024-09-16 17:15:01发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-14498.html