33namespace Wechat ;
44
55use 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 );
2018
2119/**
2220 * 微信SDK加载器
23- *
2421 * @author Anyon <[email protected] > 2522 * @date 2016-08-21 11:06
2623 */
2724class 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