This commit is contained in:
候学杰 2019-02-20 19:18:30 +08:00
parent 2f75f83084
commit 9caf26e7cd
5 changed files with 29 additions and 30 deletions

View File

@ -1,20 +0,0 @@
<?php
namespace Wechat;
class AccessToken
{
protected $token;
public function __construct($app,string $token, $expiresIn)
{
$this->token = $token;
}
public function __toString()
{
return $this->token;
}
}

View File

@ -48,7 +48,7 @@ class Base
return $request; return $request;
} }
public function transformForGetAccessToken($uri, $params) public function transformForGetRequest($uri, $params)
{ {
$uri = new Uri($uri); $uri = new Uri($uri);
foreach ($params as $param) { foreach ($params as $param) {
@ -81,7 +81,7 @@ class Base
return $token; return $token;
} }
$request = $this->transformForGetAccessToken('gettoken', [ $request = $this->transformForGetRequest('gettoken', [
'corpid' => $config['corp_id'], 'corpid' => $config['corp_id'],
'corpsecret' => $config['secret'] 'corpsecret' => $config['secret']
]); ]);

View File

@ -4,7 +4,7 @@ namespace App\Wechat;
use App\Wechat\Work\Base; use App\Wechat\Work\Base;
class ExternalContact extends Base class ExternalContact
{ {
public function __construct() public function __construct()
{ {

View File

@ -3,16 +3,26 @@
namespace Wechat\Work; namespace Wechat\Work;
class Miniprogram extends Base class Miniprogram
{ {
protected $app = 'miniprogram';
public function code2Session($type = 'authorization_code') /**
* @var Work
*/
protected $work;
public function __construct($work)
{ {
$url = "https://qyapi.weixin.qq.com/cgi-bin/miniprogram/jscode2session?js_code=$code&grant_type=$type"); $this->work = $work;
$request = $this->client->transformForJsonRequest($url); }
$resp = $this->client->send($request);
return json_decode($resp->getBody(), true); public function code2Session($code,$type = 'authorization_code')
{
$request = $this->work->transformForGetRequest('miniprogram/jscode2session', [
'js_code' => $code,
'grant_type' => $type,
]);
return $this->work->request($request);
} }
} }

View File

@ -21,10 +21,19 @@ class Work extends Base
/** /**
* 群聊接口 * 群聊接口
* @param string $id 群id
*/ */
public function chat($id) public function chat($id)
{ {
return new Chat($id, $this); return new Chat($id, $this);
} }
/**
* 小程序接口
* @return Miniprogram
*/
public function miniProgram(){
return new Miniprogram($this);
}
} }