123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- namespace huoMpMsg\controller;
- use huo\controller\common\Base;
- use huoMpMsg\status\OfficialAccountStatus;
- class OaMenuApi extends Base {
-
- public function createMenu($wx_app_id, $wx_app_secret, $menu_data = []) {
- $_url = 'https://api.weixin.qq.com/cgi-bin/menu/create';
- $_access_token = Common::getAccessToken($wx_app_id, $wx_app_secret);
- $_url = $_url.'?access_token='.$_access_token;
- $_param = json_encode($menu_data, JSON_UNESCAPED_UNICODE);
- $_header = ['Content-Type: application/octet-stream; charset=utf-8'];
- $_ret = Common::curl($_url, $_param, 'POST', $_header);
- $_rdata = [];
- if (Common::isJson($_ret)) {
- $_rdata = json_decode($_ret, true);
- }
- if (isset($_rdata['errcode']) && '0' != $_rdata['errcode']) {
- $_code = $_rdata['errcode'];
- return $this->huoError($_code, $_rdata['errmsg']);
- }
- $_code = OfficialAccountStatus::NO_ERROR;
- return $this->huoSuccess($_code, OfficialAccountStatus::getMsg($_code), $_rdata);
- }
-
- public function getMenu($wx_app_id, $wx_app_secret) {
- $_url = 'https://api.weixin.qq.com/cgi-bin/menu/get';
- $_access_token = Common::getAccessToken($wx_app_id, $wx_app_secret);
- $_url = $_url.'?access_token='.$_access_token;
- $_ret = Common::curl($_url, '');
- $_rdata = [];
- if (Common::isJson($_ret)) {
- $_rdata = json_decode($_ret, true);
- }
- if (isset($_rdata['errcode']) && '0' != $_rdata['errcode']) {
- $_code = $_rdata['errcode'];
- return $this->huoError($_code, $_rdata['errmsg']);
- }
- $_code = OfficialAccountStatus::NO_ERROR;
- return $this->huoSuccess($_code, OfficialAccountStatus::getMsg($_code), $_rdata);
- }
-
- public function deleteAllMenu($wx_app_id, $wx_app_secret) {
- $_url = 'https://api.weixin.qq.com/cgi-bin/menu/delete';
- $_access_token = Common::getAccessToken($wx_app_id, $wx_app_secret);
- $_url = $_url.'?access_token='.$_access_token;
- $_ret = Common::curl($_url, '');
- $_rdata = [];
- if (Common::isJson($_ret)) {
- $_rdata = json_decode($_ret, true);
- }
- if (isset($_rdata['errcode']) && '0' != $_rdata['errcode']) {
- $_code = $_rdata['errcode'];
- return $this->huoError($_code, $_rdata['errmsg']);
- }
- $_code = OfficialAccountStatus::NO_ERROR;
- return $this->huoSuccess($_code, OfficialAccountStatus::getMsg($_code), $_rdata);
- }
-
- public function addConditionalMenu($wx_app_id, $wx_app_secret, $menuid = 0) {
- $_url = 'https://api.weixin.qq.com/cgi-bin/menu/addconditional';
- $_access_token = Common::getAccessToken($wx_app_id, $wx_app_secret);
- $_url = $_url.'?access_token='.$_access_token;
- $_param['menuid'] = $menuid;
- $_param = json_encode($_param);
- $_header = ['Content-Type: application/octet-stream; charset=utf-8'];
- $_ret = Common::curl($_url, $_param, 'POST', $_header);
- $_rdata = [];
- if (Common::isJson($_ret)) {
- $_rdata = json_decode($_ret, true);
- }
- if (isset($_rdata['errcode']) && '0' != $_rdata['errcode']) {
- $_code = $_rdata['errcode'];
- return $this->huoError($_code, $_rdata['errmsg']);
- }
- $_code = OfficialAccountStatus::NO_ERROR;
- return $this->huoSuccess($_code, OfficialAccountStatus::getMsg($_code), $_rdata);
- }
-
- public function tryMatchConditionalMenu($wx_app_id, $wx_app_secret, $open_id) {
- $_url = 'https://api.weixin.qq.com/cgi-bin/menu/trymatch';
- $_access_token = Common::getAccessToken($wx_app_id, $wx_app_secret);
- $_url = $_url.'?access_token='.$_access_token;
- $_param['user_id'] = $open_id;
- $_param = json_encode($_param);
- $_header = ['Content-Type: application/octet-stream; charset=utf-8'];
- $_ret = Common::curl($_url, $_param, 'POST', $_header);
- $_rdata = [];
- if (Common::isJson($_ret)) {
- $_rdata = json_decode($_ret, true);
- }
- if (isset($_rdata['errcode']) && '0' != $_rdata['errcode']) {
- $_code = $_rdata['errcode'];
- return $this->huoError($_code, $_rdata['errmsg']);
- }
- $_code = OfficialAccountStatus::NO_ERROR;
- return $this->huoSuccess($_code, OfficialAccountStatus::getMsg($_code), $_rdata);
- }
- }
|