123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Log;
- use App\Models\AdPlacementLog;
- use App\Models\CustomerDetails;
- use App\Models\OfficialAccount;
- use App\Models\View\CustomerDetail;
- use App\RedisModel;
- use App\Service\AccessTokenService;
- use App\Service\ChatService;
- use App\Service\ContactService;
- use App\Service\CorpAuthService;
- use App\Service\CustomerService;
- use App\Service\DjOrderService;
- use App\Service\GroupChatJoinWayService;
- use App\Service\HttpService;
- use App\Service\MiniProgramService;
- use App\Service\PitcherService;
- use App\Service\RadarService;
- use App\Service\TokenService;
- use App\Support\EmailQueue;
- use App\Support\qyApi\QyCommon;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Hash;
- use Illuminate\Support\Facades\Storage;
- use SimpleSoftwareIO\QrCode\Facades\QrCode;
- class TestController extends Controller
- {
- /*
- * 获取分表
- * */
- public function getLabel($corpid)
- {
- $label = get_hash_code($corpid, 50);
- dd($label);
- }
- public function detectMobileBrand($userAgent) {
- // 定义常见品牌关键字
- $brands = [
- 'Apple' => 'iPhone|iPad|iPod',
- 'Samsung' => 'Samsung|SM-',
- 'Huawei' => 'Huawei|Honor',
- 'Xiaomi' => 'Xiaomi|Mi|Redmi',
- 'OPPO' => 'OPPO|CPH',
- 'Vivo' => 'Vivo',
- 'OnePlus' => 'OnePlus',
- 'Google' => 'Pixel',
- 'Sony' => 'Sony|Xperia',
- 'LG' => 'LG',
- 'Motorola' => 'Moto|Motorola',
- 'Nokia' => 'Nokia',
- 'Realme' => 'Realme',
- 'Meizu' => 'Meizu|MX|M9',
- 'ZTE' => 'ZTE',
- 'Lenovo' => 'Lenovo',
- 'Asus' => 'Asus|ZenFone',
- 'HTC' => 'HTC',
- 'BlackBerry' => 'BlackBerry|BB10',
- ];
- // 遍历品牌关键字匹配
- foreach ($brands as $brand => $pattern) {
- if (preg_match("/$pattern/i", $userAgent)) {
- return $brand;
- }
- }
- // 如果没有匹配到,返回未知
- return '';
- }
- /**
- * 测试员工搜索
- * */
- public function customer(Request $request)
- {
- try {
- $clickTotalRds = 'JuXing::AdClickTotal_';
- $promotionChannelId = $request->input('promotion_channel_id');
- $actionType = $request->input('action_type');
- $trackingId = $request->input('tracking_id');
- $accountId = $request->input('account_id');
- $campaignId = $request->input('campaign_id');
- $campaignName = $request->input('campaign_name');
- $adId = $request->input('ad_id');
- $creativeId = $request->input('creative_id');
- $idfaWithDashMd5 = $request->input('idfa_withdash_md5');
- $macUpperWithColon = $request->input('mac_upper_withcolon');
- $macUpperWithColonMd5 = $request->input('mac_upper_withcolon_md5');
- $macUpperNoColonMd5 = $request->input('mac_upper_nocolon_md5');
- $timestampMs = $request->input('timestamp_ms');
- $ip = $request->input('ip');
- $callbackUrl = $request->input('callback_url');
- $csite = $request->input('csite');
- $idfaSha1 = $request->input('idfa_sha1');
- $imeiMd5 = $request->input('imei_md5');
- $androiDidMd5 = $request->input('androidid_md5');
- $oaid = $request->input('oaid');
- $oaidMd5 = $request->input('oaid_md5');
- $imeiSha1 = $request->input('imei_sha1');
- $androididSha1 = $request->input('androidid_sha1');
- $ua = $request->input('ua');
- $brand = $this->detectMobileBrand($ua);
- $osCode = $request->input('os_code');
- $kuaiShouPhotoId = $request->input('kuaishou_photo_id');
- $isActivateReport = 0;
- if($actionType == 'impression') {
- $actionType = 1;
- } elseif($actionType == 'click') {
- Log::logInfo('数据回调成功', [
- 'data' => $request->all()
- ], 'JuXingCallBack');
- $total = RedisModel::incr($clickTotalRds . $adId);
- RedisModel::expire($clickTotalRds . $adId, 86400 * 30);
- EmailQueue::rPush('聚星回调数据收到', $actionType . $total, ['xiaohua.hou@kuxuan-inc.com'], '猎羽');
- $actionType = 2;
- if($total % 2 != 0){ // 隔1传1
- if(!$brand) { // 非品牌机,查询上一个未上传的品牌机
- $callbackUrlUse = '';
- $clickUserWhichIsBrand = AdPlacementLog::select('callback_url', 'id')
- ->where('ad_id', $adId)->where('account_id', $accountId)
- ->where('action_type', 2)
- ->where('is_activate_report', 0)
- ->where('brand', '>', '')->orderBy('id', 'desc')
- ->first();
- Log::logInfo('非品牌机,查询上一个未上传的品牌机信息', [
- 'record' => $clickUserWhichIsBrand, 'ua' => $ua, 'total' => $total, 'account_id' => $accountId,
- 'ad_id' => $adId
- ], 'JuXingCallBack');
- if(!empty($clickUserWhichIsBrand)) {
- $callbackUrlUse = $clickUserWhichIsBrand->callback_url;
- AdPlacementLog::where('id', $clickUserWhichIsBrand->id)->update(['is_activate_report' => 1]);
- }
- } else {
- $callbackUrlUse = $callbackUrl;
- $isActivateReport = 1;
- }
- sleep(rand(3, 5));
- # 上传激活数据
- Log::logInfo('上传日志', [
- 'record' => $clickUserWhichIsBrand ?? $brand, 'ua' => $ua, 'total' => $total, 'account_id' => $accountId,
- 'ad_id' => $adId, 'url' => $callbackUrl, 'url_use' => $callbackUrlUse
- ], 'JuXingCallBack');
- $rst = HttpService::httpGet($callbackUrlUse . '&event_type=1&event_time=' . time() . rand(100, 999) );
- EmailQueue::rPush('聚星广告激活数据回传完成', $rst, ['xiaohua.hou@kuxuan-inc.com'], '猎羽');
- }
- } else {
- EmailQueue::rPush('聚星回调数据收到', $actionType, ['xiaohua.hou@kuxuan-inc.com'], '猎羽');
- $actionType = 0;
- }
- AdPlacementLog::insert(['promotion_channel_id' => $promotionChannelId, 'action_type' => $actionType, 'tracking_id' => $trackingId, 'campaign_id' => $campaignId, 'campaign_name' => $campaignName, 'ad_id' => $adId, 'creative_id' => $creativeId, 'idfa_withdash_md5' => $idfaWithDashMd5, 'mac_upper_withcolon' => $macUpperWithColon, 'mac_upper_withcolon_md5' => $macUpperWithColonMd5, 'mac_upper_nocolon_md5' => $macUpperNoColonMd5, 'timestamp_ms' => $timestampMs, 'ip' => $ip, 'callback_url' => $callbackUrl, 'csite' => $csite, 'idfa_sha1' => $idfaSha1, 'imei_md5' => $imeiMd5, 'androidid_md5' => $androiDidMd5, 'oaid' => $oaid, 'oaid_md5' => $oaidMd5, 'imei_sha1' => $imeiSha1, 'androidid_sha1' => $androididSha1, 'ua' => $ua, 'os_code' => $osCode, 'account_id' => $accountId, 'kuaishou_photo_id' => $kuaiShouPhotoId, 'is_activate_report' => $isActivateReport, 'brand' => $brand]);
- } catch (\Exception $e) {
- Log::logError('处理回调数据过程出现异常', ['line' => $e->getLine(), 'msg' => $e->getTraceAsString()], 'JuXingCallBack');
- EmailQueue::rPush('处理回调数据过程出现异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com'], '猎羽');
- }
- // // 获取企微信息
- // $corpid = $request->input('corpid');
- // $permanentCode = $request->input('permanent_code');
- // $url = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_auth_info?suite_access_token=';
- // $component = config('qyWechat.suite_info');
- // $suiteId = $component['app_template_id'];
- // $suiteSecret = $component['app_template_secret'];
- // $suiteAccessToken = TokenService::getAuthToken($suiteId, $suiteSecret);
- // $url .= $suiteAccessToken;
- // var_dump($suiteAccessToken);
- // $params = [
- // 'auth_corpid' => $corpid,
- // 'permanent_code' => $permanentCode
- // ];
- // $response = HttpService::httpPost($url, json_encode($params), true);
- // var_dump($response);
- // // 获取应用的接口许可状态
- // $corpid = $request->input('corpid');
- // $component = config('qyWechat.suite_info');
- // $suiteId = $component['app_template_id'];
- // $suiteCorpid = $component['server_corpid'];
- // $suiteSecret = $component['server_provider_secret'];
- // $response = QyCommon::getAppLicenseInfo($corpid, $suiteId, $suiteCorpid, $suiteSecret);
- // var_dump($response);
- // $name = $request->input('name');
- // $avatar = $request->input('avatar');
- // $createtime = $request->input('createtime');
- //
- // $result = CustomerService::updateCustomerFirstAddTime($name, $avatar, $createtime);
- # 创建知识库分组
- // $response = QyCommon::addGroup('', '短剧问答库');
- // var_dump($response);
- # 添加知识库问答
- // $groupId = 'asezvKNwAACl_AjlEz0VWvCpE-M6k-yw';
- // $question = $request->input('question');
- // $similarQuestionList = $request->input('similar_question_list');
- // if(!is_array($similarQuestionList)) $similarQuestionList = explode(',', $similarQuestionList);
- // $similarQuestions = [];
- // foreach ($similarQuestionList as $item) {
- // $similarQuestions['items'][] = [
- // 'text' => [
- // 'content' => $item
- // ]
- // ];
- // }
- //
- // $answers = $request->input('answers');
- //
- // $response = QyCommon::addIntent('', $groupId, $question, $similarQuestions, $answers);
- // var_dump($response);
- // $code = $request->input('code');
- // $corpid = 'wpezvKNwAA9d7LlcuOOAhvlx5ikwJjHg';
- // $accessToken = AccessTokenService::getAccessToken($corpid);
- // $url = 'https://qyapi.weixin.qq.com/cgi-bin/miniprogram/jscode2session?access_token='.$accessToken.'&js_code='.$code.'&grant_type=authorization_code';
- //
- // $response = HttpService::httpGet($url);
- //
- // return self::returnValue(json_decode($response, true));
- // $sysGroupId = $request->input('sys_group_id');
- // $adminId = $request->input('admin_id');
- // $isSystemAdmin = $request->input('is_system_admin');
- // # 获取可见的adq账号
- // $adqList = PitcherService::adqAccountListForUser($adminId, $sysGroupId, $isSystemAdmin);
- // # 获取可见的mp账号
- // $mpList = OfficialAccount::getAccountMpAppIdList($adminId, $sysGroupId, $isSystemAdmin);
- // var_dump($adqList);
- // var_dump($mpList);
- # 获取群活码配置信息
- // $corpid = $request->input('corpid');
- // $userId = $request->input('user_id');
- // $data = QyCommon::getUserActiveInfo($corpid, $userId, $this->suiteId, $this->suiteSecret);
- // var_dump($data);die;
- // # 获取群活码配置信息
- // $corpid = $request->input('corpid');
- // $configId = $request->input('config_id');
- // $qrcode = GroupChatJoinWayService::getChatGroupJoinWay($corpid, $configId);
- // var_dump($qrcode);
- # 生成二维码
- // $img = QrCode::size(200)->merge(public_path().'/qrcode.png',.3,true)->encoding('UTF-8')->generate('https://www.jb51.cc/laravel/2957806.html');
- // return $img;
- # 企微客服userId转openUserId
- // $corpid = $request->input('corpid');
- // $userId = $request->input('user_id');
- // $responseData = QyCommon::useridToOpenUserid($corpid, [$userId]);
- // var_dump($responseData);
- // # 获取累计充值人数
- // $accountData = array(['app_id' => 'wxc154cf1187af870c', 'start_date' => '2022-07-21', 'end_date' => '2022-07-21'], ['app_id' => 'wx303334360fe60305', 'start_date' => '2022-07-21', 'end_date' => '2022-07-21']);
- //
- // $data = DjOrderService::getChargeUserTotalUnique($accountData);
- //// # 获取累计充值人数
- //// $accountData = array(['app_id' => 'wxc154cf1187af870c', 'start_date' => '2022-07-21', 'end_date' => '2022-07-21'], ['app_id' => 'wx303334360fe60305', 'start_date' => '2022-07-21', 'end_date' => '2022-07-21']);
- ////
- //// $data = DjOrderService::getChargeUserTotalUnique($accountData);
- // var_dump($responseData);
- // $code = $request->input('code');
- // $corpid = $request->input('corpid');
- // # 根据code获取外部联系人ID
- // $responseData = QyCommon::getCustomerInfoByCode($corpid, $code);
- //
- // # 解析用户企微数据【1.企业成员 2.非企业成员】
- // $externalUserid = $responseData['external_userid'] ?? '';
- // $deviceId = $responseData['DeviceId'] ?? '';
- // $openid = $responseData['OpenId'] ?? '';
- // $userId = $responseData['UserId'] ?? '';
- // $errCode = $responseData['errcode'] ?? 9999;
- //
- // $queryParam = [
- // 'external_userid' => $externalUserid,
- // 'openid' => $openid,
- // 'user_id' => $userId
- // ];
- //
- // Log::logInfo('获取用户企微身份信息: ', [
- // 'corpid' => $corpid,
- // 'code' => $code,
- // 'response' => $responseData
- // ], 'Oauth2Authorize');
- //
- //
- // $appId = 'wxd16e96172ce05ddc';
- // $appSecret = 'fb9ac5755e38b7aebab28e4a5fd77a87';
- //
- // $urlLink = MiniProgramService::createLinkUrl($appId, $appSecret);
- // var_dump($urlLink);
- // # 检出scheme链接
- // $link = $urlLink['openlink'] ?? '';
- // return self::returnValue(['link' => $link]);
- // var_dump($urlLink);
- // $traceUri = RadarService::getTraceLink($radarId, $extra);
- // $corpid = 'wwc8d3e33f8e096671';
- // $search = array();
- // $page = 1;
- // $pageSize = 2;
- //
- // list($list, $count) = CustomerDetail::getUserInfo($corpid, $search, $page, $pageSize, 'createtime');
- // $requestUri = 'https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_groupmsg_list_v2?access_token=fzGvnmYVk-6Kk9G9Il_G2J6g-lhVDm6BWXDLXQUYXOP43Cxv5TTTCLgpGk-EuZ9WlzSlP3KGMj65TL08EJy7VJ0OgOJPIGZWEBxkFRBIZxngCs7SNbhBwnqHhZ5Krvzj8ae7xZ2nLQshws6GR8eKw_A0rdQLusY8Bh6uykZ0QHOEexpUxKhh4Dqt9CIfkthNEIN-uS_AbE_fzaItkdZMyQ';
- // $postData = [
- // 'chat_type' => 'single',
- // 'start_time' => 1646064000,
- // 'end_time' => 1648483200,
- // ];
- //
- // $response = HttpService::httpPost($requestUri, json_encode($postData));
- //
- // $requestUri = 'https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_groupmsg_task?access_token=fzGvnmYVk-6Kk9G9Il_G2J6g-lhVDm6BWXDLXQUYXOP43Cxv5TTTCLgpGk-EuZ9WlzSlP3KGMj65TL08EJy7VJ0OgOJPIGZWEBxkFRBIZxngCs7SNbhBwnqHhZ5Krvzj8ae7xZ2nLQshws6GR8eKw_A0rdQLusY8Bh6uykZ0QHOEexpUxKhh4Dqt9CIfkthNEIN-uS_AbE_fzaItkdZMyQ';
- //
- // $postData = [
- // 'msgid' => 'msgezvKNwAAVpvDezw13yHf9_7tFr1KPQ'
- // ];
- // $response = HttpService::httpPost($requestUri, json_encode($postData));
- // var_dump($response);
- // $corpid = 'wwc8d3e33f8e096671';
- // $corpid = $request->input('corpid');
- // $userid = 'bc85094e2cfd56a8bd6cd726bd98b14b';
- // $response = ContactService::getContactUserDetail($corpid, $userid);
- // $response = CorpAuthService::getOpenCorpid($corpid, $this->suiteId, $this->suiteSecret);
- // var_dump($response);
- # 测试外部联系人搜索
- // $corpid = 'wpezvKNwAAAjABjCEaYNHR0wBzn1YDqQ';
- // $search = [
- // 'gender' => 0,
- // 'add_time_end' => '1649646180',
- // 'add_time_start' => '1645646180',
- // 'tag_screen_type' => 1,
- // 'tag_list' => [33,34],
- // 'exclude_tag_list' => [1],
- // ];
- // $fields = 'external_userid, user_id';
- // $sort = [
- // 'createtime' => 'DESC',
- // ];
- // list($externalUserList, $total) = CustomerDetails::getUserInfo(
- // $corpid, $search, $fields, 1, 200, $sort, 'external_userid'
- // );
- // var_dump($externalUserList);
- // $corpid = $request->input('corpid');
- // $token = $request->input('token');
- // $externalUserid = $request->input('external_userid');
- // # 测试代开发应用external_userid转第三方平台external_userid
- // $requestUri = 'https://qyapi.weixin.qq.com/cgi-bin/externalcontact/to_service_external_userid?access_token=';
- // # 测试外部联系人openid转换
- //// $requestUri = 'https://qyapi.weixin.qq.com/cgi-bin/externalcontact/convert_to_openid?access_token=';
- // $requestUri .= AccessTokenService::getAccessToken($corpid);
- // var_dump($requestUri);
- //
- // $params = array('external_userid' => $externalUserid);
- // var_dump($params);
- // $response = HttpService::httpPost($requestUri, json_encode($params));
- // dd($response);
- // $responseData = ChatService::syncChatMsg($corpid, $token, 10);
- // dd($responseData);
- }
- /**
- * 获取雷达专属链接
- * */
- public function traceLink(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'radar_id' => 'required|int',
- 'corpid' => 'required|string',
- 'user_id' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $radarId = $request->input('radar_id');
- $params['rule_id'] = $request->input('rule_id');
- $params['corpid'] = $request->input('corpid');
- $params['user_id'] = $request->input('user_id');
- $params['channel'] = $request->input('channel');
- $params['state'] = $request->input('state', 'STATE');
- $errno = 0;
- $traceLink = RadarService::getTraceLink($radarId, $params, $errno);
- if($errno) return self::returnValue([], $errno);
- return self::returnValue($traceLink);
- }
- /**
- * 通过第三方主体unionid转换为第三方external_userid
- * */
- public function getExternalUserid(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'unionid' => 'required|string',
- 'openid' => 'required|string',
- 'corpid' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $openid = $request->input('openid');
- $unionid = $request->input('unionid');
- # 获取access_token
- $accessToken = AccessTokenService::getAccessToken($corpid, 'Openid+unionId转换external_userid');
- $requestUri = 'https://qyapi.weixin.qq.com/cgi-bin/externalcontact/unionid_to_external_userid?access_token='. $accessToken;
- $postData = [
- 'unionid' => $unionid,
- 'openid' => $openid
- ];
- $response = HttpService::httpPost($requestUri, json_encode($postData));
- var_dump($response);
- }
- }
|