使用连接器
本节介绍连接器在表单上的使用,如何可视化的通过连接器调用第三方接口
准备工作
创建一个表单 天气测试 WeatherTesting,包含以下字段
Name 城市名称 文本框 字符串 长度50
Weather 天气 文本框 字符串 长度50
Note 备注 多行文本 字符串 长度2000
CreateTime 创建时间 日期时间
界面如下:
我们希望在新增的时候 用户只需要输入城市名称
在保存的时候 我们调用高德地图连接器 把所有返回信息放到备注字段 把天气获取到放到天气字段里面
保存流程设置
在业务设计-》表单里面找到该表单
点击编辑 后台流程 保存 找到在新增前
点击后编辑码流 添加常用工具-》连接器节点
选中高德地图连接器
初始化哪里 密钥ClientSecret 地方填写高德地图key:0f23b3c96ceaf0278ad2276a00767bbc
执行动作那里选择获取天气getweather方法
然后需要填写city参数
city参数就是用户在界面上输入的城市名称
说明:表单保存这里 data变量会保存整个表单的数据 这个选择属性 data 然后选择Name
返回值那里添加变量 声明 变量名称为wretmsg 类型为 ZmReturnMsg
这样通过高德地图获取到的天气数据就保存到wretmsg 变量里面了
接着添加实体数据节点
实体表选择 天气测试
对象名 填入data
调用类型 录入使用已有的实体表对象
初始化地方选择自动赋值 点击生成
在生成的字段中我们只需要Weather和Note 字段 只保留这两个字段 其他字段删除
数据见下面的json
json
"status": "1",
"count": "1",
"info": "OK",
"infocode": "10000",
"lives": [{
"province": "北京",
"city": "东城区",
"adcode": "110101",
"weather": "晴",
"temperature": "25",
"winddirection": "西南",
"windpower": "≤3",
"humidity": "14",
"reporttime": "2024-05-07 12:03:47",
"temperature_float": "25.0",
"humidity_float": "14.0"
}]
}
wretmsg 里面的ResponseString字段代表上面整个json
Note 取值类型 哈希取值 值wretmsg 属性ResponseString 取值类型获取字符串值
Weather 先顺便写个固定字符串 test
点击保存 然后保存整个表单 到运行端 新建
城市输入 浦东新区 点击保存 看看效果
如上图可以看到整个json信息是已经录入到了备注字段里面
上面获取到的json不是简单 我们需要的weather字段在lives数组里面的元素里面的weather字段里
接下来我们一步步取到这个天气字段
1:获取整个json的哈希对象,手写添加函数调用节点
设置的地方选择函数
appcom.common.util-》HttpUtil -》GetResponseJsonHash 获取响应body里面的Json字符串转换为Hash的内容
参数里面录入我获取到的wretmsg
返回那里填写变量声明 起个变量名称rethash 类型为ZmHash 哈希对象 代码整个json的哈希数据
2:从该对象里面获取lives 哈希对象列表对象
调用rethash的GetHashListValue方法获取lives 这个ZmHashList对象
3:从lives中获取第一个哈希对象(不考虑没有或者多个数据的情况)
调用lives的GetIndex方法 得到第一个对象
返回值为变量声明 datahash ZmHash对象
到此数据datahash就是我们要的lives下面的有天气的对象了
修改刚才我们谁便设置的那个天气字段 Weather
哈希取值 值datahash 属性weather 取值类型获取字符串值
到此取值全部完成 保存再运行
运行后可以看到取到正确结果了
|_|_zhu-ma-clipboard_|_|scriptcodeflow|_|_zhu-ma-clipboard_|_|com.zhuma.zmone|_|_zhu-ma-clipboard_|_|{"copyType":"scriptcodeflow","copyValue":"amapConnector curamapConnector=new amapConnector();\r\ncuramapConnector.ClientSecret=\"0f23b3c96ceaf0278ad2276a00767bbc\";\r\nZmReturnMsg wretmsg=curamapConnector.getweather(data.Name);\r\nZmHash rethash=HttpUtil.GetResponseJsonHash(wretmsg);\r\nZmHashList lives=rethash.GetHashListValue(\"lives\");\r\nZmHash datahash=lives.GetIndex(0);\r\n\r\ndata.Weather=datahash.GetStringValue(\"weather\");\r\ndata.Note=wretmsg.GetStringValue(\"ResponseString\");|_|__|_|import com.zhuma.zmone.connector.amapConnector;\r\nimport com.zhuma.zmone.appcom.common.framework.ZmReturnMsg;\r\nimport com.zhuma.zmone.appcom.common.util.HttpUtil;\r\nimport com.zhuma.zmone.appcom.common.framework.ZmHash;\r\nimport com.zhuma.zmone.appcom.common.framework.ZmHashList;|_|__|_|flow|_|__|_|{\"cells\":[{\"tag\":\"begin\",\"id\":\"bbf3f246-90f1-4db7-a0fb-806ff8895af7\",\"zIndex\":1,\"position\":{\"x\":100,\"y\":30},\"portItems\":[{\"group\":\"bottom\",\"id\":\"78b4f05a-9b3b-4727-a946-e624223cd78a\"}],\"body\":{},\"text\":{}},{\"tag\":\"connector\",\"caller\":\"curamapConnector\",\"callertype\":\"amapConnector\",\"callerltype\":\"varDeclare\",\"connectorname\":\"\",\"rval\":\"retMsg\",\"callersno\":\"46e5d92d0f484d0abe3be79a3f8d3489\",\"name\":\"node1\",\"package\":\"connector\",\"assignList\":[{\"name\":\"ClientSecret\",\"note\":\"密钥\",\"assignType\":\"String\",\"sourceType\":\"select\",\"rtype\":\"str\",\"rval\":\"0f23b3c96ceaf0278ad2276a00767bbc\",\"rpackage\":\"\",\"rprop\":\"\",\"ntype\":\"\"}],\"funName\":\"getweather\",\"paramList\":[{\"name\":\"city\",\"note\":\"city\",\"paramType\":\"String\",\"sourceType\":\"select\",\"rtype\":\"varProp\",\"rval\":\"data\",\"rprop\":\"Name\",\"rpackage\":\"\",\"ntype\":\"\"}],\"ltype\":\"varDeclare\",\"lname\":\"wretmsg\",\"vtype\":\"ZmReturnMsg\",\"lpackage\":\"appcom.common.framework\",\"id\":\"9499cdca-e3a5-475f-8bec-cd6424306e1d\",\"zIndex\":1,\"position\":{\"x\":100,\"y\":160},\"portItems\":[{\"group\":\"top\",\"id\":\"4f952e3c-2a66-4949-9b55-c462c50c8a0e\"},{\"group\":\"bottom\",\"id\":\"b7d8f962-3c9d-45cc-85fb-9e691caf53d0\"}],\"body\":{},\"text\":{}},{\"tag\":\"entitydata\",\"caller\":\"data\",\"code\":\"\",\"ltype\":\"none\",\"lpackage\":\"\",\"lname\":\"\",\"lprop\":\"\",\"vtype\":\"\",\"refcol\":\"\",\"alias\":\"\",\"resultType\":\"void\",\"selectType\":\"all\",\"dataLimit\":0,\"dataStart\":0,\"isRawName\":0,\"fields\":[],\"conditions\":[],\"assignList\":[{\"name\":\"Weather\",\"note\":\"天气\",\"assignType\":\"\",\"sourceType\":\"none\",\"rtype\":\"hash\",\"rval\":\"datahash\",\"rpackage\":\"\",\"rprop\":\"weather\",\"ntype\":\"GetStringValue\"},{\"name\":\"Note\",\"note\":\"备注\",\"assignType\":\"\",\"sourceType\":\"none\",\"rtype\":\"hash\",\"rval\":\"wretmsg\",\"rpackage\":\"\",\"rprop\":\"ResponseString\",\"ntype\":\"GetStringValue\"}],\"cusJoins\":\"\",\"assigntype\":\"entityauto\",\"cusOrders\":\"\",\"cusConditions\":\"\",\"package\":\"entity\",\"funName\":\"\",\"callertype\":\"WeatherTesting\",\"callerltype\":\"variable\",\"cusFields\":\"\",\"rval\":\"retMsg\",\"callersno\":\"e9d93812158d4be69edb6d879b424976\",\"name\":\"node2\",\"id\":\"74d565d6-e84f-4df0-85fb-563337dd563d\",\"zIndex\":1,\"position\":{\"x\":300,\"y\":490},\"portItems\":[{\"group\":\"top\",\"id\":\"a9f47869-7bac-4a5e-a4dd-56649f627c9a\"},{\"group\":\"bottom\",\"id\":\"a7ca52e2-ba69-4995-8711-2563023a54f3\"}],\"body\":{},\"text\":{}},{\"tag\":\"fun\",\"tstatic\":\"static\",\"caller\":\"HttpUtil\",\"funName\":\"GetResponseJsonHash\",\"ltype\":\"varDeclare\",\"lpackage\":\"appcom.common.framework\",\"lname\":\"rethash\",\"lprop\":\"\",\"vtype\":\"ZmHash\",\"paramList\":[{\"name\":\"returnMsg\",\"note\":\"ZmReturnMsg对象 包含响应response里面的全部内容\",\"paramType\":\"ZmReturnMsg\",\"sourceType\":\"select\",\"rtype\":\"variable\",\"rval\":\"wretmsg\",\"rprop\":\"\",\"rpackage\":\"\",\"ntype\":\"\"}],\"name\":\"node3\",\"package\":\"appcom.common.util\",\"id\":\"c4d5ce12-c99a-4d4e-bf49-0e3dac8096fc\",\"zIndex\":1,\"position\":{\"x\":250,\"y\":180},\"portItems\":[{\"group\":\"top\",\"id\":\"d500228c-019b-4a91-9cb4-68c16419c8cc\"},{\"group\":\"top\",\"id\":\"039c4916-0181-4e4b-80ae-ab07adc634a3\"},{\"group\":\"bottom\",\"id\":\"89b70263-09c8-46dc-82a2-179798196b61\"},{\"group\":\"bottom\",\"id\":\"8afc7ea5-2299-482a-91e3-8487cd1bcf13\"},{\"group\":\"right\",\"id\":\"fa813a0c-4ecb-42e3-a24b-d31e26e8b31f\"},{\"group\":\"left\",\"id\":\"b71580c5-401d-4df7-a0db-876cb7df8b57\"}],\"body\":{},\"text\":{}},{\"tag\":\"fun\",\"tstatic\":\"none\",\"caller\":\"rethash\",\"funName\":\"GetHashListValue\",\"ltype\":\"varDeclare\",\"lpackage\":\"appcom.common.framework\",\"lname\":\"lives\",\"lprop\":\"\",\"vtype\":\"ZmHashList\",\"paramList\":[{\"name\":\"key\",\"note\":\"键\",\"paramType\":\"String\",\"sourceType\":\"select\",\"rtype\":\"str\",\"rval\":\"lives\",\"rprop\":\"\",\"rpackage\":\"\",\"ntype\":\"\"}],\"name\":\"node4\",\"package\":\"appcom.common.framework\",\"id\":\"6a4153d9-e5cf-45e0-8d54-b35f20fa6f0d\",\"zIndex\":1,\"position\":{\"x\":290,\"y\":280},\"portItems\":[{\"group\":\"top\",\"id\":\"46c584e2-0786-41e6-8e4d-e01b78e3923d\"},{\"group\":\"top\",\"id\":\"fd699f35-ab1f-4f01-a5b2-21366a21c828\"},{\"group\":\"bottom\",\"id\":\"5cc3a926-50a9-4b8c-a10f-21be54ac4277\"},{\"group\":\"bottom\",\"id\":\"3315eba0-ac91-42a7-bc9c-c0a796a4e044\"},{\"group\":\"right\",\"id\":\"a9703fc0-ce64-4438-a051-583991cdb730\"},{\"group\":\"left\",\"id\":\"147204bc-40a7-4854-9be2-883af3718b55\"}],\"body\":{},\"text\":{}},{\"tag\":\"fun\",\"tstatic\":\"none\",\"caller\":\"lives\",\"funName\":\"GetIndex\",\"ltype\":\"varDeclare\",\"lpackage\":\"appcom.common.framework\",\"lname\":\"datahash\",\"lprop\":\"\",\"vtype\":\"ZmHash\",\"paramList\":[{\"name\":\"index\",\"note\":\"指定位置\",\"paramType\":\"Int\",\"sourceType\":\"select\",\"rtype\":\"num\",\"rval\":\"0\",\"rprop\":\"\",\"rpackage\":\"\",\"ntype\":\"\"}],\"name\":\"node5\",\"package\":\"appcom.common.framework\",\"id\":\"10fee018-e3a1-4426-9fd9-892dc36675b8\",\"zIndex\":1,\"position\":{\"x\":400,\"y\":350},\"portItems\":[{\"group\":\"top\",\"id\":\"46c584e2-0786-41e6-8e4d-e01b78e3923d\"},{\"group\":\"top\",\"id\":\"fd699f35-ab1f-4f01-a5b2-21366a21c828\"},{\"group\":\"bottom\",\"id\":\"5cc3a926-50a9-4b8c-a10f-21be54ac4277\"},{\"group\":\"bottom\",\"id\":\"3315eba0-ac91-42a7-bc9c-c0a796a4e044\"},{\"group\":\"right\",\"id\":\"a9703fc0-ce64-4438-a051-583991cdb730\"},{\"group\":\"left\",\"id\":\"147204bc-40a7-4854-9be2-883af3718b55\"}],\"body\":{},\"text\":{}},{\"tag\":\"end\",\"id\":\"f5ac0c16-b42f-4624-bfdf-cbb11cc5c82d\",\"zIndex\":2,\"position\":{\"x\":120,\"y\":680},\"portItems\":[{\"group\":\"top\",\"id\":\"4c4c6a72-052a-42fa-b9ce-d2d5c9a31d9a\"}],\"body\":{},\"text\":{}},{\"tag\":\"block\",\"etype\":\"code\",\"code\":\"\",\"id\":\"e54978dc-be4c-47d5-85db-6d2c9a5a2383\",\"zIndex\":3,\"position\":{\"x\":230,\"y\":580},\"portItems\":[{\"group\":\"top\",\"id\":\"0c686168-1d11-4c55-9315-8f47f8b54831\"},{\"group\":\"bottom\",\"id\":\"3f023c5d-e073-4930-bab7-b04cd5ec7b4c\"}],\"body\":{},\"text\":{}},{\"tag\":\"edge\",\"etype\":\"edge\",\"ekey\":\"\",\"text\":{},\"id\":\"d202a454-15e0-4fc9-a224-78abfd618089\",\"zIndex\":4,\"source\":{\"cell\":\"bbf3f246-90f1-4db7-a0fb-806ff8895af7\",\"port\":\"78b4f05a-9b3b-4727-a946-e624223cd78a\"},\"target\":{\"cell\":\"9499cdca-e3a5-475f-8bec-cd6424306e1d\",\"port\":\"4f952e3c-2a66-4949-9b55-c462c50c8a0e\"},\"line\":{},\"connector\":{}},{\"tag\":\"edge\",\"etype\":\"edge\",\"ekey\":\"\",\"text\":{},\"id\":\"fced1f9d-7381-435d-91cf-92fbbeee3054\",\"zIndex\":5,\"source\":{\"cell\":\"e54978dc-be4c-47d5-85db-6d2c9a5a2383\",\"port\":\"3f023c5d-e073-4930-bab7-b04cd5ec7b4c\"},\"target\":{\"cell\":\"f5ac0c16-b42f-4624-bfdf-cbb11cc5c82d\",\"port\":\"4c4c6a72-052a-42fa-b9ce-d2d5c9a31d9a\"},\"line\":{},\"connector\":{}},{\"tag\":\"edge\",\"etype\":\"edge\",\"stype\":\"common\",\"ekey\":\"\",\"name\":\"line1\",\"text\":{},\"id\":\"123470b0-cf0d-4916-9c0b-8c09afe96e66\",\"zIndex\":6,\"source\":{\"cell\":\"9499cdca-e3a5-475f-8bec-cd6424306e1d\",\"port\":\"b7d8f962-3c9d-45cc-85fb-9e691caf53d0\"},\"target\":{\"cell\":\"c4d5ce12-c99a-4d4e-bf49-0e3dac8096fc\",\"port\":\"d500228c-019b-4a91-9cb4-68c16419c8cc\"},\"line\":{},\"connector\":{}},{\"tag\":\"edge\",\"etype\":\"edge\",\"stype\":\"common\",\"ekey\":\"\",\"name\":\"line2\",\"text\":{},\"id\":\"d3e00125-8234-43f8-8be7-bd8ca03e8f09\",\"zIndex\":7,\"source\":{\"cell\":\"74d565d6-e84f-4df0-85fb-563337dd563d\",\"port\":\"a7ca52e2-ba69-4995-8711-2563023a54f3\"},\"target\":{\"cell\":\"e54978dc-be4c-47d5-85db-6d2c9a5a2383\",\"port\":\"0c686168-1d11-4c55-9315-8f47f8b54831\"},\"line\":{},\"connector\":{}},{\"tag\":\"edge\",\"etype\":\"callback\",\"stype\":\"common\",\"ekey\":\"\",\"name\":\"line3\",\"text\":{},\"id\":\"5143976d-8c5c-4986-9e51-f84878c373fd\",\"zIndex\":8,\"source\":{\"cell\":\"c4d5ce12-c99a-4d4e-bf49-0e3dac8096fc\",\"port\":\"89b70263-09c8-46dc-82a2-179798196b61\"},\"target\":{\"cell\":\"6a4153d9-e5cf-45e0-8d54-b35f20fa6f0d\",\"port\":\"46c584e2-0786-41e6-8e4d-e01b78e3923d\"},\"line\":{},\"connector\":{}},{\"tag\":\"edge\",\"etype\":\"callback\",\"stype\":\"common\",\"ekey\":\"\",\"name\":\"line4\",\"id\":\"50035713-4d41-4e02-a65b-64b65e9b1840\",\"zIndex\":9,\"source\":{\"cell\":\"6a4153d9-e5cf-45e0-8d54-b35f20fa6f0d\",\"port\":\"5cc3a926-50a9-4b8c-a10f-21be54ac4277\"},\"target\":{\"cell\":\"10fee018-e3a1-4426-9fd9-892dc36675b8\",\"port\":\"46c584e2-0786-41e6-8e4d-e01b78e3923d\"},\"line\":{},\"connector\":{},\"text\":{}},{\"tag\":\"edge\",\"etype\":\"callback\",\"stype\":\"common\",\"ekey\":\"\",\"name\":\"line5\",\"id\":\"8af8e8bc-adda-425f-b855-6c96a061d9bf\",\"zIndex\":10,\"source\":{\"cell\":\"10fee018-e3a1-4426-9fd9-892dc36675b8\",\"port\":\"3315eba0-ac91-42a7-bc9c-c0a796a4e044\"},\"target\":{\"cell\":\"74d565d6-e84f-4df0-85fb-563337dd563d\",\"port\":\"a9f47869-7bac-4a5e-a4dd-56649f627c9a\"},\"line\":{},\"connector\":{},\"text\":{}}]}|_|__|_|"}|_|_zhu-ma-clipboard_|_|