我正在使用以下php发送SMS,该消息位于php中。因此,我无法使用Node Js项目添加。所以我需要更改为Node。但是,有针对Web服务用户here的Web服务。当我在SoapUI中尝试链接时,它可以正常工作并发送SMS。当我在Node Js中尝试代码时,我没有得到Sesson ID,也没有发送SMS。
我在Node中尝试过的操作
router.post("/register", upload.single('image'), function (req, res, next)
{
var url = 'http://smeapps.mobitel.lk:8585/EnterpriseSMSV2/EnterpriseSMSWS?wsdl';
var session = {username: 'myUserName', password: 'myPassword'}
soap.createClient(url, function(err, client)
{
if(err)
console.log(err)
client.createSession(session, function(err, result)
{
console.log('The result is : ' + result);
});
var smsMessage = {message:'Sample', recipient:'9471xxxxxxx'}
client.sendMessages(smsMessage, function(err, result2)
{
console.log("Send Msg err : " + err);
console.log('The result is : ' + result2);
});
})
})
控制台输出为
The result is : [object Object]
Send Msg err : Error: SOAP-ENV:Server: Procedure 'sendMessages' not present
The result is : [object Object]
php代码
<?php
require_once('ESMSWS.php');
$username = 'username';
$password = 'password';
$recipient = 9471xxxxxxx;
$alias = 'App Name';
$message_body = "Sample";
$session = createSession('',$username,$password,'');
var_dump($session);
$sndMsg = sendMessages($session,$alias,$message_body,$recipient);
var_dump($sndMsg);
//closeSession($session);
?>
成功的php输出
C:\wamp64\www\sms\esmsclientapp.php:11:
object(stdClass)[6]
public 'expiryDate' => string '2018-10-04T06:40:07+05:30' (length=25)
public 'isActive' => boolean true
public 'sessionId' => string '775858578314' (length=12)
public 'user' => int 0
C:\wamp64\www\sms\esmsclientapp.php:16:int 200 // 200 means message sent
SoapUI创建会话
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.esms.mobitel.lk/">
<soapenv:Header/>
<soapenv:Body>
<ws:createSession>
<!--Optional:-->
<arg0>
<!--Optional:-->
<customer>12</customer>
<!--Optional:-->
<id>12</id>
<!--Optional:-->
<password>password</password>
<!--Optional:-->
<username>username</username>
</arg0>
</ws:createSession>
</soapenv:Body>
</soapenv:Envelope>
SoapUI会话成功输出
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.esms.mobitel.lk/">
<SOAP-ENV:Body>
<ns1:createSessionResponse>
<return>
<expiryDate>2018-10-04T06:24:25+05:30</expiryDate>
<isActive>true</isActive>
<sessionId>761033662786</sessionId>
<user>0</user>
</return>
</ns1:createSessionResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SoapUI发送消息
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.esms.mobitel.lk/">
<soapenv:Header/>
<soapenv:Body>
<ws:sendMessages>
<!--Optional:-->
<arg0>
<!--Optional:-->
<expiryDate>2018-10-04T05:12:26+05:30</expiryDate>
<!--Optional:-->
<id>1</id>
<!--Optional:-->
<isActive>1</isActive>
<!--Optional:-->
<sessionId>761033662786</sessionId>
<!--Optional:-->
<user>1</user>
</arg0>
<!--Optional:-->
<arg1>
<!--Optional:-->
<message>Sample</message>
<messageId>1</messageId>
<!--Zero or more repetitions:-->
<recipients>9471xxxxxxx</recipients>
<retries>0</retries>
<!--Optional:-->
<sender>
<!--Optional:-->
<alias>App Name</alias>
<!--Optional:-->
<customer>1</customer>
<!--Optional:-->
<id>1</id>
</sender>
<sequenceNum>1</sequenceNum>
<status>1</status>
<!--Optional:-->
<time>2018-10-04T05:12:26+05:30</time>
<!--Optional:-->
<type>?</type>
<!--Optional:-->
<user>
<!--Optional:-->
<customer>1</customer>
<!--Optional:-->
<id>1</id>
<!--Optional:-->
<password>password</password>
<!--Optional:-->
<username>username</username>
</user>
</arg1>
</ws:sendMessages>
</soapenv:Body>
</soapenv:Envelope>
SoapUI成功发送消息
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.esms.mobitel.lk/">
<SOAP-ENV:Body>
<ns1:sendMessagesResponse>
<return>200</return>
</ns1:sendMessagesResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>