diff --git a/composer.json b/composer.json index 8b6f659..0217098 100644 --- a/composer.json +++ b/composer.json @@ -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": "handsomegyr@gmail.com", "homepage": "http://www.cnblogs.com/guoyongrong/" + }, + { + "name": "Hessian", + "email": "hess.4x@gmail.com", + "homepage": "http://hessian.cn" } ], "require": { diff --git a/lib/Weixin/MsgManager/ReplyMsg/WeixinReplyMsgSender.php b/lib/Weixin/MsgManager/ReplyMsg/WeixinReplyMsgSender.php index b52f135..bb7491b 100644 --- a/lib/Weixin/MsgManager/ReplyMsg/WeixinReplyMsgSender.php +++ b/lib/Weixin/MsgManager/ReplyMsg/WeixinReplyMsgSender.php @@ -27,6 +27,7 @@ class WeixinReplyMsgSender { protected $weixinMsgManager; + protected $_length = 0; /** * @@ -48,13 +49,13 @@ public function __construct(WeixinMsgManager $weixinMsgManager, $options = array public function replyText($toUser, $fromUser, $content) { $time = time(); - return " - - - - {$time} - - + return " + + + + {$time} + + "; } @@ -69,15 +70,15 @@ public function replyText($toUser, $fromUser, $content) public function replyImage($toUser, $fromUser, $media_id) { $time = time(); - return " - - - - {$time} - - - - + return " + + + + {$time} + + + + "; } @@ -92,15 +93,15 @@ public function replyImage($toUser, $fromUser, $media_id) public function replyVoice($toUser, $fromUser, $media_id) { $time = time(); - return " - - - - {$time} - - - - + return " + + + + {$time} + + + + "; } @@ -116,16 +117,16 @@ public function replyVoice($toUser, $fromUser, $media_id) public function replyVideo($toUser, $fromUser, $media_id, $thumb_media_id) { $time = time(); - return " - - - - {$time} - - + return " + + + + {$time} + + "; } @@ -146,19 +147,19 @@ public function replyMusic($toUser, $fromUser, $title, $description, $musicUrl, $time = time(); $hqMusicUrl = $hqMusicUrl == '' ? $musicUrl : $hqMusicUrl; $thumbMediaIdXml = empty($thumbMediaId) ? "" : ""; - return " - - - - {$time} - - - <![CDATA[{$title}]]> - - - - {$thumbMediaIdXml} - + return " + + + + {$time} + + + <![CDATA[{$title}]]> + + + + {$thumbMediaIdXml} + "; } @@ -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 .= " - - <![CDATA[{$article['title']}]]> - - - + $items .= " + + <![CDATA[{$article['title']}]]> + + + "; } - return " - - - - {$time} - - {$articleCount} - {$items} + return " + + + + {$time} + + {$articleCount} + {$items} "; } @@ -218,12 +219,12 @@ public function replyCustomerService($KfAccount = NULL) { $time = time(); if (empty($KfAccount)) { - return " - - _to}]]> - _from}]]> - {$time} - + return " + + _to}]]> + _from}]]> + {$time} + "; } else { return " @@ -238,4 +239,4 @@ public function replyCustomerService($KfAccount = NULL) "; } } -} +} diff --git a/lib/Weixin/QrcodeManager/WeixinQrcodeManager.php b/lib/Weixin/QrcodeManager/WeixinQrcodeManager.php index fd45648..1ba35d9 100644 --- a/lib/Weixin/QrcodeManager/WeixinQrcodeManager.php +++ b/lib/Weixin/QrcodeManager/WeixinQrcodeManager.php @@ -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 { @@ -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; } } @@ -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); } -} +} diff --git a/lib/Weixin/WeixinOAuthRequest.php b/lib/Weixin/WeixinOAuthRequest.php index 532c573..588d527 100644 --- a/lib/Weixin/WeixinOAuthRequest.php +++ b/lib/Weixin/WeixinOAuthRequest.php @@ -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(); @@ -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); @@ -371,4 +373,4 @@ public function delete($url, $parameters = array()) } return $response; } -} +}