Demo.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\library\Redis;
  5. use app\common\library\WeChatObject;
  6. use app\common\model\AdminConfig;
  7. use app\common\model\Config;
  8. use app\common\service\ActiveShareService;
  9. use app\common\service\AdService;
  10. use app\common\service\ClientuserService;
  11. use app\common\service\NovelyoulikeService;
  12. use app\main\constants\AdConstants;
  13. use app\main\constants\MqConstants;
  14. use app\main\model\object\DotObject;
  15. use app\main\service\AppGuideService;
  16. use app\main\service\ClientAppService;
  17. use app\main\service\HigeMessageService;
  18. use app\main\service\LogService;
  19. use app\main\service\MqService;
  20. use app\main\service\SmartPushDotService;
  21. use app\main\service\UserService;
  22. use app\main\service\UserSilentService;
  23. use think\Request;
  24. use Yansongda\Pay\Exceptions\Exception;
  25. /**
  26. * 示例接口
  27. */
  28. class Demo extends Api
  29. {
  30. //如果$noNeedLogin为空表示所有接口都需要登录才能请求
  31. //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
  32. //如果接口已经设置无需登录,那也就无需鉴权了
  33. //
  34. // 无需登录的接口,*表示全部
  35. protected $noNeedLogin = ['test1'];
  36. // 无需鉴权的接口,*表示全部
  37. protected $noNeedRight = ['test00', 'test01', 'test0', 'test2', 'test3', 'test5', 'test6', 'test7', 'test8', 'test9', 'clearbindcode', 'clearbindappuser', 'clearappuserphone', 'mqtest'];
  38. public function mkCommon(){
  39. $common = [
  40. 'vn' => 'v1.0',
  41. 'pkna' => '22',
  42. 'chid' => '1',
  43. 'app' => '1',
  44. 'ptx' => '1',
  45. 'ua' => '1',
  46. 'p' => '1',
  47. ];
  48. echo json_encode($common);
  49. }
  50. public function test00()
  51. {
  52. }
  53. public function mqtest()
  54. {
  55. echo 'MqTest:'.time();
  56. $mq = MqService::instance()->getDotMqInstance();
  57. $exchangename='cps.ex.topic';
  58. $routing_key = 'collect.user.subscribe1';
  59. $data = [
  60. 'admin_id' => 2,
  61. 'user_id' => 3,
  62. 'type' => 1,
  63. 'event_time' => time(),
  64. 'business_line' => 0
  65. ];
  66. $mq->transferExchange($data, $exchangename, $routing_key, 'topic');
  67. }
  68. public function test01()
  69. {
  70. $arr = [
  71. [
  72. 'title' => '你为什么还没不到口罩',
  73. 'author' => '回环针',
  74. 'cover' => './uploads/20200229/17afc3c90f68c2a46c7e36024e6589a2.png',
  75. 'content' => '国家出手控制口罩',
  76. 'digest' => '1',
  77. 'need_open_comment' => 0,
  78. 'only_fans_can_comment' => 0,
  79. 'type' => 0,
  80. 'book_id' => 1111111111,
  81. 'chapter_id' => 222222,
  82. ]
  83. ];
  84. //UserSilentService::instance()->refactorUrl();
  85. try{
  86. // 文字
  87. /*HigeMessageService::instance()->sent(
  88. [1734],
  89. 50000207,
  90. 1,
  91. [
  92. [
  93. 'content' => '文字消息内容002',
  94. 'is_url' => 0,
  95. ]]
  96. );*/
  97. // 图文
  98. HigeMessageService::instance()->sent(
  99. [1734],
  100. 50000207,
  101. 2,
  102. $arr
  103. );
  104. }catch (\Exception $exception){
  105. echo $exception->getMessage();
  106. }
  107. echo 'Success'.time();
  108. }
  109. public function test0()
  110. {
  111. $channel_id = 1749;
  112. $adminConfig = new AdminConfig();
  113. $adminInfo = $adminConfig->getAdminInfoAll($channel_id);
  114. $wechat = new WeChatObject($adminInfo);
  115. $officialAccount = $wechat->getOfficialAccount();
  116. $list = $officialAccount->user_tag->list();
  117. print_r('<textarea cols="100" rows="10">');
  118. print_r($list);
  119. print_r('</textarea>');
  120. die();
  121. }
  122. /**
  123. * 无需登录的接口
  124. *
  125. * 必选参数:无<br>
  126. * 可选参数:无
  127. */
  128. public function test1()
  129. {
  130. $this->mkCommon();
  131. die();
  132. $this->success('返回成功', ['action' => 'test1']);
  133. }
  134. public function test9()
  135. {
  136. //$this->outSql();
  137. $data = NovelyoulikeService::instance()->getNovelRecommend();
  138. print_r($data);
  139. die();
  140. }
  141. public function outSql(){
  142. for ($i= 256; $i<=512; $i++){
  143. echo "USE test_cps_user_{$i}; ALTER TABLE recharge DROP COLUMN deduct; ALTER TABLE recharge ADD COLUMN `dd` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '是否扣量'; ";
  144. echo PHP_EOL;
  145. echo "<br/>";
  146. }
  147. exit();
  148. }
  149. /**
  150. * 需要登录的接口
  151. *
  152. * 必选参数:token<br>
  153. * 可选参数:无
  154. */
  155. public function test2()
  156. {
  157. Redis::instance()->sadd('nihao2',2,4,3);
  158. $r = Redis::instance()->sRandMember('nihao2');
  159. dump($r);
  160. $this->success('返回成功', ['action' => 'test2']);
  161. }
  162. /**
  163. * 需要登录的接口
  164. *
  165. * 必选参数:token<br>
  166. * 可选参数:无
  167. */
  168. public function test3()
  169. {
  170. $dotData = SmartPushDotService::instance()->generateKefuData(
  171. 2000,
  172. 0,
  173. 0,
  174. 9999
  175. );
  176. SmartPushDotService::instance()->dotSmartPushInfo($dotData);
  177. echo 'OK'.time();
  178. }
  179. public function test4()
  180. {
  181. $default_menu_obj = model('config')->where(['name'=>'wx_menu'])->field('value')->find();
  182. $default_menu_arr = json_decode($default_menu_obj->value, true);
  183. $arr = [
  184. ['name' => '阅读记录'],
  185. ['name' => '精品推荐'],
  186. ['name' => '用户中心']
  187. ];
  188. var_dump($this->isConsistent($default_menu_arr, $arr));
  189. die();
  190. }
  191. public function test5()
  192. {
  193. // 测试打点, 将数据压入到MQ
  194. try{
  195. $dotData = new DotObject();
  196. $dotData->user_id = 50000207;
  197. $dotData->channel_id = 1734;
  198. $dotData->sex = 2;
  199. $dotData->business_line = '1';
  200. //$dotData->action_type = MqConstants::ROUTING_KEY_APP_REGISTER;
  201. //$dotData->type = MqConstants::MSG_TYPE_APP_REGISTER;
  202. //$dotData->action_type = MqConstants:: ROUTING_KEY_APP_BIND;
  203. //$dotData->type = MqConstants::MSG_TYPE_APP_BIND;
  204. $dotData->action_type = MqConstants:: ROUTING_KEY_APP_BIND_CODE;
  205. $dotData->type = MqConstants::MSG_TYPE_APP_BIND_CODE;
  206. $dotData->event_time = Request::instance()->server('REQUEST_TIME');
  207. MqService::instance()->sendMessage($dotData);
  208. echo 'OK->'.date('Y-m-d', time());
  209. }catch (\Exception $exception){
  210. print_r($exception);
  211. die();
  212. }
  213. }
  214. public function test6()
  215. {
  216. //发送打点数据
  217. $dotData = new DotObject();
  218. //打点信息初始化
  219. $dotData->channel_id = 1734;
  220. $dotData->user_id = 4;
  221. $dotData->event_time = time();;
  222. $dotData->is_first_follow = 1;
  223. $dotData->sex = 2;
  224. $dotData->action_type = MqConstants::ROUTING_KEY_SUBSCRIBE;
  225. $dotData->type = MqConstants::MSG_TYPE_SEX;
  226. MqService::instance()->sendMessage($dotData);
  227. }
  228. /**
  229. * 打点APP下载引导页UV
  230. */
  231. public function test7()
  232. {
  233. //发送打点数据
  234. $dotData = new DotObject();
  235. //打点信息初始化
  236. $dotData->channel_id = 1734;
  237. $dotData->user_id = 13;
  238. $dotData->event_time = time();
  239. $dotData->action_type = MqConstants::ROUTING_KEY_APP_GUIDE_UV;
  240. $dotData->guide_idx = 1;
  241. $dotData->guide_op_type = 1;
  242. MqService::instance()->sendMessage($dotData);
  243. echo 'Success ##'. time();
  244. }
  245. public function test8($uid, $kandian)
  246. {
  247. UserService::instance()->addFreeKanDian($uid, $kandian, time(), 'APP用户绑定手机号赠送书币');
  248. echo "添加书币成功:{$uid} , {$kandian}";
  249. }
  250. /**
  251. * @param $uid
  252. */
  253. public function clearbindcode($uid)
  254. {
  255. UserService::instance()->update(['bindtime' => ''], ['id' => $uid]);
  256. echo 'Success::'.date('Y-m-d H:i:s', time());
  257. }
  258. /**
  259. * 清空用户绑定的手机号
  260. * @param $uid
  261. */
  262. public function clearbindappuser($uid)
  263. {
  264. UserService::instance()->update(['mobile' => '', 'bindtime' => ''], ['id' => $uid]);
  265. $redis = Redis::instance();
  266. $key = 'UN:' . $uid;
  267. $redis->del($key);
  268. echo 'Scuccess, 清空用户绑定的手机号' . date('Y-m-d H:i:s', time());
  269. }
  270. public function clearappuserphone($phone)
  271. {
  272. $res = model('UserPhone')->setConnect($phone)->where('phone', '=', $phone)->delete();
  273. $redis = Redis::instance();
  274. $key = 'UPHONE:' . $phone;
  275. $redis->del($key);
  276. echo "Success,根据手机号清空用户信息" . date('Y-m-d H:i:s', time());
  277. }
  278. public function isConsistent(array $defalt_menu_arr, array $b_arr)
  279. {
  280. $defalt_name_arr = array_column($defalt_menu_arr, 'name');
  281. $b_name_arr = array_column($b_arr, 'name');
  282. $diff = array_diff_assoc($defalt_name_arr, $b_name_arr);
  283. if(!empty($diff)){
  284. return false;
  285. }else{
  286. foreach ($defalt_menu_arr as $key => $default_item)
  287. {
  288. if(isset($default_item['sub_button'])){
  289. $default_sub_btn_arr = array_column($default_item['sub_button'], 'name');
  290. $b_sub_btn_arr = isset($b_arr[$key]['sub_button']) ? array_column($b_arr[$key]['sub_button'], 'name') : array();
  291. $diff_sub_btn = array_diff_assoc($default_sub_btn_arr, $b_sub_btn_arr);
  292. if($diff_sub_btn){
  293. return false;
  294. }
  295. }
  296. }
  297. }
  298. return true;
  299. }
  300. }