123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\library\Redis;
- use app\common\library\WeChatObject;
- use app\common\model\AdminConfig;
- use app\common\model\Config;
- use app\common\service\ActiveShareService;
- use app\common\service\AdService;
- use app\common\service\ClientuserService;
- use app\common\service\NovelyoulikeService;
- use app\main\constants\AdConstants;
- use app\main\constants\MqConstants;
- use app\main\model\object\DotObject;
- use app\main\service\AppGuideService;
- use app\main\service\ClientAppService;
- use app\main\service\HigeMessageService;
- use app\main\service\LogService;
- use app\main\service\MqService;
- use app\main\service\SmartPushDotService;
- use app\main\service\UserService;
- use app\main\service\UserSilentService;
- use think\Request;
- use Yansongda\Pay\Exceptions\Exception;
- /**
- * 示例接口
- */
- class Demo extends Api
- {
- //如果$noNeedLogin为空表示所有接口都需要登录才能请求
- //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
- //如果接口已经设置无需登录,那也就无需鉴权了
- //
- // 无需登录的接口,*表示全部
- protected $noNeedLogin = ['test1'];
- // 无需鉴权的接口,*表示全部
- protected $noNeedRight = ['test00', 'test01', 'test0', 'test2', 'test3', 'test5', 'test6', 'test7', 'test8', 'test9', 'clearbindcode', 'clearbindappuser', 'clearappuserphone', 'mqtest'];
- public function mkCommon(){
- $common = [
- 'vn' => 'v1.0',
- 'pkna' => '22',
- 'chid' => '1',
- 'app' => '1',
- 'ptx' => '1',
- 'ua' => '1',
- 'p' => '1',
- ];
- echo json_encode($common);
- }
- public function test00()
- {
- }
- public function mqtest()
- {
- echo 'MqTest:'.time();
- $mq = MqService::instance()->getDotMqInstance();
- $exchangename='cps.ex.topic';
- $routing_key = 'collect.user.subscribe1';
- $data = [
- 'admin_id' => 2,
- 'user_id' => 3,
- 'type' => 1,
- 'event_time' => time(),
- 'business_line' => 0
- ];
- $mq->transferExchange($data, $exchangename, $routing_key, 'topic');
- }
- public function test01()
- {
- $arr = [
- [
- 'title' => '你为什么还没不到口罩',
- 'author' => '回环针',
- 'cover' => './uploads/20200229/17afc3c90f68c2a46c7e36024e6589a2.png',
- 'content' => '国家出手控制口罩',
- 'digest' => '1',
- 'need_open_comment' => 0,
- 'only_fans_can_comment' => 0,
- 'type' => 0,
- 'book_id' => 1111111111,
- 'chapter_id' => 222222,
- ]
- ];
- //UserSilentService::instance()->refactorUrl();
- try{
- // 文字
- /*HigeMessageService::instance()->sent(
- [1734],
- 50000207,
- 1,
- [
- [
- 'content' => '文字消息内容002',
- 'is_url' => 0,
- ]]
- );*/
- // 图文
- HigeMessageService::instance()->sent(
- [1734],
- 50000207,
- 2,
- $arr
- );
- }catch (\Exception $exception){
- echo $exception->getMessage();
- }
- echo 'Success'.time();
- }
- public function test0()
- {
- $channel_id = 1749;
- $adminConfig = new AdminConfig();
- $adminInfo = $adminConfig->getAdminInfoAll($channel_id);
- $wechat = new WeChatObject($adminInfo);
- $officialAccount = $wechat->getOfficialAccount();
- $list = $officialAccount->user_tag->list();
- print_r('<textarea cols="100" rows="10">');
- print_r($list);
- print_r('</textarea>');
- die();
- }
- /**
- * 无需登录的接口
- *
- * 必选参数:无<br>
- * 可选参数:无
- */
- public function test1()
- {
- $this->mkCommon();
- die();
- $this->success('返回成功', ['action' => 'test1']);
- }
- public function test9()
- {
- //$this->outSql();
- $data = NovelyoulikeService::instance()->getNovelRecommend();
- print_r($data);
- die();
- }
- public function outSql(){
- for ($i= 256; $i<=512; $i++){
- 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 '是否扣量'; ";
- echo PHP_EOL;
- echo "<br/>";
- }
- exit();
- }
- /**
- * 需要登录的接口
- *
- * 必选参数:token<br>
- * 可选参数:无
- */
- public function test2()
- {
- Redis::instance()->sadd('nihao2',2,4,3);
- $r = Redis::instance()->sRandMember('nihao2');
- dump($r);
- $this->success('返回成功', ['action' => 'test2']);
- }
- /**
- * 需要登录的接口
- *
- * 必选参数:token<br>
- * 可选参数:无
- */
- public function test3()
- {
- $dotData = SmartPushDotService::instance()->generateKefuData(
- 2000,
- 0,
- 0,
- 9999
- );
- SmartPushDotService::instance()->dotSmartPushInfo($dotData);
- echo 'OK'.time();
- }
- public function test4()
- {
- $default_menu_obj = model('config')->where(['name'=>'wx_menu'])->field('value')->find();
- $default_menu_arr = json_decode($default_menu_obj->value, true);
- $arr = [
- ['name' => '阅读记录'],
- ['name' => '精品推荐'],
- ['name' => '用户中心']
- ];
- var_dump($this->isConsistent($default_menu_arr, $arr));
- die();
- }
- public function test5()
- {
- // 测试打点, 将数据压入到MQ
- try{
- $dotData = new DotObject();
- $dotData->user_id = 50000207;
- $dotData->channel_id = 1734;
- $dotData->sex = 2;
- $dotData->business_line = '1';
- //$dotData->action_type = MqConstants::ROUTING_KEY_APP_REGISTER;
- //$dotData->type = MqConstants::MSG_TYPE_APP_REGISTER;
- //$dotData->action_type = MqConstants:: ROUTING_KEY_APP_BIND;
- //$dotData->type = MqConstants::MSG_TYPE_APP_BIND;
- $dotData->action_type = MqConstants:: ROUTING_KEY_APP_BIND_CODE;
- $dotData->type = MqConstants::MSG_TYPE_APP_BIND_CODE;
- $dotData->event_time = Request::instance()->server('REQUEST_TIME');
- MqService::instance()->sendMessage($dotData);
- echo 'OK->'.date('Y-m-d', time());
- }catch (\Exception $exception){
- print_r($exception);
- die();
- }
- }
- public function test6()
- {
- //发送打点数据
- $dotData = new DotObject();
- //打点信息初始化
- $dotData->channel_id = 1734;
- $dotData->user_id = 4;
- $dotData->event_time = time();;
- $dotData->is_first_follow = 1;
- $dotData->sex = 2;
- $dotData->action_type = MqConstants::ROUTING_KEY_SUBSCRIBE;
- $dotData->type = MqConstants::MSG_TYPE_SEX;
- MqService::instance()->sendMessage($dotData);
- }
- /**
- * 打点APP下载引导页UV
- */
- public function test7()
- {
- //发送打点数据
- $dotData = new DotObject();
- //打点信息初始化
- $dotData->channel_id = 1734;
- $dotData->user_id = 13;
- $dotData->event_time = time();
- $dotData->action_type = MqConstants::ROUTING_KEY_APP_GUIDE_UV;
- $dotData->guide_idx = 1;
- $dotData->guide_op_type = 1;
- MqService::instance()->sendMessage($dotData);
- echo 'Success ##'. time();
- }
- public function test8($uid, $kandian)
- {
- UserService::instance()->addFreeKanDian($uid, $kandian, time(), 'APP用户绑定手机号赠送书币');
- echo "添加书币成功:{$uid} , {$kandian}";
- }
- /**
- * @param $uid
- */
- public function clearbindcode($uid)
- {
- UserService::instance()->update(['bindtime' => ''], ['id' => $uid]);
- echo 'Success::'.date('Y-m-d H:i:s', time());
- }
- /**
- * 清空用户绑定的手机号
- * @param $uid
- */
- public function clearbindappuser($uid)
- {
- UserService::instance()->update(['mobile' => '', 'bindtime' => ''], ['id' => $uid]);
- $redis = Redis::instance();
- $key = 'UN:' . $uid;
- $redis->del($key);
- echo 'Scuccess, 清空用户绑定的手机号' . date('Y-m-d H:i:s', time());
- }
- public function clearappuserphone($phone)
- {
- $res = model('UserPhone')->setConnect($phone)->where('phone', '=', $phone)->delete();
- $redis = Redis::instance();
- $key = 'UPHONE:' . $phone;
- $redis->del($key);
- echo "Success,根据手机号清空用户信息" . date('Y-m-d H:i:s', time());
- }
- public function isConsistent(array $defalt_menu_arr, array $b_arr)
- {
- $defalt_name_arr = array_column($defalt_menu_arr, 'name');
- $b_name_arr = array_column($b_arr, 'name');
- $diff = array_diff_assoc($defalt_name_arr, $b_name_arr);
- if(!empty($diff)){
- return false;
- }else{
- foreach ($defalt_menu_arr as $key => $default_item)
- {
- if(isset($default_item['sub_button'])){
- $default_sub_btn_arr = array_column($default_item['sub_button'], 'name');
- $b_sub_btn_arr = isset($b_arr[$key]['sub_button']) ? array_column($b_arr[$key]['sub_button'], 'name') : array();
- $diff_sub_btn = array_diff_assoc($default_sub_btn_arr, $b_sub_btn_arr);
- if($diff_sub_btn){
- return false;
- }
- }
- }
- }
- return true;
- }
- }
|