gpt4 book ai didi

grails - Grails和Nexmo插件

转载 作者:行者123 更新时间:2023-12-02 15:22:32 26 4
gpt4 key购买 nike

我在整合Nexmo插件的Grails中遇到错误。发生错误的文件是“NexmoService.groovy”,如下所示:

package grails.plugin.nexmo

import groovyx.net.http.HTTPBuilder
import org.springframework.context.i18n.LocaleContextHolder as LCH

import static groovyx.net.http.ContentType.URLENC
import static groovyx.net.http.Method.POST

class NexmoService {

def grailsApplication
def messageSource

def sendSms(String to, String text, String from=config?.sms?.default_from) throws NexmoException {
if (!to || !text || !from) {
throw new NexmoException(getMessage("nexmo.sms.error.missing.param"))
}

def http = new HTTPBuilder(config?.endpoint)
def requestBody = [to: to, text: text, from: from, api_key: config?.api?.key, api_secret: config?.api?.secret]

http.request(POST) {
uri.path = "/sms/${config?.format}"
send(URLENC, requestBody)

response.success = { resp, data ->
def message = data?.messages[0]
def statusCode = message?.status
if (statusCode != "0") {
def error = getMessage("nexmo.sms.status.${statusCode}", [message?."error-text"], getMessage("nexmo.sms.error.default"))
throw new NexmoException(error)
}
log.info(getMessage("nexmo.sms.success"))
return [status: message?.status, id: message?."message-id"]
}
response.failure = { resp, data ->
def error = getMessage("nexmo.sms.error.response", [resp?.status], getMessage("nexmo.sms.error.default"))
throw new NexmoException(error)
}
}
}

def call(String to, String text, String from="") throws NexmoException {
if (!to || !text) {
throw new NexmoException(getMessage("nexmo.call.error.missing.param"))
}

def http = new HTTPBuilder(config?.endpoint)
def requestBody = [to: to, text: text, from: from, api_key: config?.api?.key, api_secret: config?.api?.secret]

http.request(POST) {
uri.path = "/tts/${config?.format}"
send(URLENC, requestBody)

response.success = { resp, data ->
def statusCode = data?.status
if (statusCode != "0") {
def error = getMessage("nexmo.call.status.${statusCode}", [data?."error-text"], getMessage("nexmo.call.error.default"))
throw new NexmoException(error)
}
log.info(getMessage("nexmo.call.success"))
return [status: data?.status, id: data?."call-id"]
}
response.failure = { resp, data ->
def error = getMessage("nexmo.call.error.response", [resp?.status], getMessage("nexmo.call.error.default"))
throw new NexmoException(error)
}
}
}

private ConfigObject getConfig() {
return grailsApplication.config?.nexmo
}

private String getMessage(String code, List args=[], String defaultMessage="") {
if (messageSource.resolveCode(code, LCH.locale)) {
return messageSource.getMessage(code, args.toArray(), LCH.locale)
}
return defaultMessage
}
}

错误如下:

| Error Compilation error: startup failed: C:\nexmo-master\grails-app\services\grails\plugin\nexmo\NexmoService.groovy: 3: unable to resolve class groovyx.net.http.HTTPBuilder @ line 3, column 1. import groovyx.net.http.HTTPBuilder ^

C:\nexmo-master\grails-app\services\grails\plugin\nexmo\NexmoService.groovy: 6: unable to resolve class groovyx.net.http.ContentType @ line 6, column 1. import static groovyx.net.http.ContentType.URLENC ^

C:\nexmo-master\grails-app\services\grails\plugin\nexmo\NexmoService.groovy: 7: unable to resolve class groovyx.net.http.Method @ line 7, column 1. import static groovyx.net.http.Method.POST ^

3 errors

最佳答案

您在类路径中没有http-builder库。查看此帖子以获取导入此库的说明。 How to import groovyx.net.httphttp://www.groovy-lang.org/mailing-lists.html#nabble-td3995735

关于grails - Grails和Nexmo插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32984912/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com