Grails和短信插件

彼得·哈

是否有任何建议可以与Grails轻松集成的SMS插件?

我正在建立一个管理系统,该系统通过短信向客户发送Y / N确认。

wwwclaes

SMS服务的成本和交付质量取决于您将SMS发送到的国家/地区,但是(在更改为瑞典供应商之前),我们使用了国际供应商Clickatell并获得了不错的结果。

您不需要使用Grails插件,只需将HTTPBuilder(例如,通过包含Grails REST插件)与Grails一起使用即可根据其文档来调用Clickatell API。

这是一些旧的示例代码(如果API已更改,则可能无法正常工作):

    import groovyx.net.http.HTTPBuilder
    import groovyx.net.http.EncoderRegistry
    import static groovyx.net.http.Method.POST
    import static groovyx.net.http.ContentType.URLENC
    import static groovyx.net.http.ContentType.TEXT

    def http = new HTTPBuilder(host)
    http.contentType = TEXT
    EncoderRegistry encoders = new EncoderRegistry();
    encoders.setCharset('ISO-8859-1')
    http.setEncoderRegistry(encoders)

    http.request(POST) {
      uri.path = 'http/sendmsg'
      requestContentType = URLENC
      body = [api_id: '1234567', user: 'john', password: 'doe', from: 'Company', to: NUMBER, text: 'Hello world', concat: '3', callback: '2', deliv_ack: '1']
      response.success = { resp, reader ->
        def msg = reader.text
        if (msg.substring(0, 2) == 'ID') {
        } else if (msg.substring(0, 3) == 'ERR') {
        } else {
        }
      }
      response.failure = { resp ->
      }
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章