Ejemplo n.º 1
0
 /**
  * 创建菜单
  *
  * @author Cui
  *
  * @date   2015-08-23
  *
  * @param  array      $button  菜单的数据
  * @param  int        $agentId 应用ID
  */
 public function create(array $button, $agentId)
 {
     if (empty($button) || empty($agentId)) {
         $this->setError('参数错误');
         return false;
     }
     $data = array();
     $data['button'] = $button;
     Api::setPostQueryStr('agentid', $agentId);
     $node = 'create';
     return $this->_post($node, $data);
 }
Ejemplo n.º 2
0
 /**
  * 获取JSSDK接口认证.
  *
  * @author Cui
  *
  * @date   2015-07-27
  *
  * @return string 认证签名.
  */
 public function getTicket()
 {
     $key = 'JSAPI_TICKET' . Api::getSecrect();
     $ticket = Api::Cache($key);
     if (!$ticket) {
         $this->module = 'get_jsapi_ticket';
         $res = $this->_get('', '');
         if (!$res) {
             exit($this->getError());
         }
         $ticket = $res['ticket'];
         $expires = $res['expires_in'];
         Api::Cache($key, $ticket, $expires - 300);
     }
     return $ticket;
 }
Ejemplo n.º 3
0
 /**
  * 上传临时媒体文件.
  *
  * @author Cui
  *
  * @date   2015-08-02
  *
  * @param string $file 文件路径
  * @param string $type 文件类型
  *
  * @return 接口返回结果
  */
 public function upload($file, $type)
 {
     if (!$file || !$type) {
         $this->setError('参数缺失');
         return false;
     }
     if (!file_exists($file)) {
         $this->setError('文件路径不正确');
         return false;
     }
     // 兼容php5.3-5.6 curl模块的上传操作
     if (class_exists('\\CURLFile')) {
         $data = array('media' => new \CURLFile(realpath($file)));
     } else {
         $data = array('media' => '@' . realpath($file));
     }
     Api::setPostQueryStr('type', $type);
     $node = 'upload';
     return $this->_post($node, $data, false);
 }
Ejemplo n.º 4
0
 /**
  * 创建微信OAuth协议的链接.
  *
  * @author Cui
  *
  * @date   2015-07-27
  *
  * @param string $redirectUri 协议的回调地址
  * @param string $state       可携带的参数, 选填.
  *
  * @return string 协议地址
  */
 public function createOAuthUrl($redirectUri, $state = '')
 {
     if (!$redirectUri) {
         $this->setError('参数错误!');
         return false;
     }
     $host = isset($_SERVER['HTTP_HOST']) ? 'http://' . $_SERVER['HTTP_HOST'] : '';
     $api = 'https://open.weixin.qq.com/connect/oauth2/authorize';
     $state = $state ? $state = base64_encode($state) : '';
     $url = array();
     $url['appid'] = Api::getCorpId();
     $url['redirect_uri'] = $host . $redirectUri;
     $url['response_type'] = 'code';
     $url['scope'] = 'snsapi_base';
     $url['state'] = $state;
     $url = http_build_query($url);
     $url .= '#wechat_redirect';
     $url = $api . '?' . $url;
     return $url;
 }
Ejemplo n.º 5
0
<?php

use WeixinAPI\Api;
// 引入 核心类
include '/WeixinAPI/Api.class.php';
$CORP_ID = '';
// 企业号CORP_ID
$CORP_SECRECT = '';
// 企业号CORP_SECRECT
$cacheDriver = 'File';
// 缓存方式 目前有两种 Redis 和 File. 使用Redis, 请先调整Redis驱动构造方法中的参数
// 初始化
Api::init($CORP_ID, $CORP_SECRECT, $cacheDriver);
// 使用工厂方法获取相应的接口模块
$api = Api::factory('Xxxx');
// 具体方法请参照 类中的具体方法注释
$res = $api->xxxx();
// 返回结果
var_dump($res);
// 如果失败
if (false === $res) {
    // 二者均可获取错误信息
    var_dump(Api::getError());
    var_dump($api->getError());
}
Ejemplo n.º 6
0
 /**
  * 返回错误信息.
  *
  * @author Cui
  *
  * @date   2015-07-31
  *
  * @return string
  */
 public final function getError()
 {
     return Api::getError();
 }