ServiceController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. Doo::loadModelAt('auser', 'admin');
  3. Doo::loadModelAt('ausers', 'admin');
  4. Doo::loadModel('users');
  5. Doo::loadClass('profile');
  6. Doo::loadClass('PasswordHash');
  7. Doo::loadClass('mailer');
  8. Doo::loadClass('nusoap');
  9. /*
  10. * To change this license header, choose License Headers in Project Properties.
  11. * To change this template file, choose Tools | Templates
  12. * and open the template in the editor.
  13. */
  14. // 列表停用 编辑 重置密码
  15. // 管理员权限管理
  16. // 管理员修改密码
  17. class ServiceController extends DooController
  18. {
  19. private $data, $users, $user, $profile, $ph, $userz, $mailer;
  20. public function __construct()
  21. {
  22. $this->users = new AUsers();
  23. $this->user = new AUser();
  24. $this->userz = new Users();
  25. $this->profile = new Profile();
  26. $this->mailer = new Mailer();
  27. $this->ph = new PasswordHash(8, FALSE);
  28. $this->data['rootUrl'] = Doo::conf()->APP_URL;
  29. }
  30. public function ZGServer()
  31. {
  32. ini_set("soap.wsdl_cache_enabled", "0");
  33. $server = new SoapServer(Doo::conf()->APP_URL . 'service/getwsdl?wsdl', array('soap_version' => SOAP_1_2));
  34. $server->setClass('ServiceController');
  35. $server->addFunction('addUser');
  36. $server->addFunction(SOAP_FUNCTIONS_ALL);
  37. $server->handle();
  38. }
  39. public function getWSDL()
  40. {
  41. ini_set("soap.wsdl_cache_enabled", "0");
  42. $soap = new soap_server;
  43. $soap->configureWSDL('UserService', 'urn:UserService', Doo::conf()->APP_URL . 'service/user');
  44. $soap->soap_defencoding = 'UTF-8';
  45. $soap->register(
  46. 'addUser',
  47. array('username' => 'xsd:string', 'realname' => 'xsd:string'),
  48. array('retval' => 'xsd:boolean'),
  49. 'urn:UserService',
  50. 'urn:UserService#addUser'
  51. );
  52. // $soap->register(
  53. // 'updateUser',
  54. // array('username' => 'xsd:string')
  55. // );
  56. // $soap->service(file_get_contents("php://input"));
  57. $soap->service(isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '');
  58. }
  59. public function testSoap(){
  60. ini_set("soap.wsdl_cache_enabled", "0");
  61. $client=new soapclient(Doo::conf()->APP_URL . '/service/user');
  62. var_dump($client);
  63. exit;
  64. $client->soap_defencoding = 'UTF-8';
  65. $paras=array('username' => "测试soap",'realname' => "测试soap");
  66. $result=$client->call("addUser",$paras);
  67. if (!$err=$client->getError()) {
  68. echo "返回结果:",$result;
  69. } else {
  70. echo "调用出错:",$err;
  71. }
  72. // $server->handle();
  73. }
  74. function addUser($username, $realname)
  75. {
  76. if (isset($username) && isset($realname)) {
  77. $uid = $this->users->createUser($username, $username);
  78. if ($uid) {
  79. $this->profile->ZGinsertProfile($uid, urldecode($realname));
  80. return true;
  81. } else {
  82. return false;
  83. }
  84. } else {
  85. return false;
  86. }
  87. }
  88. public function randomPassword()
  89. {
  90. $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
  91. $pass = array(); //remember to declare $pass as an array
  92. $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
  93. for ($i = 0; $i < 8; $i++) {
  94. $n = rand(0, $alphaLength);
  95. $pass[] = $alphabet[$n];
  96. }
  97. return implode($pass); //turn the array into a string
  98. }
  99. }