微调
This commit is contained in:
34
vendor/cjango/wechat/src/Wechat/Utils.php
vendored
34
vendor/cjango/wechat/src/Wechat/Utils.php
vendored
@@ -17,6 +17,7 @@ class Utils
|
||||
{
|
||||
/**
|
||||
* 错误信息
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $errMsg = [
|
||||
@@ -189,6 +190,7 @@ class Utils
|
||||
|
||||
/**
|
||||
* 返回数据结果集
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public static $result;
|
||||
@@ -201,10 +203,11 @@ class Utils
|
||||
|
||||
/**
|
||||
* 发送HTTP请求方法,目前只支持CURL发送请求
|
||||
* @param string $url 请求URL
|
||||
* @param array $params 请求参数
|
||||
* @param string $method 请求方法GET/POST
|
||||
* @param boolean $ssl 是否进行SSL双向认证
|
||||
*
|
||||
* @param string $url 请求URL
|
||||
* @param array $params 请求参数
|
||||
* @param string $method 请求方法GET/POST
|
||||
* @param boolean $ssl 是否进行SSL双向认证
|
||||
* @return array $data 响应数据
|
||||
*/
|
||||
public static function http($url, $params = [], $method = 'GET', $ssl = false)
|
||||
@@ -218,8 +221,8 @@ class Utils
|
||||
/* 根据请求类型设置特定参数 */
|
||||
switch (strtoupper($method)) {
|
||||
case 'GET':
|
||||
$getQuerys = !empty($params) ? '?' . urldecode(http_build_query($params)) : '';
|
||||
$opts[CURLOPT_URL] = $url . $getQuerys;
|
||||
$getQuerys = ! empty($params) ? '?'.urldecode(http_build_query($params)) : '';
|
||||
$opts[CURLOPT_URL] = $url.$getQuerys;
|
||||
break;
|
||||
case 'POST':
|
||||
$opts[CURLOPT_URL] = $url;
|
||||
@@ -235,7 +238,7 @@ class Utils
|
||||
$errmsg = curl_error($ch);
|
||||
curl_close($ch);
|
||||
if ($err > 0) {
|
||||
\cjango\Wechat::error('CURL:' . $errmsg);
|
||||
\cjango\Wechat::error('CURL:'.$errmsg);
|
||||
return false;
|
||||
} else {
|
||||
return $data;
|
||||
@@ -244,7 +247,8 @@ class Utils
|
||||
|
||||
/**
|
||||
* XML文档解析成数组,并将键值转成小写
|
||||
* @param xml $xml
|
||||
*
|
||||
* @param xml $xml
|
||||
* @return array
|
||||
*/
|
||||
public static function xml2array($xml)
|
||||
@@ -255,7 +259,8 @@ class Utils
|
||||
|
||||
/**
|
||||
* 将数组转换成XML
|
||||
* @param array $array
|
||||
*
|
||||
* @param array $array
|
||||
* @return xml
|
||||
*/
|
||||
public static function array2xml($array = [])
|
||||
@@ -267,9 +272,10 @@ class Utils
|
||||
|
||||
/**
|
||||
* 数据XML编码
|
||||
* @param xml $xml XML对象
|
||||
* @param mixed $data 数据
|
||||
* @param string $item 数字索引时的节点名称
|
||||
*
|
||||
* @param xml $xml XML对象
|
||||
* @param mixed $data 数据
|
||||
* @param string $item 数字索引时的节点名称
|
||||
* @return string xml
|
||||
*/
|
||||
private static function _data2xml($xml, $data, $item = 'item')
|
||||
@@ -293,6 +299,7 @@ class Utils
|
||||
|
||||
/**
|
||||
* 解析返回的json数据
|
||||
*
|
||||
* @param [type] $json
|
||||
* @return
|
||||
*/
|
||||
@@ -314,12 +321,13 @@ class Utils
|
||||
|
||||
/**
|
||||
* 解析错误信息
|
||||
*
|
||||
* @param array $result
|
||||
* @return string
|
||||
*/
|
||||
public static function parseError($result)
|
||||
{
|
||||
$code = $result['errcode'];
|
||||
return '[' . $code . '] ' . (isset(self::$errMsg[$code]) ? self::$errMsg[$code] : $result['errmsg']);
|
||||
return '['.$code.'] '.(isset(self::$errMsg[$code]) ? self::$errMsg[$code] : $result['errmsg']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user