Can't receive deliver_sm (SMPP) - php

I'm sending SMS by PHP, SMPP protocol and must use Net_SMPP library. After sending SMS (it comes to phone normally) I need to receive answer (deliver_sm PDU from SMSC). But listening of it hasn't take effect. My reciver's code:
$host = '*********';
$port = '****';
$login = '*****';
$password = '*******';
/*
* There is sending of SMS
*/
$smsc = new Net_SMPP_Client($host, $port);
$smsc->connect();
$resp = $smsc->bind(
array(
'system_id' => $login,
'password' => $password,
'addr_ton' => NET_SMPP_TON_INTL,
'addr_npi' => NET_SMPP_NPI_ISDN,
'system_type' => ''
),
$typeBind
);
if (!is_object($resp) || $resp->isError()) {
die('CANNOT BIND');
}
$resp = $smsc->readPDU();
if (is_object($resp) && !$resp->isError()) {
//This is needble point
}
SMS-provider says that he'd sent deliver_sm and my script responded deliver_sm_resp with error "ESME receiver temporary app error code" (errcode 0x00000064).
Intresting that after sending SMS to special "gate"-number deliver_sm will normally come to me and handle by my script.
What did I go wrong? Help me please! Or say me if any other info needs for solving.

SOLVED!
There was other daemon running by same login on other server! It was receiving all requests

Related

I tried to connect MQTTS with my HTTPS server but it didn't work. It works fine on MQTTX but with PHP it doesn't connect

I tried to connect MQTTS with my HTTPS server but it didn't work. It works fine on MQTTX but with PHP it doesn't connect.
<?php
$server = 'myServer';
$port = '8883';
$clientId = 'testing';
$username = 'XXXX';
$password = 'XXXX';
$clean_session = false;
$connectionSettings = new ConnectionSettings();
$connectionSettings->setUsername($username)
->setPassword($password)
->setKeepAliveInterval(60)
->setLastWillTopic('mytopic')
->setLastWillMessage('client disconnect')
->setLastWillQualityOfService(1);
$mqtt = new MqttClient($server, $port, $clientId);
$mqtt->connect($connectionSettings, $clean_session);
$mqtt->subscribe('mytopic/respond', function ($topic, $message) use ($mqtt) {
echo $message;
}, 2);
$mqtt->close();
$mqtt->interrupt();
?>
How to connect MQTTS with PHP.
Looking at the source code for the phpMQTT library you need to pass a cafile in the constructor to enable a SSL/TLS connection.
$mqtt = new MqttClient($server, $port, $clientId, $cafile);
Where the cafile is the path to a CA certificate to validate the broker.
OK, first answer was against the wrong phpMQTT library, trying again.
The correct library is here: https://github.com/php-mqtt/client
From the doc:
// This flag determines if TLS should be used for the connection. The port which is used to
// connect to the broker must support TLS connections.
->setUseTls(false)
e.g.
$connectionSettings->setUsername($username)
->setPassword($password)
->setKeepAliveInterval(60)
->setLastWillTopic('mytopic')
->setLastWillMessage('client disconnect')
->setUseTls(true)
->setLastWillQualityOfService(1);
For connecting MQTTS we need to add three additional params into the connectionSettings
->setUseTls(true)
->setTlsSelfSignedAllowed(true) // Allow self-signed certificates. Discouraged for production use.
->setTlsVerifyPeer(false) // Do not require the self-signed certificate to match the host. Discouraged.
https://github.com/php-mqtt/client-examples/blob/master/03_connection_settings/02_use_tls_without_client_certificate.php
<?php
$server = 'myServer';
$port = '8883';
$clientId = 'testing';
$username = 'XXXX';
$password = 'XXXX';
$clean_session = false;
$connectionSettings = (new ConnectionSettings)
->setUsername($username)
->setPassword($password)
->setKeepAliveInterval(60)
->setLastWillTopic('mytopic')
->setLastWillMessage('client disconnect')
->setUseTls(true)
->setTlsSelfSignedAllowed(true) // Allow self-signed certificates. Discouraged for production use.
->setTlsVerifyPeer(false) // Do not require the self-signed certificate to match the host. Discouraged.
->setLastWillQualityOfService(1);
$mqtt = new MqttClient($server, $port, $clientId);
$mqtt->connect($connectionSettings, $clean_session);
$mqtt->subscribe('mytopic/respond', function ($topic, $message) use ($mqtt) {
echo $message;
}, 2);
$mqtt->close();
$mqtt->interrupt();
?>

F3 Framework: how to make sure that caching is working correctly?

I'm getting the database credentials from AWS secrets manager and storing it in the cache so that it doesn't have to be fetched from AWS on every request.
The problem is that, if I change the secret name for testing, F3 won't be able to connect to the database. That means that it's detecting the secret name getting changed even though I tell F3 to check that only if it wasn't able to find anything cached.
use Aws\SecretsManager\SecretsManagerClient;
$f3->set('CACHE', true);
if ($f3->exists('dbusername')) {
$username = $f3->get('dbusername');
$password = $f3->get('dbpassword');
$host = $f3->get('dbhost');
$port = $f3->get('dbport');
} else {
$secretName = getenv('AWS_SECRET_NAME');
$client = new SecretsManagerClient([
'version' => 'latest'
]);
$secretManager = $client->getSecretValue([
'SecretId' => $secretName,
]);
$db = json_decode($secretManager['SecretString']);
$username = $db->username;
$password = $db->password;
$port = $db->port;
$host = $db->host;
}
$f3->set('dbusername', $username);
$f3->set('dbpassword', $password);
$f3->set('dbhost', $host);
$f3->set('dbport', $port);
I'm testing on my PC, I don't know if that code would work on a server, not sure if the issue from my PC or if I'm not caching correctly.
It turns out that the cache wouldn't work unless a ttl (time to live) is specified. Here's how to cache the values above for 24 hours.
$f3->set('dbusername', $username, 86400);
$f3->set('dbpassword', $password, 86400);
$f3->set('dbhost', $host, 86400);
$f3->set('dbport', $port, 86400);

