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

微信开放平台帐号管理 #817

Merged
merged 6 commits into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
95 changes: 95 additions & 0 deletions src/OpenPlatform/Account/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace EasyWeChat\OpenPlatform\Base;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

命名空间 Base?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


use EasyWeChat\Kernel\BaseClient;

/**
* Class Client.
*
* @author Scholer <[email protected]>
*/
class Client extends BaseClient
{
/**
* @var string
*/
protected $baseUri = 'https://api.weixin.qq.com/cgi-bin/open/';

/**
* 创建开放平台帐号并绑定公众号/小程序.
*
* @param string $appId 授权公众号或小程序的appid
*
* @return mixed
*/
public function createAccount(string $appId)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok,我先测试一下逻辑再一起提交

{
$params = [
'appid' => $appId,
];

return $this->httpPostJson('create', $params);
}

/**
* 将公众号/小程序绑定到开放平台帐号下.
*
* @param string $appId 授权公众号或小程序的appid
* @param string $openAppId 开放平台帐号appid
*
* @return mixed
*/
public function bind(string $appId, string $openAppId)
{
$params = [
'appid' => $appId,
'open_appid' => $openAppId,
];

return $this->httpPostJson('bind', $params);
}

/**
* 将公众号/小程序从开放平台帐号下解绑.
*
* @param string $appId 授权公众号或小程序的appid
* @param string $openAppId 开放平台帐号appid
*
* @return mixed
*/
public function unbind(string $appId, string $openAppId)
{
$params = [
'appid' => $appId,
'open_appid' => $openAppId,
];

return $this->httpPostJson('unbind', $params);
}

/**
* 获取公众号/小程序所绑定的开放平台帐号.
*
* @param string $appId 授权公众号或小程序的appid
*
* @return mixed
*/
public function getBinding(string $appId)
{
$params = [
'appid' => $appId,
];

return $this->httpPostJson('get', $params);
}
}
37 changes: 37 additions & 0 deletions src/OpenPlatform/Account/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace EasyWeChat\OpenPlatform\Account;

use EasyWeChat\OpenPlatform\Auth\AuthorizerAccessToken;
use Pimple\Container;
use Pimple\ServiceProviderInterface;

/**
* Class ServiceProvider.
*
* @author Scholer <[email protected]>
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* {@inheritdoc}.
*/
public function register(Container $app)
{
$accessToken = new AuthorizerAccessToken($app);
$accessToken->setOpenPlatformAccessToken($app['access_token']);

$app['account'] = function ($app) use ($accessToken) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里应该不用 new AuthorizerAccessToken ?这个是授权方的 AccessToken
直接这样就可以了:

$app['account'] = function ($app) {
    return new Client($app);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个也是我比较困惑的地方,这些接口是通过C端的token调用的,而api_query_auth这些B端接口是通过component_access_token调用的。似乎应该是 AuthorizerAccessToken?还是我理解有偏差?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个接口请求需要的 access_token 用的是授权方的 access_token ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,类似的还有代替第三方实现的小程序的一些独有接口

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return new Client($app, $accessToken);
};
}
}