| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace ACES\Common\domain;
- class JosBaseInfo
- {
- private $appKey;
- private $appSecret;
- private $accessToken;
- private $timestamp;
- private $v = "2.0";
- private $serverUrl;
- /**
- * JosBaseInfo constructor.
- * @param $method
- * @param $app_key
- * @param $access_token
- */
- public function __construct($appKey, $appSecret, $access_token, $serverUrl)
- {
- $this->appKey = $appKey;
- $this->appSecret = $appSecret;
- $this->accessToken = $access_token;
- $this->serverUrl = $serverUrl;
- }
- /**
- * @return string
- */
- public function getAppKey()
- {
- return $this->appKey;
- }
- /**
- * @return mixed
- */
- public function getAppSecret()
- {
- return $this->appSecret;
- }
- /**
- * @return string
- */
- public function getAccessToken()
- {
- return $this->accessToken;
- }
- /**
- * @return string
- */
- public function getV()
- {
- return $this->v;
- }
- /**
- * @return string
- */
- public function getServerUrl()
- {
- return $this->serverUrl;
- }
- /**
- * @param bool $init
- * @return string
- */
- public function getTimestamp($init = true)
- {
- if ($init || !isset($this->timestamp)) {
- //TODO delete date_default_timezone_set
- date_default_timezone_set("prc");
- $this->timestamp = date('Y-m-d H:i:s');
- }
- return $this->timestamp;
- }
- /**
- * @param \ACES\Common\ProduceRequest $josReuqest
- * @return array
- */
- public function getFormParams($josReuqest)
- {
- $request = array();
- $request['360buy_param_json'] = $josReuqest->to360buyParamJson();
- $request['app_key'] = $this->getAppKey();
- $request['access_token'] = $this->getAccessToken();
- $request['timestamp'] = $this->getTimestamp();
- $request['v'] = $this->getV();
- $request['method'] = $josReuqest->getJosMethod();
- $request['sign'] = $this->generateSign($request);
- return $request;
- }
- private function generateSign($params)
- {
- ksort($params);
- $stringToBeSigned = $this->appSecret;
- foreach ($params as $k => $v)
- {
- $stringToBeSigned .= $k . $v;
- }
- $stringToBeSigned .= $this->appSecret;
- return strtoupper(md5($stringToBeSigned));
- }
- }
|