Getting could not connect to host error when using soap

I am using SOAP to call a web servicefrom a Linux Centos 6 server and a php client. In this week I have been getting could not connect to host error from soapCall method. My code is as below and I have not changed it at all for some months but recently it gets this error most of the time. I have read most answers to related questions here but my problem have not been solved.
$wsdl="http://x.x.x.x:x/gw/services/Service?wsdl";
//Set key as HTTP Header
$aHTTP['http']['header'] = "key:" .$key ."\r\n";
$context = stream_context_create($aHTTP);
try
{
$client = new SoapClient($wsdl,array("soap_version" => SOAP_1_2,'trace' => 1,"stream_context" => $context));
}
catch(Exception $e)
{
return "something";
}
//I make $parametrs
try
{
$res = $client->__soapCall("send",array($parametrs));
}
catch(Exception $e)
{
print_r($e->getMessage()); //Most of the time it prints could not connect to host
}
I changed SOAP from _1_1 to _1_2 but nothing changed.
This is how I call SOAP webservice, please note Service?wsdl should be Service.wsdl
Example
//Initialize values
$wsdl = "Service.wsdl";
$url = "http://x.x.x.x:x/gw/services/";
$username = "********"; //add username
$password = "********"; //add password
$client = new SoapClient("$url".$wsdl);
$params = array(
"username"=>$username,
"password"=>$password
);
$response = $client->UserLogIn($params); //UserLogIn is the function name
var_dump($response); // to see webservice response

Connecting to web service using SOAP & PHP

I'm trying to connect to a web service using PHP's soap client which I can successfully do using Visual Studio, pressing F5 and running the page locally which works a treat.
As soon as I upload the exact same file to my apache web host, I keep getting the error: "failed to load external entity".
Here's my code with the credentials and url taken out...
Any ideas?
<?php
header("Access-Control-Allow-Origin: http://example.com");
header("Access-Control-Request-Method: GET,POST");
ini_set('display_errors', true);
ini_set("soap.wsdl_cache_enabled", "0");
error_reporting(E_ALL);
try
{
$soapclient = new SoapClient('http://example.com');
$params = array ('SystemID' => 'testID','Username' => 'test', 'Password' => 'test');
$response = $soapclient->GetEngineerList($params);
print_r($response);
}
catch(SoapFault $e)
{
print_r($e);
}
strings are not read twice and parsed in single quotes
$soapclient = new SoapClient('$url');
try
$soapclient = new SoapClient($url);
also...do you have $url = ''; anywhere?
UPDATE 1
please try using basic auth to get to your wsdl:
$login = 'bert';
$password = 'berts password';
$client = new SoapClient(
'http://' . urlencode($login) . ':' . urlencode($password) . '#www.server.com/path/to/wsdl',
array(
'login' => $login,
'password' => $password
)
);

Send Mail to Multiple Address in Cakephp 3 : Cannot modify an existing config

I am trying to send email to multiple recipient address in cake php 3.
my codes are :
$this->loadModel('AsIndividualDetails');
$EmailDetails = $this-> AsIndividualDetails->find('all',['fields'=>'email']);
$EmailDetails = $EmailDetails->toArray();
foreach ($EmailDetails as $key => $a) {
$this->loadModel('DomainEmailDetails');
$DomainEmailDetails = $this-> DomainEmailDetails->find('all')->first();
$DomainEmailDetails = $DomainEmailDetails->toArray();
$host = 'ssl://'.$DomainEmailDetails['host_name'];
$username = $DomainEmailDetails['user_name'];
$password = $DomainEmailDetails['user_password'];
$port = $DomainEmailDetails['port'];
$email_to = $a['email'];
$senderName = 'abc';
$email_id ='xyz110#gmail.com';
Email::configTransport('WebMail', [
'className' => 'Smtp',
'host' => $host,
'port' => $port,
'timeout' => 30,
'username' => $username,
'password' => $password,
'client' => null,
'tls' => null,
]);
////////// SEND MAIL
$email = new Email('WebMail');
$email ->template('default','default')
->emailFormat('both')
->from([$username => $senderName])
->to($email_to)
->replyTo($email_id)
->subject('Client Message');
$response = $email->send('My msg');
if($response){
echo 'success';
}else{
echo 'failed';
}
}
When I run this script just only one mail send successfully and after that an error has come :
Cannot modify an existing config "WebMail"
How to solve this error and send mail to all recipient mail address.
If you really need set the config inside a loop, you could delete it before rewrite the config:
use Cake\Mailer\Email;
Email::dropTransport($key);
See Class Email API for more info
Make your email configuration outside of the loop. You don't want to try and establish the configuration every time you send the emails - just one time. Then send all the emails based on that one configuration.

Categories