WechatCustomerMsgController.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. <?php
  2. namespace App\Http\Controllers\Wechat\OfficialAccount;
  3. use App\Http\Controllers\Channel\BaseController as ChannelBaseController;
  4. // use App\Modules\OfficialAccount\Services\CustomMsgService;
  5. use App\Http\Controllers\Wechat\OfficialAccount\Transformers\WechatTemplatesMsgTransformer;
  6. use App\Http\Controllers\Wechat\OfficialAccount\Transformers\OfficialImgtextUrlsTransformer;
  7. use App\Modules\OfficialAccount\Services\CustomMsgService;
  8. use App\Modules\Promotion\Services\PromotionService;
  9. use App\Http\Controllers\Channel\OfficialAccount\Transformers\CustomMsgControllerTransformer;
  10. use App\Http\Controllers\Channel\OfficialAccount\Transformers\CustomMsgSwitchTransformer;
  11. use App\Http\Controllers\Channel\OfficialAccount\Transformers\CustomSendMsgsTransformers;
  12. use App\Http\Controllers\Channel\Promotion\Transformers\DocumentCoversTransformer;
  13. use App\Http\Controllers\Channel\Promotion\Transformers\HeadlinelTransformer;
  14. use Illuminate\Http\Request;
  15. use GuzzleHttp\Client;
  16. use App\Libs\OSS;
  17. use App\Jobs\SendTemplate;
  18. class WechatCustomerMsgController extends ChannelBaseController
  19. {
  20. /**
  21. * @apiDefine OfficialAccount 公众号
  22. */
  23. /**
  24. * @apiVersion 1.0.0
  25. * @api {GET} OfficialAccount/wechatTemplateByAppidAndTemplateId 通过Appid和common_template_id获取模板
  26. * @apiGroup OfficialAccount
  27. * @apiName wechatTemplateByAppidAndCommonTemplateId
  28. * @apiParam {String} appid 公众号的appid.
  29. * @apiParam {String} common_template_id 公共模版的ID.
  30. * @apiSuccess {String} appid 公众号的appid.
  31. * @apiSuccess {String} common_template_id 公共模版的ID.
  32. * @apiSuccess {String} template_id 公众号对应模版ID.
  33. * @apiSuccess {String} name 名称.
  34. * @apiSuccess {String} send_time 发送时间.
  35. * @apiSuccess {String} template_content 模板内容.
  36. * @apiSuccess {String} redirect_url 重定向地址.
  37. * @apiSuccess {String} send_appid 公众号appid.
  38. * @apiParam {String} status 模板消息状态.
  39. * @apiParam {String} remark 备注.
  40. * @apiParam {Number} distribution_channel_id 分配的渠道Id.
  41. * @apiSuccessExample {json} Success-Response:
  42. *
  43. * {
  44. * "code": 0,
  45. * "msg": "",
  46. * "data": {
  47. * "appid": "112211",
  48. * "common_template_id": "qqqqq",
  49. * "template_id": "wqwqwq",
  50. * }
  51. * }
  52. */
  53. function sendNewsTask(Request $request)
  54. {
  55. CustomMsgService::sendUnpaid();
  56. return response()->success();
  57. }
  58. public function add_news_task($wechatCustomer,$users){
  59. $data = array();
  60. $data['openid'] = 'openid';
  61. $data['appid'] = 'appid';
  62. $data['news_content'] = '[[{"title":"标题啊"},{"description":"描述哦"},{"url":"http://www.baidu.com"},{"image":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=314110819,2721402218&fm=173&s=91B3C23586024F4D0235ECFB0300C036&w=550&h=550&img.JPEG"}]]';
  63. $data['type'] = 'last_task';// last_task,one_task
  64. $data['task_id'] = 3;
  65. $data['send_time'] = date("Y-m-d H:i:s");
  66. $send_data=array(
  67. 'send_time'=>date("Y-m-d H:i:s"),
  68. 'data' => $data
  69. );
  70. $delay = 0;
  71. // v('delay:'.$delay);die();
  72. $job = (new SendTemplate($send_data))->onConnection('rabbitmq')->delay($delay)->onQueue('send_news_list');
  73. }
  74. /**
  75. * 测试
  76. */
  77. //-------------------------------------------------客服消息配置开关Start---------------------------CustomMsgSwitchs
  78. /**
  79. * @apiVersion 1.0.0
  80. * @api {GET} OfficialAccount/customMsgSwitchSetting 客服消息开关设置(测通)
  81. * @apiGroup OfficialAccount
  82. * @apiName customMsgSwitchSetting
  83. * @apiParam {String} custom_category 客服消息类别.
  84. * @apiParam {String} status 客服消息状态 1:开,2:关.
  85. * @apiSuccessExample {json} Success-Response:
  86. *
  87. * {
  88. * "code": 0,
  89. * "msg": "",
  90. * "data": []
  91. * }
  92. */
  93. function customMsgSwitchSetting(Request $request) {
  94. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  95. if(empty($distribution_channel_id)) {
  96. return response()->error("PARAM_EMPTY");
  97. }
  98. $custom_category = $request->has('custom_category') ? $request->input('custom_category') : '';
  99. if(empty($custom_category)) {
  100. return response()->error("PARAM_EMPTY");
  101. }
  102. $status = $request->has('status') ? $request->input('status') : '';
  103. if(empty($status)) {
  104. return response()->error("PARAM_EMPTY");
  105. }
  106. $customMsgService = CustomMsgService::customMsgSwitchSetting($distribution_channel_id,$custom_category,$status);
  107. if($customMsgService == 1) {
  108. return response()->success();
  109. }elseif ($customMsgService == 2) {
  110. return response()->error('CUSTOMS_SETTING_FAILED');
  111. }elseif ($customMsgService == 0) {
  112. return response()->error('HAS_NO_CUSTOMS');
  113. }else{
  114. return response()->error('CUSTOMS_SETTING_FAILED');
  115. }
  116. }
  117. /**
  118. * @apiVersion 1.0.0
  119. * @api {GET} OfficialAccount/customMsgSwitchsByChannelId 客服消息开关列表获取(测通)
  120. * @apiGroup OfficialAccount
  121. * @apiName customMsgSwitchsByChannelId
  122. * @apiSuccessExample {json} Success-Response:
  123. *
  124. * {
  125. * "code": 0,
  126. * "msg": "",
  127. * "data": [
  128. * {
  129. * "title": "未支付提醒",
  130. * "custom_category": "not_pay",
  131. * "status": "1",
  132. * "distribution_channel_id": 1,
  133. * "id": 1
  134. * },
  135. * {
  136. * "title": "定制书籍推送",
  137. * "custom_category": "point_push",
  138. * "status": "0",
  139. * "distribution_channel_id": 1,
  140. * "id": 2
  141. * },
  142. * {
  143. * "title": "热门书籍推送",
  144. * "custom_category": "hot_push",
  145. * "status": "1",
  146. * "distribution_channel_id": 1,
  147. * "id": 3
  148. * }
  149. * ]
  150. * }
  151. */
  152. function customMsgSwitchsByChannelId(Request $request) {
  153. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  154. if(empty($distribution_channel_id)) {
  155. return response()->error("PARAM_EMPTY");
  156. }
  157. $customMsgService = CustomMsgService::customMsgSwitchsByChannelId($distribution_channel_id);
  158. if (!empty($customMsgService)) {
  159. # code...
  160. return response()->collection(new CustomMsgSwitchTransformer(), $customMsgService);
  161. }else{
  162. return response()->success(['data'=>0]);
  163. }
  164. }
  165. /**
  166. * @apiVersion 1.0.0
  167. * @api {GET} OfficialAccount/customMsgSwitchsByChannelCate 获取指定客服消息开关(测通)
  168. * @apiGroup OfficialAccount
  169. * @apiParam {String} custom_category 客服消息类别.
  170. * @apiName customMsgSwitchsByChannelCate
  171. * @apiSuccessExample {json} Success-Response:
  172. *
  173. * {
  174. * "code": 0,
  175. * "msg": "",
  176. * "data": {
  177. * "title": "热门书籍推送",
  178. * "custom_category": "hot_push",
  179. * "status": "1",
  180. * "distribution_channel_id": 1,
  181. * "id": 3
  182. * }
  183. * }
  184. */
  185. function customMsgSwitchsByChannelCate(Request $request) {
  186. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  187. if(empty($distribution_channel_id)) {
  188. return response()->error("PARAM_EMPTY");
  189. }
  190. $custom_category = $request->has('custom_category') ? $request->input('custom_category') : '';
  191. if(empty($custom_category)) {
  192. return response()->error("PARAM_EMPTY");
  193. }
  194. $customMsgService = CustomMsgService::customMsgSwitchsByChannelCate($distribution_channel_id,$custom_category);
  195. if (!empty($customMsgService)) {
  196. # code...
  197. return response()->item(new CustomMsgSwitchTransformer(), $customMsgService);
  198. }else{
  199. return response()->success(['data'=>0]);
  200. }
  201. }
  202. //-------------------------------------------------客服消息配置开关End---------------------------CustomMsgSwitchs
  203. //-------------------------------------------------编辑发送客服消息Start---------------------------CustomSendMsg
  204. /**
  205. * @apiVersion 1.0.0
  206. * @api {GET} OfficialAccount/customSendMsgsByChannelId 发送客服消息列表获取(测通)
  207. * @apiGroup OfficialAccount
  208. * @apiName customSendMsgsByChannelId
  209. * @apiSuccessExample {json} Success-Response:
  210. *
  211. * {
  212. * "code": 0,
  213. * "msg": "",
  214. * "data": [
  215. * {
  216. * "id": 2,
  217. * "name": "测试222",
  218. * "send_time": "2017-12-26 11:11:11",
  219. * "content": "横眉冷对千夫指,俯首甘为孺子牛",
  220. * "redirect_url": "http:\/\/www.baidu.com\/what?am=1",
  221. * "status": null,
  222. * "distribution_channel_id": 1,
  223. * "subscribe_time": "z",
  224. * "sex": "z",
  225. * "balance": "z",
  226. * "order_type": "z",
  227. * "category_id": "z"
  228. * },
  229. * {
  230. * "id": 1,
  231. * "name": "测试111",
  232. * "send_time": "2017-12-26 11:11:11",
  233. * "content": "横眉冷对千夫指,俯首甘为孺子牛",
  234. * "redirect_url": "http:\/\/www.baidu.com\/yes?en",
  235. * "status": null,
  236. * "distribution_channel_id": 1,
  237. * "subscribe_time": "z",
  238. * "sex": "z",
  239. * "balance": "z",
  240. * "order_type": "z",
  241. * "category_id": "z"
  242. * }
  243. * ]
  244. * }
  245. */
  246. function customSendMsgsByChannelId(Request $request) {
  247. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  248. if(empty($distribution_channel_id)) {
  249. return response()->error("PARAM_EMPTY");
  250. }
  251. $customMsgService = CustomMsgService::customSendMsgsByChannelId($distribution_channel_id);
  252. if (!empty($customMsgService)) {
  253. # code...
  254. return response()->collection(new CustomSendMsgsTransformers(), $customMsgService);
  255. }else{
  256. return response()->success(['data'=>0]);
  257. }
  258. }
  259. /**
  260. * @apiVersion 1.0.0
  261. * @api {GET} OfficialAccount/customSendMsgsById 通过ID获取指定客服消息(测通)
  262. * @apiGroup OfficialAccount
  263. * @apiName customSendMsgsById
  264. * @apiParam {String} id 客服消息id.
  265. * @apiSuccessExample {json} Success-Response:
  266. *
  267. * {
  268. * "code": 0,
  269. * "msg": "",
  270. * "data": {
  271. * "id": 1,
  272. * "name": "测试111",
  273. * "send_time": "2017-12-26 11:11:11",
  274. * "content": "横眉冷对千夫指,俯首甘为孺子牛",
  275. * "redirect_url": "http:\/\/www.baidu.com\/yes?en",
  276. * "status": null,
  277. * "distribution_channel_id": 1,
  278. * "subscribe_time": "z",
  279. * "sex": "z",
  280. * "balance": "z",
  281. * "order_type": "z",
  282. * "category_id": "z"
  283. * }
  284. * }
  285. */
  286. function customSendMsgsById(Request $request) {
  287. $id = $request->has('id') ? $request->input('id') : '';
  288. if(empty($id)) {
  289. return response()->error("PARAM_EMPTY");
  290. }
  291. $customMsgService = CustomMsgService::customSendMsgsById($id);
  292. if (!empty($customMsgService)) {
  293. # code...
  294. return response()->item(new CustomSendMsgsTransformers(), $customMsgService);
  295. }else{
  296. return response()->success(['data'=>0]);
  297. }
  298. }
  299. /**
  300. * @apiVersion 1.0.0
  301. * @api {GET} OfficialAccount/stopCustomSendMsgsById 停止发送客服消息
  302. * @apiGroup OfficialAccount
  303. * @apiName customSendMsgsById
  304. * @apiParam {String} id 客服消息id.
  305. * @apiSuccessExample {json} Success-Response:
  306. *
  307. * {
  308. * "code": 0,
  309. * "msg": "",
  310. * "data": {
  311. * }
  312. * }
  313. */
  314. function stopCustomSendMsgsById(Request $request) {
  315. $id = $request->has('id') ? $request->input('id') : '';
  316. if(empty($id)) {
  317. return response()->error("PARAM_EMPTY");
  318. }
  319. $customMsgService = CustomMsgService::updateCustomSendMsgsStatus($id);
  320. if ($customMsgService == 1) {
  321. return response()->success();
  322. }elseif ($customMsgService == 2) {
  323. return response()->error('CUSTOMS_SEND_FAILED');
  324. }elseif ($customMsgService == 0) {
  325. return response()->error('CUSTOMS_SEND_FAILED');
  326. }else{
  327. return response()->error('CUSTOMS_SEND_FAILED');
  328. }
  329. }
  330. /**
  331. * @apiVersion 1.0.0
  332. * @api {GET} OfficialAccount/addCustomSendMsgs 发送客服消息(测通)
  333. * @apiGroup OfficialAccount
  334. * @apiName addCustomSendMsgs
  335. * @apiParam {String} appid 服务号.
  336. * @apiParam {String} name 客服消息标题.
  337. * @apiParam {String} send_time 客服消息发送时间.
  338. * @apiParam {String} content 客服消息内容. 格式:[[{"title":"横眉冷对千夫指,俯首甘为孺子牛"},{"description":"横眉冷对千夫指,俯首甘为孺子牛"},{"url":"http://www.baidu.com"},{"image":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=314110819,2721402218&fm=173&s=91B3C23586024F4D0235ECFB0300C036&w=550&h=550&img.JPEG"}],[{"title":"来他家做佣人半年,结果天天被男主人这样!"},{"description":"来他家做佣人半年,结果天天被男主人这样!"},{"url":"http://www.baidu.com"},{"image":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=314110819,2721402218&fm=173&s=91B3C23586024F4D0235ECFB0300C036&w=550&h=550&img.JPEG"}]]
  339. * @apiParam {String} redirect_url 点击消息重定向地址.
  340. * @apiParam {String} subscribe_time 用户强关时间段.
  341. * @apiParam {String} sex 用户性别.
  342. * @apiParam {String} balance 用户账户余额.
  343. * @apiParam {String} order_type 用户订单状态.
  344. * @apiParam {String} category_id 读书分类.
  345. * @apiParam {String} [id] id.
  346. * @apiSuccessExample {json} Success-Response:
  347. *
  348. * {
  349. * "code": 0,
  350. * "msg": "",
  351. * "data": []
  352. * }
  353. */
  354. function addCustomSendMsgs(Request $request) {
  355. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  356. if(empty($distribution_channel_id)) {
  357. return response()->error("PARAM_EMPTY");
  358. }
  359. $appid = $request->has('appid') ? $request->input('appid') : '';
  360. if(empty($appid)) {
  361. return response()->error("PARAM_EMPTY");
  362. }
  363. $name = $request->has('name') ? $request->input('name') : '';
  364. if(empty($name)) {
  365. return response()->error("PARAM_EMPTY");
  366. }
  367. $send_time = $request->has('send_time') ? $request->input('send_time') : '';
  368. if(empty($send_time)) {
  369. return response()->error("PARAM_EMPTY");
  370. }
  371. $content = $request->has('content') ? $request->input('content') : '';
  372. if(empty($content)) {
  373. return response()->error("PARAM_EMPTY");
  374. }
  375. $redirect_url = $request->has('redirect_url') ? $request->input('redirect_url') : '';
  376. if(empty($redirect_url)) {
  377. return response()->error("PARAM_EMPTY");
  378. }
  379. $subscribe_time = $request->has('subscribe_time') ? $request->input('subscribe_time') : '';
  380. if(empty($subscribe_time)) {
  381. return response()->error("PARAM_EMPTY");
  382. }
  383. $sex = $request->has('sex') ? $request->input('sex') : '';
  384. if(empty($sex)) {
  385. return response()->error("PARAM_EMPTY");
  386. }
  387. $balance = $request->has('balance') ? $request->input('balance') : '';
  388. if(empty($balance)) {
  389. return response()->error("PARAM_EMPTY");
  390. }
  391. $order_type = $request->has('order_type') ? $request->input('order_type') : '';
  392. if(empty($order_type)) {
  393. return response()->error("PARAM_EMPTY");
  394. }
  395. $category_id = $request->has('category_id') ? $request->input('category_id') : '';
  396. if(empty($category_id)) {
  397. return response()->error("PARAM_EMPTY");
  398. }
  399. $is_full_send = $request->has('is_full_send') ? $request->input('is_full_send') : '0';
  400. $user_condition = $request->has('user_condition') ? $request->input('user_condition') : '';
  401. $id = $request->has('id') ? $request->input('id') : '';
  402. $customMsgPrams['appid'] = $appid;
  403. $customMsgPrams['name'] = $name;
  404. $customMsgPrams['send_time'] = $send_time;
  405. $customMsgPrams['content'] = $content;
  406. $customMsgPrams['redirect_url'] = $redirect_url;
  407. $customMsgPrams['subscribe_time'] = $subscribe_time;
  408. $customMsgPrams['sex'] = $sex;
  409. $customMsgPrams['balance'] = $balance;
  410. $customMsgPrams['order_type'] = $order_type;
  411. $customMsgPrams['category_id'] = $category_id;
  412. $customMsgPrams['distribution_channel_id'] = $distribution_channel_id;
  413. $customMsgPrams['id'] = $id;
  414. $customMsgPrams['status'] = '1';
  415. $customMsgPrams['is_full_send'] = $is_full_send;
  416. $customMsgPrams['user_condition'] = $user_condition;
  417. $customMsgService = CustomMsgService::addCustomSendMsgs($customMsgPrams);
  418. if ($customMsgService == 1) {
  419. return response()->success();
  420. }elseif ($customMsgService == 2) {
  421. return response()->error('CUSTOMS_SEND_FAILED');
  422. }elseif ($customMsgService == 0) {
  423. return response()->error('CUSTOMS_SEND_FAILED');
  424. }else{
  425. return response()->error('CUSTOMS_SEND_FAILED');
  426. }
  427. }
  428. /**
  429. * @apiVersion 1.0.0
  430. * @api {GET} OfficialAccount/getAllDocumentCovers 获取所有图库素材(测通)
  431. * @apiGroup OfficialAccount
  432. * @apiName getAllDocumentCovers
  433. * @apiSuccessExample {json} Success-Response:
  434. *
  435. * {
  436. * "code": 0,
  437. * "msg": "",
  438. * "data": [
  439. * {
  440. * "id": 1,
  441. * "origin_cover": "https:\/\/yueduyun.oss-cn-hangzhou.aliyuncs.com\/document_covers\/1.jpg"
  442. * },
  443. * {
  444. * "id": 2,
  445. * "origin_cover": "https:\/\/yueduyun.oss-cn-hangzhou.aliyuncs.com\/document_covers\/2.jpg"
  446. * },
  447. * {
  448. * "id": 3,
  449. * "origin_cover": "https:\/\/yueduyun.oss-cn-hangzhou.aliyuncs.com\/document_covers\/3.jpg"
  450. * }
  451. * ]
  452. * }
  453. */
  454. function getAllDocumentCovers(Request $request) {
  455. $promotionService = PromotionService::getAllMessageDocumentCovers();
  456. if(!empty($promotionService)) {
  457. # code...
  458. return response()->collection(new DocumentCoversTransformer(), $promotionService);
  459. }else{
  460. return response()->success(['data'=>0]);
  461. }
  462. }
  463. /**
  464. * @apiVersion 1.0.0
  465. * @api {GET} OfficialAccount/getAllHeadlinesNoType 获取所有标签文案(测通)
  466. * @apiGroup OfficialAccount
  467. * @apiName getAllHeadlinesNoType
  468. * @apiSuccessExample {json} Success-Response:
  469. *
  470. * {
  471. * "code": 0,
  472. * "msg": "",
  473. * "data": [
  474. * {
  475. * "id": 1,
  476. * "title": "三姐妹怀孕,孩子的父亲竟是同一人,婆婆竟然这样说..."
  477. * },
  478. * {
  479. * "id": 2,
  480. * "title": "看哭5000万人,一对32岁夫妻离婚后的聊天记录..."
  481. * }
  482. * ]
  483. * }
  484. */
  485. function getAllHeadlinesNoType(Request $request) {
  486. $promotionService = PromotionService::getHeadlines();
  487. if(!empty($promotionService)) {
  488. # code...
  489. return response()->collection(new HeadlinelTransformer(), $promotionService);
  490. }else{
  491. return response()->success(['data'=>0]);
  492. }
  493. }
  494. /**
  495. * @apiVersion 1.0.0
  496. * @api {GET} OfficialAccount/testAddCustomSendMsgs 测试向单个用户发送客服消息
  497. * @apiGroup OfficialAccount
  498. * @apiName testAddCustomSendMsgs
  499. * @apiParam {String} appid 服务号.
  500. * @apiParam {String} uid 服务号.
  501. * @apiParam {String} name 客服消息标题.
  502. * @apiParam {String} content 客服消息内容. 格式:[[{"title":"横眉冷对千夫指,俯首甘为孺子牛"},{"description":"横眉冷对千夫指,俯首甘为孺子牛"},{"url":"http://www.baidu.com"},{"image":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=314110819,2721402218&fm=173&s=91B3C23586024F4D0235ECFB0300C036&w=550&h=550&img.JPEG"}],[{"title":"来他家做佣人半年,结果天天被男主人这样!"},{"description":"来他家做佣人半年,结果天天被男主人这样!"},{"url":"http://www.baidu.com"},{"image":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=314110819,2721402218&fm=173&s=91B3C23586024F4D0235ECFB0300C036&w=550&h=550&img.JPEG"}]]
  503. * @apiParam {String} redirect_url 点击消息重定向地址.
  504. * @apiSuccessExample {json} Success-Response:
  505. *
  506. * {
  507. * "code": 0,
  508. * "msg": "",
  509. * "data": []
  510. * }
  511. */
  512. function testAddCustomSendMsgs(Request $request) {
  513. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  514. if(empty($distribution_channel_id)) {
  515. return response()->error("PARAM_EMPTY");
  516. }
  517. $appid = $request->has('appid') ? $request->input('appid') : '';
  518. if(empty($appid)) {
  519. return response()->error("PARAM_EMPTY");
  520. }
  521. $name = $request->has('name') ? $request->input('name') : '';
  522. if(empty($name)) {
  523. return response()->error("PARAM_EMPTY");
  524. }
  525. $content = $request->has('content') ? $request->input('content') : '';
  526. if(empty($content)) {
  527. return response()->error("PARAM_EMPTY");
  528. }
  529. $redirect_url = $request->has('redirect_url') ? $request->input('redirect_url') : '';
  530. if(empty($redirect_url)) {
  531. return response()->error("PARAM_EMPTY");
  532. }
  533. $uid = $request->has('uid') ? $request->input('uid') : '';
  534. if(empty($uid)) {
  535. return response()->error("PARAM_EMPTY");
  536. }
  537. $customMsgPrams['appid'] = $appid;
  538. $customMsgPrams['name'] = $name;
  539. $customMsgPrams['content'] = $content;
  540. $customMsgPrams['redirect_url'] = $redirect_url;
  541. $customMsgPrams['distribution_channel_id'] = $distribution_channel_id;
  542. $customMsgPrams['uid'] = $uid;
  543. $customMsgService = CustomMsgService::testAddCustomSendMsgs($customMsgPrams);
  544. if ($customMsgService == 1) {
  545. return response()->success();
  546. }elseif ($customMsgService == 2) {
  547. return response()->error('CUSTOMS_SEND_FAILED');
  548. }elseif ($customMsgService == 0) {
  549. return response()->error('CUSTOMS_SEND_FAILED');
  550. }else{
  551. return response()->error('CUSTOMS_SEND_FAILED');
  552. }
  553. }
  554. //-------------------------------------------------编辑发送客服消息End---------------------------CustomSendMsg
  555. //-------------------------------------------------生成图文链接Start---------------------------
  556. /**
  557. * 生成图文链接
  558. */
  559. static function createOfficialImgTxtUrl(Request $request)
  560. {
  561. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  562. if(empty($distribution_channel_id)) {
  563. return response()->error("PARAM_EMPTY");
  564. }
  565. //图片链接
  566. $img_url = $request->has('img_url') ? $request->input('img_url') : '';
  567. if(empty($img_url)) {
  568. return response()->error("PARAM_EMPTY");
  569. }
  570. //文章内容
  571. $content = $request->has('content') ? $request->input('content') : '';
  572. if(empty($content)) {
  573. return response()->error("PARAM_EMPTY");
  574. }
  575. //文章标题
  576. $title = $request->has('title') ? $request->input('title') : '';
  577. if(empty($title)) {
  578. return response()->error("PARAM_EMPTY");
  579. }
  580. $book_name = $request->has('book_name') ? $request->input('book_name') : '';
  581. if(empty($book_name)) {
  582. return response()->error("PARAM_EMPTY");
  583. }
  584. $chapter_sequence = $request->has('chapter_sequence') ? $request->input('chapter_sequence') : '';
  585. if(empty($chapter_sequence)) {
  586. return response()->error("PARAM_EMPTY");
  587. }
  588. $send_orders_id = $request->has('send_orders_id') ? $request->input('send_orders_id') : '';
  589. if(empty($send_orders_id)) {
  590. return response()->error("PARAM_EMPTY");
  591. }
  592. $send_orders_name = $request->has('send_orders_name') ? $request->input('send_orders_name') : '';
  593. if(empty($send_orders_name)) {
  594. return response()->error("PARAM_EMPTY");
  595. }
  596. $send_orders_url = $request->has('send_orders_url') ? $request->input('send_orders_url') : '';
  597. if(empty($send_orders_url)) {
  598. return response()->error("PARAM_EMPTY");
  599. }
  600. $officialImgTxtUrlPrams['distribution_channel_id'] = $distribution_channel_id;
  601. $officialImgTxtUrlPrams['img_url'] = $img_url;
  602. $officialImgTxtUrlPrams['content'] = $content;
  603. $officialImgTxtUrlPrams['title'] = $title;
  604. $officialImgTxtUrlPrams['book_name'] = $book_name;
  605. $officialImgTxtUrlPrams['chapter_sequence'] = $chapter_sequence;
  606. $officialImgTxtUrlPrams['send_orders_id'] = $send_orders_id;
  607. $officialImgTxtUrlPrams['send_orders_name'] = $send_orders_name;
  608. $officialImgTxtUrlPrams['send_orders_url'] = $send_orders_url;
  609. $customMsgService = CustomMsgService::createOfficialImgTxtUrl($officialImgTxtUrlPrams);
  610. if (!empty($customMsgService)) {
  611. # code...
  612. return response()->success(['img_url'=>$customMsgService]);
  613. }else{
  614. return response()->error('OFFICIAL_IMGTXT_FAILED');
  615. }
  616. }
  617. /**
  618. * 获取图文列表
  619. */
  620. static function getOfficialImgTxtUrl(Request $request)
  621. {
  622. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  623. if(empty($distribution_channel_id)) {
  624. return response()->error("PARAM_EMPTY");
  625. }
  626. $customMsgService = CustomMsgService::getOfficialImgTxtUrl($distribution_channel_id);
  627. if (!empty($customMsgService)) {
  628. # code...
  629. return response()->collection(new OfficialImgtextUrlsTransformer(), $customMsgService);
  630. }else{
  631. return response()->success(['data'=>0]);
  632. }
  633. }
  634. /**
  635. * 测试 三天回本12小时推送
  636. */
  637. static function add_news_recovery_push_hot(Request $request)
  638. {
  639. CustomMsgService::add_news_recovery_push_hot();
  640. return response()->success();
  641. }
  642. /**
  643. * 测试 三天回本24小时推送
  644. */
  645. static function add_news_recovery_push_activity(Request $request)
  646. {
  647. CustomMsgService::add_news_recovery_push_activity();
  648. return response()->success();
  649. }
  650. /**
  651. * 测试 定制图书推送
  652. */
  653. static function add_news_point_book(Request $request)
  654. {
  655. CustomMsgService::add_news_point_book();
  656. return response()->success();
  657. }
  658. /**
  659. * 测试 热门图书推送
  660. */
  661. static function add_news_top_book(Request $request)
  662. {
  663. CustomMsgService::add_news_top_book();
  664. return response()->success();
  665. }
  666. /**
  667. * 测试 发送未支付消息提醒
  668. */
  669. static function sendUnpaid(Request $request)
  670. {
  671. CustomMsgService::sendUnpaid();
  672. return response()->success();
  673. }
  674. /**
  675. * 付费用户每日提醒
  676. */
  677. static function add_template_pay_push_daily(Request $request)
  678. {
  679. CustomMsgService::add_template_pay_push_daily();
  680. return response()->success();
  681. }
  682. //-------------------------------------------------生成图文链接End---------------------------
  683. }