/** * 得到入口令 * * @author xjiujiu <*****@*****.**> * @access public */ public function requestAccessToken($identifier = 'wx-access-token') { $staticCfg = HClass::quickLoadModel('staticcfg'); $record = $staticCfg->getRecordByIdentifier($identifier); if ($record) { $json = json_decode(HString::decodeHtml($record['content']), true); if ($json['end_time'] > $_SERVER['REQUEST_TIME']) { $this->_accessToken = $json['access_token']; return $this; } } $json = HRequest::getContents(strtr(self::$_urlMap['access_token'], array('{appid}' => $this->_appid, '{secret}' => $this->_secret))); $json = json_decode($json, true); if (isset($json['errcode']) && 0 < $json['errcode']) { throw new HRequestException($json['errmsg']); } $json['end_time'] = time() + $json['expires_in']; $data = array('name' => '微信口令ACCESS-TOKEN', 'identifier' => $identifier, 'content' => json_encode($json), 'author' => HSession::getAttribute('id', 'user')); if ($record) { $staticCfg->editByWhere($data, '`id` = ' . $record['id']); } else { $staticCfg->add($data); } $this->_accessToken = $json['access_token']; return $this; }
<?php /** * @version $Id$ * @author xjiujiu <*****@*****.**> * @description HongJuZi Framework * @copyright Copyright (c) 2011-2012 http://www.xjiujiu.com.All right reserved */ defined('_HEXEC') or die('Restricted access!'); HClass::import('vendor.sdk.weixin.wechat'); /** * 微信验证帮助类 * * @author xjiujiu <*****@*****.**> * @package weixin * @since 1.0.0 */ class WechatMenuHelper extends Wechat { /** * @var private static $_createUrl 创建菜单URL */ private static $_createUrl = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token={access_token}'; /** * 创建菜单 * * {@see http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html } * * @author xjiujiu <*****@*****.**> * @access public * @param {String} JSON字符串