Skip to content

Commit 02f8459

Browse files
committed
更新第三方平台SDK
1 parent 8aa446d commit 02f8459

File tree

11 files changed

+281
-252
lines changed

11 files changed

+281
-252
lines changed

Wechat/Lib/Cache.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@
66

77
/**
88
* SDK缓存类
9-
*
10-
* @author Anyon <[email protected]>
9+
*
10+
* @author Anyon <[email protected]>
1111
* @date 2016-08-20 17:50
1212
*/
1313
class Cache {
1414

1515
/**
1616
* 缓存位置
17-
* @var type
17+
* @var type
1818
*/
1919
static public $cachepath;
2020

2121
/**
2222
* 设置缓存
23-
* @param type $name
24-
* @param type $value
25-
* @param type $expired
26-
* @return type
23+
* @param string $name
24+
* @param string $value
25+
* @param int $expired
26+
* @return mixed
2727
*/
2828
static public function set($name, $value, $expired = 0) {
2929
if (isset(Loader::$callback['CacheSet'])) {
@@ -35,8 +35,8 @@ static public function set($name, $value, $expired = 0) {
3535

3636
/**
3737
* 读取缓存
38-
* @param type $name
39-
* @return type
38+
* @param string $name
39+
* @return mixed
4040
*/
4141
static public function get($name) {
4242
if (isset(Loader::$callback['CacheGet'])) {
@@ -53,8 +53,8 @@ static public function get($name) {
5353

5454
/**
5555
* 删除缓存
56-
* @param type $name
57-
* @return type
56+
* @param string $name
57+
* @return mixed
5858
*/
5959
static public function del($name) {
6060
if (isset(Loader::$callback['CacheDel'])) {
@@ -65,9 +65,9 @@ static public function del($name) {
6565

6666
/**
6767
* 输出内容到日志
68-
* @param type $line
69-
* @param type $filename
70-
* @return type
68+
* @param string $line
69+
* @param string $filename
70+
* @return mixed
7171
*/
7272
static public function put($line, $filename = '') {
7373
if (isset(Loader::$callback['CachePut'])) {

Wechat/Lib/Common.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
/**
99
* 微信SDK基础类
10-
*
10+
*
1111
* @category WechatSDK
1212
* @subpackage library
1313
* @author Anyon <[email protected]>
@@ -76,7 +76,7 @@ public function valid() {
7676
$encryptStr = "";
7777
if ($_SERVER['REQUEST_METHOD'] == "POST") {
7878
$postStr = file_get_contents("php://input");
79-
$array = (array) simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
79+
$array = (array)simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
8080
$this->encrypt_type = isset($_GET["encrypt_type"]) ? $_GET["encrypt_type"] : '';
8181
if ($this->encrypt_type == 'aes') {
8282
$encryptStr = $array['Encrypt'];

Wechat/Lib/Tools.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class Tools {
1616

1717
/**
1818
* 产生随机字符串
19-
* @param type $length
20-
* @param type $str
21-
* @return type
19+
* @param int $length
20+
* @param string $str
21+
* @return string
2222
*/
2323
static public function createNoncestr($length = 32, $str = "") {
2424
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";

Wechat/Loader.php

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
namespace Wechat;
44

55
use Wechat\Lib\Cache;
6-
use Wechat\WechatReceive;
76

87
/**
98
* 注册SDK自动加载机制
10-
*
119
* @author Anyon <[email protected]>
1210
* @date 2016/10/26 10:21
1311
*/
14-
spl_autoload_register(function($class) {
12+
spl_autoload_register(function ($class) {
1513
if (0 === stripos($class, 'Wechat\\')) {
1614
$filename = dirname(__DIR__) . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
1715
file_exists($filename) && require($filename);
@@ -20,52 +18,34 @@
2018

2119
/**
2220
* 微信SDK加载器
23-
*
2421
* @author Anyon <[email protected]>
2522
* @date 2016-08-21 11:06
2623
*/
2724
class Loader {
2825

26+
/**
27+
* 事件注册函数
28+
* @var array
29+
*/
30+
static public $callback = array();
31+
2932
/**
3033
* 配置参数
31-
* @var type
34+
* @var array
3235
*/
3336
static protected $config = array();
3437

3538
/**
3639
* 对象缓存
37-
* @var type
40+
* @var array
3841
*/
3942
static protected $cache = array();
4043

41-
/**
42-
* 事件注册函数
43-
* @var type
44-
*/
45-
static public $callback = array();
46-
47-
/**
48-
* 设置配置参数
49-
* @param type $config
50-
* @return type
51-
*/
52-
static public function config($config = array()) {
53-
!empty($config) && self::$config = array_merge(self::$config, $config);
54-
if (!empty(self::$config['cachepath'])) {
55-
Cache::$cachepath = self::$config['cachepath'];
56-
}
57-
if (empty(self::$config['component_verify_ticket'])) {
58-
self::$config['component_verify_ticket'] = Cache::get('component_verify_ticket');
59-
}
60-
return self::$config;
61-
}
62-
6344
/**
6445
* 动态注册SDK事件处理函数
65-
* @param type $event 事件名称(getAccessToken|getJsTicket)
66-
* @param type $method 处理方法(可以是普通方法或者类中的方法)
67-
* @param type $class 处理对象(可以直接使用的类实例)
68-
* @return boolean
46+
* @param string $event 事件名称(getAccessToken|getJsTicket)
47+
* @param string $method 处理方法(可以是普通方法或者类中的方法)
48+
* @param string|null $class 处理对象(可以直接使用的类实例)
6949
*/
7050
static public function register($event, $method, $class = NULL) {
7151
if (!empty($class) && class_exists($class, FALSE) && method_exists($class, $method)) {
@@ -77,19 +57,19 @@ static public function register($event, $method, $class = NULL) {
7757

7858
/**
7959
* 获取微信SDK接口对象(别名函数)
80-
* @param type $type 接口类型(Card|Custom|Device|Extends|Media|Menu|Oauth|Pay|Receive|Script|User)
81-
* @param type $config SDK配置(token,appid,appsecret,encodingaeskey,mch_id,partnerkey,ssl_cer,ssl_key,qrc_img)
82-
* @return WechatReceive
60+
* @param string $type 接口类型(Card|Custom|Device|Extends|Media|Menu|Oauth|Pay|Receive|Script|User|Poi)
61+
* @param array $config SDK配置(token,appid,appsecret,encodingaeskey,mch_id,partnerkey,ssl_cer,ssl_key,qrc_img)
62+
* @return WechatCard|WechatCustom|WechatDevice|WechatExtends|WechatMedia|WechatMenu|WechatOauth|WechatPay|WechatPoi|WechatReceive|WechatScript|WechatService|WechatUser
8363
*/
8464
static public function & get_instance($type, $config = array()) {
8565
return self::get($type, $config);
8666
}
8767

8868
/**
8969
* 获取微信SDK接口对象
90-
* @param type $type 接口类型(Card|Custom|Device|Extends|Media|Menu|Oauth|Pay|Receive|Script|User)
91-
* @param type $config SDK配置(token,appid,appsecret,encodingaeskey,mch_id,partnerkey,ssl_cer,ssl_key,qrc_img)
92-
* @return WechatReceive
70+
* @param string $type 接口类型(Card|Custom|Device|Extends|Media|Menu|Oauth|Pay|Receive|Script|User|Poi)
71+
* @param array $config SDK配置(token,appid,appsecret,encodingaeskey,mch_id,partnerkey,ssl_cer,ssl_key,qrc_img)
72+
* @return WechatCard|WechatCustom|WechatDevice|WechatExtends|WechatMedia|WechatMenu|WechatOauth|WechatPay|WechatPoi|WechatReceive|WechatScript|WechatService|WechatUser
9373
*/
9474
static public function & get($type, $config = array()) {
9575
$index = md5(strtolower($type) . md5(json_encode(self::$config)));
@@ -103,4 +83,29 @@ static public function & get($type, $config = array()) {
10383
return self::$cache[$index];
10484
}
10585

86+
/**
87+
* 设置配置参数
88+
* @param array $config
89+
* @return array
90+
*/
91+
static public function config($config = array()) {
92+
!empty($config) && self::$config = array_merge(self::$config, $config);
93+
if (!empty(self::$config['cachepath'])) {
94+
Cache::$cachepath = self::$config['cachepath'];
95+
}
96+
if (empty(self::$config['component_verify_ticket'])) {
97+
self::$config['component_verify_ticket'] = Cache::get('component_verify_ticket');
98+
}
99+
if (empty(self::$config['token']) && !empty(self::$config['component_token'])) {
100+
self::$config['token'] = self::$config['component_token'];
101+
}
102+
if (empty(self::$config['appsecret']) && !empty(self::$config['component_appsecret'])) {
103+
self::$config['appsecret'] = self::$config['component_appsecret'];
104+
}
105+
if (empty(self::$config['encodingaeskey']) && !empty(self::$config['component_encodingaeskey'])) {
106+
self::$config['encodingaeskey'] = self::$config['encodingaeskey'];
107+
}
108+
return self::$config;
109+
}
110+
106111
}

0 commit comments

Comments
 (0)