简体   繁体   English

如何在 C# 桌面应用程序中使用 PHP 代码

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

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. 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在 c# 应用程序中,如果可能的话,在 C# 中转换此代码。

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));
}

One option is to rewrite the call using C#, check docs if needed.一种选择是使用 C# 重写调用,如果需要,请查看文档。
Another one is to made your custom php-api which wrap initial call.另一种方法是制作包含初始调用的自定义php-api
Then from C# just use your php-api .然后从 C# 只需使用您的php-api
Postman can be a useful tool to check your custom php-api and also for C# code generation Postman可以成为检查您的自定义php-api以及C# code generation的有用工具


---custom php-api--- ---自定义php-api---

<?php
$out = [];
//mainly here will be the return of api-call
$out["mykey"]="myvalue";
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)这段代码应该可以通过链接访问,例如: https://yoursite/custom-api (出于安全目的,可以在查询字符串上使用令牌/custom-api?key=123mykey ->trivial approach)

Use PostMan to check and see code-generation使用PostMan查看代码生成

C#

See, use C# directly and use the html-php method, like php embedded into html code and then link with a webbrowser proc in background and make it work: ,) Also don't do that, use direct C# and dont but any embed bugs! See, use C# directly and use the html-php method, like php embedded into html code and then link with a webbrowser proc in background and make it work: ,) Also don't do that, use direct C# and dont but any embed错误!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM