我有一项服务,我有一个方法可以打电话,我该如何访问这项服务。 我已经看过sms插件并安装了它如何从我的应用程序发送短信到不同的mobiles.I跟着grails sms插件但我没有得到任何结果ecxept ecxeptions
class SipgateService {
static transactional = true
def serviceMethod() {
def sipgateService
//def phoneNumber = 'XXXXXXXXXX' //phoneNumber according to E.164 specification
//working alternative:
println "service"
def phoneNumber = 'XXXXXXXXXX'
def result = sipgateService.sendSMS(phoneNumber, 'This is my Text to send!')
result ? 'Sending Successful':'Sending failed'
println "after service"
}
}
请以一个例子解释我。 非常感谢。
答案 0 :(得分:5)
如果要从服务方法调用插件,则需要执行以下操作:
SipgateService
)def sipgateService
添加为类定义,而不是方法一这有用吗?
class MySMSService {
static transactional = true
def sipgateService // This will be injected from the SMS plugin
def serviceMethod() {
println "service"
def phoneNumber = 'XXXXXXXXXX'
def result = sipgateService.sendSMS(phoneNumber, 'This is my Text to send!')
result ? 'Sending Successful':'Sending failed'
println "after service"
}
}
然后,从控制器,在班级定义MySMSService
的链接,并调用您的serviceMethod
方法,即:
class MyController {
def mySMSService // this will be injected from your service
// then, when you want to use it (from an action)
def someAction = {
...
mySMSService.serviceMethod()
...
}
}