-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from XueSiLf/2.x
fix(OpenPlatform):privacy inteface api
- Loading branch information
Showing
11 changed files
with
264 additions
and
51 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/OpenPlatform/Authorizer/MiniProgram/PrivacyInterface/Client.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace EasySwoole\WeChat\OpenPlatform\Authorizer\MiniProgram\PrivacyInterface; | ||
|
||
use EasySwoole\WeChat\Kernel\ServiceProviders; | ||
use EasySwoole\WeChat\OpenPlatform\BaseClient; | ||
|
||
class Client extends BaseClient | ||
{ | ||
/** | ||
* 代小程序实现业务 - 申请隐私接口 - 获取接口列表 | ||
* doc link: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/apply_api/get_privacy_interface.html | ||
* | ||
* @return bool | ||
* @throws \EasySwoole\WeChat\Kernel\Exceptions\HttpException | ||
*/ | ||
public function get() | ||
{ | ||
$response = $this->getClient() | ||
->setMethod("GET") | ||
->send($this->buildUrl( | ||
"/wxa/security/get_privacy_interface", | ||
['access_token' => $this->app[ServiceProviders::AccessToken]->getToken()] | ||
)); | ||
|
||
$this->checkResponse($response, $jsonData); | ||
|
||
return $jsonData; | ||
} | ||
|
||
/** | ||
* 代小程序实现业务 - 申请隐私接口 - 申请接口 | ||
* doc link: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/apply_api/apply_privacy_interface.html | ||
* | ||
* @param array $params | ||
* | ||
* @return bool | ||
* @throws \EasySwoole\WeChat\Kernel\Exceptions\HttpException | ||
*/ | ||
public function apply(array $params) | ||
{ | ||
$response = $this->getClient() | ||
->setMethod("POST") | ||
->setHeaders(['content-type' => 'application/json']) | ||
->setBody($this->jsonDataToStream($params)) | ||
->send($this->buildUrl( | ||
"/wxa/security/apply_privacy_interface", | ||
['access_token' => $this->app[ServiceProviders::AccessToken]->getToken()] | ||
)); | ||
|
||
$this->checkResponse($response, $jsonData); | ||
|
||
return $jsonData; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/OpenPlatform/Authorizer/MiniProgram/PrivacyInterface/ServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace EasySwoole\WeChat\OpenPlatform\Authorizer\MiniProgram\PrivacyInterface; | ||
|
||
use EasySwoole\WeChat\OpenPlatform\Authorizer\MiniProgram\Application; | ||
use Pimple\Container; | ||
use Pimple\ServiceProviderInterface; | ||
|
||
class ServiceProvider implements ServiceProviderInterface | ||
{ | ||
public function register(Container $app) | ||
{ | ||
$app[Application::PrivacyInterface] = function ($app) { | ||
return new Client($app); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
tests/OpenPlatform/Authorizer/MiniProgram/PrivacyInterface/ClientTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* Author: hlh XueSi | ||
* Email: [email protected] | ||
* Date: 2022/5/18 9:28:04 | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EasySwoole\WeChat\Tests\OpenPlatform\Authorizer\MiniProgram\PrivacyInterface; | ||
|
||
use EasySwoole\WeChat\Kernel\BaseClient; | ||
use EasySwoole\WeChat\Kernel\ServiceContainer; | ||
use EasySwoole\WeChat\OpenPlatform\Application; | ||
use EasySwoole\WeChat\OpenPlatform\Authorizer\MiniProgram\PrivacyInterface\Client; | ||
use EasySwoole\WeChat\Tests\Mock\Message\Status; | ||
use EasySwoole\WeChat\Tests\TestCase; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
|
||
class ClientTest extends TestCase | ||
{ | ||
public function testGet() | ||
{ | ||
$response = $this->buildResponse(Status::CODE_OK, $this->readMockResponseJson('get.json')); | ||
|
||
/** @var Application $component */ | ||
$component = $this->mockAccessToken(new Application([ | ||
'appId' => 'COMPONENT_APPID', | ||
'token' => 'COMPONENT_TOKEN' | ||
])); | ||
|
||
$miniProgram = $component->miniProgram( | ||
'mock_app_id', 'mock_refresh_token' | ||
); | ||
$miniProgram = $this->mockAccessToken($miniProgram); | ||
|
||
$miniProgram = $this->mockHttpClient(function (ServerRequestInterface $request) { | ||
$this->assertEquals('GET', $request->getMethod()); | ||
$this->assertEquals('/wxa/security/get_privacy_interface', $request->getUri()->getPath()); | ||
$this->assertEquals('access_token=mock_access_token', $request->getUri()->getQuery()); | ||
}, $response, $miniProgram); | ||
|
||
$client = new Client($miniProgram); | ||
|
||
$ret = $client->get(); | ||
|
||
$this->assertIsArray($ret); | ||
$this->assertSame(json_decode($this->readMockResponseJson('get.json'), true), $ret); | ||
} | ||
|
||
public function testApply() | ||
{ | ||
$response = $this->buildResponse(Status::CODE_OK, $this->readMockResponseJson('apply.json')); | ||
|
||
/** @var Application $component */ | ||
$component = $this->mockAccessToken(new Application([ | ||
'appId' => 'COMPONENT_APPID', | ||
'token' => 'COMPONENT_TOKEN' | ||
])); | ||
|
||
$miniProgram = $component->miniProgram( | ||
'mock_app_id', 'mock_refresh_token' | ||
); | ||
$miniProgram = $this->mockAccessToken($miniProgram); | ||
|
||
$miniProgram = $this->mockHttpClient(function (ServerRequestInterface $request) { | ||
$this->assertEquals('POST', $request->getMethod()); | ||
$this->assertEquals('/wxa/security/apply_privacy_interface', $request->getUri()->getPath()); | ||
$this->assertEquals('access_token=mock_access_token', $request->getUri()->getQuery()); | ||
}, $response, $miniProgram); | ||
|
||
$client = new Client($miniProgram); | ||
|
||
$params = [ | ||
"api_name" => "wx.test", | ||
"content" => "1312", | ||
"pic_list" => [ | ||
"pic_url1", | ||
"pic_url2" | ||
], | ||
"video_list" => ["video_url1", "video_ul2"], | ||
"url_list" => ["url1", "url2"] | ||
]; | ||
|
||
$ret = $client->apply($params); | ||
|
||
$this->assertIsArray($ret); | ||
$this->assertSame(json_decode($this->readMockResponseJson('apply.json'), true), $ret); | ||
} | ||
|
||
protected function readMockResponseJson(string $filename): string | ||
{ | ||
return file_get_contents(__DIR__ . '/mock_data/' . $filename); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/OpenPlatform/Authorizer/MiniProgram/PrivacyInterface/mock_data/apply.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"errcode": 0, | ||
"errmsg": "getuserriskrank succ", | ||
"audit_id": 123456 | ||
} |
48 changes: 48 additions & 0 deletions
48
tests/OpenPlatform/Authorizer/MiniProgram/PrivacyInterface/mock_data/get.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"errcode": 0, | ||
"errmsg": "ok", | ||
"interface_list": [ | ||
{ | ||
"api_name": "wx.chooseAddress", | ||
"api_ch_name": "获取用户收货地址", | ||
"api_desc": "调起用户编辑收货地址原生界面,并在编辑完成后返回用户选择的地址。", | ||
"status": 1, | ||
"api_link": "https://developers.weixin.qq.com/miniprogram/dev/api/open-api/address/wx.chooseAddress.html", | ||
"group_name": "地理位置" | ||
}, | ||
{ | ||
"api_name": "wx.choosePoi", | ||
"api_ch_name": "选择位置,支持模糊定位(精确到市)和精确定位混选", | ||
"api_desc": "选择位置,支持模糊定位和精确定位混选", | ||
"status": 4, | ||
"audit_id": 421610267, | ||
"fail_reason": "小程序内未含有相应使用场景", | ||
"api_link": "https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.choosePoi.html", | ||
"group_name": "地理位置" | ||
}, | ||
{ | ||
"api_name": "wx.getLocation", | ||
"api_ch_name": "获取当前的地理位置、速度 ", | ||
"api_desc": "获取当前的地理位置、速度。当用户离开小程序后,此接口无法调用。 ", | ||
"status": 1, | ||
"api_link": "https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.getLocation.html ", | ||
"group_name": "地理位置" | ||
}, | ||
{ | ||
"api_name": "wx.onLocationChange", | ||
"api_ch_name": "监听实时地理位置变化事件", | ||
"api_desc": "监听实时地理位置变化事件。当用户离开小程序后,此接口无法调用。", | ||
"status": 1, | ||
"api_link": "https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.onLocationChange.html", | ||
"group_name": "地理位置" | ||
}, | ||
{ | ||
"api_name": "wx.chooseLocation", | ||
"api_ch_name": "打开地图选择位置", | ||
"api_desc": "打开地图选择位置。", | ||
"status": 1, | ||
"api_link": "https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.chooseLocation.html", | ||
"group_name": "地理位置" | ||
} | ||
] | ||
} |
Oops, something went wrong.