|
@@ -22,6 +22,7 @@ use Modules\WechatPlatform\Services\WechatMenuService;
|
|
|
class WechatMenuController extends CatchController
|
|
|
{
|
|
|
use UserTrait;
|
|
|
+
|
|
|
/**
|
|
|
* 关键词列表
|
|
|
* name: List
|
|
@@ -42,7 +43,7 @@ class WechatMenuController extends CatchController
|
|
|
{
|
|
|
$param = $request->validated();
|
|
|
$param['msg_content'] = $request->input('msg_content');
|
|
|
- $param = $this->handleParam($param);
|
|
|
+ $param = $this->handleParam($param);
|
|
|
$userContext = $this->getUserContext(null);
|
|
|
$param['user_id'] = $userContext['loginUser']->id;
|
|
|
$param['puser_id'] = $userContext['loginUser']->pid;
|
|
@@ -50,19 +51,21 @@ class WechatMenuController extends CatchController
|
|
|
return WechatMenuService::addMenu($param);
|
|
|
}
|
|
|
|
|
|
- public function edit($id,WechatMenuRequest $request)
|
|
|
+ public function edit($id, WechatMenuRequest $request)
|
|
|
{
|
|
|
$param = $request->validated();
|
|
|
$param['msg_content'] = $request->input('msg_content');
|
|
|
- $param = $this->handleParam($param);
|
|
|
- return WechatMenuService::updateMenu($id,$param);
|
|
|
+ $param = $this->handleParam($param);
|
|
|
+ return WechatMenuService::updateMenu($id, $param);
|
|
|
}
|
|
|
|
|
|
- public function detail($id){
|
|
|
+ public function detail($id)
|
|
|
+ {
|
|
|
return WechatMenuService::detail($id);
|
|
|
}
|
|
|
|
|
|
- public function authList($id){
|
|
|
+ public function authList($id)
|
|
|
+ {
|
|
|
$userId = $this->getLoginUserId();
|
|
|
return WechatMenuService::authList($id, $userId);
|
|
|
}
|
|
@@ -84,7 +87,7 @@ class WechatMenuController extends CatchController
|
|
|
* @param $id
|
|
|
* date 2023/07/12 07:18
|
|
|
*/
|
|
|
- public function allocation($id,Request $request)
|
|
|
+ public function allocation($id, Request $request)
|
|
|
{
|
|
|
if (!$request->has('wx_auth_ids')) {
|
|
|
WechatMenuService::throwErrMsg("参数错误");
|
|
@@ -94,9 +97,10 @@ class WechatMenuController extends CatchController
|
|
|
} else {
|
|
|
$wxAuthIds = [];
|
|
|
}
|
|
|
- return WechatMenuService::allocation($id,$wxAuthIds);
|
|
|
+ return WechatMenuService::allocation($id, $wxAuthIds);
|
|
|
}
|
|
|
- // 处理参数
|
|
|
+
|
|
|
+ // 处理参数
|
|
|
private function handleParam($param)
|
|
|
{
|
|
|
$info = DB::table('miniprogram')->where('id', $param['miniprogram_id'])->first();
|
|
@@ -114,43 +118,43 @@ class WechatMenuController extends CatchController
|
|
|
if (empty($info)) {
|
|
|
WechatMenuService::throwErrMsg("没有此小程序的使用权限");
|
|
|
}
|
|
|
- if (count($param['content']) >3){
|
|
|
+ if (count($param['content']) > 3) {
|
|
|
WechatMenuService::throwErrMsg("底部菜单不能超过3个");
|
|
|
}
|
|
|
// $clicks = [];
|
|
|
$msgContent = [];
|
|
|
- foreach ($param['content'] as &$val){
|
|
|
- if (!empty(getProp($val,'sub_button'))){
|
|
|
- foreach ($val['sub_button'] as &$sub){
|
|
|
- if (getProp($sub,'type') == 'miniprogram'){
|
|
|
+ foreach ($param['content'] as &$val) {
|
|
|
+ if (!empty(getProp($val, 'sub_button'))) {
|
|
|
+ foreach ($val['sub_button'] as &$sub) {
|
|
|
+ if (getProp($sub, 'type') == 'miniprogram') {
|
|
|
$sub['appid'] = $param['miniprogram_appid'];
|
|
|
$sub['pagepath'] = $sub['url'];
|
|
|
}
|
|
|
- if (getProp($sub,'type') == 'click'){
|
|
|
+ if (getProp($sub, 'type') == 'click') {
|
|
|
// $clicks[] = $sub['key'];
|
|
|
- $msgContent[] =[$sub['key'] => $sub['content']];
|
|
|
+ $msgContent[] = [$sub['key'] => $sub['content']];
|
|
|
}
|
|
|
- if (!in_array(getProp($sub,'type') ,['view','miniprogram'])){
|
|
|
+ if (!in_array(getProp($sub, 'type'), ['view', 'miniprogram'])) {
|
|
|
unset($sub['url']);
|
|
|
}
|
|
|
}
|
|
|
- }else{
|
|
|
- if (getProp($val,'type') == 'miniprogram'){
|
|
|
+ } else {
|
|
|
+ if (getProp($val, 'type') == 'miniprogram') {
|
|
|
$val['appid'] = $param['miniprogram_appid'];
|
|
|
$val['pagepath'] = $val['url'];
|
|
|
}
|
|
|
- if (getProp($val,'type') == 'click'){
|
|
|
+ if (getProp($val, 'type') == 'click') {
|
|
|
// $clicks[] = $val['key'];
|
|
|
- $msgContent[] =[$val['key'] => $val['content']];
|
|
|
+ $msgContent[] = [$val['key'] => $val['content']];
|
|
|
}
|
|
|
- if (!in_array(getProp($val,'type') ,['view','miniprogram'])){
|
|
|
+ if (getProp($val, 'type') == 'view') {
|
|
|
unset($val['url']);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- $param['msg_content']= $msgContent;
|
|
|
+ $param['msg_content'] = $msgContent;
|
|
|
// unset($val,$sub,$info);
|
|
|
// // 有点击事件
|
|
|
// if (!empty($clicks)){
|
|
@@ -187,11 +191,12 @@ class WechatMenuController extends CatchController
|
|
|
return $param;
|
|
|
}
|
|
|
|
|
|
- public function test(){
|
|
|
+ public function test()
|
|
|
+ {
|
|
|
$info = WechatOpenPlatformService::getAppInfoById(8);
|
|
|
$componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($info->component_appid);
|
|
|
$openPlatform = WechatOpenPlatformService::buildApplication($componentInfo);
|
|
|
- $app = $openPlatform->officialAccount($info->authorizer_appid, getProp($info,'authorizer_refresh_token'));
|
|
|
+ $app = $openPlatform->officialAccount($info->authorizer_appid, getProp($info, 'authorizer_refresh_token'));
|
|
|
unset($appInfo);
|
|
|
return $app->menu->list();
|
|
|
}
|