123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- /**
- * OaMenuApi.php UTF-8
- * 公众号菜单接口
- *
- * @date : 2018/9/26 18:27
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HuoMp 1.0
- */
- namespace huoMpMsg\controller;
- use huo\controller\common\Base;
- use huoMpMsg\status\OfficialAccountStatus;
- class OaMenuApi extends Base {
- /**
- * 自定义菜单创建接口
- * https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141013
- *
- * @param string $wx_app_id 第三方用户唯一凭证
- * @param string $wx_app_secret 第三方用户唯一凭证密钥,即appsecret
- * @param array $menu_data 菜单数据
- *
- * @return array
- */
- 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);
- }
- /**
- * 自定义菜单查询接口
- * https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141014
- *
- * @param string $wx_app_id 第三方用户唯一凭证
- * @param string $wx_app_secret 第三方用户唯一凭证密钥,即appsecret
- *
- * @return array
- */
- 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);
- }
- /**
- * 自定义菜单删除接口
- * https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141015
- *
- * 使用接口创建自定义菜单后,开发者还可使用接口删除当前使用的自定义菜单。另请注意,在个性化菜单时,调用此接口会删除默认菜单及全部个性化菜单。
- *
- * @param string $wx_app_id 第三方用户唯一凭证
- * @param string $wx_app_secret 第三方用户唯一凭证密钥,即appsecret
- *
- * @return array
- */
- 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);
- }
- /**
- * 个性化菜单接口
- * https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1455782296
- * 为了帮助公众号实现灵活的业务运营,微信公众平台新增了个性化菜单接口,开发者可以通过该接口,让公众号的不同用户群体看到不一样的自定义菜单。该接口开放给已认证订阅号和已认证服务号。
- *
- *
- * 1、用户标签(开发者的业务需求可以借助用户标签来完成)
- * 2、性别
- * 3、手机操作系统
- * 4、地区(用户在微信客户端设置的地区)
- * 5、语言(用户在微信客户端设置的语言)
- *
- * @param string $wx_app_id 第三方用户唯一凭证
- * @param string $wx_app_secret 第三方用户唯一凭证密钥,即appsecret
- * @param int $menuid 菜单ID
- *
- * @return array
- */
- 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);
- }
- /**
- * 测试个性化菜单匹配结果
- * https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1455782296
- *
- * @param string $wx_app_id 第三方用户唯一凭证
- * @param string $wx_app_secret 第三方用户唯一凭证密钥,即appsecret
- * @param string $open_id 玩家openid
- *
- * @return array
- */
- 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);
- }
- }
|