|
|
@ -1,32 +1,26 @@ |
|
|
|
<?php |
|
|
|
namespace backend\modules\wechat_public_account\logic; |
|
|
|
namespace backend\modules\wx_public_account\logic; |
|
|
|
|
|
|
|
use backend\modules\shop\models\ars\Config; |
|
|
|
use Yii; |
|
|
|
use yii\base\Exception; |
|
|
|
use yii\web\ServerErrorHttpException; |
|
|
|
use EasyWeChat\Factory; |
|
|
|
use backend\modules\wx_public_account\models\ars\WxPublicAccountConfig; |
|
|
|
|
|
|
|
class PublicAccountManager |
|
|
|
{ |
|
|
|
public $response_type = 'array'; |
|
|
|
//已授权对象
|
|
|
|
public static $openPlatform; |
|
|
|
//自定义菜单类型
|
|
|
|
const TYPE_VIEW = 'view';//跳转网页
|
|
|
|
const TYPE_MINI_PROGRAM = 'miniprogram';//跳转小程序
|
|
|
|
const TYPE_CUSTOM_PAGE = 'customPage';//自定义页面
|
|
|
|
|
|
|
|
private static function _getEasyApp() |
|
|
|
{ |
|
|
|
$configModel = Config::find()->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) |
|
|
|
{ |
|
|
|