OfficialMenusController.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. namespace App\Http\Controllers\Wechat\OfficialAccount;
  3. use App\Modules\Channel\Services\ChannelService;
  4. use App\Modules\OfficialAccount\Models\OfficialAccount;
  5. use App\Modules\OfficialAccount\Models\OfficialInteractiveEvent;
  6. use App\Modules\Channel\Models\Channel;
  7. use App\Http\Controllers\Wechat\OfficialAccount\Transformers\OfficialMenuTransformer;
  8. use App\Modules\OfficialAccount\Services\SelfDefineService;
  9. use App\Http\Controllers\Controller;
  10. use Illuminate\Http\Request;
  11. use GuzzleHttp\Client;
  12. use App\Libs\OSS;
  13. class OfficialMenusController extends Controller
  14. {
  15. /**
  16. * @apiDefine OfficialAccount 公众号
  17. */
  18. /**
  19. * @apiVersion 1.0.0
  20. * @api {GET} OfficialAccount/officialMenusList 获取自动配置的菜单
  21. * @apiGroup OfficialAccount
  22. * @apiName officialMenusList
  23. * @apiSuccess {String} type 菜单类型.
  24. * @apiSuccess {String} name 菜单名称.
  25. * @apiSuccess {String} url 链接.
  26. * @apiSuccess {String} name 名称.
  27. * @apiSuccess {String} sub_button 子菜单.
  28. * @apiSuccessExample {json} Success-Response:·
  29. *
  30. * {
  31. * "code": 0,
  32. * "msg": "",
  33. * "data": [
  34. * {
  35. * "type": "view",
  36. * "name": "继续阅读",
  37. * "url": "www.baidu.comcontinue"
  38. * },
  39. * {
  40. * "type": "view",
  41. * "name": "书城首页",
  42. * "url": "www.baidu.com"
  43. * },
  44. * {
  45. * "name": "用户中心",
  46. * "sub_button": [
  47. * {
  48. * "type": "view",
  49. * "name": "个人中心",
  50. * "url": "www.baidu.comuser"
  51. * },
  52. * {
  53. * "type": "view",
  54. * "name": "阅读记录",
  55. * "url": "www.baidu.combookshelf"
  56. * },
  57. * {
  58. * "type": "view",
  59. * "name": "我要充值",
  60. * "url": "www.baidu.compaycenter"
  61. * },
  62. * {
  63. * "type": "click",
  64. * "name": "联系客服",
  65. * "key": "contact_customer"
  66. * }
  67. * ]
  68. * }
  69. * ]
  70. * }
  71. */
  72. function officialMenusList(Request $request)
  73. {
  74. $appid = $request->has('appid') ? $request->input('appid') : '';
  75. if (empty($appid)) {
  76. return response()->error("PARAM_EMPTY");
  77. }
  78. $officialAccount = OfficialAccount::officialAccountByAppid($appid);
  79. if (!empty($officialAccount)) {
  80. $distribution_channel_id = $officialAccount['distribution_channel_id'];
  81. $self_config = ChannelService::check_channel_account_priv($distribution_channel_id,'menu_type');
  82. $menu_type = isset($self_config->content)?$self_config->content:'menu_default';
  83. //默认菜单
  84. $buttons =SelfDefineService::getDefaultMenu($distribution_channel_id);
  85. //自定义菜单
  86. if( $selfDefinedButtons = SelfDefineService::getMenuFormated($distribution_channel_id,['status'=>1]) )
  87. {
  88. $buttons = $selfDefinedButtons;
  89. }else{
  90. if($menu_type == 'user_center'){
  91. $buttons =
  92. [
  93. [
  94. "type" => "click",
  95. "name" => "最近阅读",
  96. "key" => "recent_read",
  97. ],
  98. [
  99. "type" => "click",
  100. "name" => "今日签到",
  101. "key" => 'daily_sign',
  102. ],
  103. [
  104. "type" => "click",
  105. "name" => "用户中心",
  106. "key" => 'user_center',
  107. ],
  108. ];
  109. }
  110. }
  111. return response()->success($buttons);
  112. }
  113. }
  114. function officialMenusListV1(Request $request)
  115. {
  116. $appid = $request->has('appid') ? $request->input('appid') : '';
  117. if (empty($appid)) {
  118. return response()->error("PARAM_EMPTY");
  119. }
  120. $officialAccount = OfficialAccount::officialAccountByAppid($appid);
  121. if (!empty($officialAccount)) {
  122. $distribution_channel_id = $officialAccount['distribution_channel_id'];
  123. $WECHAT_CUSTOM_HOST = env('WECHAT_CUSTOM_HOST');
  124. $self_config = ChannelService::check_channel_account_priv($distribution_channel_id,'menu_type');
  125. $menu_type = isset($self_config->content)?$self_config->content:'menu_default';
  126. $encodeDistributionChannelId = encodeDistributionChannelId($distribution_channel_id);
  127. \Log::info('officialMenusList:distribution_channel_id:'.$distribution_channel_id.' encodeDistributionChannelId:'.$encodeDistributionChannelId.' menu_type:'.$menu_type);
  128. $base_url = env('PROTOCOL') . '://site' . $encodeDistributionChannelId . '.' . $WECHAT_CUSTOM_HOST . '.com/';
  129. $help_url = 'https://help.'.$WECHAT_CUSTOM_HOST.'.com?distribution_channel_id='.$encodeDistributionChannelId;
  130. if($is_yq_move){
  131. \Log::info('officialMenusList_is_yunqi_move:'.$distribution_channel_id);
  132. $buttons =
  133. [
  134. [
  135. "type" => "click",
  136. "name" => "最近阅读",
  137. "key" => "recent_read",
  138. ],
  139. ];
  140. }else{
  141. if($menu_type == 'user_center'){
  142. \Log::info('officialMenusList_$menu_type_1:'.$distribution_channel_id);
  143. $buttons =
  144. [
  145. [
  146. "type" => "click",
  147. "name" => "最近阅读",
  148. "key" => "recent_read",
  149. ],
  150. [
  151. "type" => "click",
  152. "name" => "今日签到",
  153. "key" => 'daily_sign',
  154. ],
  155. [
  156. "type" => "click",
  157. "name" => "用户中心",
  158. "key" => 'user_center',
  159. ],
  160. ];
  161. }else{
  162. \Log::info('officialMenusList_$menu_type_default:'.$distribution_channel_id);
  163. $buttons =
  164. [
  165. [
  166. "type" => "click",
  167. "name" => "最近阅读",
  168. "key" => "recent_read",
  169. ],
  170. [
  171. "type" => "click",
  172. "name" => "今日签到",
  173. "key" => 'daily_sign',
  174. ],
  175. [
  176. "name" => "用户中心",
  177. "sub_button" =>
  178. [
  179. [
  180. "type" => "view",
  181. "name" => "个人中心",
  182. "url" => $base_url . 'person',
  183. ],
  184. [
  185. "type" => "view",
  186. "name" => "书城首页",
  187. "url" => $base_url,
  188. ],
  189. [
  190. "type" => "view",
  191. "name" => "优惠充值",
  192. "url" => $base_url . 'pay',
  193. ],
  194. [
  195. "type" => "view",
  196. "name" => "帮助中心",
  197. "url" => $help_url,
  198. ],
  199. ],
  200. ],
  201. ];
  202. $selfDefinedButtons = SelfDefineService::getMenuFormated($distribution_channel_id);
  203. if($selfDefinedButtons){
  204. $buttons = $selfDefinedButtons;
  205. \Log::info('self_defined_buttons:'.$distribution_channel_id.':'.json_encode($selfDefinedButtons));
  206. }
  207. }
  208. }
  209. return response()->success($buttons);
  210. }
  211. }
  212. }