分享:自建插件 开发者工具箱 源码

楼主
简道云应用场景探索者

 

2022年末,参加“首届插件开发大赛”,制作了三款插件,后续经常有道友询问是否可以共享下“开发者工具箱”,一是受限于非签约开发者,无法上架插件市场,再者,自建插件功能并未开放,共享不是太方便。

 

现在好了,自建插件功能于 2023-06-28 正式开放了,具体可查阅 【官方更新】,刚好最近正在考虑是否把代码开放出来,索性就开放出来吧。

 

因仅是自己使用,相关代码基本未做优化,故而仅供参考,使用前请多做测试,另请自行遵循《自建插件安全承诺协议》

 

自建插件相关资料

 

【官方】自建插件相关资料

【官方】自建插件功能教学

【分享】从云函数到自建插件 百花齐放 生态共创

 

自建插件如何部署代码

 

01.  进入开放平台

 

02.  新建相关插件

 

 

03.  将 【请求参数】【返回参数】 调整为 【代码视图】

注:本场景调整为代码视图仅为方便后续拷贝相关代码

 

 

04.  将 相应的代码 拷贝至对应的 位置 ( 代码 、 请求参数、返回参数 )

 

 

开发者工具箱源码分享

 

【资料】开发者工具箱内容介绍

 

01. 子表自动添加行

 

# 插件代码:

re = {}

l = list(range(1,triggerConf['_hangshu_widget_16682579853701']+1))

re["zibiaodan"]= [{"xuhao":i} for i in l]

re["status"]="已完成"

return re



# 请求参数:



[

    {

        "id": "_hangshu_widget_16682579853701",

        "label": "行数",

        "description": "",

        "fieldType": "number",

        "isHidden": false,

        "isEnabled": true,

        "isRequired": true,

        "fieldConf": {}

    }

]



# 返回参数:



[

    {

        "label": "子表单",

        "id": "zibiaodan",

        "fieldConf": {

            "fields": [

                {

                    "label": "序号",

                    "id": "xuhao",

                    "fieldConf": {},

                    "fieldType": "any"

                }

            ]

        },

        "fieldType": "vector"

    },

    {

        "label": "状态",

        "id": "status",

        "fieldConf": {},

        "fieldType": "any"

    }

]

 

02. 子表汇总自动换行

 

# 插件代码:



if not triggerConf['_neirong_zbhzzdhh']:

  return {"status":"参数为空"}

else:

  re = {}

  re["huizong"] = "\n".join(triggerConf['_neirong_zbhzzdhh'].split(","))

  re["status"] = "已完成"

  return re



# 请求参数:



[

    {

        "id": "_neirong_zbhzzdhh",

        "label": "子表内容",

        "description": "",

        "fieldType": "text",

        "isHidden": false,

        "isEnabled": true,

        "isRequired": false,

        "fieldConf": {

            "isMultiLine": false

        },

        "defaultValue": ""

    }

]



# 返回参数:



[

    {

        "label": "汇总",

        "id": "huizong",

        "fieldConf": {},

        "fieldType": "any"

    },

    {

        "label": "状态",

        "id": "status",

        "fieldConf": {},

        "fieldType": "any"

    }

]

 

03. 生成一组随机数 

  

# 插件代码:



import random



zxsz = min(triggerConf['_zxsz_scyzsjs'],triggerConf['_zdsz_scyzsjs'])

zdsz = max(triggerConf['_zxsz_scyzsjs'],triggerConf['_zdsz_scyzsjs'])

tqgs = triggerConf['_tqgs_scyzsjs']



if tqgs > zdsz - zxsz + 1 :

  return {"status":"参数有误"}



re = {}



l = random.sample(range(zxsz,zdsz+1),tqgs)



re["zbd"]= [{"sjs":i} for i in l]

re["status"]="已完成"



return re



# 请求参数:



[

    {

        "id": "_zxsz_scyzsjs",

        "label": "最小数字",

        "description": "",

        "fieldType": "number",

        "isHidden": false,

        "isEnabled": true,

        "isRequired": true,

        "fieldConf": {}

    },

    {

        "id": "_zdsz_scyzsjs",

        "label": "最大数字",

        "description": "",

        "fieldType": "number",

        "isHidden": false,

        "isEnabled": true,

        "isRequired": true,

        "fieldConf": {}

    },

    {

        "id": "_tqgs_scyzsjs",

        "label": "提取个数",

        "description": "",

        "fieldType": "number",

        "isHidden": false,

        "isEnabled": true,

        "isRequired": true,

        "fieldConf": {}

    }

]



