From 9caf26e7cdf5cfa3e08c6b49cf42f4d809850e6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=80=99=E5=AD=A6=E6=9D=B0?= Date: Wed, 20 Feb 2019 19:18:30 +0800 Subject: [PATCH] message --- src/Wechat/AccessToken.php | 20 -------------------- src/Wechat/Work/Base.php | 4 ++-- src/Wechat/Work/ExternalContact.php | 2 +- src/Wechat/Work/Miniprogram.php | 24 +++++++++++++++++------- src/Wechat/Work/Work.php | 9 +++++++++ 5 files changed, 29 insertions(+), 30 deletions(-) delete mode 100644 src/Wechat/AccessToken.php diff --git a/src/Wechat/AccessToken.php b/src/Wechat/AccessToken.php deleted file mode 100644 index 39c0fa6..0000000 --- a/src/Wechat/AccessToken.php +++ /dev/null @@ -1,20 +0,0 @@ -token = $token; - } - - public function __toString() - { - return $this->token; - } - -} \ No newline at end of file diff --git a/src/Wechat/Work/Base.php b/src/Wechat/Work/Base.php index 537bd68..d37df8c 100644 --- a/src/Wechat/Work/Base.php +++ b/src/Wechat/Work/Base.php @@ -48,7 +48,7 @@ class Base return $request; } - public function transformForGetAccessToken($uri, $params) + public function transformForGetRequest($uri, $params) { $uri = new Uri($uri); foreach ($params as $param) { @@ -81,7 +81,7 @@ class Base return $token; } - $request = $this->transformForGetAccessToken('gettoken', [ + $request = $this->transformForGetRequest('gettoken', [ 'corpid' => $config['corp_id'], 'corpsecret' => $config['secret'] ]); diff --git a/src/Wechat/Work/ExternalContact.php b/src/Wechat/Work/ExternalContact.php index a2c2104..6757fd9 100644 --- a/src/Wechat/Work/ExternalContact.php +++ b/src/Wechat/Work/ExternalContact.php @@ -4,7 +4,7 @@ namespace App\Wechat; use App\Wechat\Work\Base; -class ExternalContact extends Base +class ExternalContact { public function __construct() { diff --git a/src/Wechat/Work/Miniprogram.php b/src/Wechat/Work/Miniprogram.php index 40d0c73..be7a6e4 100644 --- a/src/Wechat/Work/Miniprogram.php +++ b/src/Wechat/Work/Miniprogram.php @@ -3,16 +3,26 @@ 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"); - $request = $this->client->transformForJsonRequest($url); - $resp = $this->client->send($request); - return json_decode($resp->getBody(), true); + $this->work = $work; + } + + public function code2Session($code,$type = 'authorization_code') + { + $request = $this->work->transformForGetRequest('miniprogram/jscode2session', [ + 'js_code' => $code, + 'grant_type' => $type, + ]); + return $this->work->request($request); } } \ No newline at end of file diff --git a/src/Wechat/Work/Work.php b/src/Wechat/Work/Work.php index a54ee48..7c417cb 100644 --- a/src/Wechat/Work/Work.php +++ b/src/Wechat/Work/Work.php @@ -21,10 +21,19 @@ class Work extends Base /** * 群聊接口 + * @param string $id 群id */ public function chat($id) { return new Chat($id, $this); } + /** + * 小程序接口 + * @return Miniprogram + */ + public function miniProgram(){ + return new Miniprogram($this); + } + } \ No newline at end of file