Skip to content

Commit

Permalink
[更新]php版本语法兼容调整
Browse files Browse the repository at this point in the history
  • Loading branch information
zoujingli committed May 25, 2018
1 parent baf0ec2 commit ccd6533
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
13 changes: 6 additions & 7 deletions Wechat/Lib/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static public function getSignature($data, $method = "sha1")
return false;
}
ksort($data);
$params = [];
$params = array();
foreach ($data as $key => $value) {
$params[] = "{$key}={$value}";
}
Expand Down Expand Up @@ -124,13 +124,12 @@ static private function _data_to_xml($data, $item = 'item', $id = 'id', $content
} else {
$content .= '<![CDATA[' . preg_replace("/[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]/", '', $val) . ']]>';
}
list($_key,) = explode(' ', $key . ' ');
list($_key, ) = explode(' ', $key . ' ');
$content .= "</$_key>";
}
return $content;
}


/**
* 将xml转为array
* @param string $xml
Expand Down Expand Up @@ -167,7 +166,7 @@ static public function httpGet($url)
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
list($content, $status) = [curl_exec($curl), curl_getinfo($curl), curl_close($curl)];
list($content, $status) = array(curl_exec($curl), curl_getinfo($curl), curl_close($curl));
return (intval($status["http_code"]) === 200) ? $content : false;
}

Expand All @@ -187,7 +186,7 @@ static public function httpPost($url, $data)
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, self::_buildPost($data));
list($content, $status) = [curl_exec($curl), curl_getinfo($curl), curl_close($curl)];
list($content, $status) = array(curl_exec($curl), curl_getinfo($curl), curl_close($curl));
return (intval($status["http_code"]) === 200) ? $content : false;
}

Expand Down Expand Up @@ -219,7 +218,7 @@ static public function httpsPost($url, $data, $ssl_cer = null, $ssl_key = null,
}
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, self::_buildPost($data));
list($content, $status) = [curl_exec($curl), curl_getinfo($curl), curl_close($curl)];
list($content, $status) = array(curl_exec($curl), curl_getinfo($curl), curl_close($curl));
return (intval($status["http_code"]) === 200) ? $content : false;
}

Expand Down Expand Up @@ -247,7 +246,7 @@ static private function _buildPost(&$data)
*/
static public function getAddress()
{
foreach (['HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_X_CLIENT_IP', 'HTTP_X_CLUSTER_CLIENT_IP', 'REMOTE_ADDR'] as $header) {
foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_X_CLIENT_IP', 'HTTP_X_CLUSTER_CLIENT_IP', 'REMOTE_ADDR') as $header) {
if (!isset($_SERVER[$header]) || ($spoof = $_SERVER[$header]) === null) {
continue;
}
Expand Down
11 changes: 6 additions & 5 deletions Wechat/WechatMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
class WechatMedia extends Common
{

const MEDIA_UPLOAD_URL = '/media/upload?';
const MEDIA_UPLOADIMG_URL = '/media/uploadimg?';
const MEDIA_GET_URL = '/media/get?';
Expand Down Expand Up @@ -120,7 +121,7 @@ public function getMediaWithHttpInfo($media_id, $is_video = false)
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
$sContent = curl_exec($oCurl);
$aStatus = curl_getinfo($oCurl);
$result = [];
$result = array();
if (intval($aStatus["http_code"]) !== 200) {
return false;
}
Expand Down Expand Up @@ -181,7 +182,7 @@ public function uploadImg($data)
* @param array $video_info 视频信息数组,非视频素材不需要提供 array('title'=>'视频标题','introduction'=>'描述')
* @return bool|array
*/
public function uploadForeverMedia($data, $type, $is_video = false, $video_info = [])
public function uploadForeverMedia($data, $type, $is_video = false, $video_info = array())
{
if (!$this->access_token && !$this->getAccessToken()) {
return false;
Expand Down Expand Up @@ -269,7 +270,7 @@ public function getForeverMedia($media_id, $is_video = false)
if (!$this->access_token && !$this->getAccessToken()) {
return false;
}
$data = ['media_id' => $media_id];
$data = array('media_id' => $media_id);
$result = Tools::httpPost(self::API_URL_PREFIX . self::MEDIA_FOREVER_GET_URL . "access_token={$this->access_token}", Tools::json_encode($data));
if ($result) {
if (is_string($result) && ($json = json_decode($result, true))) {
Expand All @@ -295,7 +296,7 @@ public function delForeverMedia($media_id)
if (!$this->access_token && !$this->getAccessToken()) {
return false;
}
$data = ['media_id' => $media_id];
$data = array('media_id' => $media_id);
$result = Tools::httpPost(self::API_URL_PREFIX . self::MEDIA_FOREVER_DEL_URL . "access_token={$this->access_token}", Tools::json_encode($data));
if ($result) {
$json = json_decode($result, true);
Expand Down Expand Up @@ -327,7 +328,7 @@ public function getForeverList($type, $offset, $count)
if (!$this->access_token && !$this->getAccessToken()) {
return false;
}
$data = ['type' => $type, 'offset' => $offset, 'count' => $count,];
$data = array('type' => $type, 'offset' => $offset, 'count' => $count);
$result = Tools::httpPost(self::API_URL_PREFIX . self::MEDIA_FOREVER_BATCHGET_URL . "access_token={$this->access_token}", Tools::json_encode($data));
if ($result) {
$json = json_decode($result, true);
Expand Down

0 comments on commit ccd6533

Please sign in to comment.