api - Grails中Clickatell API的MissingPropertyException

标签 api grails groovy clickatell

我正在使用Grails开发Web应用程序,并且使用Clickatell作为Web API。
我在SMSNotifier.groovy类上有这些代码。
但是,我遇到了MissingPropertyException

groovy.lang.MissingPropertyException: No such property: POST for class: utils.SMSNotifier at utils.SMSNotifier.sendClickatellSms(SMSNotifier.groovy:54)



在SMSNotifier类内部的有错误的代码如下:
    def sendClickatellSms(def number, def text) 
    { 
    def http = new HTTPBuilder('http://api.clickatell.com/') 
    http.contentType = TEXT 
    EncoderRegistry encoders = new EncoderRegistry();
    encoders.setCharset('ISO-8859-1') http.setEncoderRegistry(encoders)

    http.request( POST ) 
    { 
    uri.path = 'http://sendmsg' 
    requestContentType = URLENC 
    if (number.substring(0, 1) == '+') 
    { 
    // Remove a leading plus sign number = number.substring(1) 
    } 
    body = [ api_id: '3442677', user: 'iTech013', password: '', from: '+639277705918', to: number, text: text, concat: '3', callback: '2', deliv_ack: '1' ]

    response.success = { resp, reader -> def msg = reader.text if (msg.substring(0, 2) == 'ID') { return 0 } else if (msg.substring(0, 3) == 'ERR') { log.error("Clickatell " + msg) return msg.substring(5, .toInteger() } else { return 1 }

    } response.failure = { resp -> log.error("Failed to contact Clickatell: ${resp.statusLine}") return 1 } } }

SMSNotifier.groovy文件:
package utils

import org.itech.klinikav2.domain.Patient import org.itech.klinikav2.enums.NotificationType;

import groovyx.net.http.EncoderRegistry 
import groovyx.net.http.HTTPBuilder 
import static groovyx.net.http.Method.GET 
import static groovyx.net.http.ContentType.TEXT import grails.persistence.Event

/** * @author Randy * */

class SMSNotifier 
{
//this method is to send a message with a patient parameter and message 
public static String chooseMessage(NotificationType notifType, Patient patient)
{ 
def message= "Greetings! You will have a follow-up appointment tomorrow." def doctor= "Doctor: "   def time= "Time: " 
def p=patient 
if (notifType.equals(NotificationType.FOLLOW_UP_APPOINTMENT))
{ 
message= "Greetings! You will have a follow-up appointment tomorrow." 
return message } 
else if (notifType.equals(NotificationType.BALANCE))
{ 
message= "Greetings! Just reminding you of your balance for appointment payment." 
return message } 
}

def sendToList(ArrayList<Patient> patients, NotificationType notifType)
{ 
def patientList= patients for (int i=0; i< patientList.size(); i++)
{ def patient = patientList.get(i) 
def message = chooseMessage(notifType, patient) 
sendClickatellSms(patient.mobileNumber, message) } 
}

def sendClickatellSms(def number, def text) 
{ 
def http = new HTTPBuilder('http://api.clickatell.com/') 
http.contentType = TEXT EncoderRegistry encoders = new EncoderRegistry();      
encoders.setCharset('ISO-8859-1') http.setEncoderRegistry(encoders)

http.request(POST)
{ 
uri.path = 'http://sendmsg' 
requestContentType = URLENC 
if (number.substring(0, 1) == '+') 
{ // Remove a leading plus sign 
number = number.substring(1) 
} 
body = [ api_id: '3442677', user: 'iTech013', password: 'ingenium123..', from: '+639277705918', to: number, text: text, concat: '3', callback: '2', deliv_ack: '1' ]

response.success = 
{ resp, reader -> def msg = reader.text if (msg.substring(0, 2) == 'ID') { return 0 } 
else if (msg.substring(0, 3) == 'ERR')
{ 
log.error("Clickatell " + msg) 
return msg.substring(5, .toInteger() } 
else { return 1 }

} 
response.failure = { resp -> log.error("Failed to contact Clickatell: ${resp.statusLine}") return 1 } } }

}

我通过Controller类的index()方法调用了此方法。这些是代码:
    def index() 
    { 
    def sms = new SMSNotifier() 
    def result= sms.sendClickatellSms("09277705918", "Hi!") 
    if(result==1) { render "success" } 
    else{ render "sorry" } 
    }

我将密码空间留为空白,但将实际密码放在了我的实际代码上。

我认为答案很简单,我只是从API入手,因此,对此问题的每一点知识和帮助都深表感谢!
先感谢您! :)

最佳答案

import static groovyx.net.http.Method.*

缺少POST的导入。

关于api - Grails中Clickatell API的MissingPropertyException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19331287/

相关文章:

grails - 为Apache Camel 设置跟踪

json - 在json文件中转换具有json格式的字符串

groovy - 在 Groovy 中查找字符是否为 ASCII 字符

java - Api 21 上的工具栏项 MaterialButton 中的颜色错误

python - 使用Python将JSON对象插入MySQL

iphone - 适用于 iOS 和网站的 Twitter 应用程序

javascript - 如何在屏幕上显示多于一部电影,而不是仅在 React Native 中显示 movieDB api 中的一部电影?

javascript - JavaScript 中的 GSP 标签

grails - 创建常规类

testing - Groovy 断言脚本在 SoapUI 中执行两次