簡體   English   中英

Java / Grails:從應用程序發送短信

[英]Java / Grails : Send SMS from application

我在grails中有一個培訓管理系統(grails版本2.0.4)

我的要求

  1. 每當用戶報名參加培訓時,他都必須收到一條短信提醒,告知其注冊時提供的手機號碼。
  2. 僅向印度手機發送短信(因為我們僅在印度提供培訓)
  3. 一種短信方式,從應用程序到移動電話(無需回復)

Grails中有可用的好插件嗎? 即使使用Java的方式在grails應用程序中也能正常工作。

我已經將Twilio用於合作伙伴的應用程序。 這是一項付費服務​​,國際短信到印度的價格在這里

有一個可用於twilio的Grails插件,但我選擇編寫一些自定義代碼來發送和接收消息。 插件存在一些問題,我不記得了。

准系統代碼如下所示:

def twilioHttpEndpointBean = new HTTPBuilder("https://api.twilio.com/2010-04-01/")
def sid = 'your SID here'
def auth_token = 'the auth token goes here'
twilioHttpEndpointBean.auth.basic(sid,auth_token)
def result = twilioHttpEndpointBean.request(Method.POST) { req -> 
    requestContentType = ContentType.URLENC
    uri.path = "Accounts/${sid}/SMS/Messages.json"
    body = [ To: <destinationPhoneNumber>, From: <mainNumberUsedToRegisterForTheService>, Body: 'your message' ]
    response.success = { resp, data ->
        def test = [status: data.status, sid: data.sid]
        return test
    }
    response.failure = { resp, data ->
        def test = [status: data.status, code: data.message]
        return test
    }
}

有一個插件,它提供了一種通過SMS-Gateway,sipgate.de,sipgate.com的XMl-RPC API發送SMS的簡便方法

使用grails install-plugin sipgate命令安裝它

和編輯conf / Config.groovy中的account-data-placeholders

grails.plugins.sipgate.username = 'YOUR_USERNAME'
grails.plugins.sipgate.password = 'YOUR_PASSWORD'
//According to E.164,

例如'4922112345678'grails.plugins.sipgate.phoneNumber grails.plugins.sipgate.phoneNumber = 'YOUR_PHONE'

然后注入“ sipgateService ”並發送一條短信

def sipgateService
def phoneNumber = '4917712345678' //phoneNumber according to E.164 specification //working alternative: def phoneNumber = '+1-719-555-1234'
def result = sipgateService.sendSMS(phoneNumber, 'This is my Text to send!')
result? println 'Sending Successful': println 'Sending failed'

我不確定grail但是如果您想使用java嘗試一下,請查看smslib.org

從站點復制:

SMSLib is a programmer library for sending and receiving SMS messages via a GSM modem or mobile phone.

希望這對您有幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM