php webservice 应用,在winforms应用程序中使用PHP webservice

目前我将C#mysql连接信息存储在类文件本身中,这看起来并不聪明,因为最终用户可以简单地使用像.NET Reflector这样的反射器来调试源代码,以防它没有被模糊 .

现在,stackoverflow上的用户建议创建一个将操纵数据库的Web服务 . 最终用户将使用的软件然后使用用户的凭据简单地使用Web服务对自身进行身份验证,然后使用它来访问资源 .

现在我有以下问题,我的服务器在linux ubuntu上运行,并且已经存储了一个使用plesk创建的网站 .

我知道我可以使用http://www.mono-project.com/在linux上托管web服务 . 但是我总是用PHP来做这些事情,而且我对如何将s#web-service上传到ssh服务器上安装的单声道版本感到困惑 .

我可以在winforms应用程序中使用类似下面的PHP代码作为C#Web服务吗?

PHP代码:

class webService extends database

{

// Web service constructor

public function __construct($username, $password, $uniqueId, $versionId)

{

$this->username = $username;

$this->password = $password;

$this->salt = 'xxx';

$this->hash = 'xxx';

$this->uniqueId = $uniqueid;

$this->versionId = $versionId;

}

// Web service functions to check database values

// Web service user account check function

private function userCheck()

{

$this->connect();

$userCheck = $this->execute_query("SELECT username, password FROM Users WHERE username = '" . $this->username . "' AND password = '" . $this->hash . "'");

if($userCheck && mysqli_num_rows($userCheck) > 0)

{

return 'true';

}

else

{

return 'false';

}

}

// Web service unique id check function

private function uniqueCheck()

{

$this->connect();

$uniqueCheck = $this->execute_query("SELECT username, uniqueid FROM Users WHERE username = '" . $this->username . "' AND uniqueid = '" . $this->uniqueId . "'");

if($uniqueCheck && mysqli_num_rows($uniqueCheck) > 0)

{

return 'true';

}

else

{

return 'false';

}

}

// Web service first run check function

private function firstRunCheck()

{

$this->connect();

$firstRunCheck = $this->execute_query("SELECT username, firstrun FROM Users WHERE username = '" . $this->username . "' AND firstrun = '0'");

if($firstRunCheck && mysqli_num_rows($firstRunCheck) > 0)

{

return 'true';

}

else

{

return 'false';

}

}

// Web service user disabled check function

private function disabledUserCheck()

{

$this->connect();

$disabledUserCheck = $this->execute_query("SELECT disabled FROM Users WHERE username = '" . $this->username . "' AND disabled = '1'");

if($disabledUserCheck && mysqli_num_rows($disabledUserCheck) > 0)

{

return 'true';

}

else

{

return 'false';

}

}

// Web service update required check function

private function updateRequiredCheck()

{

$this->connect();

$updateRequiredCheck = $this->execute_query("SELECT requiredupdate FROM requiredupdate WHERE version = '" . $this->versionId . "' AND requiredupdate = 1");

if($updateRequiredCheck && mysqli_num_rows($updateRequiredCheck) > 0)

{

return 'true';

}

else

{

return 'false';

}

}

// Web service premium check function

private function userPremiumCheck()

{

$this->connect();

$userPremiumCheck = $this->execute_query("SELECT premium FROM Users WHERE username = '" . $this->username . "' AND premium = 1");

if($userPremiumCheck && mysqli_num_rows($userPremiumCheck) > 0)

{

return 'true';

}

else

{

return 'false';

}

}

// Web service functions to update database values

// Web service update first run parameters function

private function firstRunUpdate()

{

$firstRunCheck = $this->firstRunCheck();

if($firstRunCheck == 'true')

{

$this->connect();

$this->execute_query("UPDATE Users SET uniqueid = '" . $this->uniqueId . "', firstrun = '1' WHERE username = '" . $this->username . "'");

return 'true';

}

else

{

return 'false';

}

}

function to_xml(SimpleXMLElement $object, array $data)

{

foreach ($data as $key => $value) {

if (is_array($value)) {

$new_object = $object->addChild($key);

to_xml($new_object, $value);

} else {

$object->addChild($key, $value);

}

}

}

// Web service handler function

public function webService()

{

$userCheck = $this->userCheck();

if($userCheck == 'true')

{

$userArray = array (

'username' => $this->username,

'authentificated' => $this->userCheck(),

'firstRun' => $this->firstRunCheck(),

'firstRunUpdated' => $this->firstRunUpdate(),

'uniqueIdCheck' => $this->uniqueCheck(),

'Premium' => $this->userPremiumCheck(),

'Disabled' => $this->disabledUserCheck(),

'updateRequired' => $this->updateRequiredCheck()

);

}

else

{

$userArray = array (

'username' => $this->username,

'userCheck' => $this->userCheck()

);

}

echo str_replace("\/", "/", json_encode($userArray, JSON_PRETTY_PRINT));

}

}

?>

或者如何创建可以在我的应用程序中使用的PHP Web服务?

PHP脚本的当前响应如下所示:

{ "username": "dane", "authentificated": "true", "firstRun": "false", "firstRunUpdated": "false", "uniqueIdCheck": "true", "Premium": "true", "Disabled": "false", "updateRequired": "false" }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值