I try to make dhru api based on this code https://github.com/dhru/dhru-fusion-api-standards .
My problem is to get customer input on web which is sent by dhru web in parameters.
I already determinated what exacly website send to my API:
[username] => login
[apiaccesskey] => pass
[action] => placeimeiorder
[requestformat] => JSON
[parameters] => <PARAMETERS><ID>100</ID><CUSTOMFIELD>eyJ1ZGlkIjoiMDAwMDgwMjAtMDAxQzM0MTIyNjgxMDAyRSJ9</CUSTOMFIELD><MODELID></MODELID><PROVIDERID></PROVIDERID><NETWORK></NETWORK><PIN></PIN><KBH></KBH><MEP></MEP><PRD></PRD><TYPE></TYPE><LOCKS></LOCKS><REFERENCE></REFERENCE><IMEI>423545675567658</IMEI><udid>00008020-001C34122681002E</udid></PARAMETERS>
But i'm unable to get any value from this parameters.
I already tried all of this but nothing work:
1) $udid = json_decode($parameters['udid'],true);
2) $udid = $parameters['udid'];
3) $imei = $parameters['IMEI'];
4) $udid = (string)$parameters['udid'];
Can somebody give me advice?
Related
Ok so yesterday I was working on a PHP API all day (2:30PM - 3:30AM CT).
The user/client/front end of the API can submit a filename or link to the API so it can view it, edit it, or delete it.
But that's a problem because if the user can do that that means they could edit or delete the website with the client.
So I'm wondering can I store a bunch of variables that are equal to links, so when the client submits, the API will see if that link is unauthorized or authorized
Could you do it like this
<?php
$myArray = array( //Unauthorized Links
$link1 => "http://example.com" //First Link
);
?>
Then check the links using $myArray?
If you need the API code I'll provide it.
use this code and it will work for you
<?php
$myArray = array(
1 => 'http://example-1.com',
2 => 'http://example-2.com',
3 => 'http://example-3.com',
4 => 'http://example-4.com'
);
foreach($myArray as $key => $value){
echo 'link '.$key.' = '.$value.' <br>';
}
?>
I'm using the twitter api to get my latest mentions.
Twitter api link: https://dev.twitter.com/rest/reference/get/statuses/mentions_timeline
Function used to get last mentions:
function twitter_get_tweets(){
$connection = $this->twitter_auth();
$latest_tweet = $connection->get('statuses/mentions_timeline', array('count' => 1));
return $latest_tweet;
}
Preview of response: http://projects.helpful.ninja/twitter/
Sadly im not able to access the variables in there directly, such as the text node.
Example:
[text] => #pr0b_ Submit a request to our Support team and they'll be in touch ASAP
Been testing something like:
$twitter_bot = new twitter_bot_functions($twitter_settings['api_key'], $twitter_settings['api_secret'], $twitter_settings['access_token'], $twitter_settings['access_token_secret']);
$get_latest_mention = $twitter_bot->twitter_get_tweets();
echo $get_latest_mention['text'];
Does someone have a idea what I'm doing wrong?
It is an array first and then a stdClass object. So you should use it like
echo $get_latest_mention[0]->text;
Following is my code to CodeRequest.
$username = "91xxxxxxxxxx";
$identity = strtolower(urlencode(sha1($username, true)));
$w = new WhatsProt($username, $identity, "test", true);
$r = $w->codeRequest();
print_r($r);
It gives the response as
stdClass Object ( [status] => sent [length] => 6 [method] => sms [retry_after] => 1805 )
But I'm not receiving message. Any suggestions please.
My other questions.
Is there any restriction to request code.(Every time I use new mobile number).?
For example I request a code for mobile number xxx with user agent galaxys3 shall i request another code with mobile number yyy using the same user agent?
I'm using WhatsAPI-Official
Finally I received code to mobile.
$username = "91xxxxxxxxxx";
$identity = "myIdentity";
$w = new WhatsProt($username, $identity, "test", true);
$r = $w->codeRequest('sms',$carrier);
(or)
$r = $w->codeRequest('voice',$carrier); //Voice service is fast compared to sms
$carrier is getting from networkinfo.csv file.
carrier is nothing but mobile network operator(Airtel,Idea etc.,) according to your mobile country code(mcc) and mobile network code (mnc).
You can get the mnc and mcc codes from mobile-network-codes-country-codes
Get mcc and mnc codes with your location and operation match them with networkinfo.csv to get carrier name.
Eg: My number is 919xxxxxx
country - india ( Andhra Pradesh )
operator - Idea
For above link mcc and mnc are for my number is 404 & 7
Now check those codes in networkinfo.csv file
i.e
404,1028,007,7,in,India,91,Idea Cellular Ltd.4
Here 404 -> mcc
and 007 -> mnc
My carrier name is Idea Cellular Ltd.4
If you send correct carrier name you will get sms/call to mobile.
Try this piece of code.
$destinationPhone = 'xxxxxxxxxxxx';
$w = new WhatsProt($userPhone, $userIdentity, $userName, $debug);
$w->Connect();
$w->LoginWithPassword($password);
$w->Message($destinationPhone, $argv[1]);
or more info refer this link..
http://blog.philippheckel.com/2013/07/07/send-whatsapp-messages-via-php-script-using-whatsapi/#Send-WhatsApp-messages
On the Internet there are a few topics about this problem, but I have not found any complex solution. Therefore, I would like to ask you for help.
I need to change facebook id to username.
When you type web site like this:
http://facebook.com/profile.php?id=4 (num 4 is FB id), it will give you http://www.facebook.com/zuck, which is Mark Zuckerberg's profile.
On this principle I need to find out who a id is.
I have typed id 4 a got it is zuck.
But I need it for more ids, so it would take a lot of time do it manually. Please help me, how I can do it.
If you already have an ID of that particular user, then just add it on this url:
https://graph.facebook.com/<USER_ID>
Simple example:
function get_basic_info($id) {
$url = 'https://graph.facebook.com/' . $id;
$info = json_decode(file_get_contents($url), true);
return $info;
}
$id = 4;
$user = get_basic_info($id);
echo '<pre>';
print_r($user);
This should basically yield:
Array
(
[id] => 4
[first_name] => Mark
[gender] => male
[last_name] => Zuckerberg
[link] => https://www.facebook.com/zuck
[locale] => en_US
[name] => Mark Zuckerberg
[username] => zuck
)
Then you could just call it like a normal array:
echo $user['username'];
Sidenote: Why not use the PHP SDK instead.
https://developers.facebook.com/docs/reference/php/4.0.0
As the username is NO more available from Graph API endpoint /user-id as discussed here, I propose another workaround here (but with Python code)
In brief, we open the page at fb.com/USER_ID and scrape the username from it
#get html of a page via pure python ref. https://stackoverflow.com/a/23565355/248616
import requests
r = requests.get('http://fb.com/%s' % FB_USER_ID) #open profile page of the facebook user
r.raise_for_status()
html = r.content
#search string with regex ref. https://stackoverflow.com/a/4667014/248616
import re
# m = re.search('meta http-equiv="refresh" content="0; URL=/([^?]+)\?', html)
m = re.search('a class="profileLink" href="([^"]+)"', html)
href = m.group(1) #will be https://www.facebook.com/$FB_USER_NAME on 201705.24
username = href.split('/')[-1]
print(href)
print(username)
As of October 2019, The only way it is possible is to request for user_links in request and permissions
And then pass it in a scope, something like this
scope: ['user_link']
I'm trying to get a check_authentication response working, but so far, all consumers reject it and say that my server denied check_authentication.
This is the GET and POST data that my server file receives:
$_GET:
Array
(
[mode] => profile
[username] => hachque
[domain] => roket-enterprises.com
)
$_POST:
Array
(
[openid_assoc_handle] => {HMAC-SHA1}{4b00d7b2}{vo1FEQ==}
[openid_identity] => http://www.roket-enterprises.com/openaccount/openid:hachque
[openid_mode] => check_authentication
[openid_response_nonce] => 2009-11-16T04:40:18Zrrz8R4
[openid_return_to] => http://openiddirectory.com:80/openidauth/id/c/finish_auth.php?nonce=adCevd6T
[openid_sig] => SgFE5iT9IGd5EftkrZ72mgCHiLk=
[openid_signed] => assoc_handle,identity,mode,response_nonce,return_to,signed,sreg.email,sreg.fullname,sreg.nickname
[openid_sreg_email] => jrhodes#roket-enterprises.com
[openid_sreg_fullname] => James Rhodes
[openid_sreg_nickname] => jrhodes
)
This is the header reponse that I am outputting (contains POST data as it was explained to me on IRC that sending the key-values as headers shouldn't be done to the consumer server EDIT: Come to think of it, it doesn't make much sense RESPONDING with POST data. Maybe some here can explain the whole process of check_authentication clearly).
Content-Type: text/plain;
Content-Length: 675;
openid.mode=id_res&openid.assoc_handle=%7BHMAC-SHA1%7D%7B4b00d7b2%7D%7Bvo1FEQ%3D%3D%7D&openid.identity=http%3A%2F%2Fwww.roket-enterprises.com%2Fopenaccount%2Fopenid%3Ahachque&openid.response_nonce=2009-11-16T04%3A40%3A18Zrrz8R4&openid.return_to=http%3A%2F%2Fopeniddirectory.com%3A80%2Fopenidauth%2Fid%2Fc%2Ffinish_auth.php%3Fnonce%3DadCevd6T&openid.signed=assoc_handle%2Cidentity%2Cmode%2Cresponse_nonce%2Creturn_to%2Csigned%2Csreg.email%2Csreg.fullname%2Csreg.nickname&openid.sreg_email=jrhodes%40roket-enterprises.com&openid.sreg_fullname=James+Rhodes&openid.sreg_nickname=jrhodes&openid.sig=MGVhMmQ1Mzg4ZWFlMWY1OWVlYjlmZmY0Njc3OTc5YWIzMjM3NGFjMQ%3D%3D&openid.is_valid=true;
This is the PHP code that my file is using to handle check_authentication (remember that PHP turns all . characters into _ for $_GET and $_POST variables since they aren't valid character in PHP array keys):
// Retrieve the OpenID information from the $_REQUEST data
// I'm not sure whether it's possible that this data might
// come in on the $_GET parameter instead of $_POST, so that's
// what it uses $_REQUEST.
$assoc_handle = $_REQUEST['openid_assoc_handle'];
$sig = $_REQUEST['openid_sig'];
$signed = $_REQUEST['openid_signed'];
// The method for returning data is via the headers outputted
// by the webserver. Create an array that stores the headers
// to be returned.
$keys = array(
'openid.mode' => 'id_res',
'openid.assoc_handle' => $_REQUEST['openid_assoc_handle'],
'openid.identity' => $_REQUEST['openid_identity'],
'openid.response_nonce' => $_REQUEST['openid_response_nonce'],
'openid.return_to' => $_REQUEST['openid_return_to'],
'openid.signed' => $_REQUEST['openid_signed'],
'openid.sreg_email' => $_REQUEST['openid_sreg_email'],
'openid.sreg_fullname' => $_REQUEST['openid_sreg_fullname'],
'openid.sreg_nickname' => $_REQUEST['openid_sreg_nickname']
//'openid_mode' => 'id_res'
);
// The server may request that we invalidate the user's session
// via $_REQUEST['openid_invalidate_handle']. In this case we
// will clear the session data (you may need to change this
// depending on how you implement the session). After doing so
// we continue and tell the server we did via a variable
if (strlen($_REQUEST['openid_invalidate_handle']) > 0)
{
// Reset the session
session_unset();
session_name('openid_server');
session_start();
// Set the header we need to return
$keys['openid.invalidate_handle'] = $_REQUEST['openid_invalidate_handle'];
}
// We need to validate the signature now. This constructs a token_contents
// for signing the data. The signing key is returned as openid.sig
// and is generated with base64(HMAC(secret(assoc_handle), token_contents)
$token_contents = '';
foreach (explode(',', $signed) as $param) {
$post = preg_replace('/\./', '_', $param);
$token_contents .= sprintf("%s:%s\n", $param, $_REQUEST['openid_' . $post]);
}
// Generate our openid.sig and add it to the list of keys to
// return.
$keys['openid.sig'] = base64_encode(hash_hmac('sha1',$token_contents,$assoc_handle));
// Add the data that we are sharing (via SReg) to the headers.
// For now this is fixed data (see action_authorization.php).
//$keys["sreg.fullname"] = 'James Rhodes';
//$keys["sreg.nickname"] = 'jrhodes';
//$keys["sreg.email"] = 'jrhodes#roket-enterprises.com';
// Just accept the request for now..
// phpMyID does some kind of secret-shared-key thing
// here to determine whether it is valid. I'm not
// quite sure how that process works yet, so we are just
// going to say go ahead.
$keys["openid.is_valid"] = "true";
// We need to format the $keys array into POST format
$keys_post = "";
$keys_post_first = true;
foreach ($keys as $name => $value)
{
if ($keys_post_first)
$keys_post_first = false;
else
$keys_post .= "&";
$keys_post .= urlencode($name) . "=" . urlencode($value);
}
// Now output the POST data
header('Content-Type: application/x-www-form-urlencoded');
header('Content-Length: ' . strlen($keys_post));
header($keys_post);
Can anyone help me with my problem? I've been trying to get this working for months and I can't get a straight answer on how this stage of OpenID authentication is meant to work.
First of all, although PHP transforms periods to underscores in parameter names, be sure you're sending periods and not underscores.
Secondly, your check_authentication response should only have three parameters, but you have six. Check the spec and fix up your response and see if that helps.
Andrew Arnott,you're wrong!
documentation from openid.net:
11.4.2.1. Request Parameters
openid.mode
Value: "check_authentication"
Exact copies of all fields from the authentication response, except for "openid.mode".
may be more than three fields!
I had a similar issue. In my case, the client (relying party) failed to resolve the name of the OpenId provider to the correct ip. Although this is unlikely to be the case, please check name resolution on your relying server.