1、已知bug修复

2、微信接口更新
This commit is contained in:
2017-08-26 17:57:10 +08:00
parent cfcd6250ff
commit 356cccd1d4
25 changed files with 1353 additions and 695 deletions

View File

@@ -1,12 +1,25 @@
<?php
// +----------------------------------------------------------------------
// | wechat-php-sdk
// +----------------------------------------------------------------------
// | 版权所有 2014~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方文档: https://www.kancloud.cn/zoujingli/wechat-php-sdk
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/wechat-php-sdk
// +----------------------------------------------------------------------
/**
* PKCS7算法 加解密
* @category WechatSDK
* @subpackage library
* @date 2016/06/28 11:59
*/
class PKCS7Encoder {
class PKCS7Encoder
{
public static $block_size = 32;
@@ -15,7 +28,8 @@ class PKCS7Encoder {
* @param string $text 需要进行填充补位操作的明文
* @return string 补齐明文字符串
*/
function encode($text) {
function encode($text)
{
$amount_to_pad = PKCS7Encoder::$block_size - (strlen($text) % PKCS7Encoder::$block_size);
if ($amount_to_pad == 0) {
$amount_to_pad = PKCS7Encoder::$block_size;
@@ -33,7 +47,8 @@ class PKCS7Encoder {
* @param string $text 解密后的明文
* @return string 删除填充补位后的明文
*/
function decode($text) {
function decode($text)
{
$pad = ord(substr($text, -1));
if ($pad < 1 || $pad > PKCS7Encoder::$block_size) {
$pad = 0;
@@ -49,11 +64,13 @@ class PKCS7Encoder {
* @subpackage library
* @date 2016/06/28 11:59
*/
class Prpcrypt {
class Prpcrypt
{
public $key;
function __construct($k) {
function __construct($k)
{
$this->key = base64_decode($k . "=");
}
@@ -61,9 +78,10 @@ class Prpcrypt {
* 对明文进行加密
* @param string $text 需要加密的明文
* @param string $appid 公众号APPID
* @return string 加密后的密文
* @return array
*/
public function encrypt($text, $appid) {
public function encrypt($text, $appid)
{
try {
//获得16位随机字符串填充到明文之前
$random = $this->getRandomStr();//"aaaabbbbccccdddd";
@@ -82,9 +100,10 @@ class Prpcrypt {
* 对密文进行解密
* @param string $encrypted 需要解密的密文
* @param string $appid 公众号APPID
* @return string 解密得到的明文
* @return array
*/
public function decrypt($encrypted, $appid) {
public function decrypt($encrypted, $appid)
{
try {
$iv = substr($this->key, 0, 16);
$decrypted = openssl_decrypt($encrypted, 'AES-256-CBC', substr($this->key, 0, 32), OPENSSL_ZERO_PADDING, $iv);
@@ -95,27 +114,26 @@ class Prpcrypt {
$pkc_encoder = new PKCS7Encoder;
$result = $pkc_encoder->decode($decrypted);
if (strlen($result) < 16) {
return "";
return array(ErrorCode::$DecryptAESError, null);
}
$content = substr($result, 16, strlen($result));
$len_list = unpack("N", substr($content, 0, 4));
$xml_len = $len_list[1];
$xml_content = substr($content, 4, $xml_len);
$from_appid = substr($content, $xml_len + 4);
if (!$appid) {
$appid = $from_appid;
}
return array(0, $xml_content, $from_appid);
} catch (Exception $e) {
return array(ErrorCode::$IllegalBuffer, null);
}
return array(0, $xml_content, $from_appid);
}
/**
* 随机生成16位字符串
* @return string 生成的字符串
*/
function getRandomStr() {
function getRandomStr()
{
$str = "";
$str_pol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
$max = strlen($str_pol) - 1;
@@ -132,7 +150,8 @@ class Prpcrypt {
* 不用于官方API接口的errCode码
* Class ErrorCode
*/
class ErrorCode {
class ErrorCode
{
public static $OK = 0;
public static $ValidateSignatureError = 40001;
@@ -166,7 +185,8 @@ class ErrorCode {
* @param string $err
* @return bool
*/
public static function getErrText($err) {
public static function getErrText($err)
{
if (isset(self::$errCode[$err])) {
return self::$errCode[$err];
}