1313 * @author Anyon <[email protected] > 1414 * @date 2016/05/28 11:55
1515 */
16- class Common {
16+ class Common
17+ {
1718
1819 /** API接口URL需要使用此前缀 */
1920 const API_BASE_URL_PREFIX = 'https://api.weixin.qq.com ' ;
@@ -31,13 +32,14 @@ class Common {
3132 public $ errCode = 0 ;
3233 public $ errMsg = "" ;
3334 public $ config = array ();
34- private $ _retry = FALSE ;
35+ private $ _retry = false ;
3536
3637 /**
3738 * 构造方法
3839 * @param array $options
3940 */
40- public function __construct ($ options = array ()) {
41+ public function __construct ($ options = array ())
42+ {
4143 $ config = Loader::config ($ options );
4244 $ this ->token = isset ($ config ['token ' ]) ? $ config ['token ' ] : '' ;
4345 $ this ->appid = isset ($ config ['appid ' ]) ? $ config ['appid ' ] : '' ;
@@ -46,19 +48,39 @@ public function __construct($options = array()) {
4648 $ this ->config = $ config ;
4749 }
4850
51+ /**
52+ * 获取当前操作公众号APPID
53+ * @return string
54+ */
55+ public function getAppid ()
56+ {
57+ return $ this ->appid ;
58+ }
59+
60+ /**
61+ * 获取SDK配置参数
62+ * @return array
63+ */
64+ public function getConfig ()
65+ {
66+ return $ this ->config ;
67+ }
68+
69+
4970 /**
5071 * 接口验证
5172 * @return bool
5273 */
53- public function valid () {
74+ public function valid ()
75+ {
5476 $ encryptStr = "" ;
5577 if ($ _SERVER ['REQUEST_METHOD ' ] == "POST " ) {
5678 $ postStr = file_get_contents ("php://input " );
5779 $ array = (array )simplexml_load_string ($ postStr , 'SimpleXMLElement ' , LIBXML_NOCDATA );
5880 $ this ->encrypt_type = isset ($ _GET ["encrypt_type " ]) ? $ _GET ["encrypt_type " ] : '' ;
5981 if ($ this ->encrypt_type == 'aes ' ) {
6082 $ encryptStr = $ array ['Encrypt ' ];
61- !class_exists ('Prpcrypt ' , FALSE ) && require __DIR__ . '/Prpcrypt.php ' ;
83+ !class_exists ('Prpcrypt ' , false ) && require __DIR__ . '/Prpcrypt.php ' ;
6284 $ pc = new Prpcrypt ($ this ->encodingAesKey );
6385 $ array = $ pc ->decrypt ($ encryptStr , $ this ->appid );
6486 if (!isset ($ array [0 ]) || intval ($ array [0 ]) > 0 ) {
@@ -91,7 +113,8 @@ public function valid() {
91113 * @param string $str
92114 * @return bool
93115 */
94- private function checkSignature ($ str = '' ) {
116+ private function checkSignature ($ str = '' )
117+ {
95118 // 如果存在加密验证则用加密验证段
96119 $ signature = isset ($ _GET ["msg_signature " ]) ? $ _GET ["msg_signature " ] : (isset ($ _GET ["signature " ]) ? $ _GET ["signature " ] : '' );
97120 $ timestamp = isset ($ _GET ["timestamp " ]) ? $ _GET ["timestamp " ] : '' ;
@@ -112,7 +135,8 @@ private function checkSignature($str = '') {
112135 * @param string $token 手动指定access_token,非必要情况不建议用
113136 * @return bool|string
114137 */
115- public function getAccessToken ($ appid = '' , $ appsecret = '' , $ token = '' ) {
138+ public function getAccessToken ($ appid = '' , $ appsecret = '' , $ token = '' )
139+ {
116140 if (!$ appid || !$ appsecret ) {
117141 $ appid = $ this ->appid ;
118142 $ appsecret = $ this ->appsecret ;
@@ -151,7 +175,8 @@ public function getAccessToken($appid = '', $appsecret = '', $token = '') {
151175 * @param array $arguments SDK方法参数
152176 * @return bool|mixed
153177 */
154- protected function checkRetry ($ method , $ arguments = array ()) {
178+ protected function checkRetry ($ method , $ arguments = array ())
179+ {
155180 if (!$ this ->_retry && in_array ($ this ->errCode , array ('40014 ' , '40001 ' , '41001 ' , '42001 ' ))) {
156181 Tools::log ("Run {$ method } Faild. {$ this ->errMsg }[ {$ this ->errCode }] " , 'ERR ' );
157182 ($ this ->_retry = true ) && $ this ->resetAuth ();
@@ -168,7 +193,8 @@ protected function checkRetry($method, $arguments = array()) {
168193 * @param string $appid 如在类初始化时已提供,则可为空
169194 * @return bool
170195 */
171- public function resetAuth ($ appid = '' ) {
196+ public function resetAuth ($ appid = '' )
197+ {
172198 $ authname = 'wechat_access_token_ ' . (empty ($ appid ) ? $ this ->appid : $ appid );
173199 Tools::log ("Reset Auth And Remove Old AccessToken. " );
174200 $ this ->access_token = '' ;
0 commit comments