Advertisement
Guest User

Untitled

a guest
Jul 5th, 2018
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. <?php
  2. function soapClientWSSecurityHeader($user, $password)
  3. {
  4. // Creating date using yyyy-mm-ddThh:mm:ssZ format
  5. $tm_created = gmdate('Y-m-d\TH:i:s\Z');
  6. $tm_expires = gmdate('Y-m-d\TH:i:s\Z', gmdate('U') + 180); //only necessary if using the timestamp element
  7.  
  8. // Generating and encoding a random number
  9. $simple_nonce = mt_rand();
  10. $encoded_nonce = base64_encode($simple_nonce);
  11.  
  12. // Compiling WSS string
  13. $passdigest = base64_encode(sha1($simple_nonce . $tm_created . $password, true));
  14.  
  15. // Initializing namespaces
  16. $ns_wsse = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
  17. $ns_wsu = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
  18. $password_type = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText';
  19. $encoding_type = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary';
  20.  
  21. // Creating WSS identification header using SimpleXML
  22. $root = new SimpleXMLElement('<root/>');
  23.  
  24. $security = $root->addChild('wsse:Security', null, $ns_wsse);
  25.  
  26. //the timestamp element is not required by all servers
  27. //$timestamp = $security->addChild('wsu:Timestamp', null, $ns_wsu);
  28. //$timestamp->addAttribute('wsu:Id', 'Timestamp-28');
  29. //$timestamp->addChild('wsu:Created', $tm_created, $ns_wsu);
  30. //$timestamp->addChild('wsu:Expires', $tm_expires, $ns_wsu);
  31.  
  32. $usernameToken = $security->addChild('wsse:UsernameToken', null, $ns_wsse);
  33. $usernameToken->addChild('wsse:Username', $user, $ns_wsse);
  34. $usernameToken->addChild('wsse:Password', $password, $ns_wsse)->addAttribute('Type', $password_type);
  35. //$usernameToken->addChild('wsse:Nonce', $encoded_nonce, $ns_wsse)->addAttribute('EncodingType', $encoding_type);
  36. //$usernameToken->addChild('wsu:Created', $tm_created, $ns_wsu);
  37.  
  38. // Recovering XML value from that object
  39. $root->registerXPathNamespace('wsse', $ns_wsse);
  40. $full = $root->xpath('/root/wsse:Security');
  41. $auth = $full[0]->asXML();
  42.  
  43. return new SoapHeader($ns_wsse, 'Security', new SoapVar($auth, XSD_ANYXML), true);
  44. }
  45.  
  46. $wsdl = 'https://partnerservicesiot.ytlcomms.my/partnerservices/v1/PartnerService?wsdl';
  47. $username = "topupbaruser";
  48. $password = "topuppass";
  49.  
  50. $client = new SoapClient($wsdl);
  51. $client->__setSoapHeaders(soapClientWSSecurityHeader($username,$password));
  52.  
  53. $input = array('CVPBalanceReq' => array(
  54. 'requestId' => 'testingtpbar',
  55. 'partnerName' => 'Topupbar',
  56. 'channel' => 'YCMS'));
  57. $objResponse = $client->__soapCall('GetCVPBalance', $input);
  58. var_dump($objResponse); exit;
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement