add miniprogram
This commit is contained in:
parent
aed1af638c
commit
d49cfce08c
|
@ -3,37 +3,42 @@
|
||||||
namespace Wechat\ServiceProvider;
|
namespace Wechat\ServiceProvider;
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Wechat\Work\Miniprogram;
|
||||||
|
|
||||||
class WechatServiceProvider extends ServiceProvider
|
class WechatServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
|
||||||
public function setupConfig()
|
public function boot()
|
||||||
{
|
{
|
||||||
$source = realpath(__DIR__ . '/../../config/wx.php');
|
|
||||||
|
|
||||||
if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
|
|
||||||
$this->publishes([$source => config_path('wx.php')], 'wx');
|
|
||||||
} elseif ($this->app instanceof LumenApplication) {
|
|
||||||
$this->app->configure('wx');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->mergeConfigFrom($source, 'rpc');
|
protected function setupConfig()
|
||||||
|
{
|
||||||
|
$source = realpath(dirname(__DIR__) . '/../../config/wx.php');
|
||||||
|
|
||||||
|
// if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
|
||||||
|
// $this->publishes([$source => config_path('wx.php')], 'wx');
|
||||||
|
// } elseif ($this->app instanceof LumenApplication) {
|
||||||
|
$this->app->configure('wx');
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
$this->mergeConfigFrom($source, 'wx');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
$config = config['wx'];
|
$this->setupConfig();
|
||||||
|
$config = config('wx');
|
||||||
if (isset($config['work'])) {
|
if (isset($config['work'])) {
|
||||||
|
|
||||||
foreach ($config['work']['secrets'] as $key => $item) {
|
foreach ($config['work']['secrets'] as $key => $item) {
|
||||||
$this->app->singleton('wx.work.' . $key, function () {
|
$this->app->singleton('wx.work.' . $key, function () use ($key) {
|
||||||
return new ucwords($key);
|
$class = ucwords($key);
|
||||||
|
return new $class ;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,7 +24,13 @@ class Base
|
||||||
{
|
{
|
||||||
$uri = new Uri($uri);
|
$uri = new Uri($uri);
|
||||||
$uri = Uri::withQueryValue($uri, 'access_token', $this->getAccessToken());
|
$uri = Uri::withQueryValue($uri, 'access_token', $this->getAccessToken());
|
||||||
$request = new Request($method, $uri, [], \GuzzleHttp\json_encode($params));
|
if (!empty($params)) {
|
||||||
|
$body = \GuzzleHttp\json_encode($params);
|
||||||
|
} else {
|
||||||
|
$body = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$request = new Request($method, $uri, [], $body);
|
||||||
return $request;
|
return $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
src/Wechat/Work/Miniprogram.php
Normal file
18
src/Wechat/Work/Miniprogram.php
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Wechat\Work;
|
||||||
|
|
||||||
|
|
||||||
|
class Miniprogram extends Base
|
||||||
|
{
|
||||||
|
protected $app = 'miniprogram';
|
||||||
|
|
||||||
|
public function code2Session($type = 'authorization_code')
|
||||||
|
{
|
||||||
|
$url = "https://qyapi.weixin.qq.com/cgi-bin/miniprogram/jscode2session?js_code=$code&grant_type=$type");
|
||||||
|
$request = $this->client->transformForJsonRequest($url);
|
||||||
|
$resp = $this->client->send($request);
|
||||||
|
return json_decode($resp->getBody(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user