TemplateCustomSendService.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. <?php
  2. /**
  3. * Created by sublime.
  4. * User: wosinC
  5. * Date: 2017/12/2
  6. * Time: 上午11:39
  7. */
  8. namespace App\Modules\OfficialAccount\Services;
  9. use App\Modules\OfficialAccount\Models\WechatTemplateMsgs;
  10. use App\Modules\OfficialAccount\Services\ForceSubscribeService;
  11. use App\Modules\OfficialAccount\Models\ForceSubscribeUsers;
  12. use App\Modules\OfficialAccount\Models\OfficialAccount;
  13. use App\Modules\OfficialAccount\Models\OfficialCustomMsg;
  14. use App\Modules\OfficialAccount\Models\CustomMsgSwitchs;
  15. use App\Modules\OfficialAccount\Models\CustomMsgSwitchsMsgs;
  16. use App\Modules\OfficialAccount\Models\CustomSendMsgs;
  17. use App\Modules\OfficialAccount\Models\DistributionChannelSetting;
  18. use App\Modules\OfficialAccount\Models\OfficialImgtextUrls;
  19. use App\Modules\User\Services\ReadRecordService;
  20. use App\Modules\User\Services\UserService;
  21. use App\Modules\Book\Services\BookConfigService;
  22. use App\Modules\OfficialAccount\Services\OfficialAccountService;
  23. use App\Modules\Promotion\Services\PromotionService;
  24. use App\Modules\Channel\Services\ChannelService;
  25. use App\Modules\OfficialAccount\Models\MediaCustomer;
  26. use App\Modules\OfficialAccount\Models\CustomPushActivitys;
  27. use App\Modules\OfficialAccount\Models\CustomSendDayStats;
  28. use GuzzleHttp\Client;
  29. use App\Libs\OSS;
  30. use Redis;
  31. use App\Jobs\SendNews;
  32. use App\Jobs\SendTemplate;
  33. use App\Jobs\SendTexts;
  34. use App\Jobs\CustomMsgSendJob;
  35. class TemplateCustomSendService
  36. {
  37. /**
  38. * @return int|void toCheckAndSendCustomMsg
  39. * 查找并发送模板消息
  40. */
  41. static function toCheckAndSendTemplateMsg()
  42. {
  43. try {
  44. \Log::info('toCheckAndSendTemplateMsg_start');
  45. //查找模板消息并发送
  46. $statusPram = '1';
  47. $allStandByWechatTemplateMsgs = WechatTemplateMsgs::wechatTemplateMsgsByStatusStandBy($statusPram);
  48. $allStandByWechatTemplateMsgsArray = [];
  49. if ($allStandByWechatTemplateMsgs){
  50. //先单独更新数据库 把要发送的状态改为8 以免发送期间超时,导致重复发送
  51. for ($x=0; $x < count($allStandByWechatTemplateMsgs); $x++) {
  52. $wechatTemplateMsgs = $allStandByWechatTemplateMsgs[$x];
  53. $send_time = $wechatTemplateMsgs['send_time'];
  54. if (strtotime($send_time) - time() > 600) { //发送时间大于当前时间10分钟
  55. continue;
  56. } else {
  57. \Log::info('========现将模板消息设置成发送状态 "8" 用户不能操作(删除,编辑,停止) = ' . $wechatTemplateMsgs['id']);
  58. $wechatTemplateMsgs['status'] = '8';
  59. $wechatTemplateMsgs->save();
  60. $officialAccountArray = $wechatTemplateMsgs->toArray();
  61. Redis::hset('send_wechat_msg:task_id:' . $wechatTemplateMsgs['id'], 'wechat_msg', json_encode($officialAccountArray));
  62. $allStandByWechatTemplateMsgsArray[] = $wechatTemplateMsgs;
  63. }
  64. }
  65. for ($x=0; $x < count($allStandByWechatTemplateMsgsArray); $x++){
  66. $wechatTemplateMsgs = $allStandByWechatTemplateMsgsArray[$x];
  67. \Log::info($wechatTemplateMsgs);
  68. // $send_time = $wechatTemplateMsgs['send_time'];
  69. // if (strtotime($send_time) - time() > 600){ //发送时间大于当前时间10分钟
  70. // continue;
  71. // }
  72. $wechatTemplateMsgs['redirect_url'] = self::redirect_url_add_param($wechatTemplateMsgs['redirect_url'],$wechatTemplateMsgs['id'],'template',false);
  73. \Log::info('template_redirect_url_convert:id:'.$wechatTemplateMsgs['id'].' redirect_url:'.$wechatTemplateMsgs['redirect_url']);
  74. $appid = $wechatTemplateMsgs['appid'];
  75. $template_id = $wechatTemplateMsgs['template_id'];
  76. $template_content = $wechatTemplateMsgs['template_content'];
  77. $origin_template_content = $template_content;
  78. $redirect_url = $wechatTemplateMsgs['redirect_url'];
  79. // 新版要自动添加域名
  80. $redirect_url = self::checkAddDomain($wechatTemplateMsgs['distribution_channel_id'],$redirect_url);
  81. \Log::info('checkAddDomain_after:distribution_channel_id:'.$wechatTemplateMsgs['distribution_channel_id'].' redirect_url:'.$redirect_url);
  82. $task_id = $wechatTemplateMsgs['id'];
  83. $send_time = $wechatTemplateMsgs['send_time'];
  84. $is_full_send = isset($wechatTemplateMsgs['is_full_send'])?$wechatTemplateMsgs['is_full_send']:0;
  85. \Log::info('-----------------模板消息参数--------------appid = '.$appid.', channelid = '.$wechatTemplateMsgs['distribution_channel_id']);
  86. \Log::info('========发送的模板消息内容========== template_content');
  87. \Log::info($template_content);
  88. //1,通过筛选得到条件符合的强关用户
  89. $skip = 0;
  90. $next_openid = '';
  91. $loop = 0;
  92. while ( $skip <= 2500000) {
  93. $loop++;
  94. \Log::info('-------------模板消息-----分页取强关用户,目前页数----------'.$skip.' is_full_send:'.$is_full_send.' task_id:'.$task_id.' loop:'.$loop);
  95. $users = array();
  96. // 全服务号粉丝发,要记录next_openid
  97. if($is_full_send){
  98. if($loop > 1 && empty($next_openid)){
  99. \Log::info('send_template_appid:'.$appid.' break,skip:'.$skip);
  100. break;
  101. }
  102. $user_res = ForceSubscribeService::getFullOfficialAccountUsers($appid,$next_openid);
  103. $users = $user_res['openids'];// TODO格式化成一样的格式
  104. $next_openid = $user_res['next_openid'];
  105. }else{
  106. $users = ForceSubscribeService::forceUserCountByTemplatePrams($appid,$wechatTemplateMsgs['distribution_channel_id'],$wechatTemplateMsgs['subscribe_time'],$wechatTemplateMsgs['sex'],$wechatTemplateMsgs['balance'],$wechatTemplateMsgs['category_id'],$wechatTemplateMsgs['order_type'],$skip);
  107. }
  108. \Log::info('-----------------实际发送模板消息用户数量-------------'.count($users).' $next_openid:'.$next_openid);
  109. // \Log::info($users);
  110. $skip += count($users);
  111. // continue;
  112. // die('end2');
  113. if(count($users)>0){
  114. for ($i=0; $i < count($users); $i++) {
  115. // 占位符替换
  116. $place_holder_params = array();
  117. $place_holder_params['nickname'] = isset($users[$i]['nickname'])?$users[$i]['nickname']:'';
  118. \Log::info('openid:'.$users[$i]['openid'].' nickname:'.$place_holder_params['nickname']);
  119. $template_content = ForceSubscribeService::change_placeholder($origin_template_content,$place_holder_params);
  120. //2,循环用户发送模板消息
  121. //发送到最后一条时,将
  122. if ($i == count($users)-1) {
  123. $data = array();
  124. $data['statusstr'] = (time());
  125. $data['openid'] = $users[$i]['openid'];
  126. $data['appid'] = $appid;
  127. $data['template_id'] = $template_id;
  128. //4,通过RebitMQ发送模板消息
  129. // $data['template_content'] = $templateSendContents;
  130. $data['template_content'] =str_replace(".DATA","",$template_content);
  131. $data['type'] = 'last_task';// last_task,one_task
  132. $data['url'] = $redirect_url;
  133. $data['task_id'] = $task_id;
  134. $data['send_time'] = $send_time;
  135. $send_data=array(
  136. 'send_time'=>$send_time,
  137. 'data' => $data
  138. );
  139. $now_time = strtotime($send_time)-time();
  140. $delay = $now_time < 0 ? 0:$now_time;
  141. \Log::info('------------------发送最后一条模板消息----------task_id = '.$task_id.', 时间差 = '.$now_time.' openid:'.$data['openid']);
  142. $job = (new SendTemplate($send_data))->onConnection('rabbitmq')->delay($delay)->onQueue('send_template_list');
  143. dispatch($job);
  144. }else{
  145. $data = array();
  146. $data['statusstr'] = (time());
  147. $data['openid'] = $users[$i]['openid'];
  148. $data['appid'] = $appid;
  149. $data['template_id'] = $template_id;
  150. \Log::info('========================[[[[send template message]]]]====================');
  151. \Log::info(str_replace(".DATA","",$template_content));
  152. $data['template_content'] =str_replace(".DATA","",$template_content);
  153. $data['type'] = 'one_task';// last_task,one_task
  154. $data['url'] = $redirect_url;
  155. $data['task_id'] = $task_id;
  156. $data['send_time'] = $send_time;
  157. $send_data=array(
  158. 'send_time'=>$send_time,
  159. 'data' => $data
  160. );
  161. $now_time = strtotime($send_time)-time();
  162. $delay = $now_time < 0 ? 0:$now_time;
  163. \Log::info('========================发送模板消息 不是最后一条模板=================task_id = '.$task_id.'. openid = '.$data['openid'].', 时间差 = '.$delay);
  164. $job = (new SendTemplate($send_data))->onConnection('rabbitmq')->delay($delay)->onQueue('send_template_list');
  165. dispatch($job);
  166. }
  167. }
  168. }else{
  169. \Log::info('========================发送模板消息_没找到用户===================='.$task_id);
  170. break;
  171. }
  172. }
  173. //更新模板消息的用户数量并更新redis
  174. \Log::info('========================更新模板消息并存redis====================task_id = '.$task_id);
  175. $wechatTemplateMsgs['user_num'] = $skip;
  176. // 若没有用户,则直接更新为已发送
  177. if($skip == 0){
  178. \Log::info('has_no_template_users:'.$wechatTemplateMsgs['id']);
  179. $wechatTemplateMsgs['status'] = '3';
  180. }
  181. $wechatTemplateMsgs->save();
  182. $officialAccountArray = $wechatTemplateMsgs->toArray();
  183. Redis::hset('send_wechat_msg:task_id:'.$wechatTemplateMsgs['id'], 'wechat_msg', json_encode($officialAccountArray));
  184. }
  185. }else{
  186. \Log::info('========================!!!数据库中没有要发送的模板消息!!!====================');
  187. }
  188. } catch (\Exception $e) {
  189. \Log::info('========================循环用户发送模板消息时报错====================');
  190. \Log::info($e->getMessage());
  191. }
  192. }
  193. /**
  194. * @return int|void toCheckAndSendCustomMsg
  195. * 查找并发送客服消息
  196. */
  197. static function toCheckAndSendCustomMsg()
  198. {
  199. //
  200. try {
  201. //查找模板消息并发送
  202. $statusPram = '1';
  203. $allStandByWechatCustomMsgs = CustomSendMsgs::customSendMsgsByStatusStandBy($statusPram);
  204. // \Log::info($allStandByWechatCustomMsgs);
  205. $allStandByWechatCustomMsgsArray = [];
  206. if ($allStandByWechatCustomMsgs) {
  207. //先单独更新数据库 把要发送的状态改为8 以免发送期间超时,导致重复发送
  208. for ($x = 0; $x < count($allStandByWechatCustomMsgs); $x++) {
  209. $customSendMsgsPrams = $allStandByWechatCustomMsgs[$x];
  210. $send_time = $customSendMsgsPrams['send_time'];
  211. if (strtotime($send_time) - time() > 600) { //发送时间大于当前时间10分钟
  212. continue;
  213. } else {
  214. \Log::info('========现将客服消息设置成发送状态 "8" 用户不能操作(删除,编辑,停止) = ' . $customSendMsgsPrams['id']);
  215. $customSendMsgsPrams['status'] = '8';
  216. $customSendMsgsPrams->save();
  217. $officialAccountArray = $customSendMsgsPrams->toArray();
  218. Redis::hset('send_wechat_msg:task_id:' . $customSendMsgsPrams['task_id'], 'wechat_msg', json_encode($officialAccountArray));
  219. $allStandByWechatCustomMsgsArray[] = $customSendMsgsPrams;
  220. }
  221. }
  222. for ($x = 0; $x < count($allStandByWechatCustomMsgsArray); $x++) {
  223. $customSendMsgsPrams = $allStandByWechatCustomMsgsArray[$x];
  224. // 转化链接url
  225. $customSendMsgsPrams['content'] = self::convert_custom_content($customSendMsgsPrams['content'],$customSendMsgsPrams['id'],$customSendMsgsPrams['distribution_channel_id'],$customSendMsgsPrams['trusteeship']);
  226. $appids = $customSendMsgsPrams['appid'];
  227. $is_full_send = isset($customSendMsgsPrams['is_full_send'])?$customSendMsgsPrams['is_full_send']:0;
  228. \Log::info('------------------客服消息强关用户,appids:'.$appids.' is_full_send:'.$is_full_send);
  229. $appidArray = explode(',', $appids);
  230. $usercountnum = 0;
  231. for ($j=0; $j < count($appidArray); $j++) {
  232. $skip = 0;
  233. $next_openid = '';
  234. $loop = 0;
  235. while ( $skip <= 2500000) {
  236. $loop++;
  237. \Log::info('------------------分页取强关用户,目前页数----------'.$skip.' loop:'.$loop.' next_openid:'.$next_openid);
  238. $users = array();
  239. // 全服务号粉丝发,要记录next_openid
  240. if($is_full_send){
  241. // 防止异常
  242. if($loop > 1 && empty($next_openid)){
  243. \Log::info('send_template_appid:'.$appidArray[$j].' break,skip:'.$skip);
  244. break;
  245. }
  246. try{
  247. $user_res = ForceSubscribeService::getFullOfficialAccountUsers($appidArray[$j],$next_openid);
  248. $users = $user_res['openids'];// TODO格式化成一样的格式
  249. $next_openid = $user_res['next_openid'];
  250. } catch (\Exception $e) {
  251. \Log::info($e);
  252. }
  253. }else{
  254. //5,获取所选条件下筛选出的用户
  255. $sign_time = 'z';
  256. $users = ForceSubscribeService::forceUserCountByCustomPrams($appidArray[$j],$customSendMsgsPrams['distribution_channel_id'],$customSendMsgsPrams['subscribe_time'],$customSendMsgsPrams['sex'],$customSendMsgsPrams['balance'],$customSendMsgsPrams['category_id'],$customSendMsgsPrams['order_type'],$sign_time,$skip);
  257. }
  258. \Log::info('--------------------users_num:'.count($users));
  259. // continue;
  260. if (count($users)>0) {
  261. $usercountnum += count($users);
  262. for ($i=0; $i < count($users); $i++) {
  263. if ($i == count($users)-1) {
  264. // \Log::info('--------------------客服消息接收用户 last_task');
  265. // \Log::info($users[$i]['openid']);
  266. // \Log::info($appidArray[$j]);
  267. // 7,循环用户发送客服消息
  268. $data = array();
  269. $data['openid'] = $users[$i]['openid'];
  270. $data['appid'] = $appidArray[$j];
  271. $data['news_content'] = $customSendMsgsPrams['content'];
  272. $data['type'] = 'last_task';
  273. $data['task_id'] = $customSendMsgsPrams['task_id'];
  274. $data['send_time'] = $customSendMsgsPrams['send_time'];
  275. $send_data=array(
  276. 'send_time'=>$customSendMsgsPrams['send_time'],
  277. 'data' => $data
  278. );
  279. $now_time = strtotime($customSendMsgsPrams['send_time'])-time();
  280. $delay = $now_time < 0 ? 0:$now_time;
  281. //\Log::info('start_dispatch:'.$data['openid'].' send_time:'.$customSendMsgsPrams['send_time'].' diff:'.$now_time.' dealy:'.$delay.' task_id:'.$customSendMsgsPrams['task_id']);
  282. // \Log::info('客服消息找到用户并发送===================================');
  283. // \Log::info($data['openid']);
  284. // \Log::info($data['appid']);
  285. // \Log::info($data['news_content']);
  286. //\Log::info('------------------发送最后一条客服消息----------'.$customSendMsgsPrams['task_id'].' openid:'.$data['openid']);
  287. $job = (new SendNews($send_data))->onConnection('rabbitmq')->delay($delay)->onQueue('send_news_list');
  288. dispatch($job);
  289. }else{
  290. // \Log::info('--------------------客服消息接收用户 one_task');
  291. // \Log::info($users[$i]['openid']);
  292. // \Log::info($appidArray[$j]);
  293. //7,循环用户发送客服消息
  294. $data = array();
  295. $data['openid'] = $users[$i]['openid'];
  296. $data['appid'] = $appidArray[$j];
  297. $data['news_content'] = $customSendMsgsPrams['content'];
  298. $data['type'] = 'one_task';
  299. $data['task_id'] = $customSendMsgsPrams['task_id'];
  300. $data['send_time'] = $customSendMsgsPrams['send_time'];
  301. $send_data=array(
  302. 'send_time'=>$customSendMsgsPrams['send_time'],
  303. 'data' => $data
  304. );
  305. $now_time = strtotime($customSendMsgsPrams['send_time'])-time();
  306. $delay = $now_time;
  307. $delay = $now_time < 0 ? 0:$now_time;
  308. //\Log::info('start_dispatch:'.$data['openid'].' send_time:'.$customSendMsgsPrams['send_time'].' diff:'.$now_time.' dealy:'.$delay.' task_id:'.$customSendMsgsPrams['task_id']);
  309. //\Log::info('------------------发送客服消息----------'.$customSendMsgsPrams['task_id'].' openid:'.$data['openid']);
  310. $job = (new SendNews($send_data))->onConnection('rabbitmq')->delay($delay)->onQueue('send_news_list');
  311. dispatch($job);
  312. }
  313. }
  314. }else{
  315. \Log::info('------------------发送客服消息没有查找到强关用户----------'.$customSendMsgsPrams['task_id']);
  316. break;
  317. }
  318. $skip += count($users);
  319. }
  320. }
  321. $customSendMsgsPrams['user_num'] = $usercountnum;
  322. // 若没有用户,则直接更新为已发送
  323. if($usercountnum == 0){
  324. \Log::info('has_no_custom_users:'.$customSendMsgsPrams['task_id']);
  325. $customSendMsgsPrams['status'] = '3';
  326. }
  327. \Log::info('------------------更新发送用户----------'.$customSendMsgsPrams['task_id'].' usercountnum:'.$usercountnum);
  328. $customSendMsgsPrams->save();
  329. }
  330. }else{
  331. \Log::info('========================!!!数据库中没有要发送的客服消息!!!====================');
  332. }
  333. } catch (\Exception $e) {
  334. \Log::info('===================================发送客服消息报错');
  335. \Log::info($e->getMessage());
  336. }
  337. }
  338. /**
  339. * 转换客服消息内容
  340. * 1条--新版
  341. * @param unknown_type $content
  342. * @return string
  343. */
  344. public static function convert_custom_content($content,$mark_str,$distribution_channel_id,$trusteeship=0){
  345. \Log::info('convert_custom_content_start:');
  346. $_contents = json_decode($content);
  347. // \Log::info('convert_custom_content_before:');
  348. // \Log::info($_contents);
  349. $new_contents = null;
  350. // 智能托管,加上各自渠道域名,统计精确到图文每条
  351. if($trusteeship){
  352. $origin_mark_str = $mark_str;
  353. foreach($_contents as $key=>$_content){
  354. $url = env('PROTOCOL').'://site'.encodeDistributionChannelId($distribution_channel_id).'.'.env('CUSTOM_HOST').'.com'.$_content[2]->url;
  355. $mark_str = $origin_mark_str.'_'.($key+1).'&source=wechatmsg';// source能让用户继续阅读
  356. \Log::info('convert_custom_content_url:'.$url.' mark_str:'.$mark_str);
  357. $_contents[$key][2]->url = self::redirect_url_add_param($url,$mark_str,'custom',true);
  358. $new_contents[] = $_contents[$key];
  359. break;
  360. }
  361. }
  362. // 非托管
  363. else{
  364. $origin_mark_str = $mark_str;
  365. $send_type = 'custom';
  366. // 智能推送不加前缀
  367. if(strpos($origin_mark_str,'smart_push_') > -1){
  368. $send_type = 'smart_push';
  369. $origin_mark_str = str_replace('smart_push_','',$origin_mark_str);
  370. }
  371. \Log::info('origin_mark_str:'.$origin_mark_str);
  372. foreach($_contents as $key=>$_content){
  373. // 新版要自动添加域名
  374. $_content[2]->url = self::checkAddDomain($distribution_channel_id,$_content[2]->url);
  375. $mark_str = $origin_mark_str.'&source=wechatmsg';// source能让用户继续阅读
  376. $_contents[$key][2]->url = self::redirect_url_add_param($_content[2]->url,$mark_str,$send_type,false);
  377. $new_contents[] = $_contents[$key];
  378. break;
  379. }
  380. }
  381. // \Log::info('convert_custom_content_after:');
  382. // \Log::info($new_contents);
  383. $_convert_contents = json_encode($new_contents);
  384. return $_convert_contents;
  385. }
  386. /**
  387. * 转换客服消息内容
  388. * 多条--老版
  389. * @param unknown_type $content
  390. * @return string
  391. */
  392. public static function convert_custom_content_multy($content,$mark_str,$distribution_channel_id,$trusteeship=0){
  393. \Log::info('convert_custom_content_start:');
  394. $_contents = json_decode($content);
  395. // 智能托管,加上各自渠道域名,统计精确到图文每条
  396. if($trusteeship){
  397. $origin_mark_str = $mark_str;
  398. foreach($_contents as $key=>$_content){
  399. $url = env('PROTOCOL').'://site'.encodeDistributionChannelId($distribution_channel_id).'.'.env('CUSTOM_HOST').'.com'.$_content[2]->url;
  400. $mark_str = $origin_mark_str.'_'.($key+1).'&source=wechatmsg';// source能让用户继续阅读
  401. \Log::info('convert_custom_content_url:'.$url.' mark_str:'.$mark_str);
  402. $_contents[$key][2]->url = self::redirect_url_add_param($url,$mark_str,'custom',true);
  403. }
  404. }
  405. // 非托管
  406. else{
  407. $origin_mark_str = $mark_str;
  408. $send_type = 'custom';
  409. // 智能推送不加前缀
  410. if(strpos($origin_mark_str,'smart_push_') > -1){
  411. $send_type = 'smart_push';
  412. $origin_mark_str = str_replace('smart_push_','',$origin_mark_str);
  413. }
  414. \Log::info('origin_mark_str:'.$origin_mark_str);
  415. foreach($_contents as $key=>$_content){
  416. $mark_str = $origin_mark_str.'&source=wechatmsg';// source能让用户继续阅读
  417. $_contents[$key][2]->url = self::redirect_url_add_param($_content[2]->url,$mark_str,$send_type,false);
  418. }
  419. }
  420. $_convert_contents = json_encode($_contents);
  421. //\Log::info('convert_custom_content_after:');
  422. //\Log::info($_convert_contents);
  423. return $_convert_contents;
  424. }
  425. /**
  426. * 跳转地址加参
  427. * @param unknown_type $redirect_url
  428. * @param unknown_type $type
  429. * @return string
  430. */
  431. public static function redirect_url_add_param($redirect_url,$mark_str,$type='template',$trusteeship=false){
  432. $pre_str = '';
  433. if($type == 'template'){
  434. $pre_str = 'template_';
  435. }elseif($type == 'custom'){
  436. $pre_str = 'custom_';
  437. }
  438. // 模板客服消息,单独加参
  439. $inner_order_id = '';
  440. if(!$trusteeship){
  441. $inner_order_id = '&inner_order_id='.$pre_str.$mark_str;
  442. }
  443. // 跳转链接加参
  444. if(strpos($redirect_url,'?') > -1){
  445. $redirect_url .= '&fromtype='.$pre_str.$mark_str.$inner_order_id;
  446. }else{
  447. $redirect_url .= '?fromtype='.$pre_str.$mark_str.$inner_order_id;
  448. }
  449. return $redirect_url;
  450. }
  451. // 新版要自动添加域名
  452. public static function checkAddDomain($distribution_channel_id,$redirect_url){
  453. // 非托管,如果url没有域名,则加上
  454. if(strpos($redirect_url, 'http') !== false){
  455. \Log::info('not_need_add_domain:'.$distribution_channel_id.' url:'.$redirect_url);
  456. }else{
  457. \Log::info('need_add_domain_before:'.$distribution_channel_id.' url:'.$redirect_url);
  458. $redirect_url = env('PROTOCOL').'://site'.encodeDistributionChannelId($distribution_channel_id).'.'.env('CUSTOM_HOST').'.com'.$redirect_url;
  459. \Log::info('need_add_domain_after:'.$distribution_channel_id.' url:'.$redirect_url);
  460. }
  461. return $redirect_url;
  462. }
  463. }