Skip to content

Commit

Permalink
Merge pull request #23 from TheNorthMemory/master
Browse files Browse the repository at this point in the history
fix #4 for PHP5.3
  • Loading branch information
overtrue committed May 18, 2015
2 parents 5bad9be + 970352e commit 514f713
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
13 changes: 7 additions & 6 deletions src/Wechat/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,22 @@ public function getToken()
}

// for php 5.3
$appId = $this->appId;
$appSecret = $this->appSecret;
$cache = $this->cache;
$cacheKey = $this->cacheKey;
$appId = $this->appId;
$appSecret = $this->appSecret;
$cache = $this->cache;
$cacheKey = $this->cacheKey;
$apiTokenGet = self::API_TOKEN_GET;

return $this->token = $this->cache->get(
$cacheKey, function ($cacheKey) use ($appId, $appSecret, $cache) {
$cacheKey, function ($cacheKey) use ($appId, $appSecret, $cache, $apiTokenGet) {
$params = array(
'appid' => $appId,
'secret' => $appSecret,
'grant_type' => 'client_credential',
);
$http = new Http();

$token = $http->get(self::API_TOKEN_GET, $params);
$token = $http->get($apiTokenGet, $params);

$cache->set($cacheKey, $token['access_token'], $token['expires_in']);

Expand Down
4 changes: 2 additions & 2 deletions src/Wechat/Alias.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
class Alias
{
protected static $aliases = [
protected static $aliases = array(
'WechatAuth' => 'Overtrue\\Wechat\\Auth',
'WechatCard' => 'Overtrue\\Wechat\\Card',
'WechatException' => 'Overtrue\\Wechat\\Exception',
Expand Down Expand Up @@ -39,7 +39,7 @@ class Alias
'WechatStats' => 'Overtrue\\Wechat\\Stats',
'WechatSemantic' => 'Overtrue\\Wechat\\Semantic',
'WechatColor' => 'Overtrue\\Wechat\\Color',
];
);

/**
* 是否已经注册过
Expand Down
9 changes: 5 additions & 4 deletions src/Wechat/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ public function getTicket()
$key = 'overtrue.wechat.card.api_ticket';

// for php 5.3
$http = $this->http;
$cache = $this->cache;
$http = $this->http;
$cache = $this->cache;
$apiTicket = self::API_TICKET;

return $this->ticket = $this->cache->get(
$key, function ($key) use ($http, $cache) {
$key, function ($key) use ($http, $cache, $apiTicket) {

$result = $http->get(self::API_TICKET);
$result = $http->get($apiTicket);

$cache->set($key, $result['ticket'], $result['expires_in']);

Expand Down
9 changes: 5 additions & 4 deletions src/Wechat/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ public function lists()
$key = 'overtrue.wechat.colors';

// for php 5.3
$http = $this->http;
$cache = $this->cache;
$http = $this->http;
$cache = $this->cache;
$apiList = self::API_LIST;

return $this->cache->get(
$key, function ($key) use ($http, $cache) {
$key, function ($key) use ($http, $cache, $apiList) {

$result = $http->get(self::API_LIST);
$result = $http->get($apiList);

$cache->set($key, $result['colors'], 86400);// 1 day

Expand Down
5 changes: 3 additions & 2 deletions src/Wechat/Js.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ public function getTicket()
$appId = $this->appId;
$appSecret = $this->appSecret;
$cache = $this->cache;
$apiTicket = self::API_TICKET;

return $this->cache->get(
$key, function ($key) use ($appId, $appSecret, $cache) {
$key, function ($key) use ($appId, $appSecret, $cache, $apiTicket) {
$http = new Http(new AccessToken($appId, $appSecret));

$result = $http->get(self::API_TICKET);
$result = $http->get($apiTicket);

$cache->set($key, $result['ticket'], $result['expires_in']);

Expand Down
2 changes: 1 addition & 1 deletion src/Wechat/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public function __call($method, $args)
*
* @return string
*/
protected function getUrl($type, $queries = [])
protected function getUrl($type, $queries = array())
{
if ($type === 'news') {
$api = self::API_FOREVER_NEWS_UPLOAD;
Expand Down

0 comments on commit 514f713

Please sign in to comment.