- package alipay.data.bill.accountlog.query;
- //支付宝SDK
- import com.alipay.api.AlipayApiException;
- import com.alipay.api.AlipayClient;
- import com.alipay.api.DefaultAlipayClient;
- import com.alipay.api.request.AlipayDataBillAccountlogQueryRequest;
- import com.alipay.api.response.AlipayDataBillAccountlogQueryResponse;
- //其他插件
- import lombok.EqualsAndHashCode;
- import org.json.JSONArray;
- import org.json.JSONObject;
- //活字格
- import com.grapecity.forguncy.commands.ICommandExecutableInServerSide;
- import com.grapecity.forguncy.commands.IServerCommandExecuteContext;
- import com.grapecity.forguncy.commands.annotation.ResultToProperty;
- import com.grapecity.forguncy.commands.entity.Command;
- import com.grapecity.forguncy.commands.entity.ExecuteResult;
- //import com.grapecity.forguncy.commands.enumeration.CommandScope;
- import com.grapecity.forguncy.plugincommon.common.annotation.*;
- import lombok.Data;
- import java.util.List;
- @EqualsAndHashCode(callSuper = true)
- @Data
- @Icon("resources/Icon.png")
- public class AlipayAccountlog extends Command implements ICommandExecutableInServerSide {
- @Required
- @FormulaProperty
- @DisplayName("第三方应用APPID:")
- private Object app_id;
- @Required
- @FormulaProperty
- @DisplayName("第三方应用APP_PRIVATE_KEY:")
- private Object PrivateKey;
- @Required
- @FormulaProperty
- @DisplayName("第三方支付宝ALIPAY_PUBLIC_KEY:")
- private Object AlipayPublicKey;
- @Required
- @FormulaProperty
- @DisplayName("app_auth_token:")
- private Object app_auth_token;
- @DisplayName("请求参数:")
- @FlatListProperty
- public List<MyObj> parameter;
- @ResultToProperty
- // @FormulaProperty
- @DisplayName("请求结果至变量:")
- private String resultTo;
- /**
- * 命令执行方法
- * @param dataContext 从服务器端传递给命令执行时的上下文信息
- * @return 是否执行成功
- */
- @Override
- public ExecuteResult execute(IServerCommandExecuteContext dataContext) {
- JSONArray jsonArray = new JSONArray(parameter);
- JSONObject results = new JSONObject();
- for (int i = 0; i < jsonArray.length(); i++) {
- JSONObject obj = jsonArray.getJSONObject(i);
- String name = obj.getString("参数名");
- String value = obj.getString("参数值");
- // 将名称和值添加到新的JSONObject中
- results.put(name, value);
- }
- AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", app_id.toString(), PrivateKey.toString(), "json", "UTF-8", AlipayPublicKey.toString(), "RSA2"); //获得初始化的AlipayClient
- AlipayDataBillAccountlogQueryRequest request = new AlipayDataBillAccountlogQueryRequest();//创建API对应的request类
- request.putOtherTextParam("app_auth_token", app_auth_token.toString());//授权token,代调用必传
- request.setBizContent(results.toString()); //设置业务参数
- AlipayDataBillAccountlogQueryResponse response;//通过alipayClient调用API,获得对应的response类
- try {
- response = alipayClient.execute(request);
- dataContext.getParameters().put(resultTo, response.getBody());
- } catch (AlipayApiException e) {
- throw new RuntimeException(e);
- }
- return new ExecuteResult();
- }
- /**
- * 返回插件的名称
- * @return 插件的名称
- */
- @Override
- public String toString() {
- return "支付宝商家账户账务明细查询";
- }
- }
复制代码 |