<?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) { } }