author.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2018/7/5
  6. * Time: 下午4:41
  7. */
  8. namespace room;
  9. class author
  10. {
  11. static public function sign_web($roomid,$userid)
  12. {
  13. $data = ['room' => $roomid,'user' => $userid,'acctype' => proto_type::acc_web_type];
  14. $plaintext = json_encode($data);
  15. $cipher="AES-128-CBC";
  16. $ivlen = openssl_cipher_iv_length($cipher);
  17. $iv = self::zero_iv($ivlen);
  18. return openssl_encrypt($plaintext, $cipher, self::passwd(), 0, $iv);
  19. }
  20. static public function sign_native($userid)
  21. {
  22. $data = ['user' => $userid,'room' => 0,'acctype' => proto_type::acc_native_type];
  23. $plaintext = json_encode($data);
  24. $cipher="AES-128-CBC";
  25. $ivlen = openssl_cipher_iv_length($cipher);
  26. $iv = self::zero_iv($ivlen);
  27. return openssl_encrypt($plaintext, $cipher, self::passwd(), 0, $iv);
  28. }
  29. static public function sign_all($userid)
  30. {
  31. $data = ['user' => $userid,'room' => 0,'acctype' => proto_type::acc_all_type];
  32. $plaintext = json_encode($data);
  33. $cipher="AES-128-CBC";
  34. $ivlen = openssl_cipher_iv_length($cipher);
  35. $iv = self::zero_iv($ivlen);
  36. return openssl_encrypt($plaintext, $cipher, self::passwd(), 0, $iv);
  37. }
  38. public function verify()
  39. {
  40. }
  41. static private function zero_iv($ivlen)
  42. {
  43. $iv = '';
  44. for ($i = 0; $i < $ivlen; ++$i) {
  45. $iv .= chr(0);
  46. }
  47. return $iv;
  48. }
  49. static private function passwd()
  50. {
  51. global $config;
  52. $pass = $config['room_password'];
  53. return $pass;
  54. }
  55. }