From 056d7beca2713934d556a5ecdc5ba42e8ed6b9c4 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 20 Dec 2019 09:02:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=BC=80=E5=8F=91=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E8=87=AA=E5=AE=9A=E4=B9=89=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=96=B9=E6=B3=95=EF=BC=8C=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=95=B0=E6=8D=AE=E6=A8=A1=E5=9E=8B=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E7=9A=84=E6=8A=A5=E9=94=99=E4=BF=A1=E6=81=AF=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E5=BC=80=E5=8F=91=E9=80=92=E5=BD=92=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=89=8D=E7=AB=AF=E6=95=B0=E6=8D=AE=EF=BC=8C=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E6=8B=BC=E6=8E=A5=E6=95=B0=E6=8D=AE=E4=B8=BA=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E8=8F=9C=E5=8D=95=E6=A0=BC=E5=BC=8F=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/PublicAccountManager.php | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/backend/modules/wx_public_account/logic/PublicAccountManager.php b/backend/modules/wx_public_account/logic/PublicAccountManager.php index d49ea73..e302641 100644 --- a/backend/modules/wx_public_account/logic/PublicAccountManager.php +++ b/backend/modules/wx_public_account/logic/PublicAccountManager.php @@ -1,32 +1,26 @@ one(); - if (!$configModel || !$configModel->) - $config = [ - 'app_id' => - ]; - } - /** + * 处理前端自定义菜单数据 * @param $data - * @param Config|$configModel + * @param WxPublicAccountConfig|$configModel + * @return bool * @throws ServerErrorHttpException */ public static function dealCustomMenuData($data, $configModel) @@ -37,12 +31,30 @@ class PublicAccountManager if (!$configModel->save()) { throw new Exception(self::dealSaveErrorsString($configModel->errors)); } - $button = self + $button = self::dealData($data, []); + $res = self::$openPlatform->menu->delete(); + if ($res['errcode'] != 0) { + throw new Exception($res['errmsg']); + } + if ($button) { + $res = self::$openPlatform->menu->create($button); + if ($res['errcode'] != 0) { + throw new Exception($res['errmsg']); + } + } + $tra->commit(); + return ['status' => true]; } catch (Exception $e) { - throw new ServerErrorHttpException($e->getMessage()); + $tra->rollBack(); + return ['status' => false, 'info' => $e->getMessage()]; } } + /** + * 处理数据模型保存的报错信息 + * @param $arr + * @return string + */ public static function dealSaveErrorsString($arr): string { $data = []; @@ -53,10 +65,10 @@ class PublicAccountManager } /** + * 处理前端数据,递归处理 * @param $data * @param $ret * @return mixed - * 处理前端数据,递归处理 */ private static function dealData($data, $ret) { @@ -75,11 +87,11 @@ class PublicAccountManager } /** + * 拼接数据为微信菜单格式 * @param $type * @param $value * @param $name * @return mixed - * 拼接数据为微信菜单格式 */ private static function spliceData($type, $value, $name) {