KeyRequest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace ACES\Common;
  3. use ACES\Common\domain\JosBaseInfo;
  4. class KeyRequest
  5. {
  6. public $data;
  7. public $sig;
  8. public function __construct($token, $major_sdk_ver) {
  9. $this->data = new KeyRequestData($token->get_id(), $major_sdk_ver);
  10. $json = json_encode($this->data);
  11. // $json = json_encode($this->data->jsonSerialize());
  12. $this->sig = base64_encode($token->do_sign($json));
  13. }
  14. public static function createNewKeyRequest($token, $major_sdk_ver) {
  15. $keyRequest = new KeyRequest($token, $major_sdk_ver);
  16. return json_encode($keyRequest);
  17. }
  18. /**
  19. * @param JosBaseInfo $josBaseInfo
  20. * @return array
  21. */
  22. public function toFormParams($josBaseInfo)
  23. {
  24. return $josBaseInfo->getFormParams($this);
  25. }
  26. // public function jsonSerialize()
  27. // {
  28. // $vars = get_object_vars($this);
  29. //
  30. // return $vars;
  31. // }
  32. public function to360buyParamJson()
  33. {
  34. $josKeyRequest = array();
  35. $josKeyRequest['sig'] = $this->sig;
  36. $josKeyRequest['tid'] = $this->data->getTid();
  37. $josKeyRequest['ts'] = $this->data->getTs();
  38. $josKeyRequest['sdk_ver'] = $this->data->getSdkVer();
  39. return json_encode($josKeyRequest);
  40. }
  41. public function getJosMethod()
  42. {
  43. return 'jingdong.jos.master.key.get';
  44. }
  45. }