OfficialInteractiveEventController.php 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. <?php
  2. namespace App\Http\Controllers\Wechat\OfficialAccount;
  3. use App\Consts\Channel\ChannelConst;
  4. use App\Http\Controllers\Controller;
  5. use App\Modules\Book\Services\BookService;
  6. use App\Modules\Channel\Services\ChannelService;
  7. use App\Modules\Book\Services\BookSearchStatService;
  8. use App\Modules\Channel\Models\Channel;
  9. use App\Modules\Channel\Models\YqMoveChannel;
  10. use App\Modules\OfficialAccount\Models\MediaCustomer;
  11. use App\Modules\OfficialAccount\Models\OfficialAccount;
  12. use App\Modules\OfficialAccount\Models\OfficialInteractiveEvent;
  13. use App\Modules\OfficialAccount\Models\WechatKeywordMsgs;
  14. use App\Modules\OfficialAccount\Models\DistributionReply;
  15. use App\Modules\OfficialAccount\Models\DistributionSelfDefineContent;
  16. use App\Modules\OfficialAccount\Models\DistributionSelfDefineConfig;
  17. use App\Modules\OfficialAccount\Services\OfficialAccountMsgService;
  18. use App\Modules\OfficialAccount\Services\OfficialAccountService;
  19. use App\Modules\OfficialAccount\Services\CustomMsgService;
  20. use App\Modules\OfficialAccount\Services\MsgService;
  21. use App\Modules\User\Services\ReadRecordService;
  22. use App\Modules\OfficialAccount\Services\ForceSubscribeService;
  23. use App\Http\Controllers\Wechat\OfficialAccount\Transformers\OfficialInteractiveEventTransformer;
  24. use App\Http\Controllers\Wechat\OfficialAccount\Transformers\OfficialInteractiveEventTextTransformer;
  25. use App\Modules\Book\Services\BookConfigService;
  26. use App\Modules\User\Services\UserSignService;
  27. use Illuminate\Http\Request;
  28. use GuzzleHttp\Client;
  29. use App\Libs\OSS;
  30. use Hashids;
  31. use Redis;
  32. use DB;
  33. use App\Modules\Book\Models\BookConfig;
  34. use App\Modules\Promotion\Services\PromotionService;
  35. use App\Modules\OfficialAccount\Models\ForceSubscribeUsers;
  36. use App\Modules\User\Models\User;
  37. class OfficialInteractiveEventController extends Controller
  38. {
  39. /**
  40. * @apiDefine OfficialAccount 公众号
  41. */
  42. /**
  43. * @apiVersion 1.0.0
  44. * @api {GET} OfficialAccount/OfficialInteractiveEventFeedback 公众号交互事件推送
  45. * @apiGroup OfficialAccount
  46. * @apiName OfficialInteractiveEventFeedback
  47. * @apiParam {String} appid 公众号的appid.
  48. * @apiParam {String} event 事件类型.
  49. * @apiParam {String} content text类型下的搜索条件.
  50. * @apiSuccess {String} text 返回的文字信息.
  51. * @apiSuccess {String} title 搜索出的书籍标题.
  52. * @apiSuccess {String} description 搜索出的书籍简介.
  53. * @apiSuccess {String} url 搜索出的书籍链接.
  54. * @apiSuccess {String} image 搜索出的书籍封面地址.
  55. * @apiSuccessExample {json} Success-Response:
  56. *
  57. * {
  58. * "code": 0,
  59. * "msg": "",
  60. * "data": {
  61. * "text": "用户取消强制关注"
  62. * }
  63. * }
  64. *
  65. * {
  66. * "code": 0,
  67. * "msg": "",
  68. * "data": [
  69. * {
  70. * "title": "肌缘巧合",
  71. * "description": "&nbsp;&nbsp;&nbsp;&nbsp;他是权势倾天,纵横商界的王者,却偏偏钟情于她,一宠成瘾。“女人,我要你......只要你能满足我,别墅、游轮、支票,你随便挑。”她羞涩的半低着头:“我只想要你。”他挑眉,“你野心不小啊!”她妩媚一笑,解开他的领带,“难道你不愿意!”他宠她爱她,给她所有想要的。只是有一天她终于忍不住暴走,“靠,你有没有节制呀?我要离婚。”",
  72. * "url": "test2.ycsd.cn?bid=5",
  73. * "image": "https:\/\/leyue-bucket.oss-cn-hangzhou.aliyuncs.com\/ycsd_cover\/covermiddle\/0\/8.jpg"
  74. * },
  75. * {
  76. * "title": "等你爱我",
  77. * "description": "&nbsp;&nbsp;&nbsp;&nbsp;“只要你愿意成全我,给你所有……”黑暗中,她为救他,成了他的女人,他却隔天清晨匆匆离去。六年后,她进入他的公司,与他擦肩而过,却互不相识,但一切却悄然发生改变,他有了自己爱的人,她有了爱自己的人……她带着女儿疲于奔命,他重新进入她的生活,当他决定娶她时,她却淡淡一笑,转身离开……",
  78. * "url": "test2.ycsd.cn?bid=9",
  79. * "image": "https:\/\/leyue-bucket.oss-cn-hangzhou.aliyuncs.com\/ycsd_cover\/covermiddle\/0\/4.jpg"
  80. * }
  81. * ]
  82. * }
  83. */
  84. function officialInteractiveEventFeedback(Request $request)
  85. {
  86. $appid = $request->has('appid') ? $request->input('appid') : '';
  87. $event = $request->has('event') ? $request->input('event') : '';
  88. $uid = $request->has('uid') ? $request->input('uid') : '';
  89. $openid = $request->has('openid') ? $request->input('openid') : '';
  90. if (empty($event)) {
  91. return response()->error("PARAM_EMPTY");
  92. }
  93. $content = $request->has('content') ? $request->input('content') : '';
  94. $officialAccount = OfficialAccount::officialAccountByAppid($appid);
  95. $distribution_channel_id = '';
  96. if (!empty($officialAccount)) {
  97. $distribution_channel_id = $officialAccount['distribution_channel_id'];
  98. } else {
  99. $distribution_channel_id = '';
  100. }
  101. if ($event == "text") {
  102. if (empty($content)) {
  103. return response()->error("PARAM_EMPTY");
  104. }
  105. }
  106. $encode_distribution_channel_id = encodeDistributionChannelId($distribution_channel_id);
  107. // 判断渠道是否是外站派单(需要我们帮生成强关用户)
  108. $channel = Channel::getById($distribution_channel_id);
  109. $is_outer_site = isset($channel->is_outer_site) ? $channel->is_outer_site : '0';
  110. $is_domain_simple = isset($channel->is_domain_simple) ? $channel->is_domain_simple : '0';
  111. if ($is_domain_simple == '1') {
  112. $encode_distribution_channel_id = $distribution_channel_id;
  113. }
  114. $params['openid'] = $openid;
  115. $forceSubscribeUser = ForceSubscribeService::forceSubscribeUsersByOpenid($params);
  116. $uid = isset($forceSubscribeUser->uid) ? $forceSubscribeUser->uid : '0';
  117. $WECHAT_CUSTOM_HOST = env('WECHAT_CUSTOM_HOST');
  118. $base_url = env('PROTOCOL') . "://site" . $encode_distribution_channel_id . "." . $WECHAT_CUSTOM_HOST . ".com";
  119. $help_url = env('PROTOCOL') . '://help.' . $WECHAT_CUSTOM_HOST . '.com?distribution_channel_id=' . $encode_distribution_channel_id;
  120. if ($event == "text") {
  121. // 有自定义不回复文本内容的渠道
  122. $distribution_self_define_config = DistributionSelfDefineConfig::getDistributionSelfDefineConfig($distribution_channel_id, 'force_subscribe_notext_reply');
  123. if (!empty($distribution_self_define_config)) {
  124. $feedback['text'] = "";
  125. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  126. }
  127. // 搜索写入
  128. if ($content != 'search_get_recommend_book') {
  129. if (strlen($content) <= 100) {
  130. BookSearchStatService::create($uid, $openid, 'wechat', $content);
  131. }
  132. }
  133. // 单独推送一本智能推荐的书
  134. if ($content == 'search_get_recommend_book') {
  135. \Log::info('get_recommend_book:' . $openid);
  136. $feedback['text'] = "";
  137. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  138. $bid = isset($forceSubscribeUser->bid) ? $forceSubscribeUser->bid : '0';
  139. $params['openid'] = $openid;
  140. $recommend_book = BookConfigService::getSimpleChannelBookLoop($bid, 1, $uid);
  141. $feedback['text'] = '';
  142. if (!empty($recommend_book)) {
  143. $bookUrl = env('PROTOCOL') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . $WECHAT_CUSTOM_HOST . '.com';
  144. $bookUrl = $bookUrl . $recommend_book[0]->url . '&fromtype=' . $content . '&source=wechatmsg&fromsource=smart_push';
  145. $feedback['text'] = '新书推荐: <a href="' . $bookUrl . '"> 《' . $recommend_book[0]->book_name . '》</a>';
  146. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'get_one_recommend_book');
  147. }
  148. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  149. }
  150. if ($content == '签到') {
  151. //调洋哥的接口发送签到客服消息
  152. \Log::info('text_sign:' . $openid);
  153. $feedback['text'] = UserSignService::userSignReturnContent3($openid, $distribution_channel_id, $WECHAT_CUSTOM_HOST);
  154. $top_url = OfficialAccountService::getTopUrl($officialAccount->service_type_info);
  155. if ($officialAccount->service_type_info == 1) {
  156. $top_content = "\n\n" . '为方便阅读,请<a href="' . $top_url . '">设为星标</a>';
  157. } else {
  158. $top_content = "\n\n" . '为方便阅读,请<a href="' . $top_url . '">置顶公众号</a>';
  159. }
  160. $feedback['text'] .= $top_content;
  161. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'text_sign');
  162. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  163. }
  164. if ($content == '最近阅读') {
  165. // $channel_sex = ChannelService::getChannelCompanySex($distribution_channel_id);
  166. $channelInfo = ChannelService::getById($distribution_channel_id);
  167. $property = isset($channelInfo->property) ? $channelInfo->property : '';
  168. $channel_sex = 3;
  169. if ($property === ChannelConst::PROPERTY_MALE) {
  170. $channel_sex = 1;
  171. }
  172. if ($property === ChannelConst::PROPERTY_FEMALE) {
  173. $channel_sex = 2;
  174. }
  175. \Log::info('channel_sex:' . $channel_sex . ' distribution_channel_id:' . $distribution_channel_id . ' property:' . $property);
  176. $feedback['text'] = "尊敬的会员:\n\n <a href='" . env('PROTOCOL') . "://site" . $encode_distribution_channel_id . "." . $WECHAT_CUSTOM_HOST . ".com/recent'>☞ 点我继续上次阅读 </a>";
  177. if ($channel_sex != 1) {
  178. // 根据用户性别确定男女频
  179. $sex = ForceSubscribeService::getUserRealSexByUid($uid);
  180. $channel_name = $sex == 1 ? '男频' : '女频';
  181. // 站点属性优先
  182. if ($channel_sex == 2) {
  183. $channel_name = '女频';
  184. }
  185. $recomm_books = BookConfigService::getSignRecommendBooksFromCache([], $channel_name, 2);
  186. $recent_read_reco_content = '';
  187. if ($recomm_books) {
  188. // 判断是否不展示书名
  189. $self_config = ChannelService::check_channel_account_priv($distribution_channel_id, 'hide_book_name');
  190. $hide_type = isset($self_config->type) ? $self_config->type : 'not_hide';
  191. $recommend_titles = [];
  192. if ($hide_type == 'hide_book_name') {
  193. \Log::info('hide_book_name reco:' . $distribution_channel_id . ' uid:' . $uid);
  194. $recommend_titles = PromotionService::getRandomHeadline($sex, count($recomm_books));
  195. }
  196. $recent_read_reco_content .= "\n\n" . '热门书籍推荐~';
  197. foreach ($recomm_books as $key => $book) {
  198. $book_name = $book->book_name;
  199. if ($hide_type == 'hide_book_name') {
  200. $book_name = isset($recommend_titles[$key]->title) ? $recommend_titles[$key]->title : $book->book_name;
  201. }
  202. $url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/reader?bid=' . Hashids::encode($book->bid) . '&cid=' . $book->first_cid;
  203. $recent_read_reco_content .= "\n\n" . '<a href="' . $url . '"> ☞ 《' . $book_name . '》</a>';
  204. }
  205. }
  206. $feedback['text'] .= $recent_read_reco_content;
  207. } else {
  208. // 男频站点
  209. // 1本在测的,1本优质书,共2本,如果没有在测的书,则返回2本优质书
  210. // 用户按照15天注册后的用户
  211. $sex = ForceSubscribeService::getUserRealSexByUid($uid);
  212. [$bids, $test_bid] = BookConfig::getLeftRecomBids($uid, '男频', 2);
  213. \Log::info('bids and test_bid:' . $uid . ' data:' . json_encode([$bids, $test_bid]));
  214. if ($bids) {
  215. $recomm_books = BookService::getSimpleBooksByIds($bids);
  216. $recent_read_reco_content = '';
  217. if ($recomm_books) {
  218. // 判断是否不展示书名
  219. $self_config = ChannelService::check_channel_account_priv($distribution_channel_id, 'hide_book_name');
  220. $hide_type = isset($self_config->type) ? $self_config->type : 'not_hide';
  221. $recommend_titles = [];
  222. if ($hide_type == 'hide_book_name') {
  223. \Log::info('hide_book_name reco:' . $distribution_channel_id . ' uid:' . $uid);
  224. $recommend_titles = PromotionService::getRandomHeadline($sex, count($recomm_books));
  225. }
  226. $recent_read_reco_content .= "\n\n" . '热门书籍推荐~';
  227. foreach ($recomm_books as $key => $book) {
  228. $book_name = $book->name;
  229. if ($hide_type == 'hide_book_name') {
  230. $book_name = isset($recommend_titles[$key]->title) ? $recommend_titles[$key]->title : $book_name;
  231. }
  232. $url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/reader?bid=' . Hashids::encode($book->id) . '&cid=' . $book->first_cid;
  233. if ($book->id == $test_bid) {
  234. $url .= '&fromsource=smart_push';
  235. }
  236. $recent_read_reco_content .= "\n\n" . '<a href="' . $url . '"> ☞ 《' . $book_name . '》</a>';
  237. }
  238. }
  239. $feedback['text'] .= $recent_read_reco_content;
  240. }
  241. }
  242. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'recent_read');
  243. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  244. }
  245. $booksInfo = array();
  246. // 判断是否自定义关键字
  247. $special_keyword = WechatKeywordMsgs::wechatKeywordByDistributionChannelIdAndKeyword($distribution_channel_id, $content, 1);
  248. if (!empty($special_keyword)) {
  249. \Log::info('officialInteractiveEventFeedback_has_special_keyword:' . $distribution_channel_id . ' content:' . $content);
  250. \Log::info($special_keyword);
  251. // 图文模式(页面类型)
  252. if ($special_keyword['mode'] == 1 && $special_keyword['link_type'] == 'page') {
  253. if (isset($special_keyword['send_order_id']) && $special_keyword['send_order_id'] > 0) {
  254. $special_keyword['link'] .= '/yun/' . $special_keyword['send_order_id'];
  255. } else {
  256. $special_keyword['link'] .= '?fromtype=keyword_' . $special_keyword['id'];
  257. }
  258. $datatext['text'] = [
  259. [
  260. 'url' => $special_keyword['link'],
  261. 'title' => textDecode($special_keyword['send_title']),
  262. 'description' => textDecode($special_keyword['desc']),
  263. 'image' => $special_keyword['send_cover']
  264. ]
  265. ];
  266. $datatext['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $datatext['text'], 'text_search');
  267. return response()->success($datatext);
  268. }
  269. if ($special_keyword['mode'] == 2) {
  270. $nickname = DB::connection('api_mysql')->table('users')->where(['openid'=>$openid, 'distribution_channel_id'=>$distribution_channel_id])->value('nickname');
  271. $datatext['text'] = textDecode(str_replace('{user}', $nickname, $special_keyword['content']));
  272. $datatext['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $datatext['text'], 'text_search', 'keyword_' . $special_keyword['id']);
  273. return response()->success($datatext);
  274. }
  275. $bid = Hashids::decode($special_keyword['bid'])[0];
  276. \Log::info('bid:' . $bid);
  277. $book_conf = BookConfig::getBookById($bid);
  278. if (!empty($book_conf)) {
  279. $special_keyword_new = array();
  280. $special_keyword_new['book_name'] = isset($special_keyword['send_title']) && !empty($special_keyword['send_title']) ? textDecode($special_keyword['send_title']) : $book_conf['book_name'];
  281. $special_keyword_new['cover'] = isset($special_keyword['send_cover']) && !empty($special_keyword['send_cover']) ? $special_keyword['send_cover'] : $book_conf['cover'];
  282. \Log::info('keyword_book_name:' . $special_keyword_new['book_name'] . ' cover:' . $special_keyword_new['cover']);
  283. $special_keyword_new['intro'] = $book_conf['intro'];
  284. // 有派单id的关键字不做统计
  285. if (isset($special_keyword['send_order_id']) && $special_keyword['send_order_id'] > 0) {
  286. $special_keyword_new['book_url'] = '/yun/' . $special_keyword['send_order_id'];
  287. } else {
  288. $special_keyword_new['book_url'] = '/reader?bid=' . $special_keyword['bid'] . '&cid=' . $special_keyword['cid'] . '&fromtype=keyword_' . $special_keyword['id'] . '&source=wechatmsg';
  289. }
  290. $special_keyword_new['bid'] = $special_keyword['bid'];
  291. $booksInfo[] = $special_keyword_new;
  292. } else {
  293. \Log::info('book_conf_null:' . $distribution_channel_id . ' content:' . $content);
  294. }
  295. } else {
  296. $booksInfo = BookConfig::getBooksByKey($content, 1);
  297. try {
  298. if (count($booksInfo) == 0) {
  299. //$role_book = BookConfig::getFromRole($content);
  300. $role_book = BookConfigService::getBookByRole($content);
  301. if ($role_book) {
  302. $booksInfo[] = [
  303. 'book_name' => $role_book->book_name,
  304. 'intro' => '',
  305. 'cover' => $role_book->cover,
  306. 'bid' => $role_book->bid,
  307. 'book_url' => '/detail?id=' . Hashids::encode($role_book->bid),
  308. ];
  309. }
  310. }
  311. } catch (\Exception $e) {
  312. }
  313. }
  314. if (count($booksInfo) == 0) {
  315. if (preg_match('/^[0-9]+$/', $content)) {
  316. $channel_sex = ChannelService::getChannelCompanySex($distribution_channel_id);
  317. $feedback['text'] = "尊敬的会员:\n\n <a href='" . env('PROTOCOL') . "://site" . $encode_distribution_channel_id . "." . $WECHAT_CUSTOM_HOST . ".com/recent'>☞ 点我继续上次阅读 </a>";
  318. if ($channel_sex != 1) {
  319. //热门书籍推荐
  320. $sex = ForceSubscribeService::getUserRealSexByUid($uid);
  321. $channel_name = $sex == 1 ? '男频' : '女频';
  322. $recomm_books = BookConfigService::getSignRecommendBooksFromCache([], $channel_name, 2);
  323. $recent_read_reco_content = '';
  324. if ($recomm_books) {
  325. // 判断是否不展示书名
  326. $self_config = ChannelService::check_channel_account_priv($distribution_channel_id, 'hide_book_name');
  327. $hide_type = isset($self_config->type) ? $self_config->type : 'not_hide';
  328. $recommend_titles = [];
  329. if ($hide_type == 'hide_book_name') {
  330. \Log::info('hide_book_name reco:' . $distribution_channel_id . ' uid:' . $uid);
  331. $recommend_titles = PromotionService::getRandomHeadline($sex, count($recomm_books));
  332. }
  333. $recent_read_reco_content .= "\n\n" . '热门书籍推荐~';
  334. foreach ($recomm_books as $key => $book) {
  335. $book_name = $book->book_name;
  336. if ($hide_type == 'hide_book_name') {
  337. $book_name = isset($recommend_titles[$key]->title) ? $recommend_titles[$key]->title : $book->book_name;
  338. }
  339. $url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/reader?bid=' . Hashids::encode($book->bid) . '&cid=' . $book->first_cid;
  340. $recent_read_reco_content .= "\n\n" . '<a href="' . $url . '"> ☞ 《' . $book_name . '》</a>';
  341. }
  342. }
  343. $feedback['text'] .= $recent_read_reco_content;
  344. }
  345. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'recent_read');
  346. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  347. }
  348. $feedback['text'] = '未找到相关小说,' . "\n" . '您可以试试:' . "\n" . "\n" . '<a href="' . env('PROTOCOL') . '://site' . $encode_distribution_channel_id . '.' . $WECHAT_CUSTOM_HOST . '.com/recent">查看阅读记录 >> </a> ' . "\n" . "\n" . '<a href="' . env('PROTOCOL') . '://site' . $encode_distribution_channel_id . '.' . $WECHAT_CUSTOM_HOST . '.com">去书城首页看看 >> </a> ' . "\n" . "\n" . '点此<a href="https://help.wd.amanbook.com/?distribution_channel_id=' . encodeDistributionChannelId($distribution_channel_id) . '&down=1">联系客服</a>';
  349. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'text_search');
  350. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  351. } else {
  352. $data = [];
  353. for ($i = 0; $i < count($booksInfo); $i++) {
  354. $bid = $booksInfo[$i]['bid'];
  355. $base_url = env('PROTOCOL') . '://site' . $encode_distribution_channel_id . '.' . $WECHAT_CUSTOM_HOST . '.com' . $booksInfo[$i]['book_url'];
  356. $instro_len = strlen($booksInfo[$i]['intro']);
  357. \Log::info('wechat_log_info:len:' . $instro_len . ' getURL-----' . $base_url);
  358. if ($instro_len > 100) {
  359. $booksInfo[$i]['intro'] = mb_substr($booksInfo[$i]['intro'], 0, 100, 'utf-8');
  360. $booksInfo[$i]['intro'] .= '......';
  361. \Log::info('search_instro_too_long:' . $booksInfo[$i]['intro']);
  362. }
  363. $data[$i] = ['url' => $base_url,
  364. 'title' => textDecode($booksInfo[$i]['book_name']),
  365. 'description' => textDecode($booksInfo[$i]['intro']),
  366. 'image' => $booksInfo[$i]['cover']];
  367. // 返回一条
  368. break;
  369. }
  370. $datatext['text'] = $data;
  371. $datatext['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $datatext['text'], 'text_search');
  372. return response()->success($datatext);
  373. }
  374. } elseif ($event == "scan") {
  375. // 有自定义不回复内容的渠道
  376. $distribution_self_define_config = DistributionSelfDefineConfig::getDistributionSelfDefineConfig($distribution_channel_id, 'force_subscribe_noreply');
  377. if (!empty($distribution_self_define_config)) {
  378. \Log::info('distribution_self_define_config: distribution_channel_id:' . $distribution_channel_id);
  379. $feedback['text'] = "";
  380. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  381. }
  382. $feedback['text'] = "<a href='" . env('PROTOCOL') . "://site" . $encode_distribution_channel_id . "." . $WECHAT_CUSTOM_HOST . ".com/continue'>点此继续阅读 </a> ";
  383. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'scan');
  384. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  385. } elseif ($event == "click") {
  386. \Log::info('content:' . $content);
  387. if ($content == "contact_customer" && !empty($appid)) {
  388. if (config('common.click_type')) {
  389. # code...
  390. \Log::info('wechat_log_info:getURL-----进入方法');
  391. $mediaCustomer = MediaCustomer::mediaCustomerByAppid($appid);
  392. if (count($mediaCustomer) > 0) {
  393. # code...
  394. // $send_event_contents = array();
  395. for ($i = 0; $i < count($mediaCustomer); $i++) {
  396. # code...
  397. $send_event_content = array();
  398. $send_event_content['image'] = array('media_id' => $mediaCustomer[$i]['media_id']);
  399. // $send_event_content['text'] = 'test_zhoulj';
  400. return response()->success($send_event_content);
  401. // $send_event_contents[$i] = $send_event_content;
  402. }
  403. } else {
  404. $timestamp = (time());
  405. $gzh_app_id = $appid;
  406. $group_nick = env('GROUP_NICK');
  407. $officialAccountPrams['appid'] = $appid;
  408. $officialAccount = (object)OfficialAccountService::officialAccountByAppid($officialAccountPrams);
  409. \Log::info('++++++++++++=====GET CUSTOM IMG [1] =====+++++++++++++');
  410. if (!empty($officialAccount)) {
  411. $distributionChannelSetting = CustomMsgService::customerImgUrlByChannelId($officialAccount->distribution_channel_id);
  412. \Log::info('++++++++++++=====GET CUSTOM IMG [2] =====+++++++++++++');
  413. if (!empty($distributionChannelSetting)) {
  414. # code...
  415. $params = array("gzh_app_id" => $appid, "group_nick" => $group_nick, "is_default" => 0, "img_url" => $distributionChannelSetting['customer_img_url'], "timestamp" => $timestamp);
  416. $sign = get_sign($params);
  417. $mediaCustomerJson = '';
  418. try {
  419. $mediaCustomerJson = $this->getUserClient()->request("GET", "upload_gzh_img/",
  420. ['query' => ['gzh_app_id' => $appid, 'group_nick' => env('GROUP_NICK'), "is_default" => 0, "img_url" => $distributionChannelSetting['customer_img_url'], 'timestamp' => $timestamp, 'sign' => $sign], 'connect_timeout' => 3]
  421. )->getBody()->getContents();
  422. } catch (\Exception $e) {
  423. \Log::info('++++++++++++=====GET CUSTOM IMG [0] =====+++++++++++++');
  424. }
  425. $mediaCustomerArray = json_decode($mediaCustomerJson, true);
  426. \Log::info('++++++++++++=====GET CUSTOM IMG [3] =====+++++++++++++');
  427. \Log::info($mediaCustomerArray);
  428. // \Log($mediaCustomerArray);
  429. // dd($mediaCustomerArray);
  430. if ($mediaCustomerArray['code'] == 1) {
  431. # code...
  432. $mediaCustomerData = $mediaCustomerArray['data'];
  433. if (empty($mediaCustomerDat)) {
  434. # code...
  435. $mediaCustomerCreate['media_id'] = $mediaCustomerData['media_id'];
  436. $mediaCustomerCreate['url'] = $mediaCustomerData['url'];
  437. $mediaCustomerCreate['appid'] = $appid;
  438. $mediaCustomerCreate['distribution_channel_id'] = $officialAccount->distribution_channel_id;
  439. MediaCustomer::create($mediaCustomerCreate);
  440. $send_event_content = array();
  441. $send_event_content['image'] = array('media_id' => $mediaCustomerData['media_id']);
  442. // $send_event_content['text'] = 'test_zhoulj';
  443. return response()->success($send_event_content);
  444. }
  445. } else {
  446. $feedback['text'] = env('CUSTOM_RETURN_MSG');
  447. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  448. }
  449. } else {
  450. $params = array("gzh_app_id" => $appid, "group_nick" => $group_nick, "timestamp" => $timestamp);
  451. $sign = get_sign($params);
  452. \Log::info('wechat_log_info:getURL-----' . env('MEDIA_API_BASE_URI'));
  453. \Log::info('wechat_log_info:getURL-----' . $gzh_app_id . '___' . $timestamp . '___' . $sign);
  454. $mediaCustomerJson = '';
  455. try {
  456. $mediaCustomerJson = $this->getUserClient()->request("GET", "upload_gzh_img/",
  457. ['query' => ['gzh_app_id' => $appid, 'group_nick' => env('GROUP_NICK'), 'timestamp' => $timestamp, 'sign' => $sign], 'connect_timeout' => 3]
  458. )->getBody()->getContents();
  459. } catch (\Exception $e) {
  460. \Log::info('wechat_log_info:Exception-----' . $e->getMessage());
  461. }
  462. \Log::info('wechat_log_info:getURL-----' . env('MEDIA_API_BASE_URI'));
  463. $mediaCustomerArray = json_decode($mediaCustomerJson, true);
  464. // \Log($mediaCustomerArray);
  465. // dd($mediaCustomerArray);
  466. if ($mediaCustomerArray['code'] == 1) {
  467. # code...
  468. $mediaCustomerData = $mediaCustomerArray['data'];
  469. if (empty($mediaCustomerDat)) {
  470. # code...
  471. $mediaCustomerCreate['media_id'] = $mediaCustomerData['media_id'];
  472. $mediaCustomerCreate['url'] = $mediaCustomerData['url'];
  473. $mediaCustomerCreate['appid'] = $appid;
  474. $mediaCustomerCreate['distribution_channel_id'] = $officialAccount->distribution_channel_id;
  475. MediaCustomer::create($mediaCustomerCreate);
  476. $send_event_content = array();
  477. $send_event_content['image'] = array('media_id' => $mediaCustomerData['media_id']);
  478. // $send_event_content['text'] = 'test_zhoulj';
  479. return response()->success($send_event_content);
  480. }
  481. } else {
  482. $feedback['text'] = env('CUSTOM_RETURN_MSG');
  483. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  484. }
  485. }
  486. }
  487. }
  488. } else {
  489. $feedback['text'] = env('CUSTOM_RETURN_MSG');
  490. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  491. }
  492. } elseif ($content == "daily_sign" && !empty($openid)) {
  493. //强关信息
  494. $user = ForceSubscribeUsers::getOneForceSubscribeUsersByOpenid($openid);
  495. if (!$user) {
  496. $feedback['text'] = "亲爱的用户,本次签到最高可领取150书币哦\n\n/:heart".'<a href="weixin://bizmsgmenu?msgmenucontent=签到&msgmenuid=hudonglian">点击此处签到领书币</a>';
  497. }else {
  498. //用户信息
  499. $user_info = User::where('id',$user->uid)->first();
  500. if ($user_info && !empty($user_info->nickname)) {
  501. $feedback['text'] = '亲爱的'.$user_info->nickname.",本次签到最高可领取150书币哦\n\n/:heart".'<a href="weixin://bizmsgmenu?msgmenucontent=签到&msgmenuid=hudonglian">点击此处签到领书币</a>';
  502. }else {
  503. $feedback['text'] = "亲爱的用户,本次签到最高可领取150书币哦\n\n/:heart".'<a href="weixin://bizmsgmenu?msgmenucontent=签到&msgmenuid=hudonglian">点击此处签到领书币</a>';
  504. }
  505. }
  506. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  507. //调洋哥的接口发送签到客服消息
  508. \Log::info('========================进入洋哥签到回调');
  509. try {
  510. $feedback['text'] = UserSignService::userSignReturnContent3($openid, $distribution_channel_id, $WECHAT_CUSTOM_HOST);
  511. } catch (\Exception $e) {
  512. \Log::error('sign_activity_error:');
  513. \Log::error($e);
  514. }
  515. $top_url = OfficialAccountService::getTopUrl($officialAccount->service_type_info);
  516. if ($officialAccount->service_type_info == 1) {
  517. $top_content = "\n\n" . '为方便阅读,请<a href="' . $top_url . '">设为星标</a>';
  518. } else {
  519. $top_content = "\n\n" . '为方便阅读,请<a href="' . $top_url . '">置顶公众号</a>';
  520. }
  521. $feedback['text'] .= $top_content;
  522. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'daily_sign');
  523. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  524. } elseif ($content == "recent_read" && !empty($openid)) {
  525. $feedback['text'] = '欢迎回来,<a href="weixin://bizmsgmenu?msgmenucontent=最近阅读&msgmenuid=hudonglian">点此继续阅读~</a>';
  526. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  527. // $channel_sex = ChannelService::getChannelCompanySex($distribution_channel_id);
  528. $channelInfo = ChannelService::getById($distribution_channel_id);
  529. $property = isset($channelInfo->property) ? $channelInfo->property : '';
  530. $channel_sex = 3;
  531. if ($property === ChannelConst::PROPERTY_MALE) {
  532. $channel_sex = 1;
  533. }
  534. if ($property === ChannelConst::PROPERTY_FEMALE) {
  535. $channel_sex = 2;
  536. }
  537. \Log::info('channel_sex:' . $channel_sex . ' distribution_channel_id:' . $distribution_channel_id . ' property:' . $property);
  538. $feedback['text'] = "尊敬的会员:\n\n <a href='" . env('PROTOCOL') . "://site" . $encode_distribution_channel_id . "." . $WECHAT_CUSTOM_HOST . ".com/recent'>☞ 点我继续上次阅读 </a>";
  539. if ($channel_sex != 1) {
  540. // 根据用户性别确定男女频
  541. $sex = ForceSubscribeService::getUserRealSexByUid($uid);
  542. $channel_name = $sex == 1 ? '男频' : '女频';
  543. // 站点属性优先
  544. if ($channel_sex == 2) {
  545. $channel_name = '女频';
  546. }
  547. $recomm_books = BookConfigService::getSignRecommendBooksFromCache([], $channel_name, 2);
  548. $recent_read_reco_content = '';
  549. if ($recomm_books) {
  550. // 判断是否不展示书名
  551. $self_config = ChannelService::check_channel_account_priv($distribution_channel_id, 'hide_book_name');
  552. $hide_type = isset($self_config->type) ? $self_config->type : 'not_hide';
  553. $recommend_titles = [];
  554. if ($hide_type == 'hide_book_name') {
  555. \Log::info('hide_book_name reco:' . $distribution_channel_id . ' uid:' . $uid);
  556. $recommend_titles = PromotionService::getRandomHeadline($sex, count($recomm_books));
  557. }
  558. $recent_read_reco_content .= "\n\n" . '热门书籍推荐~';
  559. foreach ($recomm_books as $key => $book) {
  560. $book_name = $book->book_name;
  561. if ($hide_type == 'hide_book_name') {
  562. $book_name = isset($recommend_titles[$key]->title) ? $recommend_titles[$key]->title : $book->book_name;
  563. }
  564. $url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/reader?bid=' . Hashids::encode($book->bid) . '&cid=' . $book->first_cid;
  565. $recent_read_reco_content .= "\n\n" . '<a href="' . $url . '"> ☞ 《' . $book_name . '》</a>';
  566. }
  567. }
  568. $feedback['text'] .= $recent_read_reco_content;
  569. } else {
  570. // 男频站点
  571. // 1本在测的,1本优质书,共2本,如果没有在测的书,则返回2本优质书
  572. // 用户按照15天注册后的用户
  573. $sex = ForceSubscribeService::getUserRealSexByUid($uid);
  574. [$bids, $test_bid] = BookConfig::getLeftRecomBids($uid, '男频', 2);
  575. \Log::info('bids and test_bid:' . $uid . ' data:' . json_encode([$bids, $test_bid]));
  576. if ($bids) {
  577. $recomm_books = BookService::getSimpleBooksByIds($bids);
  578. $recent_read_reco_content = '';
  579. if ($recomm_books) {
  580. // 判断是否不展示书名
  581. $self_config = ChannelService::check_channel_account_priv($distribution_channel_id, 'hide_book_name');
  582. $hide_type = isset($self_config->type) ? $self_config->type : 'not_hide';
  583. $recommend_titles = [];
  584. if ($hide_type == 'hide_book_name') {
  585. \Log::info('hide_book_name reco:' . $distribution_channel_id . ' uid:' . $uid);
  586. $recommend_titles = PromotionService::getRandomHeadline($sex, count($recomm_books));
  587. }
  588. $recent_read_reco_content .= "\n\n" . '热门书籍推荐~';
  589. foreach ($recomm_books as $key => $book) {
  590. $book_name = $book->name;
  591. if ($hide_type == 'hide_book_name') {
  592. $book_name = isset($recommend_titles[$key]->title) ? $recommend_titles[$key]->title : $book_name;
  593. }
  594. $url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/reader?bid=' . Hashids::encode($book->id) . '&cid=' . $book->first_cid;
  595. if ($book->id == $test_bid) {
  596. $url .= '&fromsource=smart_push';
  597. }
  598. $recent_read_reco_content .= "\n\n" . '<a href="' . $url . '"> ☞ 《' . $book_name . '》</a>';
  599. }
  600. }
  601. $feedback['text'] .= $recent_read_reco_content;
  602. }
  603. }
  604. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'recent_read');
  605. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  606. } // 个别渠道是事件
  607. elseif ($content == "user_center" && !empty($openid)) {
  608. \Log::info('click_user_center:' . $openid);
  609. $feedback['text'] = "☞ <a href='" . $base_url . "/person'>个人中心</a>\n\n";
  610. $feedback['text'] .= "☞ <a href='" . $base_url . "/'>书城首页</a>\n\n";
  611. $feedback['text'] .= "☞ <a href='" . $base_url . "/pay'>优惠充值</a>\n\n";
  612. $feedback['text'] .= "☞ <a href='" . $help_url . "'>帮助中心</a>\n";
  613. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'user_center');
  614. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  615. } elseif ($content == "qrcode_main" && !empty($openid)) {
  616. $msg = OfficialAccountMsgService::getEventMsg(['appid' => $appid, 'apply_event' => 'click', 'apply_event_key' => 'qrcode_main']);
  617. if ($msg) {
  618. $send_event_content = array();
  619. $send_event_content['image'] = array('media_id' => $msg->return_content);
  620. return response()->success($send_event_content);
  621. } else {
  622. $feedback['text'] = '配置有误';
  623. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  624. }
  625. }
  626. } elseif ($event == "unsubscribe") {
  627. $feedback['text'] = "";
  628. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  629. } elseif ($event == "subscribe") {
  630. // 统计
  631. $sub_statistic_key = 'gzh_actual_sub:' . $appid . ':' . date('Y-m-d');
  632. \Log::info('sub_statistic_key:' . $sub_statistic_key);
  633. Redis::sadd($sub_statistic_key, $openid);
  634. Redis::expire($sub_statistic_key, 30 * 3600);
  635. // 有自定义不回复内容的渠道
  636. $distribution_self_define_config = DistributionSelfDefineConfig::getDistributionSelfDefineConfig($distribution_channel_id, 'force_subscribe_noreply');
  637. if (!empty($distribution_self_define_config)) {
  638. \Log::info('distribution_self_define_config: distribution_channel_id:' . $distribution_channel_id);
  639. $feedback['text'] = "";
  640. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  641. }
  642. if (!empty($openid)) {
  643. # code...
  644. \Log::info('subscribe:' . $openid . ' distribution_channel_id:' . $distribution_channel_id);
  645. $params['openid'] = $openid;
  646. $forceSubscribeUser = ForceSubscribeService::forceSubscribeUsersByOpenid($params);
  647. \Log::info($forceSubscribeUser);
  648. // 有自定义回复内容的渠道
  649. // $distribution_self_define_content = DistributionSelfDefineContent::getDistributionSelfDefineContent($distribution_channel_id);
  650. // 从redis取
  651. $distribution_self_define_content = MsgService::getCurrentReply($distribution_channel_id);
  652. // 判断渠道,如果是场景值关注过来的,则普通回复,否则自定义回复
  653. $subscribe_from_scene = DistributionSelfDefineConfig::getDistributionSelfDefineConfig($distribution_channel_id, 'subscribe_from_scene');
  654. if (!empty($subscribe_from_scene)) {
  655. if (!empty($content) && strpos($content, 'qrscene_') === 0) {
  656. $distribution_self_define_content = null;
  657. \Log::info('subscribe_from_scene:' . $distribution_channel_id);
  658. }
  659. }
  660. if (is_null($distribution_self_define_content)) {
  661. $recommend_content = '';
  662. if (!empty($forceSubscribeUser)) {
  663. # code...
  664. \Log::info('exist_force_user:' . $openid);
  665. //通过uid获取该用户最近阅读记录的书籍
  666. $uid = isset($forceSubscribeUser->uid) ? $forceSubscribeUser->uid : '';
  667. $userBook = ReadRecordService::getFirstReadRecord($uid);
  668. $bookName = isset($userBook['book_name']) ? $userBook['book_name'] : '最近阅读';
  669. \Log::info('bookName:' . $bookName);
  670. if (!empty($recommend_content)) {
  671. $feedback['text'] = '亲,终于等到你了!' . "\n" . "\n" . '<a href="' . env('PROTOCOL') . '://site' . $encode_distribution_channel_id . '.' . $WECHAT_CUSTOM_HOST . '.com/continue">点我继续阅读 </a> ' . "\n" . "\n" . '阅读记录:' . "\n" . "\n" . '><a href="' . env('PROTOCOL') . '://site' . $encode_distribution_channel_id . '.' . $WECHAT_CUSTOM_HOST . '.com/continue">' . $bookName . '</a>';
  672. $feedback['text'] .= $recommend_content;
  673. $feedback['text'] .= "\n" . "\n" . '为方便下次阅读,请' . '<a href="https://help.leyuee.com/top.html">' . '置顶公众号' . '</a>';
  674. } else {
  675. $feedback['text'] = '亲,终于等到你了!' . "\n" . "\n" . '<a href="' . env('PROTOCOL') . '://site' . $encode_distribution_channel_id . '.' . $WECHAT_CUSTOM_HOST . '.com/continue">点我继续阅读 </a> ' . "\n" . "\n" . '阅读记录:' . "\n" . "\n" . '><a href="' . env('PROTOCOL') . '://site' . $encode_distribution_channel_id . '.' . $WECHAT_CUSTOM_HOST . '.com/continue">' . $bookName . '</a>' . "\n" . "\n" . '为方便下次阅读,请' . '<a href="https://help.leyuee.com/top.html">' . '置顶公众号' . '</a>' . "\n\n" . '今日签到成功,赠送30书币,连续签到2日后,赠送书币增加至50哦~,进入<a href="' . env('PROTOCOL') . '://site' . $encode_distribution_channel_id . '.' . $WECHAT_CUSTOM_HOST . '.com/person">个人中心 </a>查看!' . "\n\n" . '明日继续签到得书币哦!';
  676. }
  677. } else {
  678. $feedback['text'] = "<a href='" . env('PROTOCOL') . "://site" . $encode_distribution_channel_id . "." . $WECHAT_CUSTOM_HOST . ".com/continue'>点击继续阅读 </a> ";
  679. $feedback['text'] .= $recommend_content;
  680. }
  681. // 外站关注的直接回复图文qrscene_outer:123_12
  682. if (strpos($content, 'outer') > -1) {
  683. $scene_content = str_replace('qrscene_outer:', '', $content);
  684. $bid_cid = explode('_', $scene_content);
  685. $bid = isset($bid_cid[0]) ? $bid_cid[0] : '';
  686. $cid = isset($bid_cid[1]) ? $bid_cid[1] : '';
  687. if (!empty($bid) && !empty($cid)) {
  688. $book_conf = BookConfig::getBookById($bid);
  689. \Log::info('out_book_conf');
  690. \Log::info($book_conf);
  691. if (!empty($book_conf)) {
  692. $data = array();
  693. $encode_bid = Hashids::encode($bid);
  694. $data[] = ['url' => env('PROTOCOL') . '://site' . $encode_distribution_channel_id . '.' . $WECHAT_CUSTOM_HOST . '.com' . '/reader?bid=' . $encode_bid . '&cid=' . $cid . '&fromtype=outer_' . $scene_content,
  695. 'title' => $book_conf['book_name'],
  696. 'description' => $book_conf['intro'],
  697. 'image' => $book_conf['cover']
  698. ];
  699. \Log::info('outer:' . json_encode($data));
  700. $feedback['text'] = $data;
  701. }
  702. }
  703. }
  704. } else {
  705. // 判断是否图文
  706. if (isset($distribution_self_define_content->is_pic) && $distribution_self_define_content->is_pic) {
  707. $feedback['text'] = ImageNewsToArray($distribution_self_define_content->content);
  708. } else {
  709. $feedback['text'] = isset($distribution_self_define_content->content) ? $distribution_self_define_content->content : '';
  710. }
  711. }
  712. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'subscribe');
  713. // 判断是否有关注回复第二条,有则推送
  714. MsgService::pushChannelCurrentSecondReply($distribution_channel_id, $appid, $openid, 'subscribe_second_reply');
  715. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  716. } else {
  717. $feedback['text'] = "<a href='" . env('PROTOCOL') . "://site" . $encode_distribution_channel_id . "." . $WECHAT_CUSTOM_HOST . ".com/continue'>点击继续阅读 </a> ";
  718. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'subscribe');
  719. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  720. }
  721. } elseif ($event == "TEMPLATESENDJOBFINISH") {
  722. $feedback['text'] = "";
  723. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  724. } else {
  725. return response()->error('EVENT_NOT_FOUND');
  726. }
  727. }
  728. public function getUserClient()
  729. {
  730. return new Client(['base_uri' => env('MEDIA_API_BASE_URI')]);
  731. }
  732. }