I want to notify users through sms whenever a row gets updated. I've added the following code -
$transaction->commit();
$mobiletemp = User::find()->leftJoin('auth_assignment', 'auth_assignment.user_id = user.id')->select('mobileno')->andWhere(['auth_assignment.item_name' => 'c_apo'])->column();
$mobile = implode(",", $mobiletemp);
return $this->redirect('http://api.msg91.com/api/sendhttp.php?' . http_build_query(['sender'=>'TSTMSG', 'route'=>'4', 'mobiles'=> $mobile, 'authkey'=>'My Auth Key', 'country'=>'0','message'=>('Dear Sir, WP '. $wpno. ' is waiting for your approval. Please take necessary steps. Thank You.')]));
return $this->redirect(['view', 'id' => $model->wp_no]);
With this code user is getting sms notification. But, the there's a return code from the service provider which is being displayed as output. And the last piece of code to redirect to the view page is not getting read. I have to add multiple block of this notification code after update. Please let me know what is the best possible to way to handle this situation. I want to display the view after update also, users should get the notifications.
My present code after using curl
if ($flag) {
$transaction->commit();
$mobiletemp = User::find()->leftJoin('auth_assignment', 'auth_assignment.user_id = user.id')->select('mobileno')->andWhere(['auth_assignment.item_name' => 'c_apo'])->column();
$mobile = implode(",", $mobiletemp);
$curl = new curl\Curl();
$response = $curl->setGetParams(['sender'=>'TSTMSG', 'route'=>'4', 'mobiles'=> $mobile, 'authkey'=>'My Auth Code', 'country'=>'0','message'=>('Dear Sir, WP '. $wpno. ' is waiting for your approval. Please take necessary steps. Thank You.')])->get('http://api.msg91.com/api/sendhttp.php');
if ($curl->errorCode === null) {
return $this->redirect(['view', 'id' => $model->wp_no]);
}else {
// List of curl error codes here https://curl.haxx.se/libcurl/c/libcurl-errors.html
switch ($curl->errorCode) {
case 6:
//host unknown example
break;
}
}
}
composer.json
{
"name": "yiisoft/yii2-app-advanced",
"description": "Yii 2 Advanced Project Template",
"keywords": ["yii2", "framework", "advanced", "project template"],
"homepage": "http://www.yiiframework.com/",
"type": "project",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"minimum-stability": "stable",
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": "~2.0.6",
"yiisoft/yii2-bootstrap": "~2.0.0",
"yiisoft/yii2-swiftmailer": "~2.0.0 || ~2.1.0",
"kartik-v/yii2-widget-sidenav": "*",
"kartik-v/yii2-widget-activeform": "#dev",
"kartik-v/yii2-widget-datepicker": "#dev",
"kartik-v/yii2-widgets": "*",
"wbraganca/yii2-dynamicform": "dev-master",
"kartik-v/yii2-grid": "#dev",
"mpdf/mpdf": "#dev",
"kartik-v/yii2-mpdf": "*",
"linslin/yii2-curl": "*"
},
"require-dev": {
"yiisoft/yii2-debug": "~2.0.0",
"yiisoft/yii2-gii": "~2.0.0",
"yiisoft/yii2-faker": "~2.0.0",
"codeception/base": "^2.2.3",
"codeception/verify": "~0.3.1"
},
"config": {
"process-timeout": 1800
},
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
]
}
You can use curl to send the request to the API and then use
return $this->redirect(['view', 'id' => $model->wp_no]);
For the Curl calls you can use linslin library for Yii2 which is very easy to use.
Just make sure you have cURL installed or take the following steps to
install cURL.
First Install CURL by typing $ sudo apt-get install curl
Then Restart Apache by typing $ sudo service apache2 restart
Then Install PHP5 CURL by typing $ sudo apt-get install php5-curl
Will prompt to install... type y or yes!
Then Restart Apache by typing $ sudo service apache2 restart Done!
A simple curl get request using linslin/Curl will look like this.
// GET request with GET params
// http://example.com/?key=value&scondKey=secondValue
$curl = new curl\Curl();
$response = $curl->setGetParams([
'key' => 'value',
'secondKey' => 'secondValue'
])
->get('http://example.com/');
So your code will look like this
$transaction->commit();
$mobiletemp = User::find()->leftJoin('auth_assignment', 'auth_assignment.user_id = user.id')->select('mobileno')->andWhere(['auth_assignment.item_name' => 'c_apo'])->column();
$mobile = implode(",", $mobiletemp);
$curl = new curl\Curl();
$response = $curl->setGetParams(['sender'=>'TSTMSG', 'route'=>'4', 'mobiles'=> $mobile, 'authkey'=>'My Auth Key', 'country'=>'0','message'=>('Dear Sir, WP '. $wpno. ' is waiting for your approval. Please take necessary steps. Thank You.')])
->get('http://api.msg91.com/api/sendhttp.php');
if ($curl->errorCode === null) {
return $this->redirect(['view', 'id' => $model->wp_no]);
} else {
// List of curl error codes here https://curl.haxx.se/libcurl/c/libcurl-errors.html
switch ($curl->errorCode) {
case 6:
//host unknown example
break;
}
}
Related
I am trying to write a function that will send command to a device defined in Google Cloud IoT core. Sending a command from the console works fine.
I’m using the following example from Sending commands to devices
// const cloudRegion = 'us-central1';
// const deviceId = 'my-device';
// const commandMessage = 'message for device';
// const projectId = 'adjective-noun-123';
// const registryId = 'my-registry';
const iot = require('#google-cloud/iot');
const iotClient = new iot.v1.DeviceManagerClient({
// optional auth parameters.
});
const formattedName = iotClient.devicePath(
projectId,
cloudRegion,
registryId,
deviceId
);
const binaryData = Buffer.from(commandMessage);
const request = {
name: formattedName,
binaryData: binaryData,
};
try {
const responses = await iotClient.sendCommandToDevice(request);
console.log('Sent command: ', responses[0]);
} catch (err) {
console.error('Could not send command:', err);
}
However, in my function log I get the message‘Error: Node.js v10.0.0 is a minimum requirement.‘
I have run node -v in my project and I get v10.16.3 as a result so I am confused. Can anyone offer any advice?
gcloud functions describe results :
availableMemoryMb: 256
entryPoint: updateDevice
eventTrigger:
eventType: providers/cloud.firestore/eventTypes/document.create
failurePolicy: {}
resource: projects/project/databases/(default)/documents/pubsubMessages/{docID}
service: firestore.googleapis.com
ingressSettings: ALLOW_ALL
labels:
deployment-tool: cli-firebase
name: projects/project/locations/us-central1/functions/updateDevice
runtime: nodejs8
serviceAccountEmail: email#appspot.gserviceaccount.com
sourceUploadUrl: https://storage.googleapis.com/gcf-upload-us-central1-xxx
status: ACTIVE
timeout: 60s
updateTime: '2020-05-18T09:56:29.144Z'
versionId: '46'
package.json:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "8"
},
"dependencies": {
"#google-cloud/iot": "^2.0.0",
"#google-cloud/pubsub": "^1.7.3",
"express": "^4.17.1",
"firebase": "^7.14.4",
"firebase-admin": "^8.12.1",
"firebase-functions": "^3.6.1",
"google-auth-library": "^6.0.0",
"googleapis": "^51.0.0"
},
"devDependencies": {
"eslint": "^5.12.0",
"eslint-plugin-promise": "^4.0.1",
"firebase-functions-test": "^0.2.0"
},
"private": true
}
Got "UnexpectedValueException" Your github oauth token for github.com contains invalid characters:"" while composer update on yii2 project.
When i was installing jui datetimepicker via composer, I have asked to give git token to install it. I had generated the token from GitLab and provide the token to terminal.I also change the composer.json file with token. But it gives me an error of "UnexpectedValueException" Your github oauth token for github.com contains invalid characters.
I have tried following solutions :
1) I have deleted my .git folder and tried to update composer still same issue
2) I have deleted the vendor and reinstall the composer not worked.
3) I have deleted the vendor and composer.json and put the previous vendor and composer.json file from my backup. but still get same issue.
4) I have tried to change the token from the following code :
composer config --global github-oauth.github.com <TOKEN>
5) Also put the following code in composer.json :
{
"config": {
"github-oauth": {
"github.com": "<TOKEN>"
}
}
}
Still same issue.
My composer.json file is as follows :
{
"name": "yiisoft/yii2-app-advanced",
"description": "Yii 2 Advanced Application Template",
"keywords": ["yii2", "framework", "advanced", "application template"],
"homepage": "http://www.yiiframework.com/",
"type": "project",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"minimum-stability": "stable",
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": "*",
"yiisoft/yii2-bootstrap": "*",
"yiisoft/yii2-swiftmailer": "*",
"claudejanz/yii2-mygii": "dev-master",
"bower-asset/jquery": "#stable",
"bower-asset/jquery.inputmask": "#stable",
"bower-asset/punycode": "#stable",
"bower-asset/bootstrap": "#stable",
"3ch3r46/bootui-datepicker": "1.0.0",
"yiisoft/yii2-jui": "*",
"udokmeci/yii2-phone-validator" : "dev-master"
},
"require-dev": {
"yiisoft/yii2-codeception": "*",
"yiisoft/yii2-debug": "*",
"yiisoft/yii2-gii": "*"
},
"suggest": {
"codeception/codeception": "Codeception, 2.0.* is currently works well with Yii.",
"codeception/specify": "BDD style code blocks for PHPUnit and Codeception",
"codeception/verify": "BDD Assertions for PHPUnit and Codeception",
"yiisoft/yii2-faker": "Fixtures generator for Yii2 based on Faker lib"
},
"scripts": {
"post-create-project-cmd": [
"yii\\composer\\Installer::setPermission"
]
},
"config": {
"process-timeout": 1800
},
"extra": {
"writable": [
"backend/runtime",
"backend/web/assets",
"frontend/runtime",
"frontend/web/assets"
],
"executable": [
"yii"
],
"asset-installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
},
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
]
}
Please someone help.
I'm not sure what was the reason why it stopped working for you but as we discussed in comments the solution was to update the entry in auth.json that stores this GitHub token.
For everyone looking for this solution - auth.json is stored in your COMPOSER_HOME path. You can find this path by calling in the console
composer config -g data-dir
For more information about Composer configuration please refer to the Composer documentation at getcomposer.org.
I have updated my index.js as below
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const {actionssdk} = require('actions-on-google');
const app = actionssdk({debug: true});
exports.dairyProduct = functions.https.onRequest((request, response) => {
console.log("request-------------->",request);
console.log("response----------------->",response);
function handleMainIntent(app) {
console.log("Inside Main Intent");
app.ask("Main Indent "+app.getRawInput());
}
function handleTextIntent() {
console.log("Inside Main Intent");
app.tell("First Text Indent");
}
let app = new ActionsSdkApp({request, response});
let actionMap = new Map();
console.log("app---------->",app);
actionMap.set(app.StandardIntents.MAIN, handleMainIntent)
actionMap.set(app.StandardIntents.TEXT, handleTextIntent);
app.ask("This sample application is developing by Thirumani Selvam.M ");
console.log("actionMap---------->",actionMap);
app.handleRequest(actionMap);
});
My updated action.json
{
"actions": [
{
"description": "Default Welcome Intent",
"name": "MAIN",
"fulfillment": {
"conversationName": "testapp"
},
"intent": {
"name": "actions.intent.MAIN",
"trigger": {
"queryPatterns": [
"Talk to Dairy Product"
]
}
}
}
],
"conversations": {
"testapp": {
"name": "testapp",
"url": "https://us-central1-samplejs6-id.cloudfunctions.net/dairyProduct",
"fulfillmentApiVersion": 2,
"inDialogIntents": [
{
"name": "actions.intent.CANCEL"
}
]
}
},
"locale": "en"
}
My package.json code
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"actions-on-google": "^2.0.1",
"firebase-admin": "~5.12.0",
"firebase-functions": "^1.0.1"
},
"devDependencies": {
"eslint": "^4.12.0",
"eslint-plugin-promise": "^3.6.0"
},
"private": true
}
i have deployed using "firebase deploy --only functions"
I have updated action using "gactions update --action_package action.json --project samplejs6-id"
I have updated test of actions using"gactions test --action_package action.json --project samplejs6-id"
I didn't get errors in firebase logs.
i have updated title and name in gactions as "Dairy team". it is recommending to type "Talk to Dairy team" . If i type "Talk to Dairy team" , i am getting response as "We're sorry, but something went wrong. Please try again."
Please let me know, how to fix this issue. Thanks in advance
The problem is that you're using the "actions-on-google" library version 2, but your code is written using the version 1 objects and functions. There have been some dramatic changes between the two versions. See the migration guide for details how to upgrade to the new version, or change your package.json file to use version 1.
after i installed laravel 5.4 and added passport package i get these errors in console
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
app.js:11476 Uncaught (in promise) Error: Request failed with status code 500
at createError (app.js:11476)
at settle (app.js:11975)
at XMLHttpRequest.handleLoad (app.js:11315)
http://localhost:8000/oauth/personal-access-tokens Failed to load resource: the server responded with a status of 500 (Internal Server Error)
app.js:11476 Uncaught (in promise) Error: Request failed with status code 500
at createError (app.js:11476)
at settle (app.js:11975)
at XMLHttpRequest.handleLoad (app.js:11315)
here is my composer.josn
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.4.*",
"laravel/passport": "^2.0",
"laravel/tinker": "~1.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.0"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true
}
}
here is my home.blade.php
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<passport-clients></passport-clients>
<passport-authorized-clients></passport-authorized-clients>
<passport-personal-access-tokens></passport-personal-access-tokens>
</div>
</div>
#endsection
and this is my app.js file
require('./bootstrap');
Vue.component(
'passport-clients',
require('./components/passport/Clients.vue')
);
Vue.component(
'passport-authorized-clients',
require('./components/passport/AuthorizedClients.vue')
);
Vue.component(
'passport-personal-access-tokens',
require('./components/passport/PersonalAccessTokens.vue')
);
Vue.component('example', require('./components/Example.vue'));
const app = new Vue({
el: '#app'
});
after i log in and try to get personal token i get error and when i see console i finde internal server error i don't know what i am missing
i found that i forget to add use HasApiTokens; in User model after class declaration
namespace App;
use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
//that was missing
use HasApiTokens,Notifiable;
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
I'm trying to install to install the Gedmo Doctrine2 extensions in Symfony2 to use the translate composante.
I found a page online that show me how to do it (https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/symfony2.md), but I'm not shure about a few things.
First, when I change the composer.json file, I noticed that I have
"psr-0": {
"": "src/",
"SymfonyStandard": "app/"
}
And the instruction tells me to add
"psr-0": {
"Acme": "src/"
}
I don't know if I need to change the "": "src/", ligne or if I add the new ligne, or if I just let it be like it is.
I would really help me if someone juste tell what my file should looks like, so here is my composer.json:
{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-0": {
"": "src/",
"SymfonyStandard": "app/"
}
},
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.6.*",
"doctrine/orm": "~2.2,>=2.2.3,<2.5",
"doctrine/dbal": "<2.5",
"doctrine/doctrine-bundle": "~1.2",
"twig/extensions": "~1.0",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~3.0,>=3.0.12",
"sensio/framework-extra-bundle": "~3.0,>=3.0.2",
"sensio/generator-bundle": "2.0.*",
"jms/security-extra-bundle": "1.0.*",
"gedmo/doctrine-extensions": "dev-master",
"incenteev/composer-parameter-handler": "~2.0",
"ircmaxell/password-compat": "^1.0"
},
"require-dev": {
"sensio/generator-bundle": "~2.3"
},
"scripts": {
"post-root-package-install": [
"SymfonyStandard\\Composer::hookRootPackageInstall"
],
"post-install-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
],
"post-update-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
]
},
"config": {
"bin-dir": "bin"
},
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"symfony-assets-install": "relative",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": {
"dev-master": "2.6-dev"
}
}
}
The other thing is that after that step, I need to run php composer.phar update gedmo/doctrine-extensions in composer, but I don't have a a composer.phar file, so I did insted composer update.
Is that O.K., or I need to do an other line?
You can simply use
composer require gedmo/doctrine-extensions
and the composer.json will be automatically modified.
Regarding "composer" vs "composer.phar": yes, they are the same, so you can use whatever you have.
To add more details: usually everyone rename "composer.phar" to "composer" and move it to a binaries location on the os (i.e. /usr/local/bin on Linux) so that it can be used as a common system command. That is probably your situation.
The instruction is unclear, you do not need to change the line
"psr-0": {
"": "src/",
"SymfonyStandard": "app/"
}
Just add "gedmo/doctrine-extensions": "dev-master" to the require section.
Then to run a composer update you should install composer if you have not yet done so (but if you have symfony installed, I think you do unless you followed the instructions in the tutorial in which case I would reinstall symfony the official way as the tutorial refers to an outdated repository)