parent
e426c0f308
commit
01485ff0ec
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
namespace LaneWeChat\Core;
|
||||||
|
|
||||||
|
class Media {
|
||||||
|
public static function upload($filename, $type) {
|
||||||
|
$accessToken = AccessToken::getAccessToken();
|
||||||
|
$queryUrl = 'http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=' . $accessToken . '&type=' . $type;
|
||||||
|
$data = array('media' => '@' . $filename);
|
||||||
|
return Curl::callWebServer($queryUrl, $data, 'POST', 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function download($mediaId) {
|
||||||
|
$accessToken = AccessToken::getAccessToken();
|
||||||
|
$queryUrl = 'http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=' . $accessToken . '&media_id=' . $mediaId;
|
||||||
|
return Curl::callWebServer($queryUrl, '', 'GET', 0);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
namespace LaneWeChat\Core;
|
||||||
|
|
||||||
|
class Menu{
|
||||||
|
public static function setMenu($menuList){
|
||||||
|
$menuList2 = $menuList;
|
||||||
|
foreach($menuList as $key=>$menu){
|
||||||
|
foreach($menuList2 as $k=>$menu2){
|
||||||
|
if($menu['id'] == $menu2['pid']){
|
||||||
|
$menuList[$key]['sub_button'][] = $menu2;
|
||||||
|
unset($menuList[$k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach($menuList as $key=>$menu){
|
||||||
|
if($menu['type'] == 'view'){
|
||||||
|
$menuList[$key]['url'] = urlencode($menu['code']);
|
||||||
|
}else if($menu['type'] == 'click'){
|
||||||
|
$menuList[$key]['key'] = $menu['code'];
|
||||||
|
}else if(!empty($menu['type'])){
|
||||||
|
$menuList[$key]['key'] = $menu['code'];
|
||||||
|
if(!isset($menu['sub_button'])) $menuList[$key]['sub_button'] = array();
|
||||||
|
}
|
||||||
|
unset($menuList[$key]['code'], $menuList[$key]['id'], $menuList[$key]['pid']);
|
||||||
|
$menuList[$key]['name'] = urlencode($menu['name']);
|
||||||
|
if(isset($menu['sub_button'])){
|
||||||
|
unset($menuList[$key]['type']);
|
||||||
|
foreach($menu['sub_button'] as $k=>$son){
|
||||||
|
if($son['type'] == 'view'){
|
||||||
|
$menuList[$key]['sub_button'][$k]['url'] = urlencode($son['code']);
|
||||||
|
}else if($son['type'] == 'click'){
|
||||||
|
$menuList[$key]['sub_button'][$k]['key'] = $son['code'];
|
||||||
|
}else{
|
||||||
|
$menuList[$key]['sub_button'][$k]['key'] = $son['code'];
|
||||||
|
$menuList[$key]['sub_button'][$k]['sub_button'] = array();
|
||||||
|
}
|
||||||
|
unset($menuList[$key]['sub_button'][$k]['code'], $menuList[$key]['sub_button'][$k]['id'], $menuList[$key]['sub_button'][$k]['pid']);
|
||||||
|
$menuList[$key]['sub_button'][$k]['name'] = urlencode($son['name']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$data = array('button' => array_values($menuList));
|
||||||
|
$data = json_encode($data);
|
||||||
|
$data = urldecode($data);
|
||||||
|
$accessToken = AccessToken::getAccessToken();
|
||||||
|
$url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token='.$accessToken;
|
||||||
|
$result = Curl::callWebServer($url, $data, 'POST');
|
||||||
|
return $result['errcode'] == 0 ? true : $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getMenu(){
|
||||||
|
$accessToken = AccessToken::getAccessToken();
|
||||||
|
$url = 'https://api.weixin.qq.com/cgi-bin/menu/get?access_token='.$accessToken;
|
||||||
|
return Curl::callWebServer($url, '', 'GET');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function delMenu(){
|
||||||
|
$accessToken = AccessToken::getAccessToken();
|
||||||
|
$url = 'https://api.weixin.qq.com/cgi-bin/menu/delete?access_token='.$accessToken;
|
||||||
|
return Curl::callWebServer($url, '', 'GET');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
namespace LaneWeChat\Core;
|
||||||
|
|
||||||
|
class Msg {
|
||||||
|
|
||||||
|
@param int
|
||||||
|
@param string
|
||||||
|
@return Ambigous
|
||||||
|
|
||||||
|
public static function returnErrMsg($code, $errorMsg = null) {
|
||||||
|
$returnMsg = array('error_code' => $code);
|
||||||
|
if (!empty($errorMsg)) {
|
||||||
|
$returnMsg['custom_msg'] = $errorMsg;
|
||||||
|
}
|
||||||
|
$returnMsg['custom_msg'] = '出错啦!'.$returnMsg['custom_msg'];
|
||||||
|
exit($returnMsg['custom_msg']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
namespace LaneWeChat\Core;
|
||||||
|
|
||||||
|
class MsgConstant {
|
||||||
|
const ERROR_SYSTEM = 101;
|
||||||
|
const ERROR_NEWS_ITEM_COUNT_MORE_TEN = 102;
|
||||||
|
const ERROR_MENU_CLICK = 103;
|
||||||
|
|
||||||
|
const ERROR_INPUT_ERROR = 1001;
|
||||||
|
const ERROR_UNKNOW_TYPE = 1002;
|
||||||
|
const ERROR_CAPTCHA_ERROR = 1003;
|
||||||
|
const ERROR_REQUIRED_FIELDS = 1004;
|
||||||
|
|
||||||
|
const ERROR_REMOTE_SERVER_NOT_RESPOND = 1201;
|
||||||
|
const ERROR_GET_ACCESS_TOKEN = 1202;
|
||||||
|
|
||||||
|
const ERROR_MENU_NOT_EXISTS = 1401;
|
||||||
|
|
||||||
|
const ERROR_NO_BINDING_TEXT = '对不起,您尚未绑定微信,轻松绑定微信,即可查询实时流量,享受便捷服务!';
|
||||||
|
}
|
Loading…
Reference in new issue