-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWechat.php
More file actions
45 lines (36 loc) · 1.18 KB
/
Wechat.php
File metadata and controls
45 lines (36 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* 根据不同的绑定方式处理微信消息
*
* \Gibson\Wechat 授权 SDK
* \Overtrue\Wechat 设置绑定 SDK
*/
namespace App\Services;
use App\Models\Setting\Wechat as Account;
class Wechat
{
public function __construct($account)
{
$this->account = $account;
}
public function __call($name, $args)
{
$namespace = $this->account->type == Account::TYPE_AUTH ? '\Gibson\Wechat\\' : '\Overtrue\Wechat\\';
if ($name === 'Server') {
$className = $namespace . 'Server';
return new $className($this->account->app_id, $this->account->token, $this->account->encoding_aes_key);
}
if ($this->account->type == Account::TYPE_AUTH) {
$className = $namespace . $name;
return new $className($this->getAccessToken()) ;
} else {
$className = $namespace . $name;
return new $className($this->account->app_id, $this->account->app_secret);
}
}
public function getAccessToken()
{
$accessToken = new \Gibson\Wechat\AccessToken($this->account->app_id, $this->account->refresh_token);
return $accessToken->getToken();
}
}