1、已知bug修复

2、微信接口更新
This commit is contained in:
2017-08-26 17:57:10 +08:00
parent cfcd6250ff
commit 356cccd1d4
25 changed files with 1353 additions and 695 deletions

View File

@@ -1,5 +1,17 @@
<?php
// +----------------------------------------------------------------------
// | wechat-php-sdk
// +----------------------------------------------------------------------
// | 版权所有 2014~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方文档: https://www.kancloud.cn/zoujingli/wechat-php-sdk
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/wechat-php-sdk
// +----------------------------------------------------------------------
namespace Wechat;
use Wechat\Lib\Common;
@@ -8,7 +20,8 @@ use Wechat\Lib\Tools;
/**
* 微信网页授权
*/
class WechatOauth extends Common {
class WechatOauth extends Common
{
const OAUTH_PREFIX = 'https://open.weixin.qq.com/connect/oauth2';
const OAUTH_AUTHORIZE_URL = '/authorize?';
@@ -24,7 +37,8 @@ class WechatOauth extends Common {
* @param string $scope 授权类类型(可选值snsapi_base|snsapi_userinfo)
* @return string
*/
public function getOauthRedirect($callback, $state = '', $scope = 'snsapi_base') {
public function getOauthRedirect($callback, $state = '', $scope = 'snsapi_base')
{
$redirect_uri = urlencode($callback);
return self::OAUTH_PREFIX . self::OAUTH_AUTHORIZE_URL . "appid={$this->appid}&redirect_uri={$redirect_uri}&response_type=code&scope={$scope}&state={$state}#wechat_redirect";
}
@@ -33,7 +47,8 @@ class WechatOauth extends Common {
* 通过 code 获取 AccessToken 和 openid
* @return bool|array
*/
public function getOauthAccessToken() {
public function getOauthAccessToken()
{
$code = isset($_GET['code']) ? $_GET['code'] : '';
if (empty($code)) {
Tools::log("getOauthAccessToken Fail, Because there is no access to the code value in get.");
@@ -58,7 +73,8 @@ class WechatOauth extends Common {
* @param string $refresh_token
* @return bool|array
*/
public function getOauthRefreshToken($refresh_token) {
public function getOauthRefreshToken($refresh_token)
{
$result = Tools::httpGet(self::API_BASE_URL_PREFIX . self::OAUTH_REFRESH_URL . "appid={$this->appid}&grant_type=refresh_token&refresh_token={$refresh_token}");
if ($result) {
$json = json_decode($result, true);
@@ -80,7 +96,8 @@ class WechatOauth extends Common {
* @return bool|array {openid,nickname,sex,province,city,country,headimgurl,privilege,[unionid]}
* 注意unionid字段 只有在用户将公众号绑定到微信开放平台账号后才会出现。建议调用前用isset()检测一下
*/
public function getOauthUserInfo($access_token, $openid) {
public function getOauthUserInfo($access_token, $openid)
{
$result = Tools::httpGet(self::API_BASE_URL_PREFIX . self::OAUTH_USERINFO_URL . "access_token={$access_token}&openid={$openid}");
if ($result) {
$json = json_decode($result, true);
@@ -101,7 +118,8 @@ class WechatOauth extends Common {
* @param string $openid
* @return bool 是否有效
*/
public function getOauthAuth($access_token, $openid) {
public function getOauthAuth($access_token, $openid)
{
$result = Tools::httpGet(self::API_BASE_URL_PREFIX . self::OAUTH_AUTH_URL . "access_token={$access_token}&openid={$openid}");
if ($result) {
$json = json_decode($result, true);