Call.php
1.78 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace WebPlugin\Partner\wechat;
use WebPlugin\Partner\Factory;
define('WECHAT_CLASS_PATH', dirname(__FILE__) . '/class/');
require WECHAT_CLASS_PATH . 'Wechat.class.php';
/**
* 微信的调用接口
*
* @name Call
* @package lib/partner/wechat
* @copyright yoho.inc
* @version 5.0 (2016-01-12 10:54:54)
* @author xiaowei <xiaowei.gong@yoho.cn>
*/
class Call extends Factory
{
//微信对象
protected $wechat;
/**
* 初始化
*/
protected function init()
{
$this->wechat = new \WechatAuth($this->apiConfig['appId'], $this->apiConfig['appKey']);
}
/**
* 获取授权URL
*
* @return string
*/
public function getAuthorizeUrl()
{
return $this->wechat->getAuthorizeURL($this->apiConfig['callback'], $this->apiConfig['scope']);
}
/**
* 获取授权的TOKEN
*
* @return array
*/
public function getAccessToken()
{
$token = array();
if (isset($_REQUEST['code']) && !empty($_REQUEST['code'])) {
try {
$token = $this->wechat->getAccessToken($_REQUEST['code']);
}
catch (Exception $e) {
// do nothing
}
}
return $token;
}
/**
* 获取当前用户的基本资料
*
* @param object $token 授权成功的TOKEN, 默认为NULL
* @return array
*/
public function getUserInfo($token)
{
$userInfo = array();
if (!empty($token)) {
$userInfo = $this->wechat->getUserInfo($token['access_token'], $token['openid']);
}
return $userInfo;
}
public function getFriends($token, $params)
{
}
public function syncShare($token, $content, $image, $link)
{
}
}