OfficialInteractiveEventController.php 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  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. if(strpos($special_keyword['link'],'?') > -1){
  257. $special_keyword['link'] .= '&fromtype=keyword_' . $special_keyword['id'];
  258. }else {
  259. $special_keyword['link'] .= '?fromtype=keyword_' . $special_keyword['id'];
  260. }
  261. }
  262. $datatext['text'] = [
  263. [
  264. 'url' => $special_keyword['link'],
  265. 'title' => textDecode($special_keyword['send_title']),
  266. 'description' => textDecode($special_keyword['desc']),
  267. 'image' => $special_keyword['send_cover']
  268. ]
  269. ];
  270. $datatext['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $datatext['text'], 'text_search');
  271. return response()->success($datatext);
  272. }
  273. if ($special_keyword['mode'] == 2) {
  274. $nickname = DB::connection('api_mysql')->table('temp_force_subscribe_users')->leftjoin('users', 'users.id', '=', 'temp_force_subscribe_users.uid')->where(['temp_force_subscribe_users.openid'=>$openid, 'temp_force_subscribe_users.distribution_channel_id'=>$distribution_channel_id])->value('users.nickname');
  275. $datatext['text'] = textDecode(str_replace('{user}', $nickname, $special_keyword['content']));
  276. $datatext['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $datatext['text'], 'text_search', 'keyword_' . $special_keyword['id']);
  277. return response()->success($datatext);
  278. }
  279. $bid = Hashids::decode($special_keyword['bid'])[0];
  280. \Log::info('bid:' . $bid);
  281. $book_conf = BookConfig::getBookById($bid);
  282. if (!empty($book_conf)) {
  283. $special_keyword_new = array();
  284. $special_keyword_new['book_name'] = isset($special_keyword['send_title']) && !empty($special_keyword['send_title']) ? textDecode($special_keyword['send_title']) : $book_conf['book_name'];
  285. $special_keyword_new['cover'] = isset($special_keyword['send_cover']) && !empty($special_keyword['send_cover']) ? $special_keyword['send_cover'] : $book_conf['cover'];
  286. \Log::info('keyword_book_name:' . $special_keyword_new['book_name'] . ' cover:' . $special_keyword_new['cover']);
  287. $special_keyword_new['intro'] = $book_conf['intro'];
  288. // 有派单id的关键字不做统计
  289. if (isset($special_keyword['send_order_id']) && $special_keyword['send_order_id'] > 0) {
  290. $special_keyword_new['book_url'] = '/yun/' . $special_keyword['send_order_id'];
  291. } else {
  292. $special_keyword_new['book_url'] = '/reader?bid=' . $special_keyword['bid'] . '&cid=' . $special_keyword['cid'] . '&fromtype=keyword_' . $special_keyword['id'] . '&source=wechatmsg';
  293. }
  294. $special_keyword_new['bid'] = $special_keyword['bid'];
  295. $booksInfo[] = $special_keyword_new;
  296. } else {
  297. \Log::info('book_conf_null:' . $distribution_channel_id . ' content:' . $content);
  298. }
  299. } else {
  300. $booksInfo = BookConfig::getBooksByKey($content, 1);
  301. try {
  302. if (count($booksInfo) == 0) {
  303. //$role_book = BookConfig::getFromRole($content);
  304. $role_book = BookConfigService::getBookByRole($content);
  305. if ($role_book) {
  306. $booksInfo[] = [
  307. 'book_name' => $role_book->book_name,
  308. 'intro' => '',
  309. 'cover' => $role_book->cover,
  310. 'bid' => $role_book->bid,
  311. 'book_url' => '/detail?id=' . Hashids::encode($role_book->bid),
  312. ];
  313. }
  314. }
  315. } catch (\Exception $e) {
  316. }
  317. }
  318. if (count($booksInfo) == 0) {
  319. if (preg_match('/^[0-9]+$/', $content)) {
  320. $channel_sex = ChannelService::getChannelCompanySex($distribution_channel_id);
  321. $feedback['text'] = "尊敬的会员:\n\n <a href='" . env('PROTOCOL') . "://site" . $encode_distribution_channel_id . "." . $WECHAT_CUSTOM_HOST . ".com/recent'>☞ 点我继续上次阅读 </a>";
  322. if ($channel_sex != 1) {
  323. //热门书籍推荐
  324. $sex = ForceSubscribeService::getUserRealSexByUid($uid);
  325. $channel_name = $sex == 1 ? '男频' : '女频';
  326. $recomm_books = BookConfigService::getSignRecommendBooksFromCache([], $channel_name, 2);
  327. $recent_read_reco_content = '';
  328. if ($recomm_books) {
  329. // 判断是否不展示书名
  330. $self_config = ChannelService::check_channel_account_priv($distribution_channel_id, 'hide_book_name');
  331. $hide_type = isset($self_config->type) ? $self_config->type : 'not_hide';
  332. $recommend_titles = [];
  333. if ($hide_type == 'hide_book_name') {
  334. \Log::info('hide_book_name reco:' . $distribution_channel_id . ' uid:' . $uid);
  335. $recommend_titles = PromotionService::getRandomHeadline($sex, count($recomm_books));
  336. }
  337. $recent_read_reco_content .= "\n\n" . '热门书籍推荐~';
  338. foreach ($recomm_books as $key => $book) {
  339. $book_name = $book->book_name;
  340. if ($hide_type == 'hide_book_name') {
  341. $book_name = isset($recommend_titles[$key]->title) ? $recommend_titles[$key]->title : $book->book_name;
  342. }
  343. $url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/reader?bid=' . Hashids::encode($book->bid) . '&cid=' . $book->first_cid;
  344. $recent_read_reco_content .= "\n\n" . '<a href="' . $url . '"> ☞ 《' . $book_name . '》</a>';
  345. }
  346. }
  347. $feedback['text'] .= $recent_read_reco_content;
  348. }
  349. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'recent_read');
  350. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  351. }
  352. $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>';
  353. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'text_search');
  354. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  355. } else {
  356. $data = [];
  357. for ($i = 0; $i < count($booksInfo); $i++) {
  358. $bid = $booksInfo[$i]['bid'];
  359. $base_url = env('PROTOCOL') . '://site' . $encode_distribution_channel_id . '.' . $WECHAT_CUSTOM_HOST . '.com' . $booksInfo[$i]['book_url'];
  360. $instro_len = strlen($booksInfo[$i]['intro']);
  361. \Log::info('wechat_log_info:len:' . $instro_len . ' getURL-----' . $base_url);
  362. if ($instro_len > 100) {
  363. $booksInfo[$i]['intro'] = mb_substr($booksInfo[$i]['intro'], 0, 100, 'utf-8');
  364. $booksInfo[$i]['intro'] .= '......';
  365. \Log::info('search_instro_too_long:' . $booksInfo[$i]['intro']);
  366. }
  367. $data[$i] = ['url' => $base_url,
  368. 'title' => textDecode($booksInfo[$i]['book_name']),
  369. 'description' => textDecode($booksInfo[$i]['intro']),
  370. 'image' => $booksInfo[$i]['cover']];
  371. // 返回一条
  372. break;
  373. }
  374. $datatext['text'] = $data;
  375. $datatext['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $datatext['text'], 'text_search');
  376. return response()->success($datatext);
  377. }
  378. } elseif ($event == "scan") {
  379. // 有自定义不回复内容的渠道
  380. $distribution_self_define_config = DistributionSelfDefineConfig::getDistributionSelfDefineConfig($distribution_channel_id, 'force_subscribe_noreply');
  381. if (!empty($distribution_self_define_config)) {
  382. \Log::info('distribution_self_define_config: distribution_channel_id:' . $distribution_channel_id);
  383. $feedback['text'] = "";
  384. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  385. }
  386. $feedback['text'] = "<a href='" . env('PROTOCOL') . "://site" . $encode_distribution_channel_id . "." . $WECHAT_CUSTOM_HOST . ".com/continue'>点此继续阅读 </a> ";
  387. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'scan');
  388. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  389. } elseif ($event == "click") {
  390. \Log::info('content:' . $content);
  391. if ($content == "contact_customer" && !empty($appid)) {
  392. if (config('common.click_type')) {
  393. # code...
  394. \Log::info('wechat_log_info:getURL-----进入方法');
  395. $mediaCustomer = MediaCustomer::mediaCustomerByAppid($appid);
  396. if (count($mediaCustomer) > 0) {
  397. # code...
  398. // $send_event_contents = array();
  399. for ($i = 0; $i < count($mediaCustomer); $i++) {
  400. # code...
  401. $send_event_content = array();
  402. $send_event_content['image'] = array('media_id' => $mediaCustomer[$i]['media_id']);
  403. // $send_event_content['text'] = 'test_zhoulj';
  404. return response()->success($send_event_content);
  405. // $send_event_contents[$i] = $send_event_content;
  406. }
  407. } else {
  408. $timestamp = (time());
  409. $gzh_app_id = $appid;
  410. $group_nick = env('GROUP_NICK');
  411. $officialAccountPrams['appid'] = $appid;
  412. $officialAccount = (object)OfficialAccountService::officialAccountByAppid($officialAccountPrams);
  413. \Log::info('++++++++++++=====GET CUSTOM IMG [1] =====+++++++++++++');
  414. if (!empty($officialAccount)) {
  415. $distributionChannelSetting = CustomMsgService::customerImgUrlByChannelId($officialAccount->distribution_channel_id);
  416. \Log::info('++++++++++++=====GET CUSTOM IMG [2] =====+++++++++++++');
  417. if (!empty($distributionChannelSetting)) {
  418. # code...
  419. $params = array("gzh_app_id" => $appid, "group_nick" => $group_nick, "is_default" => 0, "img_url" => $distributionChannelSetting['customer_img_url'], "timestamp" => $timestamp);
  420. $sign = get_sign($params);
  421. $mediaCustomerJson = '';
  422. try {
  423. $mediaCustomerJson = $this->getUserClient()->request("GET", "upload_gzh_img/",
  424. ['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]
  425. )->getBody()->getContents();
  426. } catch (\Exception $e) {
  427. \Log::info('++++++++++++=====GET CUSTOM IMG [0] =====+++++++++++++');
  428. }
  429. $mediaCustomerArray = json_decode($mediaCustomerJson, true);
  430. \Log::info('++++++++++++=====GET CUSTOM IMG [3] =====+++++++++++++');
  431. \Log::info($mediaCustomerArray);
  432. // \Log($mediaCustomerArray);
  433. // dd($mediaCustomerArray);
  434. if ($mediaCustomerArray['code'] == 1) {
  435. # code...
  436. $mediaCustomerData = $mediaCustomerArray['data'];
  437. if (empty($mediaCustomerDat)) {
  438. # code...
  439. $mediaCustomerCreate['media_id'] = $mediaCustomerData['media_id'];
  440. $mediaCustomerCreate['url'] = $mediaCustomerData['url'];
  441. $mediaCustomerCreate['appid'] = $appid;
  442. $mediaCustomerCreate['distribution_channel_id'] = $officialAccount->distribution_channel_id;
  443. MediaCustomer::create($mediaCustomerCreate);
  444. $send_event_content = array();
  445. $send_event_content['image'] = array('media_id' => $mediaCustomerData['media_id']);
  446. // $send_event_content['text'] = 'test_zhoulj';
  447. return response()->success($send_event_content);
  448. }
  449. } else {
  450. $feedback['text'] = env('CUSTOM_RETURN_MSG');
  451. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  452. }
  453. } else {
  454. $params = array("gzh_app_id" => $appid, "group_nick" => $group_nick, "timestamp" => $timestamp);
  455. $sign = get_sign($params);
  456. \Log::info('wechat_log_info:getURL-----' . env('MEDIA_API_BASE_URI'));
  457. \Log::info('wechat_log_info:getURL-----' . $gzh_app_id . '___' . $timestamp . '___' . $sign);
  458. $mediaCustomerJson = '';
  459. try {
  460. $mediaCustomerJson = $this->getUserClient()->request("GET", "upload_gzh_img/",
  461. ['query' => ['gzh_app_id' => $appid, 'group_nick' => env('GROUP_NICK'), 'timestamp' => $timestamp, 'sign' => $sign], 'connect_timeout' => 3]
  462. )->getBody()->getContents();
  463. } catch (\Exception $e) {
  464. \Log::info('wechat_log_info:Exception-----' . $e->getMessage());
  465. }
  466. \Log::info('wechat_log_info:getURL-----' . env('MEDIA_API_BASE_URI'));
  467. $mediaCustomerArray = json_decode($mediaCustomerJson, true);
  468. // \Log($mediaCustomerArray);
  469. // dd($mediaCustomerArray);
  470. if ($mediaCustomerArray['code'] == 1) {
  471. # code...
  472. $mediaCustomerData = $mediaCustomerArray['data'];
  473. if (empty($mediaCustomerDat)) {
  474. # code...
  475. $mediaCustomerCreate['media_id'] = $mediaCustomerData['media_id'];
  476. $mediaCustomerCreate['url'] = $mediaCustomerData['url'];
  477. $mediaCustomerCreate['appid'] = $appid;
  478. $mediaCustomerCreate['distribution_channel_id'] = $officialAccount->distribution_channel_id;
  479. MediaCustomer::create($mediaCustomerCreate);
  480. $send_event_content = array();
  481. $send_event_content['image'] = array('media_id' => $mediaCustomerData['media_id']);
  482. // $send_event_content['text'] = 'test_zhoulj';
  483. return response()->success($send_event_content);
  484. }
  485. } else {
  486. $feedback['text'] = env('CUSTOM_RETURN_MSG');
  487. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  488. }
  489. }
  490. }
  491. }
  492. } else {
  493. $feedback['text'] = env('CUSTOM_RETURN_MSG');
  494. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  495. }
  496. } elseif ($content == "daily_sign" && !empty($openid)) {
  497. //强关信息
  498. $user = ForceSubscribeUsers::getOneForceSubscribeUsersByOpenid($openid);
  499. if (!$user) {
  500. $feedback['text'] = "亲爱的用户,本次签到最高可领取150书币哦\n\n/:heart".'<a href="weixin://bizmsgmenu?msgmenucontent=签到&msgmenuid=hudonglian">点击此处签到领书币</a>';
  501. }else {
  502. //用户信息
  503. $user_info = User::where('id',$user->uid)->first();
  504. if ($user_info && !empty($user_info->nickname)) {
  505. $feedback['text'] = '亲爱的'.$user_info->nickname.",本次签到最高可领取150书币哦\n\n/:heart".'<a href="weixin://bizmsgmenu?msgmenucontent=签到&msgmenuid=hudonglian">点击此处签到领书币</a>';
  506. }else {
  507. $feedback['text'] = "亲爱的用户,本次签到最高可领取150书币哦\n\n/:heart".'<a href="weixin://bizmsgmenu?msgmenucontent=签到&msgmenuid=hudonglian">点击此处签到领书币</a>';
  508. }
  509. }
  510. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  511. //调洋哥的接口发送签到客服消息
  512. \Log::info('========================进入洋哥签到回调');
  513. try {
  514. $feedback['text'] = UserSignService::userSignReturnContent3($openid, $distribution_channel_id, $WECHAT_CUSTOM_HOST);
  515. } catch (\Exception $e) {
  516. \Log::error('sign_activity_error:');
  517. \Log::error($e);
  518. }
  519. $top_url = OfficialAccountService::getTopUrl($officialAccount->service_type_info);
  520. if ($officialAccount->service_type_info == 1) {
  521. $top_content = "\n\n" . '为方便阅读,请<a href="' . $top_url . '">设为星标</a>';
  522. } else {
  523. $top_content = "\n\n" . '为方便阅读,请<a href="' . $top_url . '">置顶公众号</a>';
  524. }
  525. $feedback['text'] .= $top_content;
  526. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'daily_sign');
  527. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  528. } elseif ($content == "recent_read" && !empty($openid)) {
  529. $feedback['text'] = '欢迎回来,<a href="weixin://bizmsgmenu?msgmenucontent=最近阅读&msgmenuid=hudonglian">点此继续阅读~</a>';
  530. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  531. // $channel_sex = ChannelService::getChannelCompanySex($distribution_channel_id);
  532. $channelInfo = ChannelService::getById($distribution_channel_id);
  533. $property = isset($channelInfo->property) ? $channelInfo->property : '';
  534. $channel_sex = 3;
  535. if ($property === ChannelConst::PROPERTY_MALE) {
  536. $channel_sex = 1;
  537. }
  538. if ($property === ChannelConst::PROPERTY_FEMALE) {
  539. $channel_sex = 2;
  540. }
  541. \Log::info('channel_sex:' . $channel_sex . ' distribution_channel_id:' . $distribution_channel_id . ' property:' . $property);
  542. $feedback['text'] = "尊敬的会员:\n\n <a href='" . env('PROTOCOL') . "://site" . $encode_distribution_channel_id . "." . $WECHAT_CUSTOM_HOST . ".com/recent'>☞ 点我继续上次阅读 </a>";
  543. if ($channel_sex != 1) {
  544. // 根据用户性别确定男女频
  545. $sex = ForceSubscribeService::getUserRealSexByUid($uid);
  546. $channel_name = $sex == 1 ? '男频' : '女频';
  547. // 站点属性优先
  548. if ($channel_sex == 2) {
  549. $channel_name = '女频';
  550. }
  551. $recomm_books = BookConfigService::getSignRecommendBooksFromCache([], $channel_name, 2);
  552. $recent_read_reco_content = '';
  553. if ($recomm_books) {
  554. // 判断是否不展示书名
  555. $self_config = ChannelService::check_channel_account_priv($distribution_channel_id, 'hide_book_name');
  556. $hide_type = isset($self_config->type) ? $self_config->type : 'not_hide';
  557. $recommend_titles = [];
  558. if ($hide_type == 'hide_book_name') {
  559. \Log::info('hide_book_name reco:' . $distribution_channel_id . ' uid:' . $uid);
  560. $recommend_titles = PromotionService::getRandomHeadline($sex, count($recomm_books));
  561. }
  562. $recent_read_reco_content .= "\n\n" . '热门书籍推荐~';
  563. foreach ($recomm_books as $key => $book) {
  564. $book_name = $book->book_name;
  565. if ($hide_type == 'hide_book_name') {
  566. $book_name = isset($recommend_titles[$key]->title) ? $recommend_titles[$key]->title : $book->book_name;
  567. }
  568. $url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/reader?bid=' . Hashids::encode($book->bid) . '&cid=' . $book->first_cid;
  569. $recent_read_reco_content .= "\n\n" . '<a href="' . $url . '"> ☞ 《' . $book_name . '》</a>';
  570. }
  571. }
  572. $feedback['text'] .= $recent_read_reco_content;
  573. } else {
  574. // 男频站点
  575. // 1本在测的,1本优质书,共2本,如果没有在测的书,则返回2本优质书
  576. // 用户按照15天注册后的用户
  577. $sex = ForceSubscribeService::getUserRealSexByUid($uid);
  578. [$bids, $test_bid] = BookConfig::getLeftRecomBids($uid, '男频', 2);
  579. \Log::info('bids and test_bid:' . $uid . ' data:' . json_encode([$bids, $test_bid]));
  580. if ($bids) {
  581. $recomm_books = BookService::getSimpleBooksByIds($bids);
  582. $recent_read_reco_content = '';
  583. if ($recomm_books) {
  584. // 判断是否不展示书名
  585. $self_config = ChannelService::check_channel_account_priv($distribution_channel_id, 'hide_book_name');
  586. $hide_type = isset($self_config->type) ? $self_config->type : 'not_hide';
  587. $recommend_titles = [];
  588. if ($hide_type == 'hide_book_name') {
  589. \Log::info('hide_book_name reco:' . $distribution_channel_id . ' uid:' . $uid);
  590. $recommend_titles = PromotionService::getRandomHeadline($sex, count($recomm_books));
  591. }
  592. $recent_read_reco_content .= "\n\n" . '热门书籍推荐~';
  593. foreach ($recomm_books as $key => $book) {
  594. $book_name = $book->name;
  595. if ($hide_type == 'hide_book_name') {
  596. $book_name = isset($recommend_titles[$key]->title) ? $recommend_titles[$key]->title : $book_name;
  597. }
  598. $url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/reader?bid=' . Hashids::encode($book->id) . '&cid=' . $book->first_cid;
  599. if ($book->id == $test_bid) {
  600. $url .= '&fromsource=smart_push';
  601. }
  602. $recent_read_reco_content .= "\n\n" . '<a href="' . $url . '"> ☞ 《' . $book_name . '》</a>';
  603. }
  604. }
  605. $feedback['text'] .= $recent_read_reco_content;
  606. }
  607. }
  608. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'recent_read');
  609. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  610. } // 个别渠道是事件
  611. elseif ($content == "user_center" && !empty($openid)) {
  612. \Log::info('click_user_center:' . $openid);
  613. $feedback['text'] = "☞ <a href='" . $base_url . "/person'>个人中心</a>\n\n";
  614. $feedback['text'] .= "☞ <a href='" . $base_url . "/'>书城首页</a>\n\n";
  615. $feedback['text'] .= "☞ <a href='" . $base_url . "/pay'>优惠充值</a>\n\n";
  616. $feedback['text'] .= "☞ <a href='" . $help_url . "'>帮助中心</a>\n";
  617. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'user_center');
  618. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  619. } elseif ($content == "qrcode_main" && !empty($openid)) {
  620. $msg = OfficialAccountMsgService::getEventMsg(['appid' => $appid, 'apply_event' => 'click', 'apply_event_key' => 'qrcode_main']);
  621. if ($msg) {
  622. $send_event_content = array();
  623. $send_event_content['image'] = array('media_id' => $msg->return_content);
  624. return response()->success($send_event_content);
  625. } else {
  626. $feedback['text'] = '配置有误';
  627. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  628. }
  629. }elseif (preg_match('/^[\d]-[\d]$/', $content) && !empty($openid) && !empty($distribution_channel_id)) {
  630. $defined_menu = DB::connection('api_mysql')->table('self_defined_menu')
  631. ->where(['distribution_channel_id'=>$distribution_channel_id, 'status'=>1, 'is_generate'=>1])->value('menu');
  632. \Log::info('defined_menu: '.$defined_menu);
  633. if ($defined_menu) {
  634. $defined_menu_info_arr = json_decode(json_decode($defined_menu), true);
  635. if ($defined_menu_info_arr && !empty($defined_menu_info_arr['content'])) {
  636. $feedback['text'] = '';
  637. foreach ($defined_menu_info_arr['content'] as $v) {
  638. if ($v['key'] === $content) {
  639. $feedback['text'] = $v['content'];
  640. }
  641. }
  642. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  643. }
  644. }
  645. }
  646. } elseif ($event == "unsubscribe") {
  647. $feedback['text'] = "";
  648. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  649. } elseif ($event == "subscribe") {
  650. // 统计
  651. $sub_statistic_key = 'gzh_actual_sub:' . $appid . ':' . date('Y-m-d');
  652. \Log::info('sub_statistic_key:' . $sub_statistic_key);
  653. Redis::sadd($sub_statistic_key, $openid);
  654. Redis::expire($sub_statistic_key, 30 * 3600);
  655. // 有自定义不回复内容的渠道
  656. $distribution_self_define_config = DistributionSelfDefineConfig::getDistributionSelfDefineConfig($distribution_channel_id, 'force_subscribe_noreply');
  657. if (!empty($distribution_self_define_config)) {
  658. \Log::info('distribution_self_define_config: distribution_channel_id:' . $distribution_channel_id);
  659. $feedback['text'] = "";
  660. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  661. }
  662. if (!empty($openid)) {
  663. # code...
  664. \Log::info('subscribe:' . $openid . ' distribution_channel_id:' . $distribution_channel_id);
  665. $params['openid'] = $openid;
  666. $forceSubscribeUser = ForceSubscribeService::forceSubscribeUsersByOpenid($params);
  667. \Log::info($forceSubscribeUser);
  668. // 有自定义回复内容的渠道
  669. // $distribution_self_define_content = DistributionSelfDefineContent::getDistributionSelfDefineContent($distribution_channel_id);
  670. // 从redis取
  671. $distribution_self_define_content = MsgService::getCurrentReply($distribution_channel_id);
  672. // 判断渠道,如果是场景值关注过来的,则普通回复,否则自定义回复
  673. $subscribe_from_scene = DistributionSelfDefineConfig::getDistributionSelfDefineConfig($distribution_channel_id, 'subscribe_from_scene');
  674. if (!empty($subscribe_from_scene)) {
  675. if (!empty($content) && strpos($content, 'qrscene_') === 0) {
  676. $distribution_self_define_content = null;
  677. \Log::info('subscribe_from_scene:' . $distribution_channel_id);
  678. }
  679. }
  680. if (is_null($distribution_self_define_content)) {
  681. $recommend_content = '';
  682. if (!empty($forceSubscribeUser)) {
  683. # code...
  684. \Log::info('exist_force_user:' . $openid);
  685. //通过uid获取该用户最近阅读记录的书籍
  686. $uid = isset($forceSubscribeUser->uid) ? $forceSubscribeUser->uid : '';
  687. $userBook = ReadRecordService::getFirstReadRecord($uid);
  688. $bookName = isset($userBook['book_name']) ? $userBook['book_name'] : '最近阅读';
  689. \Log::info('bookName:' . $bookName);
  690. if (!empty($recommend_content)) {
  691. $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>';
  692. $feedback['text'] .= $recommend_content;
  693. $feedback['text'] .= "\n" . "\n" . '为方便下次阅读,请' . '<a href="https://help.leyuee.com/top.html">' . '置顶公众号' . '</a>';
  694. } else {
  695. $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" . '明日继续签到得书币哦!';
  696. }
  697. } else {
  698. $feedback['text'] = "<a href='" . env('PROTOCOL') . "://site" . $encode_distribution_channel_id . "." . $WECHAT_CUSTOM_HOST . ".com/continue'>点击继续阅读 </a> ";
  699. $feedback['text'] .= $recommend_content;
  700. }
  701. // 外站关注的直接回复图文qrscene_outer:123_12
  702. if (strpos($content, 'outer') > -1) {
  703. $scene_content = str_replace('qrscene_outer:', '', $content);
  704. $bid_cid = explode('_', $scene_content);
  705. $bid = isset($bid_cid[0]) ? $bid_cid[0] : '';
  706. $cid = isset($bid_cid[1]) ? $bid_cid[1] : '';
  707. if (!empty($bid) && !empty($cid)) {
  708. $book_conf = BookConfig::getBookById($bid);
  709. \Log::info('out_book_conf');
  710. \Log::info($book_conf);
  711. if (!empty($book_conf)) {
  712. $data = array();
  713. $encode_bid = Hashids::encode($bid);
  714. $data[] = ['url' => env('PROTOCOL') . '://site' . $encode_distribution_channel_id . '.' . $WECHAT_CUSTOM_HOST . '.com' . '/reader?bid=' . $encode_bid . '&cid=' . $cid . '&fromtype=outer_' . $scene_content,
  715. 'title' => $book_conf['book_name'],
  716. 'description' => $book_conf['intro'],
  717. 'image' => $book_conf['cover']
  718. ];
  719. \Log::info('outer:' . json_encode($data));
  720. $feedback['text'] = $data;
  721. }
  722. }
  723. }
  724. } else {
  725. // 判断是否图文
  726. if (isset($distribution_self_define_content->is_pic) && $distribution_self_define_content->is_pic) {
  727. $feedback['text'] = ImageNewsToArray($distribution_self_define_content->content);
  728. } else {
  729. $feedback['text'] = isset($distribution_self_define_content->content) ? $distribution_self_define_content->content : '';
  730. }
  731. }
  732. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'subscribe');
  733. // 判断是否有关注回复第二条,有则推送
  734. MsgService::pushChannelCurrentSecondReply($distribution_channel_id, $appid, $openid, 'subscribe_second_reply');
  735. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  736. } else {
  737. $feedback['text'] = "<a href='" . env('PROTOCOL') . "://site" . $encode_distribution_channel_id . "." . $WECHAT_CUSTOM_HOST . ".com/continue'>点击继续阅读 </a> ";
  738. $feedback['text'] = ChannelService::convertChannelReplyUrl($is_outer_site, $appid, $openid, $feedback['text'], 'subscribe');
  739. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  740. }
  741. } elseif ($event == "TEMPLATESENDJOBFINISH") {
  742. $feedback['text'] = "";
  743. return response()->item(new OfficialInteractiveEventTransformer(), (object)$feedback);
  744. } else {
  745. return response()->error('EVENT_NOT_FOUND');
  746. }
  747. }
  748. public function getUserClient()
  749. {
  750. return new Client(['base_uri' => env('MEDIA_API_BASE_URI')]);
  751. }
  752. }