# 返回参数:



[

    {

        "label": "子表单",

        "id": "zbd",

        "fieldConf": {

            "fields": [

                {

                    "label": "随机数",

                    "id": "sjs",

                    "fieldConf": {},

                    "fieldType": "any"

                }

            ]

        },

        "fieldType": "vector"

    },

    {

        "label": "状态",

        "id": "status",

        "fieldConf": {},

        "fieldType": "any"

    }

]

 

04. 手机字段转文本

 

# 插件代码:



import json

re = {}

re["sjh"] = json.loads(triggerConf['_sj_sjzdzwb'])["phone"]

re["status"] = "已完成"

return re



# 请求参数:



[

    {

        "id": "_sj_sjzdzwb",

        "label": "手机",

        "description": "aa",

        "fieldType": "text",

        "isHidden": false,

        "isEnabled": true,

        "isRequired": true,

        "fieldConf": {

            "isMultiLine": false

        },

        "defaultValue": ""

    }

]



# 返回参数:



[

    {

        "label": "手机 ( 文本 )",

        "id": "sjh",

        "fieldConf": {},

        "fieldType": "any"

    },

    {

        "label": "状态",

        "id": "status",

        "fieldConf": {},

        "fieldType": "any"

    }

]

 

05. 提取成员多选信息

 

# 插件代码:



import json



if not triggerConf['_cy_tqcydxxx']:

  return {"status":"参数为空"}



cydx = str(triggerConf['_cy_tqcydxxx']).replace("[","").replace("]","").replace('}, {','}###{').replace("'",'"').split("###")



re = {}

cy = {}

lb = list(range(0,len(cydx)))



for x in lb: 

  cy[x] = {

    "id":json.loads(cydx[x])["_id"],

    "xingming":json.loads(cydx[x])["name"],

    "bianhao":json.loads(cydx[x])["username"] 

  }



re["zbd"]=[cy[i] for i in cy]

re["status"] = "已完成"



return re



# 请求参数:



[

    {

        "id": "_cy_tqcydxxx",

        "label": "成员多选",

        "description": "",

        "fieldType": "user",

        "isHidden": false,

        "isEnabled": true,

        "isRequired": true,

        "fieldConf": {}

    }

]



# 返回参数:



[

    {

        "label": "zt",

        "id": "zt",

        "fieldConf": {},

        "fieldType": "any"

    },

    {

        "label": "子表单",

        "id": "zbd",

        "fieldConf": {

            "fields": [

                {

                    "label": "ID",

                    "id": "id",

                    "fieldConf": {},

                    "fieldType": "any"

                },

                {

                    "label": "姓名",

                    "id": "xingming",

                    "fieldConf": {},

                    "fieldType": "any"

                },

                {

                    "label": "编号",

                    "id": "bianhao",

                    "fieldConf": {},

                    "fieldType": "any"

                }

            ]

        },

        "fieldType": "vector"

    },

    {

        "label": "状态",

        "id": "status",

        "fieldConf": {},

        "fieldType": "any"

    }

]

 

06. 提取IP归属地

 

# 插件代码:



import requests



# 请求失败

def qqsb():

  re = {

  "gsd":"XX",

  "gsd1":"XX",

  "gsd2":"XX",

  "gsd3":"XX",

  "gsd4":"XX",

  "status":"请求失败"

  }

  return (re)



ip = triggerConf['_ip_tqipdzgsd']

url = f'http://ip.taobao.com/outGetIpInfo?ip={ip}&accessKey=alibaba-inc'

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}

re = {}



try:

  response = requests.get(url, headers=headers)

except:

  qqsb()



if response.status_code == 200:

    result = response.json()

    if result['code'] == 0:

        data = result['data']

        print(data['country'], data['region'], data['city'])

    else:

        qqsb()

else:

    qqsb()



re = {

  "gsd":' '.join([data['country'],data['region'],data['city']]),

  "gsd1":data['country'],

  "gsd2":data['region'],

  "gsd3":data['city'],

  "gsd4":" ".join([data['region'],data['city']]),

  "status":"请求成功"

}





return re



# 请求参数:



[

    {

        "id": "_ip_tqipdzgsd",

        "label": "IP地址",

        "description": "",

        "fieldType": "text",

        "isHidden": false,

        "isEnabled": true,

        "isRequired": false,

        "fieldConf": {

            "isMultiLine": false

        },

        "defaultValue": ""

    }

]



# 返回参数:



