Пример #1
0
  public String execute(Map<String, String> map) throws TwilioRestException {
    List<NameValuePair> params = new ArrayList<NameValuePair>(map.keySet().size());

    Set<String> keys = map.keySet();
    for (String key : keys) {
      params.add(new BasicNameValuePair(key, map.get(key)));
    }

    MessageFactory messageFactory = getAccount().getMessageFactory();
    Message message = messageFactory.create(params);
    return message.getSid();
  }
Пример #2
0
  private void sendVerNumber(String phone, String verNumber) throws TwilioRestException {
    TwilioRestClient client =
        new TwilioRestClient(Constants.TWILLIO_ACCOUNT_SID, Constants.TWILLIO_AUTH_TOKEN);

    // Build the parameters
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("To", phone));
    params.add(new BasicNameValuePair("From", "+16147636291"));
    params.add(new BasicNameValuePair("Body", "달샵 가입자 확인번호 : " + verNumber));

    MessageFactory messageFactory = client.getAccount().getMessageFactory();
    Message message = messageFactory.create(params);
    log.warning("sent phone verification number, sid: " + message.getSid());
  }
Пример #3
0
  public static void send(String phone, String text) {

    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Build a filter for the MessageList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Body", text));
    boolean to = params.add(new BasicNameValuePair("To", "+" + phone));
    params.add(new BasicNameValuePair("From", "+17075496112"));

    MessageFactory messageFactory = client.getAccount().getMessageFactory();
    Message message = null;
    try {
      message = messageFactory.create(params);
    } catch (TwilioRestException e) {
      e.printStackTrace();
    }
    System.out.println(message.getSid());
  }
Пример #4
0
  @PUT
  @Path("{title}/{body}/{isDone}")
  @Produces(value = "text/plain")
  @Consumes(MediaType.TEXT_PLAIN)
  public Response toggleStatusListItem(
      @PathParam("title") String title,
      @PathParam("body") String body,
      @PathParam("isDone") boolean isDone) {
    // Find your Account Sid and Token at twilio.com/user/account
    ListItem item = new ListItem(title, body, isDone);
    boolean done = isDone ? false : true;
    int index = list.indexOf(item);
    item.setDone(done);
    list.remove(index);
    list.add(index, item);

    if (isDone == Boolean.FALSE) {

      String ACCOUNT_SID = "AC96d0a9024203de2a4177624c789fad17";
      String AUTH_TOKEN = "919a89967cc484a35a1a0cfd0555dd57";

      TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
      try {
        // Build a filter for the MessageList
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("Body", "Task : " + body + "is complete."));
        params.add(new BasicNameValuePair("To", "+14086270378"));
        params.add(new BasicNameValuePair("From", "+18316847487"));

        MessageFactory messageFactory = client.getAccount().getMessageFactory();
        Message message = messageFactory.create(params);
        System.out.println(message.getSid());
        return Response.status(200).entity(body.toString()).build();
      } catch (TwilioRestException e) {
        System.out.println(e.getErrorMessage());
      }
    }
    return Response.status(500).entity(body.toString()).build();
  }
Пример #5
0
  @Override
  public void sendSms(SmsDto smsDto) {

    try {

      TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

      Account account = client.getAccount();

      MessageFactory messageFactory = account.getMessageFactory();
      List<NameValuePair> params = new ArrayList<NameValuePair>();
      params.add(new BasicNameValuePair("To", smsDto.getTo()));
      params.add(new BasicNameValuePair("From", FROM_PHONE));
      params.add(new BasicNameValuePair("Body", SMS_BODY));
      Message sms = messageFactory.create(params);

      log.debug("Sent SMS: " + sms.getBody() + "to: " + sms.getTo());

    } catch (TwilioRestException ex) {
      log.debug(ex.toString());
    }
  }