Server.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. namespace App\Http\Controllers\Miniprogram;
  3. use App\Exceptions\AlertException;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Controller;
  6. class Server extends Controller
  7. {
  8. /**
  9. * @param Request $request
  10. * @throws AlertException
  11. */
  12. public function message(Request $request)
  13. {
  14. if (isset($request->echostr)) {
  15. echo $request->echostr;
  16. return;
  17. }
  18. if (!$msg = json_decode($request->getContent())) {
  19. return;
  20. }
  21. // 小程序日志
  22. \DB::table('pocket.kdgx_monitor_' . substr($msg->ToUserName, -1))->insert([
  23. 'public_id' => $msg->ToUserName,
  24. 'openid' => $msg->FromUserName,
  25. 'type' => $msg->MsgType,
  26. 'value' => array2xml(json_decode($request->getContent(), true)),
  27. 'create_time' => $msg->CreateTime
  28. ]);
  29. if (!is_null($msg->ToUserName) && $msg->ToUserName != 'gh_01c089b58dda') {
  30. $config['miniprogram'] = [
  31. 'public_id' => env("LITTLE_{$msg->ToUserName}_PUBLIC_ID", null),
  32. 'public_name' => env("LITTLE_{$msg->ToUserName}_PUBLIC_NAME", ''),
  33. 'app_id' => env("LITTLE_{$msg->ToUserName}_APP_ID", ''),
  34. 'app_secret' => env("LITTLE_{$msg->ToUserName}_APP_SECRET", '')
  35. ];
  36. if (is_null($config['miniprogram']['public_id'])) {
  37. throw new AlertException('header参数错误', 101);
  38. }
  39. config($config);
  40. }
  41. switch ($msg->ToUserName) {
  42. case "gh_01c089b58dda":
  43. $this->serverfpdx($msg);
  44. break;
  45. case 'gh_eca533ae4ceb':
  46. $this->server72h($msg);
  47. break;
  48. }
  49. echo 'success';
  50. return;
  51. }
  52. private function serverfpdx($msg)
  53. {
  54. switch ($msg->MsgType) {
  55. case 'text':
  56. $this->serverFpdxText($msg->FromUserName, $msg->Content);
  57. break;
  58. case 'miniprogrampage':
  59. $fragment = parse_url($msg->PagePath ?? '')['fragment'] ?? '';
  60. $this->serverFpdxText($msg->FromUserName, $fragment);
  61. break;
  62. default:
  63. break;
  64. }
  65. }
  66. private function serverFpdxText($fromUserName, $content)
  67. {
  68. $guide = new Guide();
  69. switch (trim($content)) {
  70. // app下载
  71. case "123":
  72. $guide->custom("app", $fromUserName);
  73. break;
  74. // 活动报名
  75. case '1':
  76. $guide->custom("enroll_text", $fromUserName);
  77. $guide->custom('enroll_img', $fromUserName);
  78. break;
  79. // 时遇记情报局活动报名
  80. case '情报局':
  81. $guide->custom("qbj_enroll_text", $fromUserName);
  82. $guide->custom('qbj_enroll_img', $fromUserName);
  83. break;
  84. // 72小时活动确认客服
  85. case '3':
  86. $guide->custom('wxkf_text', $fromUserName);
  87. $guide->custom('wxkf_img', $fromUserName);
  88. break;
  89. // 添加微信认证专员
  90. case '添加专员':
  91. case '认证':
  92. $guide->custom('wxkfzy_text', $fromUserName);
  93. $guide->custom('wxkfzy_img', $fromUserName);
  94. break;
  95. // 订阅抽奖提醒
  96. case '4':
  97. $guide->custom('lotteryremind_text', $fromUserName);
  98. $guide->custom('lotteryremind_img', $fromUserName);
  99. break;
  100. // 打开通知
  101. case '5':
  102. $guide->custom('notice_text', $fromUserName);
  103. $guide->custom('notice_img', $fromUserName);
  104. break;
  105. // 订阅匹配通知
  106. case '6':
  107. $guide->custom('pair_notice_text', $fromUserName);
  108. $guide->custom('pair_notice_img', $fromUserName);
  109. break;
  110. // 进入公众号聊天
  111. case '8':
  112. case '聊天':
  113. $guide->custom('intoroom_text', $fromUserName);
  114. $guide->custom('intoroom_img', $fromUserName);
  115. break;
  116. // 联系客服小象导
  117. case '0':
  118. case '客服':
  119. $guide->custom('kfxxd_text', $fromUserName);
  120. $guide->custom('kfxxd_img', $fromUserName);
  121. break;
  122. // 心动邀请订阅通知
  123. case '2':
  124. case '邀请':
  125. case '心动邀请':
  126. $guide->custom('invitation_text', $fromUserName);
  127. $guide->custom('invitation_img', $fromUserName);
  128. break;
  129. // 订阅晚安伴侣|留言通知
  130. case '晚安':
  131. case '晚安伴侣':
  132. $guide->custom('goodnight_chat_text', $fromUserName);
  133. $guide->custom('goodnight_chat_img', $fromUserName);
  134. break;
  135. // 订阅开黑通知
  136. case '开黑':
  137. case '开黑通知':
  138. $guide->custom('gteam_notice_text', $fromUserName);
  139. $guide->custom('gteam_notice_img', $fromUserName);
  140. break;
  141. // 激活会员
  142. case '会员':
  143. $guide->custom('tobe_vip_text', $fromUserName);
  144. $guide->custom('tobe_vip_img', $fromUserName);
  145. break;
  146. // 领取会员红包
  147. case '红包':
  148. $guide->custom('get_vip_flower_text', $fromUserName);
  149. $guide->custom('get_vip_flower_img', $fromUserName);
  150. break;
  151. default:
  152. $guide->custom('gh_01c089b58dda_default', $fromUserName);
  153. break;
  154. }
  155. }
  156. private function server72h($msg)
  157. {
  158. $guide = new Guide();
  159. switch ($msg->MsgType) {
  160. case 'text':
  161. switch ($msg->Content) {
  162. case '0': # 活动报名 kd_ce5103f65339
  163. $guide->custom("enroll_text", $msg->FromUserName);
  164. $guide->custom('enroll_img_0', $msg->FromUserName);
  165. break;
  166. case '1': # 活动报名 gh_01c089b58dda
  167. $guide->custom("enroll_text", $msg->FromUserName);
  168. $guide->custom('enroll_img', $msg->FromUserName);
  169. break;
  170. case '2': # 活动报名 kd_5edc93aa148e
  171. $guide->custom("enroll_text", $msg->FromUserName);
  172. $guide->custom('enroll_img_2', $msg->FromUserName);
  173. break;
  174. case '3': # 活动报名 kd_qqzonesaohui
  175. $guide->custom("enroll_text", $msg->FromUserName);
  176. $guide->custom('enroll_img_3', $msg->FromUserName);
  177. break;
  178. case '4': # 活动报名 kd_qzoneguanzhu
  179. $guide->custom("enroll_text", $msg->FromUserName);
  180. $guide->custom('enroll_img_4', $msg->FromUserName);
  181. break;
  182. case '5': # 活动报名 kd_b598cb7474d8
  183. $guide->custom("enroll_text", $msg->FromUserName);
  184. $guide->custom('enroll_img_5', $msg->FromUserName);
  185. break;
  186. case '6': # 活动报名 kd_wxkefuxiaoyu
  187. $guide->custom("enroll_text", $msg->FromUserName);
  188. $guide->custom('enroll_img_6', $msg->FromUserName);
  189. break;
  190. case '7': # 活动报名 kd_fuwuhaoqunfa
  191. $guide->custom("enroll_text", $msg->FromUserName);
  192. $guide->custom('enroll_img_7', $msg->FromUserName);
  193. break;
  194. case '8': # 活动报名 kd_dingyuequnfa
  195. $guide->custom("enroll_text", $msg->FromUserName);
  196. $guide->custom('enroll_img_8', $msg->FromUserName);
  197. break;
  198. case '9': # 活动报名 kd_laiyuanpuapp
  199. $guide->custom("enroll_text", $msg->FromUserName);
  200. $guide->custom('enroll_img_9', $msg->FromUserName);
  201. break;
  202. default:
  203. break;
  204. }
  205. break;
  206. default:
  207. break;
  208. }
  209. }
  210. }