sri*_*ini 2 grails groovy grails-plugin
我有一个服务,我有一个方法来调用,我如何访问此服务.我已经看过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"
}
}
Run Code Online (Sandbox Code Playgroud)
请举个例子解释我.非常感谢.
如果要从服务方法调用插件,则需要执行以下操作:
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"
}
}
Run Code Online (Sandbox Code Playgroud)
然后,从控制器,定义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()
...
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3217 次 |
| 最近记录: |