最近项目需要,要远程登录别人的系统,并且在对方的系统中提交表单,所以写了一个类。
namespace app\api\controller;
use think\Db;
use think\Controller;
use think\facade\Env;
use think\facade\Request;
class Offline extends Controller
{
//域名
public $baseUrl = 'http://localhost:8080';
//登录错误返回的链接
public $loginErrorUrl = '/login';
//登录验证
public $loginUrl = '/check';
//登录成功跳转
public $loginSuccessUrl = '/loginSuccess';
//提交表单
public $orderUrl = '/save';
//提交表单返回页面URL
public $formUrl = '/proposal';
//下载URL
public $downloadUrl = '/downloads';
//记录登录返回的cookie
public $cookieFile;
//日志
public $logFile;
protected function initialize()
{
parent::initialize();
$this->cookieFile = Env::get('root_path') .'runtime/success_cookie.txt';
$this->logFile = Env::get('root_path') .'runtime/offline_log.txt';
}
/**
* @function online
* @intro 模拟form提交表单
* @return string
*/
public function online()
{
$ch = curl_init($this->baseUrl.$this->formUrl);
curl_setopt($ch,CURLOPT_COOKIEFILE, $this->cookieFile); //同时发送Cookie
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
$headers = curl_getinfo($ch);
curl_close($ch);
//通过返回