Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Php53 #41

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
"email": "[email protected]"
}
],
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
},
"minimum-stability" : "dev",
"autoload": {
"psr-4": {
Expand Down
20 changes: 14 additions & 6 deletions src/Wechat/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,22 @@ class AccessToken
/**
* constructor
*
* @param string $appId
* @param string $appSecret
* <pre>
* $config:
*
* array(
* 'app_id' => YOUR_APPID, // string mandatory;
* 'secret' => YOUR_SECRET, // string mandatory;
* )
* </pre>
*
* @param array $config configuration array
*/
public function __construct($appId, $appSecret)
public function __construct(array $config)
{
$this->appId = $appId;
$this->appSecret = $appSecret;
$this->cache = new Cache($appId);
$this->appId = $config['app_id'];
$this->appSecret = $config['secret'];
$this->cache = new Cache($this->appId);
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/Wechat/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,12 @@ class Auth
/**
* constructor
*
* @param string $appId
* @param string $appSecret
* @param array $config
*/
public function __construct($appId, $appSecret)
public function __construct(array $config)
{
$this->appId = $appId;
$this->appSecret = $appSecret;
$this->appId = $config['app_id'];
$this->appSecret = $config['secret'];
$this->http = new Http(); // 不需要公用的access_token
$this->input = new Input();
}
Expand Down
18 changes: 13 additions & 5 deletions src/Wechat/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,21 @@ class Card
/**
* constructor
*
* @param string $appId
* @param string $appSecret
* <pre>
* $config:
*
* array(
* 'app_id' => YOUR_APPID, // string mandatory;
* 'secret' => YOUR_SECRET, // string mandatory;
* )
* </pre>
*
* @param array $config configuration array
*/
public function __construct($appId, $appSecret)
public function __construct(array $config)
{
$this->http = new Http(new AccessToken($appId, $appSecret));
$this->cache = new Cache($appId);
$this->http = new Http(new AccessToken($config));
$this->cache = new Cache($config['app_id']);
}

/**
Expand Down
18 changes: 13 additions & 5 deletions src/Wechat/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,21 @@ class Color
/**
* constructor
*
* @param string $appId
* @param string $appSecret
* <pre>
* $config:
*
* array(
* 'app_id' => YOUR_APPID, // string mandatory;
* 'secret' => YOUR_SECRET, // string mandatory;
* )
* </pre>
*
* @param array $config configuration array
*/
public function __construct($appId, $appSecret)
public function __construct(array $config)
{
$this->http = new Http(new AccessToken($appId, $appSecret));
$this->cache = new Cache($appId);
$this->http = new Http(new AccessToken($config));
$this->cache = new Cache($config['app_id']);
}

/**
Expand Down
16 changes: 8 additions & 8 deletions src/Wechat/Crypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,26 @@ class Crypt





/**
* constructor
*
* @param string $appId
* @param string $token
* @param string $encodingAESKey
* @param array $config
*/
public function __construct($appId, $token, $encodingAESKey)
public function __construct(array $config)
{
if (!extension_loaded('mcrypt')) {
throw new Exception('Mcrypt 拓展未安装或未启用');
}

if (strlen($encodingAESKey) !== 43) {
if (strlen($config['encoding_key']) !== 43) {
throw new Exception('Invalid AESKey.', self::ERROR_INVALID_AESKEY);
}

$this->appId = $appId;
$this->token = $token;
$this->AESKey = base64_decode($encodingAESKey.'=', true);
$this->appId = $config['app_id'];
$this->token = $config['token'];
$this->AESKey = base64_decode($config['encoding_key'].'=', true);
$this->blockSize = 32;// mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Wechat/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,5 @@ public function __construct($message, $code = -1)
$message = "[Wechat]{$message}";

parent::__construct($message, $code);
}
}
}
20 changes: 13 additions & 7 deletions src/Wechat/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,20 @@ class Group
/**
* constructor
*
* @param string $appId
* @param string $appSecret
* <pre>
* $config:
*
* array(
* 'app_id' => YOUR_APPID, // string mandatory;
* 'secret' => YOUR_SECRET, // string mandatory;
* )
* </pre>
*
* @param array $config configuration array
*/
public function __construct($appId, $appSecret)
public function __construct(array $config)
{
$this->http = new Http(new AccessToken($appId, $appSecret));
$this->http = new Http(new AccessToken($config));
}

/**
Expand Down Expand Up @@ -106,9 +114,7 @@ public function update($groupId, $name)
public function delete($groupId)
{
$params = array(
'group' => array(
'id' => $groupId,
),
'group' => array('id' => $groupId),
);

return $this->http->jsonPost(self::API_DELETE, $params);
Expand Down
16 changes: 12 additions & 4 deletions src/Wechat/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@ class Image
/**
* constructor
*
* @param string $appId
* @param string $appSecret
* <pre>
* $config:
*
* array(
* 'app_id' => YOUR_APPID, // string mandatory;
* 'secret' => YOUR_SECRET, // string mandatory;
* )
* </pre>
*
* @param array $config configuration array
*/
public function __construct($appId, $appSecret)
public function __construct(array $config)
{
$this->http = new Http(new AccessToken($appId, $appSecret));
$this->http = new Http(new AccessToken($config));
}

/**
Expand Down
11 changes: 5 additions & 6 deletions src/Wechat/Js.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ class Js
/**
* constructor
*
* @param string $appId
* @param string $appSecret
* @param array $config
*/
public function __construct($appId, $appSecret)
public function __construct(array $config)
{
$this->appId = $appId;
$this->appSecret = $appSecret;
$this->appId = $config['app_id'];
$this->appSecret = $config['secret'];
$this->cache = new Cache($appId);
}

Expand Down Expand Up @@ -119,7 +118,7 @@ public function getTicket()
return $this->cache->get(
$key,
function ($key) use ($appId, $appSecret, $cache, $apiTicket) {
$http = new Http(new AccessToken($appId, $appSecret));
$http = new Http(new AccessToken(array('app_id' => $appId, 'secret' => $appSecret)));

$result = $http->get($apiTicket);

Expand Down
16 changes: 12 additions & 4 deletions src/Wechat/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,20 @@ class Media
/**
* constructor
*
* @param string $appId
* @param string $appSecret
* <pre>
* $config:
*
* array(
* 'app_id' => YOUR_APPID, // string mandatory;
* 'secret' => YOUR_SECRET, // string mandatory;
* )
* </pre>
*
* @param array $config configuration array
*/
public function __construct($appId, $appSecret)
public function __construct(array $config)
{
$this->http = new Http(new AccessToken($appId, $appSecret));
$this->http = new Http(new AccessToken($config));
}

/**
Expand Down
16 changes: 12 additions & 4 deletions src/Wechat/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,20 @@ class Menu
/**
* constructor
*
* @param string $appId
* @param string $appSecret
* <pre>
* $config:
*
* array(
* 'app_id' => YOUR_APPID, // string mandatory;
* 'secret' => YOUR_SECRET, // string mandatory;
* )
* </pre>
*
* @param array $config configuration array
*/
public function __construct($appId, $appSecret)
public function __construct(array $config)
{
$this->http = new Http(new AccessToken($appId, $appSecret));
$this->http = new Http(new AccessToken($config));
}

/**
Expand Down
17 changes: 3 additions & 14 deletions src/Wechat/Messages/Voice.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,16 @@ class Voice extends BaseMessage
*/
protected $media;

/**
* constructor
*
* @param string $appId
* @param string $appSecret
*/
public function __construct($appId, $appSecret)
{
$this->media = new Media($appId, $appSecret);
}

/**
* 设置语音
*
* @param string $path
* @param string $mediaId
*
* @return Voice
*/
public function media($path)
public function media($mediaId)
{
$this->setAttribute('media_id', $this->media->voice($path));
$this->setAttribute('media_id', $mediaId);

return $this;
}
Expand Down
16 changes: 12 additions & 4 deletions src/Wechat/Notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,20 @@ class Notice
/**
* constructor
*
* @param string $appId
* @param string $appSecret
* <pre>
* $config:
*
* array(
* 'app_id' => YOUR_APPID, // string mandatory;
* 'secret' => YOUR_SECRET, // string mandatory;
* )
* </pre>
*
* @param array $config configuration array
*/
public function __construct($appId, $appSecret)
public function __construct(array $config)
{
$this->http = new Http(new AccessToken($appId, $appSecret));
$this->http = new Http(new AccessToken($config));
}

/**
Expand Down
Loading