OfficialMenusController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. namespace App\Http\Controllers\Wechat\OfficialAccount;
  3. use Illuminate\Routing\Controller as ChannelBaseController;
  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 Illuminate\Http\Request;
  9. use GuzzleHttp\Client;
  10. use App\Libs\OSS;
  11. class OfficialMenusController extends ChannelBaseController
  12. {
  13. /**
  14. * @apiDefine OfficialAccount 公众号
  15. */
  16. /**
  17. * @apiVersion 1.0.0
  18. * @api {GET} OfficialAccount/officialMenusList 获取自动配置的菜单
  19. * @apiGroup OfficialAccount
  20. * @apiName officialMenusList
  21. * @apiSuccess {String} type 菜单类型.
  22. * @apiSuccess {String} name 菜单名称.
  23. * @apiSuccess {String} url 链接.
  24. * @apiSuccess {String} name 名称.
  25. * @apiSuccess {String} sub_button 子菜单.
  26. * @apiSuccessExample {json} Success-Response:·
  27. *
  28. * {
  29. * "code": 0,
  30. * "msg": "",
  31. * "data": [
  32. * {
  33. * "type": "view",
  34. * "name": "继续阅读",
  35. * "url": "www.baidu.comcontinue"
  36. * },
  37. * {
  38. * "type": "view",
  39. * "name": "书城首页",
  40. * "url": "www.baidu.com"
  41. * },
  42. * {
  43. * "name": "用户中心",
  44. * "sub_button": [
  45. * {
  46. * "type": "view",
  47. * "name": "个人中心",
  48. * "url": "www.baidu.comuser"
  49. * },
  50. * {
  51. * "type": "view",
  52. * "name": "阅读记录",
  53. * "url": "www.baidu.combookshelf"
  54. * },
  55. * {
  56. * "type": "view",
  57. * "name": "我要充值",
  58. * "url": "www.baidu.compaycenter"
  59. * },
  60. * {
  61. * "type": "click",
  62. * "name": "联系客服",
  63. * "key": "contact_customer"
  64. * }
  65. * ]
  66. * }
  67. * ]
  68. * }
  69. */
  70. function officialMenusList(Request $request)
  71. {
  72. $appid = $request->has('appid') ? $request->input('appid') : '';
  73. if (empty($appid)) {
  74. return response()->error("PARAM_EMPTY");
  75. }
  76. $officialAccount = OfficialAccount::officialAccountByAppid($appid);
  77. if (!empty($officialAccount)) {
  78. $distribution_channel_id = $officialAccount['distribution_channel_id'];
  79. $host = env('WECHAT_CUSTOM_HOST');
  80. if(in_array($distribution_channel_id,array(5,123))){
  81. // $host = 'imycmh';
  82. }
  83. // $base_url = env('PROTOCOL') . '://site' . $distribution_channel_id . '.' . $host . '.com/';
  84. // // 渠道id加密
  85. // if(in_array($distribution_channel_id,array(123))){
  86. // $encodeDistributionChannelId = encodeDistributionChannelId($distribution_channel_id);
  87. // $base_url = env('PROTOCOL') . '://site' . $encodeDistributionChannelId . '.' . $host . '.com/';
  88. // }
  89. // 获取渠道配置,如果是云栖迁移站点的
  90. $channel = Channel::getById($distribution_channel_id);
  91. $is_yq_move = isset($channel->is_yq_move)?$channel->is_yq_move:'0';
  92. $is_domain_simple = isset($channel->is_domain_simple)?$channel->is_domain_simple:'0';
  93. if($is_domain_simple == '1'){
  94. $encodeDistributionChannelId = $distribution_channel_id;
  95. }else{
  96. $encodeDistributionChannelId = encodeDistributionChannelId($distribution_channel_id);
  97. }
  98. \Log::info('officialMenusList:distribution_channel_id:'.$distribution_channel_id.' encodeDistributionChannelId:'.$encodeDistributionChannelId.' is_yq_move:'.$is_yq_move.' is_domain_simple:'.$is_domain_simple);
  99. $base_url = env('PROTOCOL') . '://site' . $encodeDistributionChannelId . '.' . $host . '.com/';
  100. $help_url = 'https://help.zhuishuyun.com?distribution_channel_id='.$encodeDistributionChannelId;
  101. if($is_yq_move){
  102. \Log::info('officialMenusList_is_yunqi_move:'.$distribution_channel_id);
  103. $buttons =
  104. [
  105. [
  106. "type" => "click",
  107. "name" => "最近阅读",
  108. "key" => "recent_read",
  109. ],
  110. ];
  111. }else{
  112. \Log::info('officialMenusList_not_yunqi_move:'.$distribution_channel_id);
  113. $buttons =
  114. [
  115. [
  116. "type" => "click",
  117. "name" => "最近阅读",
  118. "key" => "recent_read",
  119. ],
  120. [
  121. "type" => "click",
  122. "name" => "今日签到",
  123. "key" => 'daily_sign',
  124. ],
  125. [
  126. "name" => "用户中心",
  127. "sub_button" =>
  128. [
  129. [
  130. "type" => "view",
  131. "name" => "个人中心",
  132. "url" => $base_url . 'person',
  133. ],
  134. [
  135. "type" => "view",
  136. "name" => "书城首页",
  137. "url" => $base_url,
  138. ],
  139. [
  140. "type" => "view",
  141. "name" => "优惠充值",
  142. "url" => $base_url . 'pay',
  143. ],
  144. [
  145. "type" => "view",
  146. "name" => "帮助中心",
  147. "url" => $help_url,
  148. ],
  149. ],
  150. ],
  151. ];
  152. }
  153. return response()->success($buttons);
  154. }
  155. }
  156. }