Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修正无参数时url末尾依然添加问号导致部分API调用错误问题 #12

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{
"name": "weixin/weixin",
"name": "HessianZ/Weixin",
"type": "library",
"description": "A simple PHP client library for weixin",
"keywords": ["weixin"],
"homepage": "http://github.com/handsomegyr/weixin",
"keywords": ["weixin", "wechat", "sdk"],
"homepage": "http://github.com/HessianZ/weixin",
"license": "MIT",
"authors": [
{
"name": "guoyongrong",
"email": "[email protected]",
"homepage": "http://www.cnblogs.com/guoyongrong/"
},
{
"name": "Hessian",
"email": "[email protected]",
"homepage": "http://hessian.cn"
}
],
"require": {
Expand Down
139 changes: 70 additions & 69 deletions lib/Weixin/MsgManager/ReplyMsg/WeixinReplyMsgSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class WeixinReplyMsgSender
{

protected $weixinMsgManager;
protected $_length = 0;

/**
*
Expand All @@ -48,13 +49,13 @@ public function __construct(WeixinMsgManager $weixinMsgManager, $options = array
public function replyText($toUser, $fromUser, $content)
{
$time = time();
return "
<xml>
<ToUserName><![CDATA[{$toUser}]]></ToUserName>
<FromUserName><![CDATA[{$fromUser}]]></FromUserName>
<CreateTime>{$time}</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[{$content}]]></Content>
return "
<xml>
<ToUserName><![CDATA[{$toUser}]]></ToUserName>
<FromUserName><![CDATA[{$fromUser}]]></FromUserName>
<CreateTime>{$time}</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[{$content}]]></Content>
</xml>";
}

Expand All @@ -69,15 +70,15 @@ public function replyText($toUser, $fromUser, $content)
public function replyImage($toUser, $fromUser, $media_id)
{
$time = time();
return "
<xml>
<ToUserName><![CDATA[{$toUser}]]></ToUserName>
<FromUserName><![CDATA[{$fromUser}]]></FromUserName>
<CreateTime>{$time}</CreateTime>
<MsgType><![CDATA[image]]></MsgType>
<Image>
<MediaId><![CDATA[{$media_id}]]></MediaId>
</Image>
return "
<xml>
<ToUserName><![CDATA[{$toUser}]]></ToUserName>
<FromUserName><![CDATA[{$fromUser}]]></FromUserName>
<CreateTime>{$time}</CreateTime>
<MsgType><![CDATA[image]]></MsgType>
<Image>
<MediaId><![CDATA[{$media_id}]]></MediaId>
</Image>
</xml>";
}

Expand All @@ -92,15 +93,15 @@ public function replyImage($toUser, $fromUser, $media_id)
public function replyVoice($toUser, $fromUser, $media_id)
{
$time = time();
return "
<xml>
<ToUserName><![CDATA[{$toUser}]]></ToUserName>
<FromUserName><![CDATA[{$fromUser}]]></FromUserName>
<CreateTime>{$time}</CreateTime>
<MsgType><![CDATA[voice]]></MsgType>
<Voice>
<MediaId><![CDATA[{$media_id}]]></MediaId>
</Voice>
return "
<xml>
<ToUserName><![CDATA[{$toUser}]]></ToUserName>
<FromUserName><![CDATA[{$fromUser}]]></FromUserName>
<CreateTime>{$time}</CreateTime>
<MsgType><![CDATA[voice]]></MsgType>
<Voice>
<MediaId><![CDATA[{$media_id}]]></MediaId>
</Voice>
</xml>";
}

Expand All @@ -116,16 +117,16 @@ public function replyVoice($toUser, $fromUser, $media_id)
public function replyVideo($toUser, $fromUser, $media_id, $thumb_media_id)
{
$time = time();
return "
<xml>
<ToUserName><![CDATA[{$toUser}]]></ToUserName>
<FromUserName><![CDATA[{$fromUser}]]></FromUserName>
<CreateTime>{$time}</CreateTime>
<MsgType><![CDATA[video]]></MsgType>
<Video>
<MediaId><![CDATA[{$media_id}]]></MediaId>
<ThumbMediaId><![CDATA[{$thumb_media_id}]]></ThumbMediaId>
</Video>
return "
<xml>
<ToUserName><![CDATA[{$toUser}]]></ToUserName>
<FromUserName><![CDATA[{$fromUser}]]></FromUserName>
<CreateTime>{$time}</CreateTime>
<MsgType><![CDATA[video]]></MsgType>
<Video>
<MediaId><![CDATA[{$media_id}]]></MediaId>
<ThumbMediaId><![CDATA[{$thumb_media_id}]]></ThumbMediaId>
</Video>
</xml>";
}

Expand All @@ -146,19 +147,19 @@ public function replyMusic($toUser, $fromUser, $title, $description, $musicUrl,
$time = time();
$hqMusicUrl = $hqMusicUrl == '' ? $musicUrl : $hqMusicUrl;
$thumbMediaIdXml = empty($thumbMediaId) ? "" : "<ThumbMediaId><![CDATA[{$thumbMediaId}]]></ThumbMediaId>";
return "
<xml>
<ToUserName><![CDATA[{$toUser}]]></ToUserName>
<FromUserName><![CDATA[{$fromUser}]]></FromUserName>
<CreateTime>{$time}</CreateTime>
<MsgType><![CDATA[music]]></MsgType>
<Music>
<Title><![CDATA[{$title}]]></Title>
<Description><![CDATA[{$description}]]></Description>
<MusicUrl><![CDATA[{$musicUrl}]]></MusicUrl>
<HQMusicUrl><![CDATA[{$hqMusicUrl}]]></HQMusicUrl>
{$thumbMediaIdXml}
</Music>
return "
<xml>
<ToUserName><![CDATA[{$toUser}]]></ToUserName>
<FromUserName><![CDATA[{$fromUser}]]></FromUserName>
<CreateTime>{$time}</CreateTime>
<MsgType><![CDATA[music]]></MsgType>
<Music>
<Title><![CDATA[{$title}]]></Title>
<Description><![CDATA[{$description}]]></Description>
<MusicUrl><![CDATA[{$musicUrl}]]></MusicUrl>
<HQMusicUrl><![CDATA[{$hqMusicUrl}]]></HQMusicUrl>
{$thumbMediaIdXml}
</Music>
</xml>";
}

Expand Down Expand Up @@ -190,22 +191,22 @@ public function replyGraphText($toUser, $fromUser, Array $articles)
if (mb_strlen($article['description'], 'utf-8') > $this->_length) {
$article['description'] = mb_substr($article['description'], 0, $this->WeixinMsgManager->getLength(), 'utf-8') . '……';
}
$items .= "
<item>
<Title><![CDATA[{$article['title']}]]></Title>
<Description><![CDATA[{$article['description']}]]></Description>
<PicUrl><![CDATA[{$article['picurl']}]]></PicUrl>
<Url><![CDATA[{$article['url']}]]></Url>
$items .= "
<item>
<Title><![CDATA[{$article['title']}]]></Title>
<Description><![CDATA[{$article['description']}]]></Description>
<PicUrl><![CDATA[{$article['picurl']}]]></PicUrl>
<Url><![CDATA[{$article['url']}]]></Url>
</item>";
}
return "
<xml>
<ToUserName><![CDATA[{$toUser}]]></ToUserName>
<FromUserName><![CDATA[{$fromUser}]]></FromUserName>
<CreateTime>{$time}</CreateTime>
<MsgType><![CDATA[news]]></MsgType>
<ArticleCount>{$articleCount}</ArticleCount>
<Articles>{$items}</Articles>
return "
<xml>
<ToUserName><![CDATA[{$toUser}]]></ToUserName>
<FromUserName><![CDATA[{$fromUser}]]></FromUserName>
<CreateTime>{$time}</CreateTime>
<MsgType><![CDATA[news]]></MsgType>
<ArticleCount>{$articleCount}</ArticleCount>
<Articles>{$items}</Articles>
</xml>";
}

Expand All @@ -218,12 +219,12 @@ public function replyCustomerService($KfAccount = NULL)
{
$time = time();
if (empty($KfAccount)) {
return "
<xml>
<ToUserName><![CDATA[{$this->_to}]]></ToUserName>
<FromUserName><![CDATA[{$this->_from}]]></FromUserName>
<CreateTime>{$time}</CreateTime>
<MsgType><![CDATA[transfer_customer_service]]></MsgType>
return "
<xml>
<ToUserName><![CDATA[{$this->_to}]]></ToUserName>
<FromUserName><![CDATA[{$this->_from}]]></FromUserName>
<CreateTime>{$time}</CreateTime>
<MsgType><![CDATA[transfer_customer_service]]></MsgType>
</xml>";
} else {
return "
Expand All @@ -238,4 +239,4 @@ public function replyCustomerService($KfAccount = NULL)
</xml>";
}
}
}
}
11 changes: 7 additions & 4 deletions lib/Weixin/QrcodeManager/WeixinQrcodeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function create($scene_id, $isTemporary = true, $expire_seconds = 0)
{
$params = array();
if ($isTemporary) {
$params['expire_seconds'] = min($expire_seconds, 1800);
$params['expire_seconds'] = $expire_seconds;
$params['action_name'] = "QR_SCENE";
$params['action_info']['scene']['scene_id'] = $scene_id;
} else {
Expand All @@ -98,8 +98,11 @@ public function create($scene_id, $isTemporary = true, $expire_seconds = 0)
throw new WeixinException($rst['errmsg'], $rst['errcode']);
} else {
// 返回说明
//ticket 获取的二维码ticket,凭借此ticket可以在有效时间内换取二维码。
//expire_seconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天)。
//url 二维码图片解析后的地址,开发者可根据该地址自行生成需要的二维码图片
// 正确的Json返回结果:
// {"ticket":"gQG28DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL0FuWC1DNmZuVEhvMVp4NDNMRnNRAAIEesLvUQMECAcAAA==","expire_seconds":1800}
// {"ticket":"gQH47joAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL2taZ2Z3TVRtNzJXV1Brb3ZhYmJJAAIEZ23sUwMEmm3sUw==","expire_seconds":60,"url":"http:\/\/weixin.qq.com\/q\/kZgfwMTm72WWPkovabbI"}
return $rst;
}
}
Expand All @@ -115,6 +118,6 @@ public function getQrcodeUrl($ticket)
// https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET
// 返回说明
// ticket正确情况下,http 返回码是200,是一张图片,可以直接展示或者下载。
return "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket={$ticket}";
return "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . urlencode($ticket);
}
}
}
8 changes: 5 additions & 3 deletions lib/Weixin/WeixinOAuthRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ protected function oAuthRequest($url, $method, $parameters, $multi = false)
{
switch ($method) {
case 'GET':
$url = $url . '?' . http_build_query($parameters);
if ($parameters) {
$url .= '?' . http_build_query($parameters);
}
return $this->http($url, 'GET');
default:
$headers = array();
Expand Down Expand Up @@ -291,7 +293,7 @@ protected function http($url, $method, $postfields = NULL, $headers = array())
}
// if (isset($this->access_token) && $this->access_token)
// $headers[] = "Authorization: OAuth2 " . $this->access_token;
$headers[] = "API-RemoteIP: " . $_SERVER['REMOTE_ADDR'];
$headers[] = "API-RemoteIP: " . filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_SANITIZE_STRING);
curl_setopt($ci, CURLOPT_URL, $url);
curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE);
Expand Down Expand Up @@ -371,4 +373,4 @@ public function delete($url, $parameters = array())
}
return $response;
}
}
}