我使用这个lib目录下:https://github.com/vpulim/node-soap,获得来自API的数据。我用下面的代码文件caled apiDecoder.ts:
class NuSoapClient{
public GetNuSoapInfo():string{
var soap = require('soap')
var url = "https://my.url.com/consultNFSe/server.php?wsdl"
var args = {token. :"mysecrettoken",
doc : "000000000",
number : "000000000"
}
soap.CreateClient(url, function(err, client){
client.MyFunction(args, function(err, result){
console.log(result);
});
});
return
}
}
var nf = new NuSoapClient()
nf.GetNuSoapInfo()
console.log(nf)
我收到以下错误,当我编译代码:
" SyntaxError: Unexpected identifier
at Module._compile (internal/modules/cjs/loader.js:895:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
at internal/main/run_main_module.js:17:11 "
PS:我是编码PHP相同的功能(OO太),存在丢失的说法,我没有得到$水库变量打字稿中,“consultaNFSe”使用的方式。它定义谁我在API中我打电话。下面是用的NuSOAP的lib工作的PHP代码:
$client = new nusoap_client('https://my.url.com/consultNFSe/server.php?wsdl');
$parameters = array('token'=> $results->token,
'cnpj'=> $results->cnpj,
'nrNota'=> $results->nota);
$res = $client->call('consultaNFSe', $parameters);
$contents = file_get_contents("data.php");
$arr = json_decode($res, true);
有什么想法吗?我被困在这一点上。
我sugest您拨打所有的库外类的范围内,例如:
const soap = require('soap')
class Examp {}
我不是很确定,但我认为soap.CreateClient需要另一个不可选参数(选项)。所以,将是:
soap.CreateClient(url, {}, function(err, client){ //here second parameter
if (err) throw(err);
client.MyFunction(args, function(err, result){
console.log(result);
});
});
我希望它可以帮助你。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句