开放接口demo

街机捕鱼大富翁破解版 www.ywfxb.tw 若您初次使用智能外呼系统开放平台接口,请在使用前阅读说明文档

街机捕鱼大富翁破解版Demo:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import net.sf.json.JSONArray;

/**
*智能外呼开放接口请求示例 
*该示例包括两个接口:创建任务和提交数据
*/
  public class PlatformDemo {

  private static String BASEURI = " [https://icall.sobot.com/icall/platform/](https://icall.sobot.com/icall/platform/)";

  public static void main(String[] args) {
      System.out.println(addTask()); // 创建任务
      System.out.println(addTaskData()); // 提交数据
  }

  // 创建任务
  public static String addTask() {
      // 链接
      String addTaskUri = BASEURI + "addTask";
      // 参数
      Map<String, Object> parmaMap = new HashMap<String, Object>();
      parmaMap.put("appId", "xxxxxx");
      parmaMap.put("signature", "xxxxxxxxxxxxxxxxxx");
      parmaMap.put("templateId", "xxxxxxxxxxxxxxxxxxxxx");
      parmaMap.put("taskName", "创建任务");
      parmaMap.put("lineType", "1");
      parmaMap.put("telephone", "xxxxxxxx");
      parmaMap.put("robotNum", "1");
      parmaMap.put("timeType", "2");
      parmaMap.put("callTimeSlot", "8:00-19:00");
      parmaMap.put("taskStatus", "0");
      String result = sendPost(addTaskUri, parmaMap);
      return result;
  }

  // 添加任务数据
  public static String addTaskData() {
      // 链接
      String addTaskUri = BASEURI + "addTaskData";
      // 参数
      Map<String, Object> parmaMap = new HashMap<String, Object>();
      parmaMap.put("appId", "xxxxxxx");
      parmaMap.put("signature", "xxxxxxxxxxxxxxxxxxxxxxxxxx");
      parmaMap.put("taskId", "xxxxxxxxxxxxxxxxxxxxxxxx");
      // 变量信息
      List<Map<String, String>> dataList = new ArrayList<Map<String, String>>();
      Map<String, String> dataMap = new HashMap<String, String>();
      dataMap.put("telephone", "1591083****");
      dataMap.put("outId", String.valueOf(UUID.randomUUID()));
      dataMap.put("variable", "公司^公司名");
      dataList.add(dataMap);
      JSONArray dataJson = JSONArray.fromObject(dataMap);
      parmaMap.put("data", dataJson);
      String result = sendPost(addTaskUri, parmaMap);
      return result;
  }

  public static String sendPost(String url, Map<String, Object> param) {
      StringBuffer buffer = new StringBuffer();
      if (param != null && !param.isEmpty()) {
          for (Map.Entry<String, Object> entry : param.entrySet()) {
              try {
                  if (entry.getValue() != null) {
                      buffer.append(entry.getKey()).append("=")
                              .append(URLEncoder.encode(entry.getValue().toString(), "utf-8")).append("&");
                  }
              } catch (UnsupportedEncodingException e) {
                  e.printStackTrace();
              }
          }
          buffer.deleteCharAt(buffer.length() - 1);
      }
      PrintWriter out = null;
      BufferedReader in = null;
      String result = "";
      try {
          URL realUrl = new URL(url);
          // 打开和URL之间的连接
          URLConnection conn = realUrl.openConnection();
          // 设置通用的请求属性
          conn.setRequestProperty("accept", "*/*");
          conn.setRequestProperty("connection", "Keep-Alive");
          conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
          conn.setConnectTimeout(30000);
          conn.setReadTimeout(30000);
          // 发送POST请求必须设置如下两行
          conn.setDoOutput(true);
          conn.setDoInput(true);
          // 获取URLConnection对象对应的输出流
          out = new PrintWriter(conn.getOutputStream());
          // 发送请求参数
          out.print(buffer);
          // flush输出流的缓冲
          out.flush();
          // 定义BufferedReader输入流来读取URL的响应
          in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
          String line;
          while ((line = in.readLine()) != null) {
              result += line;
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
      // 使用finally块来关闭输出流、输入流
      finally {
          try {
              if (out != null) {
                  out.close();
              }
              if (in != null) {
                  in.close();
              }
          } catch (IOException ex) {
              ex.printStackTrace();
          }
      }
      return result;
  }
  }

results matching ""

    No results matching ""