[

    {

        "label": "归属地",

        "id": "gsd",

        "fieldConf": {},

        "fieldType": "any"

    },

    {

        "label": "所在国",

        "id": "gsd1",

        "fieldConf": {},

        "fieldType": "any"

    },

    {

        "label": "所在省",

        "id": "gsd2",

        "fieldConf": {},

        "fieldType": "any"

    },

    {

        "label": "所在市",

        "id": "gsd3",

        "fieldConf": {},

        "fieldType": "any"

    },

    {

        "label": "所在省市",

        "id": "gsd4",

        "fieldConf": {},

        "fieldType": "any"

    },

    {

        "label": "状态",

        "id": "status",

        "fieldConf": {},

        "fieldType": "any"

    }

]

 

07. 字符查找与替换

 

# 插件代码:



if not triggerConf['_ysnr_zfczyth']:

  return {"status":"原始内容为空"}



if not triggerConf['_cznr_zfczyth']:

  return {"status":"查找内容为空"}



re = {}

re["scnr"] = triggerConf['_ysnr_zfczyth'].replace(triggerConf['_cznr_zfczyth'],triggerConf['_thnr_zfczyth'])

re["status"] = "已完成"



return re



# 请求参数:



[

    {

        "id": "_ysnr_zfczyth",

        "label": "原始内容",

        "description": "",

        "fieldType": "text",

        "isHidden": false,

        "isEnabled": true,

        "isRequired": false,

        "fieldConf": {

            "isMultiLine": false

        },

        "defaultValue": ""

    },

    {

        "id": "_cznr_zfczyth",

        "label": "查找内容",

        "description": "",

        "fieldType": "text",

        "isHidden": false,

        "isEnabled": true,

        "isRequired": false,

        "fieldConf": {

            "isMultiLine": false

        },

        "defaultValue": ""

    },

    {

        "id": "_thnr_zfczyth",

        "label": "替换内容",

        "description": "",

        "fieldType": "text",

        "isHidden": false,

        "isEnabled": true,

        "isRequired": false,

        "fieldConf": {

            "isMultiLine": false

        },

        "defaultValue": ""

    }

]



# 返回参数:



[

    {

        "label": "生成内容",

        "id": "scnr",

        "fieldConf": {},

        "fieldType": "any"

    },

    {

        "label": "状态",

        "id": "status",

        "fieldConf": {},

        "fieldType": "any"

    }

]

 

08. 生成二维码链接

 

# 插件代码:



import urllib.parse



if not triggerConf['_nr_scewmlj']:

  return {"status":"内容为空"}



re = {}

re["lj"] = "".join(["https://cli.im/api/qrcode/code?text=",urllib.parse.quote(triggerConf['_nr_scewmlj'])])

re["status"] = "已完成"



return re



# 请求参数:



[

    {

        "id": "_nr_scewmlj",

        "label": "二维码内容",

        "description": "",

        "fieldType": "text",

        "isHidden": false,

        "isEnabled": true,

        "isRequired": false,

        "fieldConf": {

            "isMultiLine": false

        },

        "defaultValue": ""

    }

]



# 返回参数:



[

    {

        "label": "二维码链接",

        "id": "lj",

        "fieldConf": {},

        "fieldType": "any"

    },

    {

        "label": "状态",

        "id": "status",

        "fieldConf": {},

        "fieldType": "any"

    }

]

 

09. 中文转统一码

 

# 插件代码:



import urllib.parse



if not triggerConf['_zwnr_zwztym']:

  return {"status":"内容为空"}



re = {}

re["tym"] = urllib.parse.quote(triggerConf['_zwnr_zwztym'])

re["status"] = "已完成"



return re





# 请求参数:



[

    {

        "id": "_zwnr_zwztym",

        "label": "中文内容",

        "description": "",

        "fieldType": "text",

        "isHidden": false,

        "isEnabled": true,

        "isRequired": false,

        "fieldConf": {

            "isMultiLine": false

        },

        "defaultValue": ""

    }

]



# 返回参数:



[

    {

        "label": "统一码内容",

        "id": "tym",

        "fieldConf": {},

        "fieldType": "any"

    },

    {

        "label": "状态",

        "id": "status",

        "fieldConf": {},

        "fieldType": "any"

    }

]

 

更多内容:

 

导航:云函数&前端事件&自建插件 内容集 

汇总:论坛中发表过的所有帖子

 

承接简道云技术咨询与应用定制

更多沟通交流可添加微信(zmlnow)

添加时请备注:简道云

 

 

 

分享扩散:

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

0回帖数 2关注人数 7645浏览人数
最后回复于:2024-9-7 16:16

返回顶部 返回列表