其实单点登录的逻辑在帮助手册中说的很清楚,我们只是以C#代码写了个示例,其他的代码也是一样的逻辑
这是之前有客户通过php写的单点登录的代码,大同小异,如果你对代码比较了解,这个对你来说并不是问题
- <?php
- namespace app\index\controller;
- use think\Controller;
- class Index extends Controller
- {
- public function index()
- {
- $url = "http://localhost:48143/SSO/GetUserToken";
- $userName = "administrator";
- $password = "";//密码
- $data = "{userName:"" . $userName . "", password:"" . $password . ""}";
- var_dump($url);
- var_dump($data);
- return $this->https_request($url, $data);
- }
- public function https_request($url, $data){
- $data = array('userName' => 'administrator', 'password' => 'DXRLcwhQBiqX');
- $options = array(
- 'http' => array(
- 'header' => "Content-type: application/x-www-form-urlencoded\r\n",
- 'method' => 'POST',
- 'content' => http_build_query($data)
- )
- );
- $context = stream_context_create($options);
- $result = file_get_contents($url, false, $context);
- if ($result === FALSE) {
- return $result;
- }
- var_dump($result);
- }
-
- }
复制代码
|