!
PhpStorm 是我常用的IDE
ReSharper 是帮助VS成为更佳的IDE
上面这两个软件已经成为了我现在开发中不可缺失的软件了
之前一直使用lanyus提供的授权服务器,但是这些域名都已遭JetBrains封杀。
自己有不想单独去运行lanyus提供的本地版本。所以一直使用别人提供的域名,但是不怎么稳定,所以自己考虑使用PHP写一个。
使用需要注意的
- 需要开启openssl
- 可以直接使用php运行
授权服务类
<?php
/**
* JetBrains许可服务器
*
* @author 情留メ蚊子 <qlwz@qq.com>
* @link http://www.94qing.com
* @version 1.0.0.0 By 2017-04-24
*/
class JetBrainsLicenseServer
{
// 授权给谁
public $licensee = 'qlwz';
// license 有效时间(单位:毫秒),默认约为7天多(607875500),原厂server传递的数值。
public $prolongationPeriod = 607875500;
// RSA 私钥
public $privateKey = <<<Eof
-----BEGIN RSA PRIVATE KEY-----
MIIBOwIBAAJBALecq3BwAI4YJZwhJ+snnDFj3lF3DMqNPorV6y5ZKXCiCMqj8OeO
mxk4YZW9aaV9ckl/zlAOI0mpB3pDT+Xlj2sCAwEAAQJAW6/aVD05qbsZHMvZuS2A
a5FpNNj0BDlf38hOtkhDzz/hkYb+EBYLLvldhgsD0OvRNy8yhz7EjaUqLCB0juIN
4QIhAMsJQ3xiJemnJ2pD65iRNCC/Kr7jtxbbBwa6ZFLjp12pAiEA54JCn41fF8GZ
90b9L5dtFQB2/yIcGX4Xo7bCvl8DaPMCIBgOZ+2T33QYtwXTOFXiVm/O1qy5ZFcT
6ng0m3BqwsjJAiEAqna/l7wAyP1E4U7kHqbhKxWsiTAUgLDXtzRbMNHFMQECIQCA
xlpXEPqnC3P8if0G9xHomqJ531rOJuzB8fNtRFmxnA==
-----END RSA PRIVATE KEY-----
Eof;
public function ping($salt, $isAnswer = false)
{
$str = '<PingResponse><message></message><responseCode>OK</responseCode><salt>%s</salt></PingResponse>';
$out = sprintf($str, $salt);
return $isAnswer ? $this->writeAnswer($out) : $out;
}
public function obtainTicket($salt, $isAnswer = false)
{
$ticketId = 1;
$str = "<ObtainTicketResponse><message></message><prolongationPeriod>%u</prolongationPeriod><responseCode>OK</responseCode><salt>%s</salt><ticketId>%d</ticketId><ticketProperties>licensee=%s\tlicenseType=0\t</ticketProperties></ObtainTicketResponse>";
$out = sprintf($str, $this->prolongationPeriod, $salt, $ticketId, $this->licensee);
return $isAnswer ? $this->writeAnswer($out) : $out;
}
public function prolongTicket($salt, $isAnswer = false)
{
$ticketId = 1;
$str = '<ProlongTicketResponse><message></message><responseCode>OK</responseCode><salt>%s</salt><ticketId>%d</ticketId></ProlongTicketResponse>';
$out = sprintf($str, $salt, $ticketId);
return $isAnswer ? $this->writeAnswer($out) : $out;
}
public function releaseTicket($salt, $isAnswer = false)
{
$str = '<ReleaseTicketResponse><message></message><responseCode>OK</responseCode><salt>%s</salt></ReleaseTicketResponse>';
$out = sprintf($str, $salt);
return $isAnswer ? $this->writeAnswer($out) : $out;
}
public function writeAnswer($str)
{
$signature = $this->sign($str);
$signatureHex = bin2hex($signature);
$out = sprintf("<!-- %s -->\n%s", $signatureHex, $str);
return $out;
}
private function sign($data)
{
if (empty ($data)) {
return null;
}
$pkeyid = openssl_get_privatekey($this->privateKey);
if (empty ($pkeyid)) {
return null;
}
$signature = '';
$verify = openssl_sign($data, $signature, $pkeyid, OPENSSL_ALGO_MD5);
openssl_free_key($pkeyid);
return $verify ? $signature : null;
}
}
使用JetBrainsLicenseServer类
<?php
include 'JetBrainsLicenseServer.php';
$uri = htmlspecialchars($_SERVER['REQUEST_URI']);
if (stripos($uri, '/rpc/ping.action') !== false) {
$method = 'ping';
} elseif (stripos($uri, '/rpc/obtainTicket.action') !== false) {
$method = 'obtainTicket';
} elseif (stripos($uri, '/rpc/prolongTicket.action') !== false) {
$method = 'prolongTicket';
} elseif (stripos($uri, '/rpc/releaseTicket.action') !== false) {
$method = 'releaseTicket';
} else {
show404();
exit();
}
$jblicsvr = new JetBrainsLicenseServer();
$salt = htmlspecialchars(isset ($_GET['salt']) ? $_GET['salt'] : null);
if (!$salt) {
if (preg_match('/(&|&|\?)salt=(?<salt>.*?)(&|$)/', $uri, $result)) {
$salt = $result['salt'];
}
}
if (!$salt || !method_exists($jblicsvr, $method)) {
show404();
}
echo $jblicsvr->$method ($salt, true);
exit();
function show404($msg = '')
{
$protocol = htmlspecialchars($_SERVER['SERVER_PROTOCOL']) ?: 'HTTP/1.0';
header($protocol . ' 404 Not Found');
header('Status: 404 Not Found');
echo $msg ?: 'Not Found';
exit ();
}
使用重定向
RewriteRule ^rpc/(ping|obtainTicket|prolongTicket|releaseTicket).action$ jblicsvr.php [QSA,PT,L]
使用方法
- 软件授权软件选择License server
- Licese server address填写
a. http://xxxx/jblicsvr.php?
b. http://xxxx/jblicsvr.php (如果使用该地址出错,则使用上面的地址)
c. http://xxxx (使用重定向后)