You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.0 KiB
66 lines
2.0 KiB
package com.fr.plugin.dingding.webhook.fun; |
|
|
|
import com.fr.general.http.HttpRequest; |
|
import com.fr.general.http.HttpToolbox; |
|
import com.fr.intelli.record.Focus; |
|
import com.fr.intelli.record.Original; |
|
import com.fr.log.FineLoggerFactory; |
|
import com.fr.plugin.context.PluginContexts; |
|
import com.fr.plugin.dingding.webhook.PluginConstants; |
|
import com.fr.script.AbstractFunction; |
|
import com.fr.stable.ArrayUtils; |
|
import com.fr.stable.Primitive; |
|
import com.fr.stable.StringUtils; |
|
import com.fr.stable.exception.FormulaException; |
|
import com.fr.stable.fun.Authorize; |
|
|
|
import java.io.IOException; |
|
import java.util.HashMap; |
|
import java.util.Map; |
|
|
|
/** |
|
* @Author fr.open |
|
* @Date 2021/9/15 |
|
* @Description |
|
**/ |
|
@Authorize(callSignKey = PluginConstants.PLUGIN_ID) |
|
public class TicketFun extends AbstractFunction { |
|
@Override |
|
@Focus(id = PluginConstants.PLUGIN_ID, text = "钉钉webhook", source = Original.PLUGIN) |
|
public Object run(Object[] args) throws FormulaException { |
|
if (!PluginContexts.currentContext().isAvailable()) { |
|
return null; |
|
} |
|
int len = ArrayUtils.getLength(args); |
|
if (len == 0) { |
|
return Primitive.ERROR_VALUE; |
|
} |
|
String user = (String) args[0]; |
|
String target = (String) args[1]; |
|
|
|
if(StringUtils.isBlank(user) || StringUtils.isBlank(target)){ |
|
return Primitive.ERROR_VALUE; |
|
} |
|
String url =StringUtils.EMPTY; |
|
if(args.length < 3){ |
|
url = "http://xxxx:xxx/trusted"; |
|
}else { |
|
url = (String) args[2]; |
|
if(StringUtils.isBlank(url)){ |
|
url = "http://xxx:xxx/trusted"; |
|
} |
|
} |
|
|
|
Map<String, String> param = new HashMap<>(); |
|
param.put("username",user); |
|
param.put("target_site",target); |
|
try { |
|
String execute = HttpToolbox.executeAndParse(HttpRequest.custom().post(param).url(url).build()); |
|
return execute; |
|
} catch (IOException e) { |
|
FineLoggerFactory.getLogger().error(e.getMessage(),e); |
|
} |
|
|
|
return null; |
|
} |
|
}
|
|
|