How I can use a PHP code in C# desktop application

Viewed 95

Is there any way to run the PHP code on the c# app since I'm working on an application that requires to implement of this site's API but there is no documentation except for PHP, so is there any way I can use this piece of code in a c# application or convert this code in C# if that is possible.

public $api_url = 'https://smm-bomb.com/api/v2'; // API URL

public $api_key = ''; // Your API key

public function order($data) { // add order
    $post = array_merge(array('key' => $this->api_key, 'action' => 'add'), $data);
    return json_decode($this->connect($post));
}
1 Answers

One option is to rewrite the call using C#, check docs if needed.
Another one is to made your custom php-api which wrap initial call.
Then from C# just use your php-api.
Postman can be a useful tool to check your custom php-api and also for C# code generation


---custom php-api---
--update to fit https://smm-bomb.com/api--

<?php
class Api
{
    public $api_url = 'https://smm-bomb.com/api/v2'; // API URL
    public $api_key = '4a99333333333333333dummy'; // Your API key
...
//just copy-paste from example
}

//from-docs, create an instance an invoke any methods
//since it's a self contained class no imports required
//main 
$api = new Api();
$services = $api->services(); # return all services

$out = [];
//mainly here will be the return of api-call
$out["mykey"]="myvalue";
//output as json whatever wanted
$out["listServices"]=$services;
echo json_encode($out);
?>
//sample output
//{"mykey":"myvalue"}

This piece of code should be accessible via link eg: https://yoursite/custom-api (for security purpose can use a token on query-string. /custom-api?key=123mykey ->trivial approach)

Use PostMan to check and see code-generation

C#
C#2

Related