66
77/**
88 * 微信接口通用类
9- *
9+ *
1010 * @category WechatSDK
1111 * @subpackage library
1212 * @author Anyon <[email protected] > @@ -32,7 +32,7 @@ static public function createNoncestr($length = 32, $str = "") {
3232 * 获取签名
3333 * @param array $arrdata 签名数组
3434 * @param string $method 签名方法
35- * @return boolean |string 签名值
35+ * @return bool |string 签名值
3636 */
3737 static public function getSignature ($ arrdata , $ method = "sha1 " ) {
3838 if (!function_exists ($ method )) {
@@ -48,9 +48,9 @@ static public function getSignature($arrdata, $method = "sha1") {
4848
4949 /**
5050 * 生成支付签名
51- * @param type $option
52- * @param type $partnerKey
53- * @return type
51+ * @param array $option
52+ * @param string $partnerKey
53+ * @return string
5454 */
5555 static public function getPaySign ($ option , $ partnerKey ) {
5656 ksort ($ option );
@@ -66,8 +66,7 @@ static public function getPaySign($option, $partnerKey) {
6666 * @param mixed $data 数据
6767 * @param string $root 根节点名
6868 * @param string $item 数字索引的子节点名
69- * @param string $attr 根节点属性
70- * @param string $id 数字索引子节点key转换的属性名
69+ * @param string $id 数字索引子节点key转换的属性名
7170 * @return string
7271 */
7372 static public function arr2xml ($ data , $ root = 'xml ' , $ item = 'item ' , $ id = 'id ' ) {
@@ -83,7 +82,7 @@ function _data_to_xml($data, $item = 'item', $id = 'id', $content = '') {
8382 } else {
8483 $ content .= '<![CDATA[ ' . preg_replace ("/[ \\x00- \\x08 \\x0b- \\x0c \\x0e- \\x1f]/ " , '' , $ val ) . ']]> ' ;
8584 }
86- list ($ _key , ) = explode (' ' , $ key . ' ' );
85+ list ($ _key ,) = explode (' ' , $ key . ' ' );
8786 $ content .= "</ $ _key> " ;
8887 }
8988 return $ content ;
@@ -94,16 +93,26 @@ function _data_to_xml($data, $item = 'item', $id = 'id', $content = '') {
9493
9594 /**
9695 * 将xml转为array
97- * @param type $xml
98- * @return type
96+ * @param string $xml
97+ * @return array
9998 */
10099 static public function xml2arr ($ xml ) {
101100 return json_decode (Tools::json_encode (simplexml_load_string ($ xml , 'SimpleXMLElement ' , LIBXML_NOCDATA )), true );
102101 }
103102
104103 /**
105- * GET 请求
106- * @param string $url
104+ * 生成安全JSON数据
105+ * @param $array
106+ * @return string
107+ */
108+ static public function json_encode ($ array ) {
109+ return preg_replace_callback ('/ \\\\u([0-9a-f]{4})/i ' , create_function ('$matches ' , 'return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE"); ' ), json_encode ($ array ));
110+ }
111+
112+ /**
113+ * 以get方式提交请求
114+ * @param $url
115+ * @return bool|mixed
107116 */
108117 static public function httpGet ($ url ) {
109118 $ oCurl = curl_init ();
@@ -125,10 +134,10 @@ static public function httpGet($url) {
125134 }
126135
127136 /**
128- * 以post方式提交xml到对应的接口url
129- * @param type $url
130- * @param type $postdata
131- * @return boolean
137+ * 以post方式提交请求
138+ * @param string $url
139+ * @param array $postdata
140+ * @return bool|mixed
132141 */
133142 static public function httpPost ($ url , $ postdata ) {
134143 $ ch = curl_init ();
@@ -156,12 +165,12 @@ static public function httpPost($url, $postdata) {
156165
157166 /**
158167 * 使用证书,以post方式提交xml到对应的接口url
159- * @param type $url POST提交的内容
160- * @param type $postdata 请求的地址
161- * @param type $ssl_cer 证书Cer路径 | 证书内容
162- * @param type $ssl_key 证书Key路径 | 证书内容
163- * @param type $second 设置请求超时时间
164- * @return boolean
168+ * @param string $url POST提交的内容
169+ * @param array $postdata 请求的地址
170+ * @param string $ssl_cer 证书Cer路径 | 证书内容
171+ * @param string $ssl_key 证书Key路径 | 证书内容
172+ * @param int $second 设置请求超时时间
173+ * @return bool|mixed
165174 */
166175 static public function httpsPost ($ url , $ postdata , $ ssl_cer = null , $ ssl_key = null , $ second = 30 ) {
167176 $ ch = curl_init ();
@@ -200,17 +209,8 @@ static public function httpsPost($url, $postdata, $ssl_cer = null, $ssl_key = nu
200209 }
201210
202211 /**
203- * 生成JSON,保留汉字
204- * @param type $array
205- * @return type
206- */
207- static public function json_encode ($ array ) {
208- return preg_replace_callback ('/ \\\\u([0-9a-f]{4})/i ' , create_function ('$matches ' , 'return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE"); ' ), json_encode ($ array ));
209- }
210-
211- /**
212- * 读取客户端IP
213- * @return type
212+ * 读取微信客户端IP
213+ * @return null|string
214214 */
215215 static public function getAddress () {
216216 foreach (array ('HTTP_X_FORWARDED_FOR ' , 'HTTP_CLIENT_IP ' , 'HTTP_X_CLIENT_IP ' , 'HTTP_X_CLUSTER_CLIENT_IP ' , 'REMOTE_ADDR ' ) as $ header ) {
@@ -232,7 +232,7 @@ static public function getAddress() {
232232 * @param string $cachename
233233 * @param mixed $value
234234 * @param int $expired
235- * @return boolean
235+ * @return bool
236236 */
237237 static public function setCache ($ cachename , $ value , $ expired = 0 ) {
238238 return Cache::set ($ cachename , $ value , $ expired );
@@ -250,16 +250,16 @@ static public function getCache($cachename) {
250250 /**
251251 * 清除缓存,按需重载
252252 * @param string $cachename
253- * @return boolean
253+ * @return bool
254254 */
255255 static public function removeCache ($ cachename ) {
256256 return Cache::del ($ cachename );
257257 }
258258
259259 /**
260260 * SDK日志处理方法
261- * @param type $msg
262- * @param type $type
261+ * @param string $msg 日志行内容
262+ * @param string $type 日志级别
263263 */
264264 static public function log ($ msg , $ type = 'MSG ' ) {
265265 Cache::put ($ type . ' - ' . $ msg );
0 commit comments